From b1d9c3edd87fb9e547c5e374d836b673989747a7 Mon Sep 17 00:00:00 2001 From: srushti Date: Tue, 5 Apr 2016 13:27:43 +0000 Subject: [PATCH] Fix invalid uuid warnings Currently, unit testcases emit FutureWarnings from oslo.versionedobjects about invalid uuids as documented here[1]. This commit changes these tests to use valid uuids so that when they are run these warnings are no longer emitted. [1] http://docs.openstack.org/developer/oslo.versionedobjects/api/fields.html#oslo_versionedobjects.fields.UUIDField Closes-Bug: #1557378 Change-Id: I21a60e916e183f7c0fc6193d4b7caa88ae3b6d56 --- .../filters/test_affinity_filters.py | 17 +-- .../filters/test_isolated_hosts_filter.py | 7 +- .../scheduler/filters/test_type_filters.py | 7 +- .../unit/scheduler/filters/test_utils.py | 10 +- .../unit/scheduler/test_filter_scheduler.py | 15 ++- nova/tests/unit/scheduler/test_filters.py | 7 +- .../tests/unit/scheduler/test_host_manager.py | 122 ++++++++++-------- .../scheduler/test_ironic_host_manager.py | 25 ++-- .../unit/scheduler/test_scheduler_utils.py | 21 +-- nova/tests/unit/test_block_device.py | 51 ++++---- nova/tests/unit/test_metadata.py | 7 +- nova/tests/unit/test_notifications.py | 3 +- 12 files changed, 163 insertions(+), 129 deletions(-) diff --git a/nova/tests/unit/scheduler/filters/test_affinity_filters.py b/nova/tests/unit/scheduler/filters/test_affinity_filters.py index fcf8f5ccafc4..6cf7dadbae79 100644 --- a/nova/tests/unit/scheduler/filters/test_affinity_filters.py +++ b/nova/tests/unit/scheduler/filters/test_affinity_filters.py @@ -17,6 +17,7 @@ from nova import objects from nova.scheduler.filters import affinity_filter from nova import test from nova.tests.unit.scheduler import fakes +from nova.tests import uuidsentinel as uuids CONF = nova.conf.CONF @@ -29,7 +30,7 @@ class TestDifferentHostFilter(test.NoDBTestCase): def test_affinity_different_filter_passes(self): host = fakes.FakeHostState('host1', 'node1', {}) - inst1 = objects.Instance(uuid='different') + inst1 = objects.Instance(uuid=uuids.instance) host.instances = {inst1.uuid: inst1} spec_obj = objects.RequestSpec( context=mock.sentinel.ctx, @@ -37,16 +38,16 @@ class TestDifferentHostFilter(test.NoDBTestCase): self.assertTrue(self.filt_cls.host_passes(host, spec_obj)) def test_affinity_different_filter_fails(self): - inst1 = objects.Instance(uuid='same') + inst1 = objects.Instance(uuid=uuids.instance) host = fakes.FakeHostState('host1', 'node1', {}) host.instances = {inst1.uuid: inst1} spec_obj = objects.RequestSpec( context=mock.sentinel.ctx, - scheduler_hints=dict(different_host=['same'])) + scheduler_hints=dict(different_host=[uuids.instance])) self.assertFalse(self.filt_cls.host_passes(host, spec_obj)) def test_affinity_different_filter_handles_none(self): - inst1 = objects.Instance(uuid='same') + inst1 = objects.Instance(uuid=uuids.instance) host = fakes.FakeHostState('host1', 'node1', {}) host.instances = {inst1.uuid: inst1} spec_obj = objects.RequestSpec( @@ -62,12 +63,12 @@ class TestSameHostFilter(test.NoDBTestCase): self.filt_cls = affinity_filter.SameHostFilter() def test_affinity_same_filter_passes(self): - inst1 = objects.Instance(uuid='same') + inst1 = objects.Instance(uuid=uuids.instance) host = fakes.FakeHostState('host1', 'node1', {}) host.instances = {inst1.uuid: inst1} spec_obj = objects.RequestSpec( context=mock.sentinel.ctx, - scheduler_hints=dict(same_host=['same'])) + scheduler_hints=dict(same_host=[uuids.instance])) self.assertTrue(self.filt_cls.host_passes(host, spec_obj)) def test_affinity_same_filter_no_list_passes(self): @@ -79,7 +80,7 @@ class TestSameHostFilter(test.NoDBTestCase): self.assertFalse(self.filt_cls.host_passes(host, spec_obj)) def test_affinity_same_filter_fails(self): - inst1 = objects.Instance(uuid='different') + inst1 = objects.Instance(uuid=uuids.instance) host = fakes.FakeHostState('host1', 'node1', {}) host.instances = {inst1.uuid: inst1} spec_obj = objects.RequestSpec( @@ -88,7 +89,7 @@ class TestSameHostFilter(test.NoDBTestCase): self.assertFalse(self.filt_cls.host_passes(host, spec_obj)) def test_affinity_same_filter_handles_none(self): - inst1 = objects.Instance(uuid='different') + inst1 = objects.Instance(uuid=uuids.instance) host = fakes.FakeHostState('host1', 'node1', {}) host.instances = {inst1.uuid: inst1} spec_obj = objects.RequestSpec( diff --git a/nova/tests/unit/scheduler/filters/test_isolated_hosts_filter.py b/nova/tests/unit/scheduler/filters/test_isolated_hosts_filter.py index 97e6ef9c10ec..07cfd324ec16 100644 --- a/nova/tests/unit/scheduler/filters/test_isolated_hosts_filter.py +++ b/nova/tests/unit/scheduler/filters/test_isolated_hosts_filter.py @@ -14,6 +14,7 @@ from nova import objects from nova.scheduler.filters import isolated_hosts_filter from nova import test from nova.tests.unit.scheduler import fakes +from nova.tests import uuidsentinel as uuids class TestIsolatedHostsFilter(test.NoDBTestCase): @@ -26,12 +27,12 @@ class TestIsolatedHostsFilter(test.NoDBTestCase): set_flags=True, restrict_isolated_hosts_to_isolated_images=True): if set_flags: - self.flags(isolated_images=['isolated_image'], + self.flags(isolated_images=[uuids.image_ref], isolated_hosts=['isolated_host'], restrict_isolated_hosts_to_isolated_images= restrict_isolated_hosts_to_isolated_images) host_name = 'isolated_host' if host_in_list else 'free_host' - image_ref = 'isolated_image' if image_in_list else 'free_image' + image_ref = uuids.image_ref if image_in_list else uuids.fake_image_ref spec_obj = objects.RequestSpec(image=objects.ImageMeta(id=image_ref)) host = fakes.FakeHostState(host_name, 'node', {}) return self.filt_cls.host_passes(host, spec_obj) @@ -57,7 +58,7 @@ class TestIsolatedHostsFilter(test.NoDBTestCase): self.assertTrue(self._do_test_isolated_hosts(False, False, False)) def test_isolated_hosts_no_hosts_config(self): - self.flags(isolated_images=['isolated_image']) + self.flags(isolated_images=[uuids.image_ref]) # If there are no hosts in the config, it should only filter out # images that are listed self.assertFalse(self._do_test_isolated_hosts(False, True, False)) diff --git a/nova/tests/unit/scheduler/filters/test_type_filters.py b/nova/tests/unit/scheduler/filters/test_type_filters.py index e201322c48b8..da7efee539b5 100644 --- a/nova/tests/unit/scheduler/filters/test_type_filters.py +++ b/nova/tests/unit/scheduler/filters/test_type_filters.py @@ -16,6 +16,7 @@ from nova import objects from nova.scheduler.filters import type_filter from nova import test from nova.tests.unit.scheduler import fakes +from nova.tests import uuidsentinel as uuids class TestTypeFilter(test.NoDBTestCase): @@ -31,13 +32,15 @@ class TestTypeFilter(test.NoDBTestCase): # True since no instances on host self.assertTrue(self.filt_cls.host_passes(host, spec_obj)) # Add an instance with the same instance_type_id - inst1 = objects.Instance(uuid='aa', instance_type_id=target_id) + inst1 = objects.Instance(uuid=uuids.instance_1, + instance_type_id=target_id) host.instances = {inst1.uuid: inst1} # True since only same instance_type_id on host self.assertTrue(self.filt_cls.host_passes(host, spec_obj)) # Add an instance with a different instance_type_id diff_type = target_id + 1 - inst2 = objects.Instance(uuid='bb', instance_type_id=diff_type) + inst2 = objects.Instance(uuid=uuids.instance_2, + instance_type_id=diff_type) host.instances.update({inst2.uuid: inst2}) # False since host now has an instance of a different type self.assertFalse(self.filt_cls.host_passes(host, spec_obj)) diff --git a/nova/tests/unit/scheduler/filters/test_utils.py b/nova/tests/unit/scheduler/filters/test_utils.py index 270beb7da145..1fc27fbe5c0f 100644 --- a/nova/tests/unit/scheduler/filters/test_utils.py +++ b/nova/tests/unit/scheduler/filters/test_utils.py @@ -17,6 +17,7 @@ from nova import objects from nova.scheduler.filters import utils from nova import test from nova.tests.unit.scheduler import fakes +from nova.tests import uuidsentinel as uuids _AGGREGATE_FIXTURES = [ objects.Aggregate( @@ -99,17 +100,18 @@ class TestUtils(test.NoDBTestCase): self.assertEqual(9, f(set(['10', '9']), based_on=min)) def test_instance_uuids_overlap(self): - inst1 = objects.Instance(uuid='aa') - inst2 = objects.Instance(uuid='bb') + inst1 = objects.Instance(uuid=uuids.instance_1) + inst2 = objects.Instance(uuid=uuids.instance_2) instances = [inst1, inst2] host_state = fakes.FakeHostState('host1', 'node1', {}) host_state.instances = {instance.uuid: instance for instance in instances} - self.assertTrue(utils.instance_uuids_overlap(host_state, ['aa'])) + self.assertTrue(utils.instance_uuids_overlap(host_state, + [uuids.instance_1])) self.assertFalse(utils.instance_uuids_overlap(host_state, ['zz'])) def test_other_types_on_host(self): - inst1 = objects.Instance(uuid='aa', instance_type_id=1) + inst1 = objects.Instance(uuid=uuids.instance, instance_type_id=1) host_state = fakes.FakeHostState('host1', 'node1', {}) host_state.instances = {inst1.uuid: inst1} self.assertFalse(utils.other_types_on_host(host_state, 1)) diff --git a/nova/tests/unit/scheduler/test_filter_scheduler.py b/nova/tests/unit/scheduler/test_filter_scheduler.py index 7a064a4de5ef..4ffa21eac789 100644 --- a/nova/tests/unit/scheduler/test_filter_scheduler.py +++ b/nova/tests/unit/scheduler/test_filter_scheduler.py @@ -27,6 +27,7 @@ from nova.scheduler import weights from nova import test # noqa from nova.tests.unit.scheduler import fakes from nova.tests.unit.scheduler import test_scheduler +from nova.tests import uuidsentinel as uuids def fake_get_filtered_hosts(hosts, filter_properties, index): @@ -70,7 +71,7 @@ class FilterSchedulerTestCase(test_scheduler.SchedulerTestCase): vcpus=1), project_id=1, os_type='Linux', - uuid='fake-uuid', + uuid=uuids.instance, pci_requests=None, numa_topology=None, instance_group=None) @@ -129,7 +130,7 @@ class FilterSchedulerTestCase(test_scheduler.SchedulerTestCase): num_instances=1, project_id=1, os_type='Linux', - uuid='fake-uuid', + uuid=uuids.instance, flavor=objects.Flavor(root_gb=512, memory_mb=512, ephemeral_gb=0, @@ -166,7 +167,7 @@ class FilterSchedulerTestCase(test_scheduler.SchedulerTestCase): num_instances=1, project_id=1, os_type='Linux', - uuid='fake-uuid', + uuid=uuids.instance, flavor=objects.Flavor(root_gb=512, memory_mb=512, ephemeral_gb=0, @@ -214,7 +215,7 @@ class FilterSchedulerTestCase(test_scheduler.SchedulerTestCase): num_instances=1, project_id=1, os_type='Linux', - uuid='fake-uuid', + uuid=uuids.instance, flavor=objects.Flavor(root_gb=512, memory_mb=512, ephemeral_gb=0, @@ -271,7 +272,7 @@ class FilterSchedulerTestCase(test_scheduler.SchedulerTestCase): vcpus=1), project_id=1, os_type='Linux', - instance_uuid='fake-uuid', + instance_uuid=uuids.instance, num_instances=1, pci_requests=None, numa_topology=None, @@ -292,11 +293,11 @@ class FilterSchedulerTestCase(test_scheduler.SchedulerTestCase): with mock.patch.object(self.driver.notifier, 'info') as mock_info: expected = {'num_instances': 1, - 'instance_properties': {'uuid': 'uuid1'}, + 'instance_properties': {'uuid': uuids.instance}, 'instance_type': {}, 'image': {}} spec_obj = objects.RequestSpec(num_instances=1, - instance_uuid='uuid1') + instance_uuid=uuids.instance) self.driver.select_destinations(self.context, spec_obj) diff --git a/nova/tests/unit/scheduler/test_filters.py b/nova/tests/unit/scheduler/test_filters.py index c1977e16cc35..273a1d4f9ccd 100644 --- a/nova/tests/unit/scheduler/test_filters.py +++ b/nova/tests/unit/scheduler/test_filters.py @@ -24,6 +24,7 @@ from nova import filters from nova import loadables from nova import objects from nova import test +from nova.tests import uuidsentinel as uuids class Filter1(filters.BaseFilter): @@ -191,7 +192,7 @@ class FiltersTestCase(test.NoDBTestCase): filter_b = FilterB() all_filters = [filter_a, filter_b] hosts = ["Host0", "Host1", "Host2"] - fake_uuid = "uuid" + fake_uuid = uuids.instance spec_obj = objects.RequestSpec(instance_uuid=fake_uuid) with mock.patch.object(LOG, "info") as mock_log: result = self.filter_handler.get_filtered_objects( @@ -221,7 +222,7 @@ class FiltersTestCase(test.NoDBTestCase): filter_b = FilterB() all_filters = [filter_a, filter_b] hosts = ["Host0", "Host1", "Host2"] - fake_uuid = "uuid" + fake_uuid = uuids.instance spec_obj = objects.RequestSpec(instance_uuid=fake_uuid) with mock.patch.object(LOG, "debug") as mock_log: result = self.filter_handler.get_filtered_objects( @@ -251,7 +252,7 @@ class FiltersTestCase(test.NoDBTestCase): filter_b = FilterB() all_filters = [filter_a, filter_b] hosts = ["Host0", "Host1", "Host2"] - fake_uuid = "uuid" + fake_uuid = uuids.instance filt_props = {"request_spec": {"instance_properties": { "uuid": fake_uuid}}} with mock.patch.object(LOG, "info") as mock_log: diff --git a/nova/tests/unit/scheduler/test_host_manager.py b/nova/tests/unit/scheduler/test_host_manager.py index 61fd8a281ed5..75417fccc713 100644 --- a/nova/tests/unit/scheduler/test_host_manager.py +++ b/nova/tests/unit/scheduler/test_host_manager.py @@ -95,9 +95,9 @@ class HostManagerTestCase(test.NoDBTestCase): mock_get_by_filters): cn1 = objects.ComputeNode(host='host1') cn2 = objects.ComputeNode(host='host2') - inst1 = objects.Instance(host='host1', uuid='uuid1') - inst2 = objects.Instance(host='host1', uuid='uuid2') - inst3 = objects.Instance(host='host2', uuid='uuid3') + inst1 = objects.Instance(host='host1', uuid=uuids.instance_1) + inst2 = objects.Instance(host='host1', uuid=uuids.instance_2) + inst3 = objects.Instance(host='host2', uuid=uuids.instance_3) mock_get_all.return_value = objects.ComputeNodeList(objects=[cn1, cn2]) mock_get_by_filters.return_value = objects.InstanceList( objects=[inst1, inst2, inst3]) @@ -106,9 +106,9 @@ class HostManagerTestCase(test.NoDBTestCase): hm._init_instance_info() self.assertEqual(len(hm._instance_info), 2) fake_info = hm._instance_info['host1'] - self.assertIn('uuid1', fake_info['instances']) - self.assertIn('uuid2', fake_info['instances']) - self.assertNotIn('uuid3', fake_info['instances']) + self.assertIn(uuids.instance_1, fake_info['instances']) + self.assertIn(uuids.instance_2, fake_info['instances']) + self.assertNotIn(uuids.instance_3, fake_info['instances']) exp_filters = {'deleted': False, 'host': [u'host1', u'host2']} mock_get_by_filters.assert_called_once_with(mock.ANY, exp_filters) @@ -209,7 +209,7 @@ class HostManagerTestCase(test.NoDBTestCase): def test_get_filtered_hosts(self): fake_properties = objects.RequestSpec(ignore_hosts=[], - instance_uuid='fake-uuid1', + instance_uuid=uuids.instance, force_hosts=[], force_nodes=[]) @@ -224,7 +224,7 @@ class HostManagerTestCase(test.NoDBTestCase): def test_get_filtered_hosts_with_ignore(self): fake_properties = objects.RequestSpec( - instance_uuid='fake-uuid1', + instance_uuid=uuids.instance, ignore_hosts=['fake_host1', 'fake_host3', 'fake_host5', 'fake_multihost'], force_hosts=[], @@ -257,7 +257,7 @@ class HostManagerTestCase(test.NoDBTestCase): def test_get_filtered_hosts_with_force_hosts(self): fake_properties = objects.RequestSpec( - instance_uuid='fake-uuid1', + instance_uuid=uuids.instance, ignore_hosts=[], force_hosts=['fake_host1', 'fake_host3', 'fake_host5'], force_nodes=[]) @@ -291,7 +291,7 @@ class HostManagerTestCase(test.NoDBTestCase): def test_get_filtered_hosts_with_no_matching_force_hosts(self): fake_properties = objects.RequestSpec( - instance_uuid='fake-uuid1', + instance_uuid=uuids.instance, ignore_hosts=[], force_hosts=['fake_host5', 'fake_host6'], force_nodes=[]) @@ -311,7 +311,7 @@ class HostManagerTestCase(test.NoDBTestCase): def test_get_filtered_hosts_with_ignore_and_force_hosts(self): # Ensure ignore_hosts processed before force_hosts in host filters. fake_properties = objects.RequestSpec( - instance_uuid='fake-uuid1', + instance_uuid=uuids.instance, ignore_hosts=['fake_host1'], force_hosts=['fake_host3', 'fake_host1'], force_nodes=[]) @@ -328,7 +328,7 @@ class HostManagerTestCase(test.NoDBTestCase): def test_get_filtered_hosts_with_force_host_and_many_nodes(self): # Ensure all nodes returned for a host with many nodes fake_properties = objects.RequestSpec( - instance_uuid='fake-uuid1', + instance_uuid=uuids.instance, ignore_hosts=[], force_hosts=['fake_multihost'], force_nodes=[]) @@ -344,7 +344,7 @@ class HostManagerTestCase(test.NoDBTestCase): def test_get_filtered_hosts_with_force_nodes(self): fake_properties = objects.RequestSpec( - instance_uuid='fake-uuid1', + instance_uuid=uuids.instance, ignore_hosts=[], force_hosts=[], force_nodes=['fake-node2', 'fake-node4', 'fake-node9']) @@ -361,7 +361,7 @@ class HostManagerTestCase(test.NoDBTestCase): def test_get_filtered_hosts_with_force_hosts_and_nodes(self): # Ensure only overlapping results if both force host and node fake_properties = objects.RequestSpec( - instance_uuid='fake-uuid1', + instance_uuid=uuids.instance, ignore_hosts=[], force_hosts=['fake-host1', 'fake_multihost'], force_nodes=['fake-node2', 'fake-node9']) @@ -378,7 +378,7 @@ class HostManagerTestCase(test.NoDBTestCase): def test_get_filtered_hosts_with_force_hosts_and_wrong_nodes(self): # Ensure non-overlapping force_node and force_host yield no result fake_properties = objects.RequestSpec( - instance_uuid='fake-uuid1', + instance_uuid=uuids.instance, ignore_hosts=[], force_hosts=['fake_multihost'], force_nodes=['fake-node']) @@ -394,7 +394,7 @@ class HostManagerTestCase(test.NoDBTestCase): def test_get_filtered_hosts_with_ignore_hosts_and_force_nodes(self): # Ensure ignore_hosts can coexist with force_nodes fake_properties = objects.RequestSpec( - instance_uuid='fake-uuid1', + instance_uuid=uuids.instance, ignore_hosts=['fake_host1', 'fake_host2'], force_hosts=[], force_nodes=['fake-node4', 'fake-node2']) @@ -410,7 +410,7 @@ class HostManagerTestCase(test.NoDBTestCase): def test_get_filtered_hosts_with_ignore_hosts_and_force_same_nodes(self): # Ensure ignore_hosts is processed before force_nodes fake_properties = objects.RequestSpec( - instance_uuid='fake-uuid1', + instance_uuid=uuids.instance, ignore_hosts=['fake_multihost'], force_hosts=[], force_nodes=['fake_node4', 'fake_node2']) @@ -558,9 +558,9 @@ class HostManagerTestCase(test.NoDBTestCase): mock_get_svc_by_binary.return_value = fakes.SERVICES context = 'fake_context' hm = self.host_manager - inst1 = objects.Instance(uuid='uuid1') + inst1 = objects.Instance(uuid=uuids.instance) cn1 = objects.ComputeNode(host='host1') - hm._instance_info = {'host1': {'instances': {'uuid1': inst1}, + hm._instance_info = {'host1': {'instances': {uuids.instance: inst1}, 'updated': True}} host_state = host_manager.HostState('host1', cn1) self.assertFalse(host_state.instances) @@ -569,7 +569,7 @@ class HostManagerTestCase(test.NoDBTestCase): inst_dict=hm._get_instance_info(context, cn1)) self.assertFalse(mock_get_by_host.called) self.assertTrue(host_state.instances) - self.assertEqual(host_state.instances['uuid1'], inst1) + self.assertEqual(host_state.instances[uuids.instance], inst1) @mock.patch('nova.objects.ServiceList.get_by_binary') @mock.patch('nova.objects.ComputeNodeList.get_all') @@ -581,9 +581,9 @@ class HostManagerTestCase(test.NoDBTestCase): mock_get_svc_by_binary.return_value = fakes.SERVICES context = 'fake_context' hm = self.host_manager - inst1 = objects.Instance(uuid='uuid1') + inst1 = objects.Instance(uuid=uuids.instance) cn1 = objects.ComputeNode(host='host1') - hm._instance_info = {'host1': {'instances': {'uuid1': inst1}, + hm._instance_info = {'host1': {'instances': {uuids.instance: inst1}, 'updated': False}} host_state = host_manager.HostState('host1', cn1) self.assertFalse(host_state.instances) @@ -592,14 +592,16 @@ class HostManagerTestCase(test.NoDBTestCase): inst_dict=hm._get_instance_info(context, cn1)) mock_get_by_host.assert_called_once_with(context, cn1.host) self.assertTrue(host_state.instances) - self.assertEqual(host_state.instances['uuid1'], inst1) + self.assertEqual(host_state.instances[uuids.instance], inst1) @mock.patch('nova.objects.InstanceList.get_by_host') def test_recreate_instance_info(self, mock_get_by_host): host_name = 'fake_host' - inst1 = fake_instance.fake_instance_obj('fake_context', uuid='aaa', + inst1 = fake_instance.fake_instance_obj('fake_context', + uuid=uuids.instance_1, host=host_name) - inst2 = fake_instance.fake_instance_obj('fake_context', uuid='bbb', + inst2 = fake_instance.fake_instance_obj('fake_context', + uuid=uuids.instance_2, host=host_name) orig_inst_dict = {inst1.uuid: inst1, inst2.uuid: inst2} new_inst_list = objects.InstanceList(objects=[inst1, inst2]) @@ -616,9 +618,11 @@ class HostManagerTestCase(test.NoDBTestCase): def test_update_instance_info(self): host_name = 'fake_host' - inst1 = fake_instance.fake_instance_obj('fake_context', uuid='aaa', + inst1 = fake_instance.fake_instance_obj('fake_context', + uuid=uuids.instance_1, host=host_name) - inst2 = fake_instance.fake_instance_obj('fake_context', uuid='bbb', + inst2 = fake_instance.fake_instance_obj('fake_context', + uuid=uuids.instance_2, host=host_name) orig_inst_dict = {inst1.uuid: inst1, inst2.uuid: inst2} self.host_manager._instance_info = { @@ -626,9 +630,11 @@ class HostManagerTestCase(test.NoDBTestCase): 'instances': orig_inst_dict, 'updated': False, }} - inst3 = fake_instance.fake_instance_obj('fake_context', uuid='ccc', + inst3 = fake_instance.fake_instance_obj('fake_context', + uuid=uuids.instance_3, host=host_name) - inst4 = fake_instance.fake_instance_obj('fake_context', uuid='ddd', + inst4 = fake_instance.fake_instance_obj('fake_context', + uuid=uuids.instance_4, host=host_name) update = objects.InstanceList(objects=[inst3, inst4]) self.host_manager.update_instance_info('fake_context', host_name, @@ -640,9 +646,11 @@ class HostManagerTestCase(test.NoDBTestCase): def test_update_instance_info_unknown_host(self): self.host_manager._recreate_instance_info = mock.MagicMock() host_name = 'fake_host' - inst1 = fake_instance.fake_instance_obj('fake_context', uuid='aaa', + inst1 = fake_instance.fake_instance_obj('fake_context', + uuid=uuids.instance_1, host=host_name) - inst2 = fake_instance.fake_instance_obj('fake_context', uuid='bbb', + inst2 = fake_instance.fake_instance_obj('fake_context', + uuid=uuids.instance_2, host=host_name) orig_inst_dict = {inst1.uuid: inst1, inst2.uuid: inst2} self.host_manager._instance_info = { @@ -651,7 +659,8 @@ class HostManagerTestCase(test.NoDBTestCase): 'updated': False, }} bad_host = 'bad_host' - inst3 = fake_instance.fake_instance_obj('fake_context', uuid='ccc', + inst3 = fake_instance.fake_instance_obj('fake_context', + uuid=uuids.instance_3, host=bad_host) inst_list3 = objects.InstanceList(objects=[inst3]) self.host_manager.update_instance_info('fake_context', bad_host, @@ -664,9 +673,11 @@ class HostManagerTestCase(test.NoDBTestCase): def test_delete_instance_info(self): host_name = 'fake_host' - inst1 = fake_instance.fake_instance_obj('fake_context', uuid='aaa', + inst1 = fake_instance.fake_instance_obj('fake_context', + uuid=uuids.instance_1, host=host_name) - inst2 = fake_instance.fake_instance_obj('fake_context', uuid='bbb', + inst2 = fake_instance.fake_instance_obj('fake_context', + uuid=uuids.instance_2, host=host_name) orig_inst_dict = {inst1.uuid: inst1, inst2.uuid: inst2} self.host_manager._instance_info = { @@ -683,9 +694,11 @@ class HostManagerTestCase(test.NoDBTestCase): def test_delete_instance_info_unknown_host(self): self.host_manager._recreate_instance_info = mock.MagicMock() host_name = 'fake_host' - inst1 = fake_instance.fake_instance_obj('fake_context', uuid='aaa', + inst1 = fake_instance.fake_instance_obj('fake_context', + uuid=uuids.instance_1, host=host_name) - inst2 = fake_instance.fake_instance_obj('fake_context', uuid='bbb', + inst2 = fake_instance.fake_instance_obj('fake_context', + uuid=uuids.instance_2, host=host_name) orig_inst_dict = {inst1.uuid: inst1, inst2.uuid: inst2} self.host_manager._instance_info = { @@ -694,7 +707,8 @@ class HostManagerTestCase(test.NoDBTestCase): 'updated': False, }} bad_host = 'bad_host' - self.host_manager.delete_instance_info('fake_context', bad_host, 'aaa') + self.host_manager.delete_instance_info('fake_context', bad_host, + uuids.instance_1) new_info = self.host_manager._instance_info[host_name] self.host_manager._recreate_instance_info.assert_called_once_with( 'fake_context', bad_host) @@ -704,9 +718,11 @@ class HostManagerTestCase(test.NoDBTestCase): def test_sync_instance_info(self): self.host_manager._recreate_instance_info = mock.MagicMock() host_name = 'fake_host' - inst1 = fake_instance.fake_instance_obj('fake_context', uuid='aaa', + inst1 = fake_instance.fake_instance_obj('fake_context', + uuid=uuids.instance_1, host=host_name) - inst2 = fake_instance.fake_instance_obj('fake_context', uuid='bbb', + inst2 = fake_instance.fake_instance_obj('fake_context', + uuid=uuids.instance_2, host=host_name) orig_inst_dict = {inst1.uuid: inst1, inst2.uuid: inst2} self.host_manager._instance_info = { @@ -715,7 +731,8 @@ class HostManagerTestCase(test.NoDBTestCase): 'updated': False, }} self.host_manager.sync_instance_info('fake_context', host_name, - ['bbb', 'aaa']) + [uuids.instance_2, + uuids.instance_1]) new_info = self.host_manager._instance_info[host_name] self.assertFalse(self.host_manager._recreate_instance_info.called) self.assertTrue(new_info['updated']) @@ -723,9 +740,11 @@ class HostManagerTestCase(test.NoDBTestCase): def test_sync_instance_info_fail(self): self.host_manager._recreate_instance_info = mock.MagicMock() host_name = 'fake_host' - inst1 = fake_instance.fake_instance_obj('fake_context', uuid='aaa', + inst1 = fake_instance.fake_instance_obj('fake_context', + uuid=uuids.instance_1, host=host_name) - inst2 = fake_instance.fake_instance_obj('fake_context', uuid='bbb', + inst2 = fake_instance.fake_instance_obj('fake_context', + uuid=uuids.instance_2, host=host_name) orig_inst_dict = {inst1.uuid: inst1, inst2.uuid: inst2} self.host_manager._instance_info = { @@ -734,7 +753,8 @@ class HostManagerTestCase(test.NoDBTestCase): 'updated': False, }} self.host_manager.sync_instance_info('fake_context', host_name, - ['bbb', 'aaa', 'new']) + [uuids.instance_2, + uuids.instance_1, 'new']) new_info = self.host_manager._instance_info[host_name] self.host_manager._recreate_instance_info.assert_called_once_with( 'fake_context', host_name) @@ -960,7 +980,7 @@ class HostStateTestCase(test.NoDBTestCase): numa_fit_mock.return_value = fake_numa_topology instance_init_mock.return_value = fake_instance spec_obj = objects.RequestSpec( - instance_uuid='fake-uuid', + instance_uuid=uuids.instance, flavor=objects.Flavor(root_gb=0, ephemeral_gb=0, memory_mb=0, vcpus=0), numa_topology=fake_numa_topology, @@ -981,7 +1001,7 @@ class HostStateTestCase(test.NoDBTestCase): second_numa_topology = objects.InstanceNUMATopology( cells=[objects.InstanceNUMACell()]) spec_obj = objects.RequestSpec( - instance_uuid='fake-uuid', + instance_uuid=uuids.instance, flavor=objects.Flavor(root_gb=0, ephemeral_gb=0, memory_mb=0, vcpus=0), numa_topology=second_numa_topology, @@ -1005,14 +1025,14 @@ class HostStateTestCase(test.NoDBTestCase): cpuset=set([0]), memory=512, id=0)]) - fake_requests = [{'request_id': 'fake_request1', 'count': 1, + fake_requests = [{'request_id': uuids.request_id, 'count': 1, 'spec': [{'vendor_id': '8086'}]}] fake_requests_obj = objects.InstancePCIRequests( requests=[objects.InstancePCIRequest(**r) for r in fake_requests], - instance_uuid='fake-uuid') + instance_uuid=uuids.instance) req_spec = objects.RequestSpec( - instance_uuid='fake-uuid', + instance_uuid=uuids.instance, project_id='12345', numa_topology=inst_topology, pci_requests=fake_requests_obj, @@ -1038,14 +1058,14 @@ class HostStateTestCase(test.NoDBTestCase): self.assertIsNotNone(host.updated) def test_stat_consumption_from_instance_with_pci_exception(self): - fake_requests = [{'request_id': 'fake_request1', 'count': 3, + fake_requests = [{'request_id': uuids.request_id, 'count': 3, 'spec': [{'vendor_id': '8086'}]}] fake_requests_obj = objects.InstancePCIRequests( requests=[objects.InstancePCIRequest(**r) for r in fake_requests], - instance_uuid='fake-uuid') + instance_uuid=uuids.instance) req_spec = objects.RequestSpec( - instance_uuid='fake-uuid', + instance_uuid=uuids.instance, project_id='12345', numa_topology=None, pci_requests=fake_requests_obj, diff --git a/nova/tests/unit/scheduler/test_ironic_host_manager.py b/nova/tests/unit/scheduler/test_ironic_host_manager.py index 7433f7738ee9..de3277201a1f 100644 --- a/nova/tests/unit/scheduler/test_ironic_host_manager.py +++ b/nova/tests/unit/scheduler/test_ironic_host_manager.py @@ -27,6 +27,7 @@ from nova.scheduler import host_manager from nova.scheduler import ironic_host_manager from nova import test from nova.tests.unit.scheduler import ironic_fakes +from nova.tests import uuidsentinel as uuids class FakeFilterClass1(filters.BaseHostFilter): @@ -208,7 +209,7 @@ class IronicHostManagerChangedNodesTestCase(test.NoDBTestCase): spec_obj = objects.RequestSpec( flavor=objects.Flavor(root_gb=10, ephemeral_gb=0, memory_mb=1024, vcpus=1), - uuid='fake-uuid') + uuid=uuids.instance) host.consume_from_request(spec_obj) self.assertEqual(1, host.vcpus_used) @@ -332,7 +333,7 @@ class IronicHostManagerTestFilters(test.NoDBTestCase): def test_get_filtered_hosts(self): fake_properties = objects.RequestSpec( - instance_uuid='fake-uuid', + instance_uuid=uuids.instance, ignore_hosts=[], force_hosts=[], force_nodes=[]) @@ -348,7 +349,7 @@ class IronicHostManagerTestFilters(test.NoDBTestCase): def test_get_filtered_hosts_with_ignore(self): fake_properties = objects.RequestSpec( - instance_uuid='fake-uuid', + instance_uuid=uuids.instance, ignore_hosts=['fake_host1', 'fake_host3', 'fake_host5', 'fake_multihost'], force_hosts=[], @@ -365,7 +366,7 @@ class IronicHostManagerTestFilters(test.NoDBTestCase): def test_get_filtered_hosts_with_force_hosts(self): fake_properties = objects.RequestSpec( - instance_uuid='fake-uuid', + instance_uuid=uuids.instance, ignore_hosts=[], force_hosts=['fake_host1', 'fake_host3', 'fake_host5'], force_nodes=[]) @@ -381,7 +382,7 @@ class IronicHostManagerTestFilters(test.NoDBTestCase): def test_get_filtered_hosts_with_no_matching_force_hosts(self): fake_properties = objects.RequestSpec( - instance_uuid='fake-uuid', + instance_uuid=uuids.instance, ignore_hosts=[], force_hosts=['fake_host5', 'fake_host6'], force_nodes=[]) @@ -397,7 +398,7 @@ class IronicHostManagerTestFilters(test.NoDBTestCase): def test_get_filtered_hosts_with_ignore_and_force_hosts(self): # Ensure ignore_hosts processed before force_hosts in host filters. fake_properties = objects.RequestSpec( - instance_uuid='fake-uuid', + instance_uuid=uuids.instance, ignore_hosts=['fake_host1'], force_hosts=['fake_host3', 'fake_host1'], force_nodes=[]) @@ -414,7 +415,7 @@ class IronicHostManagerTestFilters(test.NoDBTestCase): def test_get_filtered_hosts_with_force_host_and_many_nodes(self): # Ensure all nodes returned for a host with many nodes fake_properties = objects.RequestSpec( - instance_uuid='fake-uuid', + instance_uuid=uuids.instance, ignore_hosts=[], force_hosts=['fake_multihost'], force_nodes=[]) @@ -430,7 +431,7 @@ class IronicHostManagerTestFilters(test.NoDBTestCase): def test_get_filtered_hosts_with_force_nodes(self): fake_properties = objects.RequestSpec( - instance_uuid='fake-uuid', + instance_uuid=uuids.instance, ignore_hosts=[], force_hosts=[], force_nodes=['fake-node2', 'fake-node4', 'fake-node9']) @@ -447,7 +448,7 @@ class IronicHostManagerTestFilters(test.NoDBTestCase): def test_get_filtered_hosts_with_force_hosts_and_nodes(self): # Ensure only overlapping results if both force host and node fake_properties = objects.RequestSpec( - instance_uuid='fake-uuid', + instance_uuid=uuids.instance, ignore_hosts=[], force_hosts=['fake_host1', 'fake_multihost'], force_nodes=['fake-node2', 'fake-node9']) @@ -464,7 +465,7 @@ class IronicHostManagerTestFilters(test.NoDBTestCase): def test_get_filtered_hosts_with_force_hosts_and_wrong_nodes(self): # Ensure non-overlapping force_node and force_host yield no result fake_properties = objects.RequestSpec( - instance_uuid='fake-uuid', + instance_uuid=uuids.instance, ignore_hosts=[], force_hosts=['fake_multihost'], force_nodes=['fake-node']) @@ -480,7 +481,7 @@ class IronicHostManagerTestFilters(test.NoDBTestCase): def test_get_filtered_hosts_with_ignore_hosts_and_force_nodes(self): # Ensure ignore_hosts can coexist with force_nodes fake_properties = objects.RequestSpec( - instance_uuid='fake-uuid', + instance_uuid=uuids.instance, ignore_hosts=['fake_host1', 'fake_host2'], force_hosts=[], force_nodes=['fake-node4', 'fake-node2']) @@ -496,7 +497,7 @@ class IronicHostManagerTestFilters(test.NoDBTestCase): def test_get_filtered_hosts_with_ignore_hosts_and_force_same_nodes(self): # Ensure ignore_hosts is processed before force_nodes fake_properties = objects.RequestSpec( - instance_uuid='fake-uuid', + instance_uuid=uuids.instance, ignore_hosts=['fake_multihost'], force_hosts=[], force_nodes=['fake_node4', 'fake_node2']) diff --git a/nova/tests/unit/scheduler/test_scheduler_utils.py b/nova/tests/unit/scheduler/test_scheduler_utils.py index 23325f2a90d9..0dd61346c5ec 100644 --- a/nova/tests/unit/scheduler/test_scheduler_utils.py +++ b/nova/tests/unit/scheduler/test_scheduler_utils.py @@ -29,6 +29,7 @@ from nova.scheduler import utils as scheduler_utils from nova import test from nova.tests.unit import fake_instance from nova.tests.unit.objects import test_flavor +from nova.tests import uuidsentinel as uuids class SchedulerUtilsTestCase(test.NoDBTestCase): @@ -38,7 +39,7 @@ class SchedulerUtilsTestCase(test.NoDBTestCase): self.context = 'fake-context' def test_build_request_spec_without_image(self): - instance = {'uuid': 'fake-uuid'} + instance = {'uuid': uuids.instance} instance_type = objects.Flavor(**test_flavor.fake_flavor) with mock.patch.object(flavors, 'extract_flavor') as mock_extract: @@ -46,7 +47,7 @@ class SchedulerUtilsTestCase(test.NoDBTestCase): request_spec = scheduler_utils.build_request_spec(self.context, None, [instance]) - mock_extract.assert_called_once_with({'uuid': 'fake-uuid'}) + mock_extract.assert_called_once_with({'uuid': uuids.instance}) self.assertEqual({}, request_spec['image']) def test_build_request_spec_with_object(self): @@ -65,7 +66,7 @@ class SchedulerUtilsTestCase(test.NoDBTestCase): @mock.patch.object(compute_utils, 'add_instance_fault_from_exc') @mock.patch.object(objects.Instance, 'save') def test_set_vm_state_and_notify(self, mock_save, mock_add, mock_get): - expected_uuid = 'fake-uuid' + expected_uuid = uuids.instance request_spec = dict(instance_properties=dict(uuid='other-uuid')) updates = dict(vm_state='fake-vm-state') service = 'fake-service' @@ -208,7 +209,7 @@ class SchedulerUtilsTestCase(test.NoDBTestCase): exc_reason=[msg])) nvh = self.assertRaises(exception.MaxRetriesExceeded, scheduler_utils.populate_retry, - filter_properties, 'fake-uuid') + filter_properties, uuids.instance) # make sure 'msg' is a substring of the complete exception text self.assertIn(msg, six.text_type(nvh)) @@ -324,7 +325,7 @@ class SchedulerUtilsTestCase(test.NoDBTestCase): scheduler_utils._SUPPORTS_SOFT_ANTI_AFFINITY = None self.assertRaises(exception.UnsupportedPolicyException, scheduler_utils._get_group_details, - self.context, 'fake-uuid') + self.context, uuids.instance) def test_get_group_details_with_filter_not_configured(self): policies = ['anti-affinity', 'affinity', @@ -337,12 +338,12 @@ class SchedulerUtilsTestCase(test.NoDBTestCase): mock_ggd.return_value = scheduler_utils.GroupDetails( hosts=set(['hostA', 'hostB']), policies=['policy'], members=['instance1']) - spec = {'instance_properties': {'uuid': 'fake-uuid'}} + spec = {'instance_properties': {'uuid': uuids.instance}} filter_props = {'group_hosts': ['hostC']} scheduler_utils.setup_instance_group(self.context, spec, filter_props) - mock_ggd.assert_called_once_with(self.context, 'fake-uuid', + mock_ggd.assert_called_once_with(self.context, uuids.instance, ['hostC']) expected_filter_props = {'group_updated': True, 'group_hosts': set(['hostA', 'hostB']), @@ -353,12 +354,12 @@ class SchedulerUtilsTestCase(test.NoDBTestCase): @mock.patch.object(scheduler_utils, '_get_group_details') def test_setup_instance_group_with_no_group(self, mock_ggd): mock_ggd.return_value = None - spec = {'instance_properties': {'uuid': 'fake-uuid'}} + spec = {'instance_properties': {'uuid': uuids.instance}} filter_props = {'group_hosts': ['hostC']} scheduler_utils.setup_instance_group(self.context, spec, filter_props) - mock_ggd.assert_called_once_with(self.context, 'fake-uuid', + mock_ggd.assert_called_once_with(self.context, uuids.instance, ['hostC']) self.assertNotIn('group_updated', filter_props) self.assertNotIn('group_policies', filter_props) @@ -367,7 +368,7 @@ class SchedulerUtilsTestCase(test.NoDBTestCase): @mock.patch.object(scheduler_utils, '_get_group_details') def test_setup_instance_group_with_filter_not_configured(self, mock_ggd): mock_ggd.side_effect = exception.NoValidHost(reason='whatever') - spec = {'instance_properties': {'uuid': 'fake-uuid'}} + spec = {'instance_properties': {'uuid': uuids.instance}} filter_props = {'group_hosts': ['hostC']} self.assertRaises(exception.NoValidHost, diff --git a/nova/tests/unit/test_block_device.py b/nova/tests/unit/test_block_device.py index 2777cbc67013..6891558ddf2a 100644 --- a/nova/tests/unit/test_block_device.py +++ b/nova/tests/unit/test_block_device.py @@ -23,6 +23,7 @@ from nova import objects from nova import test from nova.tests.unit import fake_block_device from nova.tests.unit import matchers +from nova.tests import uuidsentinel as uuids class BlockDeviceTestCase(test.NoDBTestCase): @@ -31,7 +32,7 @@ class BlockDeviceTestCase(test.NoDBTestCase): BDM = block_device.BlockDeviceDict self.new_mapping = [ - BDM({'id': 1, 'instance_uuid': 'fake-instance', + BDM({'id': 1, 'instance_uuid': uuids.instance, 'device_name': '/dev/sdb1', 'source_type': 'blank', 'destination_type': 'local', @@ -39,21 +40,21 @@ class BlockDeviceTestCase(test.NoDBTestCase): 'volume_size': 1, 'guest_format': 'swap', 'boot_index': -1}), - BDM({'id': 2, 'instance_uuid': 'fake-instance', + BDM({'id': 2, 'instance_uuid': uuids.instance, 'device_name': '/dev/sdc1', 'source_type': 'blank', 'destination_type': 'local', 'volume_size': 10, 'delete_on_termination': True, 'boot_index': -1}), - BDM({'id': 3, 'instance_uuid': 'fake-instance', + BDM({'id': 3, 'instance_uuid': uuids.instance, 'device_name': '/dev/sda1', 'source_type': 'volume', 'destination_type': 'volume', 'volume_id': 'fake-volume-id-1', 'connection_info': "{'fake': 'connection_info'}", 'boot_index': 0}), - BDM({'id': 4, 'instance_uuid': 'fake-instance', + BDM({'id': 4, 'instance_uuid': uuids.instance, 'device_name': '/dev/sda2', 'source_type': 'snapshot', 'destination_type': 'volume', @@ -61,7 +62,7 @@ class BlockDeviceTestCase(test.NoDBTestCase): 'snapshot_id': 'fake-snapshot-id-1', 'volume_id': 'fake-volume-id-2', 'boot_index': -1}), - BDM({'id': 5, 'instance_uuid': 'fake-instance', + BDM({'id': 5, 'instance_uuid': uuids.instance, 'no_device': True, 'device_name': '/dev/vdc'}), ] @@ -252,58 +253,58 @@ class TestBlockDeviceDict(test.NoDBTestCase): BDM = block_device.BlockDeviceDict self.api_mapping = [ - {'id': 1, 'instance_uuid': 'fake-instance', + {'id': 1, 'instance_uuid': uuids.instance, 'device_name': '/dev/sdb1', 'source_type': 'blank', 'destination_type': 'local', 'delete_on_termination': True, 'guest_format': 'swap', 'boot_index': -1}, - {'id': 2, 'instance_uuid': 'fake-instance', + {'id': 2, 'instance_uuid': uuids.instance, 'device_name': '/dev/sdc1', 'source_type': 'blank', 'destination_type': 'local', 'delete_on_termination': True, 'boot_index': -1}, - {'id': 3, 'instance_uuid': 'fake-instance', + {'id': 3, 'instance_uuid': uuids.instance, 'device_name': '/dev/sda1', 'source_type': 'volume', 'destination_type': 'volume', 'uuid': 'fake-volume-id-1', 'boot_index': 0}, - {'id': 4, 'instance_uuid': 'fake-instance', + {'id': 4, 'instance_uuid': uuids.instance, 'device_name': '/dev/sda2', 'source_type': 'snapshot', 'destination_type': 'volume', 'uuid': 'fake-snapshot-id-1', 'boot_index': -1}, - {'id': 5, 'instance_uuid': 'fake-instance', + {'id': 5, 'instance_uuid': uuids.instance, 'no_device': True, 'device_name': '/dev/vdc'}, ] self.new_mapping = [ - BDM({'id': 1, 'instance_uuid': 'fake-instance', + BDM({'id': 1, 'instance_uuid': uuids.instance, 'device_name': '/dev/sdb1', 'source_type': 'blank', 'destination_type': 'local', 'delete_on_termination': True, 'guest_format': 'swap', 'boot_index': -1}), - BDM({'id': 2, 'instance_uuid': 'fake-instance', + BDM({'id': 2, 'instance_uuid': uuids.instance, 'device_name': '/dev/sdc1', 'source_type': 'blank', 'destination_type': 'local', 'delete_on_termination': True, 'boot_index': -1}), - BDM({'id': 3, 'instance_uuid': 'fake-instance', + BDM({'id': 3, 'instance_uuid': uuids.instance, 'device_name': '/dev/sda1', 'source_type': 'volume', 'destination_type': 'volume', 'volume_id': 'fake-volume-id-1', 'connection_info': "{'fake': 'connection_info'}", 'boot_index': 0}), - BDM({'id': 4, 'instance_uuid': 'fake-instance', + BDM({'id': 4, 'instance_uuid': uuids.instance, 'device_name': '/dev/sda2', 'source_type': 'snapshot', 'destination_type': 'volume', @@ -311,43 +312,43 @@ class TestBlockDeviceDict(test.NoDBTestCase): 'snapshot_id': 'fake-snapshot-id-1', 'volume_id': 'fake-volume-id-2', 'boot_index': -1}), - BDM({'id': 5, 'instance_uuid': 'fake-instance', + BDM({'id': 5, 'instance_uuid': uuids.instance, 'no_device': True, 'device_name': '/dev/vdc'}), ] self.legacy_mapping = [ - {'id': 1, 'instance_uuid': 'fake-instance', + {'id': 1, 'instance_uuid': uuids.instance, 'device_name': '/dev/sdb1', 'delete_on_termination': True, 'virtual_name': 'swap'}, - {'id': 2, 'instance_uuid': 'fake-instance', + {'id': 2, 'instance_uuid': uuids.instance, 'device_name': '/dev/sdc1', 'delete_on_termination': True, 'virtual_name': 'ephemeral0'}, - {'id': 3, 'instance_uuid': 'fake-instance', + {'id': 3, 'instance_uuid': uuids.instance, 'device_name': '/dev/sda1', 'volume_id': 'fake-volume-id-1', 'connection_info': "{'fake': 'connection_info'}"}, - {'id': 4, 'instance_uuid': 'fake-instance', + {'id': 4, 'instance_uuid': uuids.instance, 'device_name': '/dev/sda2', 'connection_info': "{'fake': 'connection_info'}", 'snapshot_id': 'fake-snapshot-id-1', 'volume_id': 'fake-volume-id-2'}, - {'id': 5, 'instance_uuid': 'fake-instance', + {'id': 5, 'instance_uuid': uuids.instance, 'no_device': True, 'device_name': '/dev/vdc'}, ] self.new_mapping_source_image = [ - BDM({'id': 6, 'instance_uuid': 'fake-instance', + BDM({'id': 6, 'instance_uuid': uuids.instance, 'device_name': '/dev/sda3', 'source_type': 'image', 'destination_type': 'volume', 'connection_info': "{'fake': 'connection_info'}", 'volume_id': 'fake-volume-id-3', 'boot_index': -1}), - BDM({'id': 7, 'instance_uuid': 'fake-instance', + BDM({'id': 7, 'instance_uuid': uuids.instance, 'device_name': '/dev/sda4', 'source_type': 'image', 'destination_type': 'local', @@ -357,7 +358,7 @@ class TestBlockDeviceDict(test.NoDBTestCase): ] self.legacy_mapping_source_image = [ - {'id': 6, 'instance_uuid': 'fake-instance', + {'id': 6, 'instance_uuid': uuids.instance, 'device_name': '/dev/sda3', 'connection_info': "{'fake': 'connection_info'}", 'volume_id': 'fake-volume-id-3'}, @@ -411,7 +412,7 @@ class TestBlockDeviceDict(test.NoDBTestCase): self.assertEqual('bar', dev_dict['field2']) def test_init_prepend_dev_to_device_name(self): - bdm = {'id': 3, 'instance_uuid': 'fake-instance', + bdm = {'id': 3, 'instance_uuid': uuids.instance, 'device_name': 'vda', 'source_type': 'volume', 'destination_type': 'volume', @@ -431,7 +432,7 @@ class TestBlockDeviceDict(test.NoDBTestCase): def test_init_boolify_delete_on_termination(self): # Make sure that when delete_on_termination is not passed it's # still set to False and not None - bdm = {'id': 3, 'instance_uuid': 'fake-instance', + bdm = {'id': 3, 'instance_uuid': uuids.instance, 'device_name': 'vda', 'source_type': 'volume', 'destination_type': 'volume', diff --git a/nova/tests/unit/test_metadata.py b/nova/tests/unit/test_metadata.py index 256e931a6e0a..4a0def1bc104 100644 --- a/nova/tests/unit/test_metadata.py +++ b/nova/tests/unit/test_metadata.py @@ -49,6 +49,7 @@ from nova import test from nova.tests.unit.api.openstack import fakes from nova.tests.unit import fake_block_device from nova.tests.unit import fake_network +from nova.tests import uuidsentinel as uuids from nova.virt import netutils CONF = cfg.CONF @@ -71,7 +72,7 @@ def fake_inst_obj(context): launch_index=1, reservation_id='r-xxxxxxxx', user_data=ENCODE_USER_DATA_STRING, - image_ref=7, + image_ref=uuids.image_ref, kernel_id=None, ramdisk_id=None, vcpus=1, @@ -275,7 +276,7 @@ class MetadataTestCase(test.TestCase): def test_image_type_ramdisk(self): inst = self.instance.obj_clone() - inst['ramdisk_id'] = 'ari-853667c0' + inst['ramdisk_id'] = uuids.ramdisk_id md = fake_InstanceMetadata(self.stubs, inst) data = md.lookup("/latest/meta-data/ramdisk-id") @@ -284,7 +285,7 @@ class MetadataTestCase(test.TestCase): def test_image_type_kernel(self): inst = self.instance.obj_clone() - inst['kernel_id'] = 'aki-c2e26ff2' + inst['kernel_id'] = uuids.kernel_id md = fake_InstanceMetadata(self.stubs, inst) data = md.lookup("/2009-04-04/meta-data/kernel-id") diff --git a/nova/tests/unit/test_notifications.py b/nova/tests/unit/test_notifications.py index 67696e4bb3d1..0b63057e2195 100644 --- a/nova/tests/unit/test_notifications.py +++ b/nova/tests/unit/test_notifications.py @@ -32,6 +32,7 @@ from nova.objects import base as obj_base from nova import test from nova.tests.unit import fake_network from nova.tests.unit import fake_notifier +from nova.tests import uuidsentinel as uuids class NotificationsTestCase(test.TestCase): @@ -70,7 +71,7 @@ class NotificationsTestCase(test.TestCase): def _wrapped_create(self, params=None): instance_type = flavors.get_flavor_by_name('m1.tiny') - inst = objects.Instance(image_ref=1, + inst = objects.Instance(image_ref=uuids.image_ref, user_id=self.user_id, project_id=self.project_id, instance_type_id=instance_type['id'],