diff --git a/nova/tests/unit/api/openstack/compute/legacy_v2/test_servers.py b/nova/tests/unit/api/openstack/compute/legacy_v2/test_servers.py index 57d023d01b8f..5e3b82119e3a 100644 --- a/nova/tests/unit/api/openstack/compute/legacy_v2/test_servers.py +++ b/nova/tests/unit/api/openstack/compute/legacy_v2/test_servers.py @@ -76,10 +76,6 @@ INSTANCE_IDS = {FAKE_UUID: 1} FIELDS = instance_obj.INSTANCE_DEFAULT_FIELDS -def fake_gen_uuid(): - return FAKE_UUID - - def return_servers_empty(context, *args, **kwargs): return objects.InstanceList(objects=[]) @@ -1892,7 +1888,7 @@ class ServersControllerCreateTest(test.TestCase): instance = fake_instance.fake_db_instance(**{ 'id': self.instance_cache_num, 'display_name': inst['display_name'] or 'test', - 'uuid': FAKE_UUID, + 'uuid': inst['uuid'], 'instance_type': inst_type, 'access_ip_v4': '1.2.3.4', 'access_ip_v6': 'fead::1234', @@ -1941,7 +1937,6 @@ class ServersControllerCreateTest(test.TestCase): fakes.stub_out_rate_limiting(self.stubs) fakes.stub_out_key_pair_funcs(self.stubs) fake.stub_out_image_service(self) - self.stubs.Set(uuid, 'uuid4', fake_gen_uuid) self.stub_out('nova.db.instance_add_security_group', return_security_group) self.stub_out('nova.db.project_get_networks', project_get_networks) @@ -1953,7 +1948,6 @@ class ServersControllerCreateTest(test.TestCase): server_update_and_get_original) self.stubs.Set(manager.VlanManager, 'allocate_fixed_ip', fake_method) - self.stub_out('nova.objects.RequestSpec.create', fake_method) self.body = { 'server': { 'min_count': 2, @@ -1997,7 +1991,8 @@ class ServersControllerCreateTest(test.TestCase): self.req.body = jsonutils.dump_as_bytes(self.body) server = self.controller.create(self.req, self.body).obj['server'] self._check_admin_pass_len(server) - self.assertEqual(FAKE_UUID, server['id']) + instance = self.instance_cache_by_uuid.values()[0] + self.assertEqual(instance['uuid'], server['id']) return server def test_create_instance_private_flavor(self): @@ -2079,7 +2074,8 @@ class ServersControllerCreateTest(test.TestCase): self.ext_mgr.extensions = {'os-multiple-create': 'fake'} self.req.body = jsonutils.dump_as_bytes(self.body) res = self.controller.create(self.req, self.body).obj - self.assertEqual(FAKE_UUID, res["server"]["id"]) + instance_uuids = self.instance_cache_by_uuid.keys() + self.assertIn(res["server"]["id"], instance_uuids) self._check_admin_pass_len(res["server"]) def test_create_multiple_instances_pass_disabled(self): @@ -2090,7 +2086,8 @@ class ServersControllerCreateTest(test.TestCase): self.flags(enable_instance_password=False) self.req.body = jsonutils.dump_as_bytes(self.body) res = self.controller.create(self.req, self.body).obj - self.assertEqual(FAKE_UUID, res["server"]["id"]) + instance_uuids = self.instance_cache_by_uuid.keys() + self.assertIn(res["server"]["id"], instance_uuids) self._check_admin_pass_missing(res["server"]) def test_create_multiple_instances_resv_id_return(self): @@ -2136,7 +2133,8 @@ class ServersControllerCreateTest(test.TestCase): self.req.body = jsonutils.dump_as_bytes(self.body) res = self.controller.create(self.req, self.body).obj server = res['server'] - self.assertEqual(FAKE_UUID, server['id']) + instance = self.instance_cache_by_uuid.values()[0] + self.assertEqual(instance['uuid'], server['id']) def test_create_instance_image_ref_is_invalid(self): image_uuid = 'this_is_not_a_valid_uuid' @@ -2304,7 +2302,8 @@ class ServersControllerCreateTest(test.TestCase): server = res['server'] self._check_admin_pass_len(server) - self.assertEqual(FAKE_UUID, server['id']) + instance = self.instance_cache_by_uuid.values()[0] + self.assertEqual(instance['uuid'], server['id']) def test_create_instance_pass_disabled(self): self.flags(enable_instance_password=False) @@ -2313,7 +2312,8 @@ class ServersControllerCreateTest(test.TestCase): server = res['server'] self._check_admin_pass_missing(server) - self.assertEqual(FAKE_UUID, server['id']) + instance = self.instance_cache_by_uuid.values()[0] + self.assertEqual(instance['uuid'], server['id']) @mock.patch('nova.virt.hardware.numa_get_constraints') def test_create_instance_numa_topology_wrong(self, numa_constraints_mock): @@ -2404,7 +2404,8 @@ class ServersControllerCreateTest(test.TestCase): self.req.body = jsonutils.dump_as_bytes(self.body) res = self.controller.create(self.req, self.body).obj - self.assertEqual(FAKE_UUID, res["server"]["id"]) + instance = self.instance_cache_by_uuid.values()[0] + self.assertEqual(instance['uuid'], res["server"]["id"]) self._check_admin_pass_len(res["server"]) def test_create_instance_invalid_flavor_href(self): @@ -2441,7 +2442,8 @@ class ServersControllerCreateTest(test.TestCase): self.req.body = jsonutils.dump_as_bytes(self.body) res = self.controller.create(self.req, self.body).obj server = res['server'] - self.assertEqual(FAKE_UUID, server['id']) + instance = self.instance_cache_by_uuid.values()[0] + self.assertEqual(instance['uuid'], server['id']) def test_create_instance_with_bad_config_drive(self): self.ext_mgr.extensions = {'os-config-drive': 'fake'} @@ -2456,7 +2458,8 @@ class ServersControllerCreateTest(test.TestCase): self.req.body = jsonutils.dump_as_bytes(self.body) res = self.controller.create(self.req, self.body).obj server = res['server'] - self.assertEqual(FAKE_UUID, server['id']) + instance = self.instance_cache_by_uuid.values()[0] + self.assertEqual(instance['uuid'], server['id']) def test_create_instance_with_config_drive_disabled(self): config_drive = [{'config_drive': 'foo'}] @@ -2483,7 +2486,8 @@ class ServersControllerCreateTest(test.TestCase): res = self.controller.create(self.req, self.body).obj server = res['server'] - self.assertEqual(FAKE_UUID, server['id']) + instance = self.instance_cache_by_uuid.values()[0] + self.assertEqual(instance['uuid'], server['id']) def test_create_instance_admin_pass(self): self.body['server']['flavorRef'] = 3, @@ -2847,11 +2851,12 @@ class ServersControllerCreateTest(test.TestCase): self.controller.create, self.req, self.body) def test_create_location(self): - selfhref = 'http://localhost/v2/fake/servers/%s' % FAKE_UUID image_href = 'http://localhost/v2/images/%s' % self.image_uuid self.body['server']['imageRef'] = image_href self.req.body = jsonutils.dump_as_bytes(self.body) robj = self.controller.create(self.req, self.body) + instance = self.instance_cache_by_uuid.values()[0] + selfhref = 'http://localhost/v2/fake/servers/%s' % instance['uuid'] self.assertEqual(selfhref, robj['Location']) def _do_test_create_instance_above_quota(self, resource, allowed, quota, diff --git a/nova/tests/unit/api/openstack/compute/test_multiple_create.py b/nova/tests/unit/api/openstack/compute/test_multiple_create.py index 077ebf98489a..0424c1381e1a 100644 --- a/nova/tests/unit/api/openstack/compute/test_multiple_create.py +++ b/nova/tests/unit/api/openstack/compute/test_multiple_create.py @@ -14,7 +14,6 @@ # under the License. import datetime -import uuid from oslo_config import cfg import webob @@ -36,11 +35,6 @@ from nova.tests.unit import fake_instance from nova.tests.unit.image import fake CONF = cfg.CONF -FAKE_UUID = fakes.FAKE_UUID - - -def fake_gen_uuid(): - return FAKE_UUID def return_security_group(context, instance_id, security_group_id): @@ -76,7 +70,7 @@ class MultiCreateExtensionTestV21(test.TestCase): instance = fake_instance.fake_db_instance(**{ 'id': self.instance_cache_num, 'display_name': inst['display_name'] or 'test', - 'uuid': FAKE_UUID, + 'uuid': inst['uuid'], 'instance_type': inst_type, 'access_ip_v4': '1.2.3.4', 'access_ip_v6': 'fead::1234', @@ -124,7 +118,6 @@ class MultiCreateExtensionTestV21(test.TestCase): fakes.stub_out_key_pair_funcs(self.stubs) fake.stub_out_image_service(self) fakes.stub_out_nw_api(self) - self.stubs.Set(uuid, 'uuid4', fake_gen_uuid) self.stub_out('nova.db.instance_add_security_group', return_security_group) self.stub_out('nova.db.project_get_networks', project_get_networks) @@ -136,7 +129,6 @@ class MultiCreateExtensionTestV21(test.TestCase): server_update) self.stubs.Set(manager.VlanManager, 'allocate_fixed_ip', fake_method) - self.stub_out('nova.objects.RequestSpec.create', fake_method) self.req = fakes.HTTPRequest.blank('') def _test_create_extra(self, params, no_image=False, @@ -355,7 +347,8 @@ class MultiCreateExtensionTestV21(test.TestCase): res = self.controller.create(self.req, body=body).obj - self.assertEqual(FAKE_UUID, res["server"]["id"]) + instance_uuids = self.instance_cache_by_uuid.keys() + self.assertIn(res["server"]["id"], instance_uuids) self._check_admin_password_len(res["server"]) def test_create_multiple_instances_pass_disabled(self): @@ -378,7 +371,8 @@ class MultiCreateExtensionTestV21(test.TestCase): res = self.controller.create(self.req, body=body).obj - self.assertEqual(FAKE_UUID, res["server"]["id"]) + instance_uuids = self.instance_cache_by_uuid.keys() + self.assertIn(res["server"]["id"], instance_uuids) self._check_admin_password_missing(res["server"]) def _check_admin_password_len(self, server_dict): @@ -543,7 +537,7 @@ class MultiCreateExtensionTestV2(MultiCreateExtensionTestV21): instance = fake_instance.fake_db_instance(**{ 'id': self.instance_cache_num, 'display_name': inst['display_name'] or 'test', - 'uuid': FAKE_UUID, + 'uuid': inst['uuid'], 'instance_type': inst_type, 'access_ip_v4': '1.2.3.4', 'access_ip_v6': 'fead::1234', @@ -575,7 +569,6 @@ class MultiCreateExtensionTestV2(MultiCreateExtensionTestV21): fakes.stub_out_rate_limiting(self.stubs) fakes.stub_out_key_pair_funcs(self.stubs) fake.stub_out_image_service(self) - self.stubs.Set(uuid, 'uuid4', fake_gen_uuid) self.stub_out('nova.db.instance_create', instance_create) self.stub_out('nova.db.instance_get', instance_get) diff --git a/nova/tests/unit/api/openstack/compute/test_serversV21.py b/nova/tests/unit/api/openstack/compute/test_serversV21.py index 578ccc393e00..f4318588cd96 100644 --- a/nova/tests/unit/api/openstack/compute/test_serversV21.py +++ b/nova/tests/unit/api/openstack/compute/test_serversV21.py @@ -2390,7 +2390,6 @@ class ServersControllerCreateTest(test.TestCase): server_update_and_get_original) self.stubs.Set(manager.VlanManager, 'allocate_fixed_ip', fake_method) - self.stub_out('nova.objects.RequestSpec.create', fake_method) self.body = { 'server': { 'name': 'server_test', diff --git a/nova/tests/unit/compute/test_compute.py b/nova/tests/unit/compute/test_compute.py index 16602131be77..a53c2ee04261 100644 --- a/nova/tests/unit/compute/test_compute.py +++ b/nova/tests/unit/compute/test_compute.py @@ -255,12 +255,6 @@ class BaseTestCase(test.TestCase): fake_allocate_for_instance) self.compute_api = compute.API() - def fake_spec_create(*args, **kwargs): - pass - - # Tests in this module do not depend on this running. - self.stub_out('nova.objects.RequestSpec.create', fake_spec_create) - # Just to make long lines short self.rt = self.compute._get_resource_tracker(NODENAME)