Exemple #1
0
 def test_start_instance_success(self):
     bs = openstack.OpenStackLatentWorker('bot', 'pass', **self.bs_image_args)
     bs._poll_resolution = 0
     uuid, image_uuid, time_waiting = bs._start_instance()
     self.assertTrue(uuid)
     self.assertEqual(image_uuid, 'image-uuid')
     self.assertTrue(time_waiting)
Exemple #2
0
 def test_start_instance_fail_to_find(self):
     bs = openstack.OpenStackLatentWorker(
         'bot', 'pass', **self.bs_image_args)
     bs._poll_resolution = 0
     self.patch(novaclient.Servers, 'fail_to_get', True)
     self.assertRaises(interfaces.LatentWorkerFailedToSubstantiate,
                       bs._start_instance)
 def test_start_instance_fail_to_start(self):
     bs = openstack.OpenStackLatentWorker(
         'bot', 'pass', **self.bs_image_args)
     bs._poll_resolution = 0
     self.patch(novaclient.Servers, 'fail_to_start', True)
     yield self.assertFailure(bs.start_instance(self.build),
                              interfaces.LatentWorkerFailedToSubstantiate)
Exemple #4
0
 def test_stop_instance_missing(self):
     bs = openstack.OpenStackLatentWorker('bot', 'pass', **self.bs_image_args)
     instance = mock.Mock()
     instance.id = 'uuid'
     bs.instance = instance
     # TODO: Check log for instance not found.
     bs.stop_instance()
 def test_constructor_no_image(self):
     """
     Must have one of image or block_devices specified.
     """
     with self.assertRaises(ValueError):
         openstack.OpenStackLatentWorker('bot', 'pass', flavor=1,
                                         **self.os_auth)
 def test_start_instance_check_meta(self):
     meta_arg = {'some_key': 'some-value'}
     bs = openstack.OpenStackLatentWorker('bot', 'pass', meta=meta_arg,
                                          **self.bs_image_args)
     bs._poll_resolution = 0
     uuid, image_uuid, time_waiting = yield bs.start_instance(self.build)
     self.assertIn('meta', bs.instance.boot_kwargs)
     self.assertIdentical(bs.instance.boot_kwargs['meta'], meta_arg)
Exemple #7
0
 def test_stop_instance_not_set(self):
     """
     Test stopping the instance but with no instance to stop.
     """
     bs = openstack.OpenStackLatentWorker('bot', 'pass', **self.bs_image_args)
     bs.instance = None
     stopped = yield bs.stop_instance()
     self.assertEqual(stopped, None)
Exemple #8
0
 def setupWorker(self, *args, **kwargs):
     worker = openstack.OpenStackLatentWorker(*args, **kwargs)
     master = fakemaster.make_master(self, wantData=True)
     fakemaster.master = master
     worker.setServiceParent(master)
     yield master.startService()
     self.addCleanup(master.stopService)
     return worker
Exemple #9
0
 def test_getImage_renderable(self):
     bs = openstack.OpenStackLatentWorker(
         'bot',
         'pass',
         flavor=1,
         image=Interpolate('%(prop:image)s'),
         **self.os_auth)
     image_uuid = yield bs._getImage(self.build)
     self.assertEqual(novaclient.TEST_UUIDS['image'], image_uuid)
Exemple #10
0
    def test_getImage_callable(self):
        def image_callable(images):
            return images[0]

        bs = openstack.OpenStackLatentWorker('bot', 'pass', flavor=1,
                                             image=image_callable, **self.os_auth)
        os_client = novaclient.Client('1.1', 'user', 'pass', 'tenant', 'auth')
        os_client.images.images = ['uuid1', 'uuid2', 'uuid2']
        self.assertEqual('uuid1', bs._getImage(os_client, image_callable))
 def test_constructor_minimal(self):
     bs = openstack.OpenStackLatentWorker(
         'bot', 'pass', **self.bs_image_args)
     self.assertEqual(bs.workername, 'bot')
     self.assertEqual(bs.password, 'pass')
     self.assertEqual(bs.flavor, 1)
     self.assertEqual(bs.image, 'image-uuid')
     self.assertEqual(bs.block_devices, None)
     self.assertIsInstance(bs.novaclient, novaclient.Client)
Exemple #12
0
 def test_stop_instance_notfast(self):
     bs = openstack.OpenStackLatentWorker('bot', 'pass', **self.bs_image_args)
     # Make instance immediately active.
     self.patch(novaclient.Servers, 'gets_until_active', 0)
     s = novaclient.Servers()
     bs.instance = inst = s.create()
     self.assertIn(inst.id, s.instances)
     bs.stop_instance(fast=False)
     self.assertNotIn(inst.id, s.instances)
    def test_constructor_block_devices_missing(self):
        block_devices = [
            {'source_type': 'image', 'uuid': '9fb2e6e8-110d-4388-8c23-0fcbd1e2fcc1'},
        ]

        lw = openstack.OpenStackLatentWorker('bot', 'pass', flavor=1,
                                             block_devices=block_devices,
                                             **self.os_auth)
        yield self.assertFailure(lw.start_instance(self.build),
                                 novaclient.NotFound)
Exemple #14
0
 def test_constructor_minimal(self):
     bs = openstack.OpenStackLatentWorker('bot', 'pass', **self.bs_image_args)
     self.assertEqual(bs.workername, 'bot')
     self.assertEqual(bs.password, 'pass')
     self.assertEqual(bs.flavor, 1)
     self.assertEqual(bs.image, 'image-uuid')
     self.assertEqual(bs.block_devices, None)
     self.assertEqual(bs.os_username, 'user')
     self.assertEqual(bs.os_password, 'pass')
     self.assertEqual(bs.os_tenant_name, 'tenant')
     self.assertEqual(bs.os_auth_url, 'auth')
 def test_constructor_block_devices_default(self):
     block_devices = [{'uuid': 'uuid', 'volume_size': 10}]
     bs = openstack.OpenStackLatentWorker('bot', 'pass', flavor=1,
                                          block_devices=block_devices,
                                          **self.os_auth)
     self.assertEqual(bs.image, None)
     self.assertEqual(len(bs.block_devices), 1)
     self.assertEqual(bs.block_devices, [{'boot_index': 0,
                                          'delete_on_termination': True,
                                          'destination_type': 'volume', 'device_name': 'vda',
                                          'source_type': 'image', 'volume_size': 10, 'uuid': 'uuid'}])
Exemple #16
0
 def test_stop_instance_unknown(self):
     bs = openstack.OpenStackLatentWorker('bot', 'pass', **self.bs_image_args)
     # Make instance immediately active.
     self.patch(novaclient.Servers, 'gets_until_active', 0)
     s = novaclient.Servers()
     bs.instance = inst = s.create()
     # Set status to DELETED. Instance should not be deleted when shutting
     # down as it already is.
     inst.status = novaclient.DELETED
     self.assertIn(inst.id, s.instances)
     bs.stop_instance()
     self.assertIn(inst.id, s.instances)
 def test_constructor_minimal_keystone_v3(self):
     bs = openstack.OpenStackLatentWorker(
         'bot', 'pass', os_user_domain='test_oud', os_project_domain='test_opd',
         **self.bs_image_args)
     self.assertEqual(bs.workername, 'bot')
     self.assertEqual(bs.password, 'pass')
     self.assertEqual(bs.flavor, 1)
     self.assertEqual(bs.image, 'image-uuid')
     self.assertEqual(bs.block_devices, None)
     self.assertIsInstance(bs.novaclient, novaclient.Client)
     self.assertEqual(bs.novaclient.session.auth.user_domain_name, 'test_oud')
     self.assertEqual(bs.novaclient.session.auth.project_domain_name, 'test_opd')
    def test_getImage_callable(self):
        def image_callable(images):
            filtered = [i for i in images if i.id == 'uuid1']
            return filtered[0].id

        bs = openstack.OpenStackLatentWorker('bot', 'pass', flavor=1,
                                             image=image_callable, **self.os_auth)
        os_client = bs.novaclient
        os_client.images._add_items([
            novaclient.Image('uuid1', 'name1', 1),
            novaclient.Image('uuid2', 'name2', 1),
            novaclient.Image('uuid3', 'name3', 1),
            ])
        image_uuid = yield bs._getImage(self.build)
        self.assertEqual('uuid1', image_uuid)
    def test_constructor_block_devices_get_sizes(self):
        block_devices = [
            {'source_type': 'image', 'uuid': novaclient.TEST_UUIDS['image']},
            {'source_type': 'image', 'uuid': novaclient.TEST_UUIDS['image'], 'volume_size': 4},
            {'source_type': 'volume', 'uuid': novaclient.TEST_UUIDS['volume']},
            {'source_type': 'snapshot', 'uuid': novaclient.TEST_UUIDS['snapshot']},
        ]

        def check_volume_sizes(_images, block_devices):
            self.assertEqual(len(block_devices), 4)
            self.assertEqual(block_devices[0]['volume_size'], 1)
            self.assertIsInstance(block_devices[0]['volume_size'], int,
                                  "Volume size is an integer.")
            self.assertEqual(block_devices[1]['volume_size'], 4)
            self.assertEqual(block_devices[2]['volume_size'], 4)
            self.assertEqual(block_devices[3]['volume_size'], 2)

        lw = openstack.OpenStackLatentWorker('bot', 'pass', flavor=1,
                                             block_devices=block_devices,
                                             **self.os_auth)
        self.assertEqual(lw.image, None)
        self.assertEqual(lw.block_devices, [{'boot_index': 0,
                                             'delete_on_termination': True,
                                             'destination_type': 'volume', 'device_name': 'vda',
                                             'source_type': 'image', 'volume_size': None,
                                             'uuid': novaclient.TEST_UUIDS['image']},
                                            {'boot_index': 0,
                                             'delete_on_termination': True,
                                             'destination_type': 'volume', 'device_name': 'vda',
                                             'source_type': 'image', 'volume_size': 4,
                                             'uuid': novaclient.TEST_UUIDS['image']},
                                            {'boot_index': 0,
                                             'delete_on_termination': True,
                                             'destination_type': 'volume', 'device_name': 'vda',
                                             'source_type': 'volume', 'volume_size': None,
                                             'uuid': novaclient.TEST_UUIDS['volume']},
                                            {'boot_index': 0,
                                             'delete_on_termination': True,
                                             'destination_type': 'volume', 'device_name': 'vda',
                                             'source_type': 'snapshot', 'volume_size': None,
                                             'uuid': novaclient.TEST_UUIDS['snapshot']}])
        self.patch(lw, "_start_instance", check_volume_sizes)
        yield lw.start_instance(self.build)
Exemple #20
0
 def test_constructor_nokeystoneauth(self):
     self.patch(openstack, "loading", None)
     with self.assertRaises(config.ConfigErrors):
         openstack.OpenStackLatentWorker('bot', 'pass',
                                         **self.bs_image_args)
 def test_constructor_region(self):
     bs = openstack.OpenStackLatentWorker(
         'bot', 'pass', region="test-region", **self.bs_image_args)
     self.assertEqual(bs.novaclient.client.region_name, "test-region")
Exemple #22
0
 def test_getImage_string(self):
     bs = openstack.OpenStackLatentWorker(
         'bot', 'pass', **self.bs_image_args)
     self.assertEqual('image-uuid', bs._getImage(None, bs.image))
Exemple #23
0
 def test_start_instance_already_exists(self):
     bs = openstack.OpenStackLatentWorker(
         'bot', 'pass', **self.bs_image_args)
     bs.instance = mock.Mock()
     self.assertRaises(ValueError, bs.start_instance, None)
 def test_start_instance_already_exists(self):
     bs = openstack.OpenStackLatentWorker(
         'bot', 'pass', **self.bs_image_args)
     bs.instance = mock.Mock()
     yield self.assertFailure(bs.start_instance(self.build), ValueError)
 def test_getImage_string(self):
     bs = openstack.OpenStackLatentWorker(
         'bot', 'pass', **self.bs_image_args)
     image_uuid = yield bs._getImage(self.build)
     self.assertEqual('image-uuid', image_uuid)
Exemple #26
0
 def test_constructor_nonova(self):
     self.patch(openstack, "client", None)
     with self.assertRaises(config.ConfigErrors):
         openstack.OpenStackLatentWorker('bot', 'pass',
                                         **self.bs_image_args)