Exemplo n.º 1
0
    def test_create_instances_here_pops_problematic_properties(self, mock_update):
        values = {
            "uuid": uuidsentinel.instance,
            "metadata": [],
            "id": 1,
            "name": "foo",
            "info_cache": "bar",
            "security_groups": "not secure",
            "flavor": "chocolate",
            "pci_requests": "no thanks",
            "ec2_ids": "prime",
        }
        block_device_mapping = [
            objects.BlockDeviceMapping(
                context=self.ctxt,
                **fake_block_device.FakeDbBlockDeviceDict(
                    block_device.create_image_bdm(uuidsentinel.fake_image_ref), anon=True
                )
            )
        ]

        @mock.patch.object(self.scheduler.compute_api, "create_db_entry_for_new_instance")
        @mock.patch.object(self.scheduler.compute_api, "_bdm_validate_set_size_and_instance")
        def test(mock_bdm_validate, mock_create_db):
            self.scheduler._create_instances_here(
                self.ctxt, [uuidsentinel.instance], values, objects.Flavor(), "foo", [], block_device_mapping
            )

        test()

        # NOTE(danms): Make sure that only the expected properties
        # are applied to the instance object. The complex ones that
        # would have been mangled over RPC should be removed.
        mock_update.assert_called_once_with({"uuid": uuidsentinel.instance, "metadata": {}})
Exemplo n.º 2
0
    def test_create_instances_here(self):
        # Just grab the first instance type
        inst_type = objects.Flavor.get_by_id(self.ctxt, 1)
        image = {'properties': {}}
        instance_uuids = self.instance_uuids
        instance_props = {
            'id': 'removed',
            'security_groups': 'removed',
            'info_cache': 'removed',
            'name': 'instance-00000001',
            'hostname': 'meow',
            'display_name': 'moo',
            'image_ref': uuidsentinel.fake_image_ref,
            'user_id': self.ctxt.user_id,
            # Test these as lists
            'metadata': {
                'moo': 'cow'
            },
            'system_metadata': {
                'meow': 'cat'
            },
            'flavor': inst_type,
            'project_id': self.ctxt.project_id
        }

        call_info = {'uuids': []}
        block_device_mapping = objects.BlockDeviceMappingList(objects=[
            objects.BlockDeviceMapping(
                context=self.ctxt,
                **fake_block_device.FakeDbBlockDeviceDict(
                    block_device.create_image_bdm(uuidsentinel.fake_image_ref),
                    anon=True))
        ])

        def _fake_instance_update_at_top(self, _ctxt, instance):
            call_info['uuids'].append(instance['uuid'])

        self.stub_out(
            'nova.cells.messaging.MessageRunner.'
            'instance_update_at_top', _fake_instance_update_at_top)

        self.scheduler._create_instances_here(self.ctxt, instance_uuids,
                                              instance_props, inst_type, image,
                                              ['default'],
                                              block_device_mapping)
        self.assertEqual(instance_uuids, call_info['uuids'])

        for count, instance_uuid in enumerate(instance_uuids):
            bdms = db.block_device_mapping_get_all_by_instance(
                self.ctxt, instance_uuid)
            self.assertIsNotNone(bdms)
            instance = db.instance_get_by_uuid(self.ctxt, instance_uuid)
            meta = utils.instance_meta(instance)
            self.assertEqual('cow', meta['moo'])
            sys_meta = utils.instance_sys_meta(instance)
            self.assertEqual('cat', sys_meta['meow'])
            self.assertEqual('meow', instance['hostname'])
            self.assertEqual('moo-%d' % (count + 1), instance['display_name'])
            self.assertEqual(uuidsentinel.fake_image_ref,
                             instance['image_ref'])
Exemplo n.º 3
0
    def test_create_instances_here(self):
        # Just grab the first instance type
        inst_type = flavors.get_flavor(1)
        image = {'properties': {}}
        instance_uuids = self.instance_uuids
        instance_props = {
            'id': 'removed',
            'security_groups': 'removed',
            'info_cache': 'removed',
            'name': 'instance-00000001',
            'hostname': 'meow',
            'display_name': 'moo',
            'image_ref': 'fake_image_ref',
            'user_id': self.ctxt.user_id,
            # Test these as lists
            'metadata': {
                'moo': 'cow'
            },
            'system_metadata': {
                'meow': 'cat'
            },
            'flavor': inst_type,
            'project_id': self.ctxt.project_id
        }

        call_info = {'uuids': []}
        block_device_mapping = [
            objects.BlockDeviceMapping(
                context=self.ctxt,
                **fake_block_device.FakeDbBlockDeviceDict(
                    block_device.create_image_bdm('fake_image_ref'),
                    anon=True))
        ]

        def _fake_instance_update_at_top(_ctxt, instance):
            call_info['uuids'].append(instance['uuid'])

        self.stubs.Set(self.msg_runner, 'instance_update_at_top',
                       _fake_instance_update_at_top)

        self.scheduler._create_instances_here(self.ctxt, instance_uuids,
                                              instance_props, inst_type, image,
                                              ['default'],
                                              block_device_mapping)
        self.assertEqual(instance_uuids, call_info['uuids'])

        for count, instance_uuid in enumerate(instance_uuids):
            instance = db.instance_get_by_uuid(self.ctxt, instance_uuid)
            meta = utils.instance_meta(instance)
            self.assertEqual('cow', meta['moo'])
            sys_meta = utils.instance_sys_meta(instance)
            self.assertEqual('cat', sys_meta['meow'])
            self.assertEqual('meow', instance['hostname'])
            self.assertEqual('moo-%d' % (count + 1), instance['display_name'])
            self.assertEqual('fake_image_ref', instance['image_ref'])
Exemplo n.º 4
0
    def test_create_instances_here(self):
        # Just grab the first instance type
        inst_type = objects.Flavor.get_by_id(self.ctxt, 1)
        image = {'properties': {}}
        instance_uuids = self.instance_uuids
        instance_props = {'id': 'removed',
                          'security_groups': 'removed',
                          'info_cache': 'removed',
                          'name': 'instance-00000001',
                          'hostname': 'meow',
                          'display_name': 'moo',
                          'image_ref': uuidsentinel.fake_image_ref,
                          'user_id': self.ctxt.user_id,
                          # Test these as lists
                          'metadata': {'moo': 'cow'},
                          'system_metadata': {'meow': 'cat'},
                          'flavor': inst_type,
                          'project_id': self.ctxt.project_id}

        call_info = {'uuids': []}
        block_device_mapping = objects.BlockDeviceMappingList(
            objects=[
                objects.BlockDeviceMapping(context=self.ctxt,
                    **fake_block_device.FakeDbBlockDeviceDict(
                            block_device.create_image_bdm(
                                uuidsentinel.fake_image_ref),
                        anon=True))
               ])

        def _fake_instance_update_at_top(self, _ctxt, instance):
            call_info['uuids'].append(instance['uuid'])

        self.stub_out('nova.cells.messaging.MessageRunner.'
                      'instance_update_at_top',
                      _fake_instance_update_at_top)

        self.scheduler._create_instances_here(self.ctxt, instance_uuids,
                instance_props, inst_type, image,
                ['default'], block_device_mapping)
        self.assertEqual(instance_uuids, call_info['uuids'])

        for count, instance_uuid in enumerate(instance_uuids):
            bdms = db.block_device_mapping_get_all_by_instance(self.ctxt,
                                                               instance_uuid)
            self.assertIsNotNone(bdms)
            instance = db.instance_get_by_uuid(self.ctxt, instance_uuid)
            meta = utils.instance_meta(instance)
            self.assertEqual('cow', meta['moo'])
            sys_meta = utils.instance_sys_meta(instance)
            self.assertEqual('cat', sys_meta['meow'])
            self.assertEqual('meow', instance['hostname'])
            self.assertEqual('moo-%d' % (count + 1),
                             instance['display_name'])
            self.assertEqual(uuidsentinel.fake_image_ref,
                             instance['image_ref'])
Exemplo n.º 5
0
    def test_create_instances_here(self):
        # Just grab the first instance type
        inst_type = objects.Flavor.get_by_id(self.ctxt, 1)
        image = {"properties": {}}
        instance_uuids = self.instance_uuids
        instance_props = {
            "id": "removed",
            "security_groups": "removed",
            "info_cache": "removed",
            "name": "instance-00000001",
            "hostname": "meow",
            "display_name": "moo",
            "image_ref": uuidsentinel.fake_image_ref,
            "user_id": self.ctxt.user_id,
            # Test these as lists
            "metadata": {"moo": "cow"},
            "system_metadata": {"meow": "cat"},
            "flavor": inst_type,
            "project_id": self.ctxt.project_id,
        }

        call_info = {"uuids": []}
        block_device_mapping = objects.BlockDeviceMappingList(
            objects=[
                objects.BlockDeviceMapping(
                    context=self.ctxt,
                    **fake_block_device.FakeDbBlockDeviceDict(
                        block_device.create_image_bdm(uuidsentinel.fake_image_ref), anon=True
                    )
                )
            ]
        )

        def _fake_instance_update_at_top(_ctxt, instance):
            call_info["uuids"].append(instance["uuid"])

        self.stubs.Set(self.msg_runner, "instance_update_at_top", _fake_instance_update_at_top)

        self.scheduler._create_instances_here(
            self.ctxt, instance_uuids, instance_props, inst_type, image, ["default"], block_device_mapping
        )
        self.assertEqual(instance_uuids, call_info["uuids"])

        for count, instance_uuid in enumerate(instance_uuids):
            bdms = db.block_device_mapping_get_all_by_instance(self.ctxt, instance_uuid)
            self.assertIsNotNone(bdms)
            instance = db.instance_get_by_uuid(self.ctxt, instance_uuid)
            meta = utils.instance_meta(instance)
            self.assertEqual("cow", meta["moo"])
            sys_meta = utils.instance_sys_meta(instance)
            self.assertEqual("cat", sys_meta["meow"])
            self.assertEqual("meow", instance["hostname"])
            self.assertEqual("moo-%d" % (count + 1), instance["display_name"])
            self.assertEqual(uuidsentinel.fake_image_ref, instance["image_ref"])
    def test_create_instances_here(self):
        # Just grab the first instance type
        inst_type = db.flavor_get(self.ctxt, 1)
        image = {'properties': {}}
        instance_uuids = self.instance_uuids
        instance_props = {
            'id': 'removed',
            'security_groups': 'removed',
            'info_cache': 'removed',
            'name': 'instance-00000001',
            'hostname': 'meow',
            'display_name': 'moo',
            'image_ref': 'fake_image_ref',
            'user_id': self.ctxt.user_id,
            # Test these as lists
            'metadata': [{
                'key': 'moo',
                'value': 'cow'
            }],
            'system_metadata': [{
                'key': 'meow',
                'value': 'cat'
            }],
            'project_id': self.ctxt.project_id
        }

        call_info = {'uuids': []}
        block_device_mapping = [
            block_device.create_image_bdm('fake_image_ref')
        ]

        def _fake_instance_update_at_top(_ctxt, instance):
            call_info['uuids'].append(instance['uuid'])

        self.stubs.Set(self.msg_runner, 'instance_update_at_top',
                       _fake_instance_update_at_top)

        self.scheduler._create_instances_here(self.ctxt, instance_uuids,
                                              instance_props, inst_type, image,
                                              ['default'],
                                              block_device_mapping)
        self.assertEqual(instance_uuids, call_info['uuids'])

        for instance_uuid in instance_uuids:
            instance = db.instance_get_by_uuid(self.ctxt, instance_uuid)
            meta = utils.instance_meta(instance)
            self.assertEqual('cow', meta['moo'])
            sys_meta = utils.instance_sys_meta(instance)
            self.assertEqual('cat', sys_meta['meow'])
            self.assertEqual('meow', instance['hostname'])
            self.assertEqual('moo-%s' % instance['uuid'],
                             instance['display_name'])
            self.assertEqual('fake_image_ref', instance['image_ref'])
Exemplo n.º 7
0
    def test_create_instances_here(self):
        # Just grab the first instance type
        inst_type = flavors.get_flavor(1)
        image = {'properties': {}}
        instance_uuids = self.instance_uuids
        instance_props = {'id': 'removed',
                          'security_groups': 'removed',
                          'info_cache': 'removed',
                          'name': 'instance-00000001',
                          'hostname': 'meow',
                          'display_name': 'moo',
                          'image_ref': 'fake_image_ref',
                          'user_id': self.ctxt.user_id,
                          # Test these as lists
                          'metadata': {'moo': 'cow'},
                          'system_metadata': {'meow': 'cat'},
                          'flavor': inst_type,
                          'project_id': self.ctxt.project_id}

        call_info = {'uuids': []}
        block_device_mapping = [
                objects.BlockDeviceMapping(context=self.ctxt,
                    **fake_block_device.FakeDbBlockDeviceDict(
                            block_device.create_image_bdm('fake_image_ref'),
                            anon=True))
               ]

        def _fake_instance_update_at_top(_ctxt, instance):
            call_info['uuids'].append(instance['uuid'])

        self.stubs.Set(self.msg_runner, 'instance_update_at_top',
                       _fake_instance_update_at_top)

        self.scheduler._create_instances_here(self.ctxt, instance_uuids,
                instance_props, inst_type, image,
                ['default'], block_device_mapping)
        self.assertEqual(instance_uuids, call_info['uuids'])

        for count, instance_uuid in enumerate(instance_uuids):
            instance = db.instance_get_by_uuid(self.ctxt, instance_uuid)
            meta = utils.instance_meta(instance)
            self.assertEqual('cow', meta['moo'])
            sys_meta = utils.instance_sys_meta(instance)
            self.assertEqual('cat', sys_meta['meow'])
            self.assertEqual('meow', instance['hostname'])
            self.assertEqual('moo-%d' % (count + 1),
                             instance['display_name'])
            self.assertEqual('fake_image_ref', instance['image_ref'])
Exemplo n.º 8
0
    def test_create_instances_here(self):
        # Just grab the first instance type
        inst_type = db.flavor_get(self.ctxt, 1)
        image = {'properties': {}}
        instance_uuids = self.instance_uuids
        instance_props = {'id': 'removed',
                          'security_groups': 'removed',
                          'info_cache': 'removed',
                          'name': 'instance-00000001',
                          'hostname': 'meow',
                          'display_name': 'moo',
                          'image_ref': 'fake_image_ref',
                          'user_id': self.ctxt.user_id,
                          # Test these as lists
                          'metadata': [{'key': 'moo', 'value': 'cow'}],
                          'system_metadata': [{'key': 'meow', 'value': 'cat'}],
                          'project_id': self.ctxt.project_id}

        call_info = {'uuids': []}
        block_device_mapping = [block_device.create_image_bdm(
            'fake_image_ref')]

        def _fake_instance_update_at_top(_ctxt, instance):
            call_info['uuids'].append(instance['uuid'])

        self.stubs.Set(self.msg_runner, 'instance_update_at_top',
                       _fake_instance_update_at_top)

        self.scheduler._create_instances_here(self.ctxt, instance_uuids,
                instance_props, inst_type, image,
                ['default'], block_device_mapping)
        self.assertEqual(instance_uuids, call_info['uuids'])

        for instance_uuid in instance_uuids:
            instance = db.instance_get_by_uuid(self.ctxt, instance_uuid)
            meta = utils.instance_meta(instance)
            self.assertEqual('cow', meta['moo'])
            sys_meta = utils.instance_sys_meta(instance)
            self.assertEqual('cat', sys_meta['meow'])
            self.assertEqual('meow', instance['hostname'])
            self.assertEqual('moo-%s' % instance['uuid'],
                             instance['display_name'])
            self.assertEqual('fake_image_ref', instance['image_ref'])
    def test_create_instances_here(self):
        # Just grab the first instance type
        inst_type = flavors.get_flavor(1)
        image = {"properties": {}}
        instance_uuids = self.instance_uuids
        instance_props = {
            "id": "removed",
            "security_groups": "removed",
            "info_cache": "removed",
            "name": "instance-00000001",
            "hostname": "meow",
            "display_name": "moo",
            "image_ref": "fake_image_ref",
            "user_id": self.ctxt.user_id,
            # Test these as lists
            "metadata": {"moo": "cow"},
            "system_metadata": {"meow": "cat"},
            "flavor": inst_type,
            "project_id": self.ctxt.project_id,
        }

        call_info = {"uuids": []}
        block_device_mapping = [block_device.create_image_bdm("fake_image_ref")]

        def _fake_instance_update_at_top(_ctxt, instance):
            call_info["uuids"].append(instance["uuid"])

        self.stubs.Set(self.msg_runner, "instance_update_at_top", _fake_instance_update_at_top)

        self.scheduler._create_instances_here(
            self.ctxt, instance_uuids, instance_props, inst_type, image, ["default"], block_device_mapping
        )
        self.assertEqual(instance_uuids, call_info["uuids"])

        for count, instance_uuid in enumerate(instance_uuids):
            instance = db.instance_get_by_uuid(self.ctxt, instance_uuid)
            meta = utils.instance_meta(instance)
            self.assertEqual("cow", meta["moo"])
            sys_meta = utils.instance_sys_meta(instance)
            self.assertEqual("cat", sys_meta["meow"])
            self.assertEqual("meow", instance["hostname"])
            self.assertEqual("moo-%d" % (count + 1), instance["display_name"])
            self.assertEqual("fake_image_ref", instance["image_ref"])
Exemplo n.º 10
0
    def test_create_instances_here_pops_problematic_properties(
            self, mock_update):
        values = {
            'uuid': uuidsentinel.instance,
            'metadata': [],
            'id': 1,
            'name': 'foo',
            'info_cache': 'bar',
            'security_groups': 'not secure',
            'flavor': 'chocolate',
            'pci_requests': 'no thanks',
            'ec2_ids': 'prime',
        }
        block_device_mapping = [
            objects.BlockDeviceMapping(
                context=self.ctxt,
                **fake_block_device.FakeDbBlockDeviceDict(
                    block_device.create_image_bdm(uuidsentinel.fake_image_ref),
                    anon=True))
        ]

        @mock.patch.object(self.scheduler.compute_api,
                           'create_db_entry_for_new_instance')
        @mock.patch.object(self.scheduler.compute_api,
                           '_bdm_validate_set_size_and_instance')
        def test(mock_bdm_validate, mock_create_db):
            self.scheduler._create_instances_here(self.ctxt,
                                                  [uuidsentinel.instance],
                                                  values, objects.Flavor(),
                                                  'foo', [],
                                                  block_device_mapping)

        test()

        # NOTE(danms): Make sure that only the expected properties
        # are applied to the instance object. The complex ones that
        # would have been mangled over RPC should be removed.
        mock_update.assert_called_once_with({
            'uuid': uuidsentinel.instance,
            'metadata': {}
        })
Exemplo n.º 11
0
    def test_create_instances_here_pops_problematic_properties(self,
                                                               mock_update):
        values = {
            'uuid': uuidsentinel.instance,
            'metadata': [],
            'id': 1,
            'name': 'foo',
            'info_cache': 'bar',
            'security_groups': 'not secure',
            'flavor': 'chocolate',
            'pci_requests': 'no thanks',
            'ec2_ids': 'prime',
        }
        block_device_mapping = [
                objects.BlockDeviceMapping(context=self.ctxt,
                    **fake_block_device.FakeDbBlockDeviceDict(
                            block_device.create_image_bdm(
                                uuidsentinel.fake_image_ref),
                            anon=True))
               ]

        @mock.patch.object(self.scheduler.compute_api,
                           'create_db_entry_for_new_instance')
        @mock.patch.object(self.scheduler.compute_api,
                           '_bdm_validate_set_size_and_instance')
        def test(mock_bdm_validate, mock_create_db):
            self.scheduler._create_instances_here(
                self.ctxt, [uuidsentinel.instance], values,
                objects.Flavor(), 'foo', [], block_device_mapping)

        test()

        # NOTE(danms): Make sure that only the expected properties
        # are applied to the instance object. The complex ones that
        # would have been mangled over RPC should be removed.
        mock_update.assert_called_once_with(
            {'uuid': uuidsentinel.instance,
             'metadata': {}})