~ubuntu-branches/ubuntu/trusty/landscape-client/trusty-proposed

« back to all changes in this revision

Viewing changes to landscape/manager/tests/test_eucalyptus.py

  • Committer: Bazaar Package Importer
  • Author(s): Free Ekanayaka
  • Date: 2010-04-07 16:27:45 UTC
  • mfrom: (1.1.14 upstream) (24.1.1 karmic-proposed)
  • Revision ID: james.westby@ubuntu.com-20100407162745-oeyoppvl0qyvii55
Tags: 1.5.0-0ubuntu0.10.04.0
* New upstream version (LP: #557244)
  - Fix package-changer running before smart-update has completed (LP: #542215)
  - Report the version of Eucalyptus used to generate topology data (LP: #554007)
  - Enable the Eucalyptus plugin by default, if supported (LP: #546531)
  - Use a whitelist of allowed filesystem types to instead of a blacklist (LP: #351927)
  - Report the update-manager logs to the server (LP: #503384)
  - Turn off Curl's DNS caching for requests. (LP: #522688)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import os
 
2
 
1
3
from twisted.internet.defer import succeed, fail
2
4
 
3
5
try:
5
7
except ImportError:
6
8
    FakeEucaInfo = None
7
9
 
8
 
from landscape.manager.eucalyptus import EucalyptusCloudManager
 
10
from landscape.manager.eucalyptus import (
 
11
    Eucalyptus, EucalyptusInfo, start_service_hub, get_eucalyptus_info)
9
12
from landscape.tests.helpers import LandscapeTest, ManagerHelper
10
13
 
11
14
 
 
15
fake_version_output = """\
 
16
Eucalyptus version: 1.6.2
 
17
"""
 
18
 
12
19
fake_walrus_output = """\
13
20
registered walruses:
14
21
  walrus 10.0.1.113
35
42
 
36
43
 
37
44
class FakeEucalyptusInfo(object):
 
45
    """A fake version of L{EucalyptusInfo} for use in tests."""
38
46
 
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
45
55
 
 
56
    def get_version_info(self):
 
57
        return succeed(self._version_output)
 
58
 
46
59
    def get_walrus_info(self):
47
60
        return succeed(self._walrus_output)
48
61
 
69
82
        self.stopped += 1
70
83
 
71
84
 
72
 
class EucalyptusCloudManagerTest(LandscapeTest):
 
85
class EucalyptusTest(LandscapeTest):
73
86
 
74
87
    helpers = [ManagerHelper]
75
88
 
76
89
    def setUp(self):
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
83
96
 
84
97
    def get_plugin(self, result=None):
85
98
        self.service_hub = FakeServiceHub(result)
86
 
        plugin = EucalyptusCloudManager(
 
99
        plugin = Eucalyptus(
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)
92
106
        return plugin
93
107
 
94
108
    def test_plugin_registers_with_a_name(self):
95
109
        """
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.
98
112
        """
99
113
        plugin = self.get_plugin()
100
114
        self.assertIs(plugin, self.manager.get_plugin("eucalyptus-manager"))
101
115
 
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)
106
120
 
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,
146
161
                self.broker_service.message_store.get_pending_messages(),
147
162
                [])
148
163
 
149
 
        plugin = EucalyptusCloudManager(lambda x: 1/0, lambda x: 1/0)
 
164
        plugin = Eucalyptus(lambda x: 1/0, lambda x: 1/0)
150
165
        self.manager.add(plugin)
151
166
        deferred = plugin.run()
152
167
        deferred.addCallback(check)
210
225
        test_successful_run_stops_service_hub.skip = skip_message
211
226
 
212
227
 
213
 
class EucalyptusCloudManagerWithoutImageStoreTest(LandscapeTest):
 
228
class EucalyptusWithoutImageStoreTest(LandscapeTest):
214
229
 
215
230
    helpers = [ManagerHelper]
216
231
 
217
232
    def setUp(self):
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)
223
238
 
224
239
    def test_plugin_disabled_on_imagestore_import_fail(self):
225
240
        """
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
229
244
        example).
232
247
        self.log_helper.ignore_errors(ZeroDivisionError)
233
248
        self.plugin.run()
234
249
        self.assertFalse(self.plugin.enabled)
 
250
 
 
251
 
 
252
class StartServiceHubTest(LandscapeTest):
 
253
    """Tests for L{start_service_hub}."""
 
254
 
 
255
    def test_start_service_hub(self):
 
256
        """
 
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.
 
260
        """
 
261
        from twisted.internet import reactor
 
262
 
 
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()
 
268
 
 
269
        base_path = self.makeDir("start-service-hub")
 
270
        data_path = os.path.join(base_path, "eucalyptus")
 
271
 
 
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())
 
277
        self.mocker.replay()
 
278
 
 
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))
 
282
 
 
283
    def test_start_service_hub_with_existing_data_dir(self):
 
284
        """
 
285
        L{start_service_hub} creates and starts the L{ServiceHub} used to
 
286
        retrieve information about Eucalyptus. If the directory already
 
287
        exists it is used.
 
288
        """
 
289
        base_path = self.makeDir("start-service-hub")
 
290
        data_path = os.path.join(base_path, "eucalyptus")
 
291
        os.makedirs(data_path)
 
292
 
 
293
        from twisted.internet import reactor
 
294
 
 
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()
 
300
 
 
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())
 
306
        self.mocker.replay()
 
307
 
 
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))
 
311
 
 
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
 
316
 
 
317
 
 
318
class GetEucalyptusInfoTest(LandscapeTest):
 
319
    """Tests for L{get_eucalyptus_info}."""
 
320
 
 
321
    def test_wb_get_eucalyptus_info(self):
 
322
        """
 
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.
 
326
        """
 
327
        euca_tools_factory = self.mocker.replace(
 
328
            "imagestore.eucaservice.EucaTools", passthrough=False)
 
329
        euca_tools = object()
 
330
        credentials = object()
 
331
 
 
332
        self.expect(euca_tools_factory(credentials)).result(euca_tools)
 
333
        self.mocker.replay()
 
334
 
 
335
        info = get_eucalyptus_info(credentials)
 
336
        self.assertTrue(isinstance(info, EucalyptusInfo))
 
337
        self.assertIdentical(euca_tools, info._tools)
 
338
 
 
339
    if FakeEucaInfo is None:
 
340
        skip_message = "imagestore module not available"
 
341
        test_wb_get_eucalyptus_info.skip = skip_message