37
44
class FakeEucalyptusInfo(object):
45
"""A fake version of L{EucalyptusInfo} for use in tests."""
39
def __init__(self, walrus_output=None, cluster_controller_output=None,
47
def __init__(self, version_output=None, walrus_output=None,
48
cluster_controller_output=None,
40
49
storage_controller_output=None, node_controller_output=None):
50
self._version_output = version_output
41
51
self._walrus_output = walrus_output
42
52
self._cluster_controller_output = cluster_controller_output
43
53
self._storage_controller_output = storage_controller_output
44
54
self._node_controller_output = node_controller_output
56
def get_version_info(self):
57
return succeed(self._version_output)
46
59
def get_walrus_info(self):
47
60
return succeed(self._walrus_output)
72
class EucalyptusCloudManagerTest(LandscapeTest):
85
class EucalyptusTest(LandscapeTest):
74
87
helpers = [ManagerHelper]
77
super(EucalyptusCloudManagerTest, self).setUp()
78
message_type = EucalyptusCloudManager.message_type
79
error_message_type = EucalyptusCloudManager.error_message_type
90
super(EucalyptusTest, self).setUp()
91
message_type = Eucalyptus.message_type
92
error_message_type = Eucalyptus.error_message_type
80
93
self.broker_service.message_store.set_accepted_types(
81
94
[message_type, error_message_type])
82
95
self.service_hub = None
84
97
def get_plugin(self, result=None):
85
98
self.service_hub = FakeServiceHub(result)
86
plugin = EucalyptusCloudManager(
87
100
service_hub_factory=lambda data_path: self.service_hub,
88
101
eucalyptus_info_factory=lambda tools: FakeEucalyptusInfo(
89
fake_walrus_output, fake_cluster_controller_output,
90
fake_storage_controller_output, fake_node_controller_output))
102
fake_version_output, fake_walrus_output,
103
fake_cluster_controller_output, fake_storage_controller_output,
104
fake_node_controller_output))
91
105
self.manager.add(plugin)
94
108
def test_plugin_registers_with_a_name(self):
96
L{EucalyptusCloudManager} provides a C{plugin_name}, which is used
110
L{Eucalyptus} provides a C{plugin_name}, which is used
97
111
when the plugin is registered with the manager plugin registry.
99
113
plugin = self.get_plugin()
100
114
self.assertIs(plugin, self.manager.get_plugin("eucalyptus-manager"))
102
116
def test_run_interval(self):
103
"""The L{EucalyptusCloudManager} plugin is run every 15 minutes."""
117
"""The L{Eucalyptus} plugin is run every 15 minutes."""
104
118
plugin = self.get_plugin()
105
119
self.assertEqual(900, plugin.run_interval)
120
134
"private_key_path": "/fake/path",
121
135
"secret_key": None,
122
136
"url_for_ec2": "http://fake/url",
123
"url_for_s3": "http://fake/url"},
137
"url_for_s3": "http://fake/url",
138
"eucalyptus_version": "1.6.2"},
124
139
"cluster_controller_info": fake_cluster_controller_output,
125
140
"node_controller_info": fake_node_controller_output,
126
141
"storage_controller_info": fake_storage_controller_output,
210
225
test_successful_run_stops_service_hub.skip = skip_message
213
class EucalyptusCloudManagerWithoutImageStoreTest(LandscapeTest):
228
class EucalyptusWithoutImageStoreTest(LandscapeTest):
215
230
helpers = [ManagerHelper]
218
super(EucalyptusCloudManagerWithoutImageStoreTest, self).setUp()
219
message_type = EucalyptusCloudManager.message_type
233
super(EucalyptusWithoutImageStoreTest, self).setUp()
234
message_type = Eucalyptus.message_type
220
235
self.broker_service.message_store.set_accepted_types([message_type])
221
self.plugin = EucalyptusCloudManager(service_hub_factory=lambda x: 1/0)
236
self.plugin = Eucalyptus(service_hub_factory=lambda x: 1/0)
222
237
self.manager.add(self.plugin)
224
239
def test_plugin_disabled_on_imagestore_import_fail(self):
226
When L{EucalyptusCloudManager.run} is called it tries to import code
241
When L{Eucalyptus.run} is called it tries to import code
227
242
from the C{imagestore} package. The plugin disables itself if an
228
243
exception is raised during this process (such as C{ImportError}, for
232
247
self.log_helper.ignore_errors(ZeroDivisionError)
233
248
self.plugin.run()
234
249
self.assertFalse(self.plugin.enabled)
252
class StartServiceHubTest(LandscapeTest):
253
"""Tests for L{start_service_hub}."""
255
def test_start_service_hub(self):
257
L{start_service_hub} creates and starts the L{ServiceHub} used to
258
retrieve information about Eucalyptus. The data directory is created
259
if it doesn't already exist.
261
from twisted.internet import reactor
263
euca_service_factory = self.mocker.replace(
264
"imagestore.eucaservice.EucaService", passthrough=False)
265
service_hub_factory = self.mocker.replace(
266
"imagestore.lib.service.ServiceHub", passthrough=False)
267
euca_service = object()
269
base_path = self.makeDir("start-service-hub")
270
data_path = os.path.join(base_path, "eucalyptus")
272
euca_service_factory(reactor, data_path)
273
self.mocker.result(euca_service)
274
service_hub = service_hub_factory()
275
self.expect(service_hub.addService(euca_service))
276
self.expect(service_hub.start())
279
self.assertFalse(os.path.exists(data_path))
280
self.assertNotIdentical(None, start_service_hub(base_path))
281
self.assertTrue(os.path.exists(data_path))
283
def test_start_service_hub_with_existing_data_dir(self):
285
L{start_service_hub} creates and starts the L{ServiceHub} used to
286
retrieve information about Eucalyptus. If the directory already
289
base_path = self.makeDir("start-service-hub")
290
data_path = os.path.join(base_path, "eucalyptus")
291
os.makedirs(data_path)
293
from twisted.internet import reactor
295
euca_service_factory = self.mocker.replace(
296
"imagestore.eucaservice.EucaService", passthrough=False)
297
service_hub_factory = self.mocker.replace(
298
"imagestore.lib.service.ServiceHub", passthrough=False)
299
euca_service = object()
301
euca_service_factory(reactor, data_path)
302
self.mocker.result(euca_service)
303
service_hub = service_hub_factory()
304
self.expect(service_hub.addService(euca_service))
305
self.expect(service_hub.start())
308
self.assertTrue(os.path.exists(data_path))
309
self.assertNotIdentical(None, start_service_hub(base_path))
310
self.assertTrue(os.path.exists(data_path))
312
if FakeEucaInfo is None:
313
skip_message = "imagestore module not available"
314
test_start_service_hub.skip = skip_message
315
test_start_service_hub_with_existing_data_dir.skip = skip_message
318
class GetEucalyptusInfoTest(LandscapeTest):
319
"""Tests for L{get_eucalyptus_info}."""
321
def test_wb_get_eucalyptus_info(self):
323
L{get_eucalyptus_info} returns a L{EucalyptusInfo} instance.
324
L{EucalyptusInfo} is passed, and stores, a C{EucaTools} instance which
325
is used to retrieved information about Eucalyptus.
327
euca_tools_factory = self.mocker.replace(
328
"imagestore.eucaservice.EucaTools", passthrough=False)
329
euca_tools = object()
330
credentials = object()
332
self.expect(euca_tools_factory(credentials)).result(euca_tools)
335
info = get_eucalyptus_info(credentials)
336
self.assertTrue(isinstance(info, EucalyptusInfo))
337
self.assertIdentical(euca_tools, info._tools)
339
if FakeEucaInfo is None:
340
skip_message = "imagestore module not available"
341
test_wb_get_eucalyptus_info.skip = skip_message