Fix invalid uuid warnings in api testcases
Currently, unit testcases of api 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. Made changes to project_id in fakes.py to use valid project_id which removes warnings related to invalid uuids in testcases. Also made changes to project_id in JSON headers to use valid uuids in functional testcases same as that in unit testcases. [1] http://docs.openstack.org/developer/oslo.versionedobjects/api/fields.html#oslo_versionedobjects.fields.UUIDField Partial-Bug: #1557378 Change-Id: I5f69a2c3dc4d0279aed11750e6758b624debb64f
This commit is contained in:
parent
95ede914f8
commit
3e527265b6
@ -24,7 +24,7 @@
|
||||
"netmask": "255.255.255.248",
|
||||
"netmask_v6": null,
|
||||
"priority": null,
|
||||
"project_id": "1234",
|
||||
"project_id": "6133f8b603924f45bc0c9e21f6df12fa",
|
||||
"rxtx_base": null,
|
||||
"share_address": false,
|
||||
"updated_at": "2011-08-16T09:26:13.048257",
|
||||
|
@ -25,7 +25,7 @@
|
||||
"netmask": "255.255.255.248",
|
||||
"netmask_v6": null,
|
||||
"priority": null,
|
||||
"project_id": "1234",
|
||||
"project_id": "6133f8b603924f45bc0c9e21f6df12fa",
|
||||
"rxtx_base": null,
|
||||
"share_address": false,
|
||||
"updated_at": "2011-08-16T09:26:13.048257",
|
||||
|
@ -22,7 +22,7 @@
|
||||
"netmask": "%(ip)s",
|
||||
"netmask_v6": null,
|
||||
"priority": null,
|
||||
"project_id": "1234",
|
||||
"project_id": "6133f8b603924f45bc0c9e21f6df12fa",
|
||||
"rxtx_base": null,
|
||||
"updated_at": "%(strtime)s",
|
||||
"vlan": 100,
|
||||
|
@ -22,7 +22,7 @@
|
||||
"netmask": "%(ip)s",
|
||||
"netmask_v6": null,
|
||||
"priority": null,
|
||||
"project_id": "1234",
|
||||
"project_id": "6133f8b603924f45bc0c9e21f6df12fa",
|
||||
"rxtx_base": null,
|
||||
"updated_at": "%(strtime)s",
|
||||
"vlan": 100,
|
||||
|
@ -57,6 +57,7 @@ from nova.tests.unit import fake_network
|
||||
from nova.tests.unit.image import fake
|
||||
from nova.tests.unit import matchers
|
||||
from nova.tests.unit.objects import test_keypair
|
||||
from nova.tests import uuidsentinel as uuids
|
||||
from nova import utils as nova_utils
|
||||
|
||||
CONF = nova.conf.CONF
|
||||
@ -1477,7 +1478,7 @@ class ServersControllerDeleteTest(ControllerTest):
|
||||
self.server_delete_called = False
|
||||
|
||||
def fake_delete(api, context, instance):
|
||||
if instance.uuid == 'non-existent-uuid':
|
||||
if instance.uuid == uuids.non_existent_uuid:
|
||||
raise exception.InstanceNotFound(instance_id=instance.uuid)
|
||||
self.server_delete_called = True
|
||||
|
||||
@ -1504,7 +1505,7 @@ class ServersControllerDeleteTest(ControllerTest):
|
||||
def test_delete_server_instance_not_found(self):
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
self._delete_server_instance,
|
||||
uuid='non-existent-uuid')
|
||||
uuid=uuids.non_existent_uuid)
|
||||
|
||||
def test_delete_locked_server(self):
|
||||
req = self._create_delete_request(FAKE_UUID)
|
||||
|
@ -30,6 +30,7 @@ from nova import exception
|
||||
from nova import test
|
||||
from nova.tests.unit.api.openstack import fakes
|
||||
from nova.tests.unit.image import fake
|
||||
from nova.tests import uuidsentinel as uuids
|
||||
|
||||
CONF = cfg.CONF
|
||||
|
||||
@ -117,7 +118,7 @@ class BlockDeviceMappingTestV21(test.TestCase):
|
||||
self.mox.StubOutWithMock(compute_api.API, '_validate_bdm')
|
||||
self.mox.StubOutWithMock(compute_api.API, '_get_bdm_image_metadata')
|
||||
volume = {
|
||||
'id': 1,
|
||||
'id': uuids.volume_id,
|
||||
'status': 'active',
|
||||
'volume_image_metadata':
|
||||
{'test_key': 'test_value'}
|
||||
|
@ -23,6 +23,7 @@ from nova import network
|
||||
from nova.objects import virtual_interface as vif_obj
|
||||
from nova import test
|
||||
from nova.tests.unit.api.openstack import fakes
|
||||
from nova.tests import uuidsentinel as uuids
|
||||
|
||||
|
||||
FAKE_UUID = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'
|
||||
@ -35,12 +36,12 @@ def _generate_fake_vifs(context):
|
||||
vif = vif_obj.VirtualInterface(context=context)
|
||||
vif.address = '00-00-00-00-00-00'
|
||||
vif.net_uuid = 123
|
||||
vif.uuid = '00000000-0000-0000-0000-00000000000000000'
|
||||
vif.uuid = uuids.vif1_uuid
|
||||
fake_vifs = [vif]
|
||||
vif = vif_obj.VirtualInterface(context=context)
|
||||
vif.address = '11-11-11-11-11-11'
|
||||
vif.net_uuid = 456
|
||||
vif.uuid = '11111111-1111-1111-1111-11111111111111111'
|
||||
vif.uuid = uuids.vif2_uuid
|
||||
fake_vifs.append(vif)
|
||||
return fake_vifs
|
||||
|
||||
|
@ -24,13 +24,14 @@ from nova import exception
|
||||
from nova import test
|
||||
from nova.tests.unit.api.openstack import fakes
|
||||
from nova.tests.unit.objects import test_network
|
||||
from nova.tests import uuidsentinel as uuids
|
||||
|
||||
|
||||
fake_fixed_ips = [{'id': 1,
|
||||
'address': '192.168.1.1',
|
||||
'network_id': 1,
|
||||
'virtual_interface_id': 1,
|
||||
'instance_uuid': '1',
|
||||
'instance_uuid': uuids.instance_1,
|
||||
'allocated': False,
|
||||
'leased': False,
|
||||
'reserved': False,
|
||||
@ -45,7 +46,7 @@ fake_fixed_ips = [{'id': 1,
|
||||
'address': '192.168.1.2',
|
||||
'network_id': 1,
|
||||
'virtual_interface_id': 2,
|
||||
'instance_uuid': '2',
|
||||
'instance_uuid': uuids.instance_2,
|
||||
'allocated': False,
|
||||
'leased': False,
|
||||
'reserved': False,
|
||||
@ -60,7 +61,7 @@ fake_fixed_ips = [{'id': 1,
|
||||
'address': '10.0.0.2',
|
||||
'network_id': 1,
|
||||
'virtual_interface_id': 3,
|
||||
'instance_uuid': '3',
|
||||
'instance_uuid': uuids.instance_3,
|
||||
'allocated': False,
|
||||
'leased': False,
|
||||
'reserved': False,
|
||||
|
@ -26,6 +26,7 @@ from nova import exception
|
||||
from nova import objects
|
||||
from nova import test
|
||||
from nova.tests.unit.api.openstack import fakes
|
||||
from nova.tests import uuidsentinel as uuids
|
||||
|
||||
CONF = cfg.CONF
|
||||
|
||||
@ -92,7 +93,7 @@ class FloatingIPBulkV21(test.TestCase):
|
||||
|
||||
@mock.patch('nova.objects.FloatingIPList.get_all')
|
||||
def _test_list_ips_associated(self, req, mock_get):
|
||||
instance_uuid = "fake-uuid"
|
||||
instance_uuid = uuids.instance
|
||||
fixed_address = "10.0.0.1"
|
||||
floating_address = "192.168.0.1"
|
||||
fixed_ip = objects.FixedIP(instance_uuid=instance_uuid,
|
||||
|
@ -30,6 +30,7 @@ from nova import objects
|
||||
from nova import test
|
||||
from nova.tests.unit.api.openstack import fakes
|
||||
from nova.tests.unit import fake_instance
|
||||
from nova.tests import uuidsentinel as uuids
|
||||
|
||||
|
||||
TEST_HYPERS = [
|
||||
@ -98,10 +99,10 @@ TEST_HYPERS_OBJ = [objects.ComputeNode(**hyper_dct)
|
||||
TEST_HYPERS[0].update({'service': TEST_SERVICES[0]})
|
||||
TEST_HYPERS[1].update({'service': TEST_SERVICES[1]})
|
||||
|
||||
TEST_SERVERS = [dict(name="inst1", uuid="uuid1", host="compute1"),
|
||||
dict(name="inst2", uuid="uuid2", host="compute2"),
|
||||
dict(name="inst3", uuid="uuid3", host="compute1"),
|
||||
dict(name="inst4", uuid="uuid4", host="compute2")]
|
||||
TEST_SERVERS = [dict(name="inst1", uuid=uuids.instance_1, host="compute1"),
|
||||
dict(name="inst2", uuid=uuids.instance_2, host="compute2"),
|
||||
dict(name="inst3", uuid=uuids.instance_3, host="compute1"),
|
||||
dict(name="inst4", uuid=uuids.instance_4, host="compute2")]
|
||||
|
||||
|
||||
def fake_compute_node_get_all(context):
|
||||
@ -228,10 +229,10 @@ class HypervisorsTestV21(test.NoDBTestCase):
|
||||
False, self.TEST_SERVERS)
|
||||
expected_dict = copy.deepcopy(self.INDEX_HYPER_DICTS[0])
|
||||
expected_dict.update({'servers': [
|
||||
dict(name="inst1", uuid="uuid1"),
|
||||
dict(name="inst2", uuid="uuid2"),
|
||||
dict(name="inst3", uuid="uuid3"),
|
||||
dict(name="inst4", uuid="uuid4")]})
|
||||
dict(name="inst1", uuid=uuids.instance_1),
|
||||
dict(name="inst2", uuid=uuids.instance_2),
|
||||
dict(name="inst3", uuid=uuids.instance_3),
|
||||
dict(name="inst4", uuid=uuids.instance_4)]})
|
||||
|
||||
self.assertEqual(result, expected_dict)
|
||||
|
||||
@ -359,11 +360,11 @@ class HypervisorsTestV21(test.NoDBTestCase):
|
||||
|
||||
expected_dict = copy.deepcopy(self.INDEX_HYPER_DICTS)
|
||||
expected_dict[0].update({'servers': [
|
||||
dict(uuid="uuid1"),
|
||||
dict(uuid="uuid3")]})
|
||||
dict(uuid=uuids.instance_1),
|
||||
dict(uuid=uuids.instance_3)]})
|
||||
expected_dict[1].update({'servers': [
|
||||
dict(uuid="uuid2"),
|
||||
dict(uuid="uuid4")]})
|
||||
dict(uuid=uuids.instance_2),
|
||||
dict(uuid=uuids.instance_4)]})
|
||||
|
||||
for output in result['hypervisors']:
|
||||
servers = output['servers']
|
||||
|
@ -39,9 +39,11 @@ from nova.network.neutronv2 import api as neutron
|
||||
from nova import objects
|
||||
from nova import test
|
||||
from nova.tests.unit.api.openstack import fakes
|
||||
from nova.tests import uuidsentinel as uuids
|
||||
import nova.utils
|
||||
|
||||
CONF = cfg.CONF
|
||||
FAKE_NETWORK_PROJECT_ID = '6133f8b603924f45bc0c9e21f6df12fa'
|
||||
|
||||
UTC = iso8601.iso8601.Utc()
|
||||
FAKE_NETWORKS = [
|
||||
@ -50,10 +52,10 @@ FAKE_NETWORKS = [
|
||||
'dhcp_start': '10.0.0.3', 'bridge_interface': 'eth0',
|
||||
'updated_at': datetime.datetime(2011, 8, 16, 9, 26, 13, 48257,
|
||||
tzinfo=UTC),
|
||||
'id': 1, 'uuid': '20c8acc0-f747-4d71-a389-46d078ebf047',
|
||||
'id': 1, 'uuid': uuids.network_1,
|
||||
'cidr_v6': None, 'deleted_at': None,
|
||||
'gateway': '10.0.0.1', 'label': 'mynet_0',
|
||||
'project_id': '1234', 'rxtx_base': None,
|
||||
'project_id': FAKE_NETWORK_PROJECT_ID, 'rxtx_base': None,
|
||||
'vpn_private_address': '10.0.0.2', 'deleted': False,
|
||||
'vlan': 100, 'broadcast': '10.0.0.7',
|
||||
'netmask': '255.255.255.248', 'injected': False,
|
||||
@ -70,7 +72,7 @@ FAKE_NETWORKS = [
|
||||
'bridge': 'br101', 'vpn_public_port': 1001,
|
||||
'dhcp_start': '10.0.0.11', 'bridge_interface': 'eth0',
|
||||
'updated_at': None, 'id': 2, 'cidr_v6': None,
|
||||
'uuid': '20c8acc0-f747-4d71-a389-46d078ebf000',
|
||||
'uuid': uuids.network_2,
|
||||
'deleted_at': None, 'gateway': '10.0.0.9',
|
||||
'label': 'mynet_1', 'project_id': None,
|
||||
'vpn_private_address': '10.0.0.10', 'deleted': False,
|
||||
@ -92,13 +94,13 @@ FAKE_USER_NETWORKS = [
|
||||
'id': 1, 'cidr': '10.0.0.0/29', 'netmask': '255.255.255.248',
|
||||
'gateway': '10.0.0.1', 'broadcast': '10.0.0.7', 'dns1': None,
|
||||
'dns2': None, 'cidr_v6': None, 'gateway_v6': None, 'label': 'mynet_0',
|
||||
'netmask_v6': None, 'uuid': '20c8acc0-f747-4d71-a389-46d078ebf047',
|
||||
'netmask_v6': None, 'uuid': uuids.network_1,
|
||||
},
|
||||
{
|
||||
'id': 2, 'cidr': '10.0.0.10/29', 'netmask': '255.255.255.248',
|
||||
'gateway': '10.0.0.9', 'broadcast': '10.0.0.15', 'dns1': None,
|
||||
'dns2': None, 'cidr_v6': None, 'gateway_v6': None, 'label': 'mynet_1',
|
||||
'netmask_v6': None, 'uuid': '20c8acc0-f747-4d71-a389-46d078ebf000',
|
||||
'netmask_v6': None, 'uuid': uuids.network_2,
|
||||
},
|
||||
]
|
||||
|
||||
@ -336,15 +338,19 @@ class NetworksTestV21(test.NoDBTestCase):
|
||||
fakes.stub_out_networking(self)
|
||||
fakes.stub_out_rate_limiting(self.stubs)
|
||||
self.new_network = copy.deepcopy(NEW_NETWORK)
|
||||
self.non_admin_req = fakes.HTTPRequest.blank('')
|
||||
self.admin_req = fakes.HTTPRequest.blank('', use_admin_context=True)
|
||||
self.non_admin_req = fakes.HTTPRequest.blank(
|
||||
'', project_id=fakes.FAKE_PROJECT_ID)
|
||||
self.admin_req = fakes.HTTPRequest.blank('',
|
||||
project_id=fakes.FAKE_PROJECT_ID,
|
||||
use_admin_context=True)
|
||||
|
||||
def _setup(self):
|
||||
self.controller = networks_v21.NetworkController(
|
||||
self.fake_network_api)
|
||||
self.neutron_ctrl = networks_v21.NetworkController(
|
||||
neutron.API(skip_policy_check=True))
|
||||
self.req = fakes.HTTPRequest.blank('')
|
||||
self.req = fakes.HTTPRequest.blank('',
|
||||
project_id=fakes.FAKE_PROJECT_ID)
|
||||
|
||||
def _check_status(self, res, method, code):
|
||||
self.assertEqual(method.wsgi_code, code)
|
||||
@ -426,8 +432,10 @@ class NetworksTestV21(test.NoDBTestCase):
|
||||
uuid = FAKE_NETWORKS[1]['uuid']
|
||||
res = self.controller.add(self.req, body={'id': uuid})
|
||||
self._check_status(res, self.controller.add, 202)
|
||||
res_dict = self.controller.show(self.admin_req, uuid)
|
||||
self.assertEqual(res_dict['network']['project_id'], 'fake')
|
||||
res_dict = self.controller.show(self.admin_req,
|
||||
uuid)
|
||||
self.assertEqual(res_dict['network']['project_id'],
|
||||
fakes.FAKE_PROJECT_ID)
|
||||
|
||||
@mock.patch('nova.tests.unit.api.openstack.compute.test_networks.'
|
||||
'FakeNetworkAPI.add_network_to_project',
|
||||
@ -439,7 +447,8 @@ class NetworksTestV21(test.NoDBTestCase):
|
||||
|
||||
@mock.patch('nova.tests.unit.api.openstack.compute.test_networks.'
|
||||
'FakeNetworkAPI.add_network_to_project',
|
||||
side_effect=exception.NetworkNotFoundForUUID(uuid='fake_uuid'))
|
||||
side_effect=exception.
|
||||
NetworkNotFoundForUUID(uuid=fakes.FAKE_PROJECT_ID))
|
||||
def test_network_add_network_not_found_networks_fail(self, mock_add):
|
||||
uuid = FAKE_NETWORKS[1]['uuid']
|
||||
self.assertRaises(webob.exc.HTTPBadRequest, self.controller.add,
|
||||
@ -497,7 +506,9 @@ class NetworksTestV2(NetworksTestV21):
|
||||
ext_mgr)
|
||||
self.neutron_ctrl = networks.NetworkController(
|
||||
neutron.API(skip_policy_check=False))
|
||||
self.req = fakes.HTTPRequest.blank('', use_admin_context=True)
|
||||
self.req = fakes.HTTPRequest.blank('',
|
||||
project_id=fakes.FAKE_PROJECT_ID,
|
||||
use_admin_context=True)
|
||||
|
||||
def _check_status(self, res, method, code):
|
||||
self.assertEqual(res.status_int, code)
|
||||
|
@ -25,6 +25,7 @@ from nova.objects import pci_device_pool
|
||||
from nova import test
|
||||
from nova.tests.unit.api.openstack import fakes
|
||||
from nova.tests.unit.objects import test_pci_device
|
||||
from nova.tests import uuidsentinel as uuids
|
||||
|
||||
|
||||
pci_stats = [{"count": 3,
|
||||
@ -65,7 +66,7 @@ class PciServerControllerTestV21(test.NoDBTestCase):
|
||||
|
||||
def _create_fake_instance(self):
|
||||
self.inst = objects.Instance()
|
||||
self.inst.uuid = 'fake-inst-uuid'
|
||||
self.inst.uuid = uuids.instance
|
||||
self.inst.pci_devices = objects.PciDeviceList()
|
||||
|
||||
def _create_fake_pci_device(self):
|
||||
|
@ -28,6 +28,7 @@ from nova import exception
|
||||
from nova import policy
|
||||
from nova import test
|
||||
from nova.tests.unit.api.openstack import fakes
|
||||
from nova.tests import uuidsentinel as uuids
|
||||
|
||||
|
||||
def fake_instance_get(context, instance_id,
|
||||
@ -75,7 +76,7 @@ class ServerStartStopTestV21(test.TestCase):
|
||||
self.mox.ReplayAll()
|
||||
|
||||
body = dict(start="")
|
||||
self.controller._start_server(self.req, 'test_inst', body)
|
||||
self.controller._start_server(self.req, uuids.instance, body)
|
||||
|
||||
def test_start_policy_failed(self):
|
||||
rules = {
|
||||
@ -86,7 +87,7 @@ class ServerStartStopTestV21(test.TestCase):
|
||||
body = dict(start="")
|
||||
exc = self.assertRaises(exception.PolicyNotAuthorized,
|
||||
self.controller._start_server,
|
||||
self.req, 'test_inst', body)
|
||||
self.req, uuids.instance, body)
|
||||
self.assertIn(self.start_policy, exc.format_message())
|
||||
|
||||
def test_start_not_ready(self):
|
||||
@ -94,21 +95,21 @@ class ServerStartStopTestV21(test.TestCase):
|
||||
self.stubs.Set(compute_api.API, 'start', fake_start_stop_not_ready)
|
||||
body = dict(start="")
|
||||
self.assertRaises(webob.exc.HTTPConflict,
|
||||
self.controller._start_server, self.req, 'test_inst', body)
|
||||
self.controller._start_server, self.req, uuids.instance, body)
|
||||
|
||||
def test_start_locked_server(self):
|
||||
self.stub_out('nova.db.instance_get_by_uuid', fake_instance_get)
|
||||
self.stubs.Set(compute_api.API, 'start', fake_start_stop_locked_server)
|
||||
body = dict(start="")
|
||||
self.assertRaises(webob.exc.HTTPConflict,
|
||||
self.controller._start_server, self.req, 'test_inst', body)
|
||||
self.controller._start_server, self.req, uuids.instance, body)
|
||||
|
||||
def test_start_invalid_state(self):
|
||||
self.stub_out('nova.db.instance_get_by_uuid', fake_instance_get)
|
||||
self.stubs.Set(compute_api.API, 'start', fake_start_stop_invalid_state)
|
||||
body = dict(start="")
|
||||
ex = self.assertRaises(webob.exc.HTTPConflict,
|
||||
self.controller._start_server, self.req, 'test_inst', body)
|
||||
self.controller._start_server, self.req, uuids.instance, body)
|
||||
self.assertIn('is locked', six.text_type(ex))
|
||||
|
||||
def test_stop(self):
|
||||
@ -118,7 +119,7 @@ class ServerStartStopTestV21(test.TestCase):
|
||||
self.mox.ReplayAll()
|
||||
|
||||
body = dict(stop="")
|
||||
self.controller._stop_server(self.req, 'test_inst', body)
|
||||
self.controller._stop_server(self.req, uuids.instance, body)
|
||||
|
||||
def test_stop_policy_failed(self):
|
||||
rules = {
|
||||
@ -129,7 +130,7 @@ class ServerStartStopTestV21(test.TestCase):
|
||||
body = dict(stop="")
|
||||
exc = self.assertRaises(exception.PolicyNotAuthorized,
|
||||
self.controller._stop_server,
|
||||
self.req, 'test_inst', body)
|
||||
self.req, uuids.instance, body)
|
||||
self.assertIn(self.stop_policy, exc.format_message())
|
||||
|
||||
def test_stop_not_ready(self):
|
||||
@ -137,14 +138,14 @@ class ServerStartStopTestV21(test.TestCase):
|
||||
self.stubs.Set(compute_api.API, 'stop', fake_start_stop_not_ready)
|
||||
body = dict(stop="")
|
||||
self.assertRaises(webob.exc.HTTPConflict,
|
||||
self.controller._stop_server, self.req, 'test_inst', body)
|
||||
self.controller._stop_server, self.req, uuids.instance, body)
|
||||
|
||||
def test_stop_locked_server(self):
|
||||
self.stub_out('nova.db.instance_get_by_uuid', fake_instance_get)
|
||||
self.stubs.Set(compute_api.API, 'stop', fake_start_stop_locked_server)
|
||||
body = dict(stop="")
|
||||
ex = self.assertRaises(webob.exc.HTTPConflict,
|
||||
self.controller._stop_server, self.req, 'test_inst', body)
|
||||
self.controller._stop_server, self.req, uuids.instance, body)
|
||||
self.assertIn('is locked', six.text_type(ex))
|
||||
|
||||
def test_stop_invalid_state(self):
|
||||
@ -152,17 +153,17 @@ class ServerStartStopTestV21(test.TestCase):
|
||||
self.stubs.Set(compute_api.API, 'stop', fake_start_stop_invalid_state)
|
||||
body = dict(start="")
|
||||
self.assertRaises(webob.exc.HTTPConflict,
|
||||
self.controller._stop_server, self.req, 'test_inst', body)
|
||||
self.controller._stop_server, self.req, uuids.instance, body)
|
||||
|
||||
def test_start_with_bogus_id(self):
|
||||
body = dict(start="")
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
self.controller._start_server, self.req, 'test_inst', body)
|
||||
self.controller._start_server, self.req, uuids.instance, body)
|
||||
|
||||
def test_stop_with_bogus_id(self):
|
||||
body = dict(stop="")
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
self.controller._stop_server, self.req, 'test_inst', body)
|
||||
self.controller._stop_server, self.req, uuids.instance, body)
|
||||
|
||||
|
||||
class ServerStartStopTestV2(ServerStartStopTestV21):
|
||||
|
@ -65,6 +65,7 @@ from nova.tests.unit import fake_instance
|
||||
from nova.tests.unit import fake_network
|
||||
from nova.tests.unit.image import fake
|
||||
from nova.tests.unit import matchers
|
||||
from nova.tests import uuidsentinel as uuids
|
||||
from nova import utils as nova_utils
|
||||
|
||||
CONF = nova.conf.CONF
|
||||
@ -1528,7 +1529,7 @@ class ServersControllerDeleteTest(ControllerTest):
|
||||
self.server_delete_called = False
|
||||
|
||||
def fake_delete(api, context, instance):
|
||||
if instance.uuid == 'non-existent-uuid':
|
||||
if instance.uuid == uuids.non_existent_uuid:
|
||||
raise exception.InstanceNotFound(instance_id=instance.uuid)
|
||||
self.server_delete_called = True
|
||||
|
||||
@ -1555,7 +1556,7 @@ class ServersControllerDeleteTest(ControllerTest):
|
||||
def test_delete_server_instance_not_found(self):
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
self._delete_server_instance,
|
||||
uuid='non-existent-uuid')
|
||||
uuid=uuids.non_existent_uuid)
|
||||
|
||||
def test_delete_server_instance_while_building(self):
|
||||
req = self._create_delete_request(FAKE_UUID)
|
||||
|
@ -34,6 +34,7 @@ from nova import policy
|
||||
from nova import test
|
||||
from nova.tests.unit.api.openstack import fakes
|
||||
from nova.tests.unit import fake_flavor
|
||||
from nova.tests import uuidsentinel as uuids
|
||||
|
||||
SERVERS = 5
|
||||
TENANTS = 2
|
||||
@ -70,7 +71,7 @@ def get_fake_db_instance(start, end, instance_id, tenant_id,
|
||||
vm_state=vm_states.ACTIVE):
|
||||
inst = fakes.stub_instance(
|
||||
id=instance_id,
|
||||
uuid='00000000-0000-0000-0000-00000000000000%02d' % instance_id,
|
||||
uuid=getattr(uuids, 'instance_%d' % instance_id),
|
||||
image_ref='1',
|
||||
project_id=tenant_id,
|
||||
user_id='fakeuser',
|
||||
@ -198,15 +199,15 @@ class SimpleTenantUsageTestV21(test.TestCase):
|
||||
usage = res_dict['tenant_usage']
|
||||
servers = usage['server_usages']
|
||||
self.assertEqual(TENANTS * SERVERS, len(usage['server_usages']))
|
||||
uuids = ['00000000-0000-0000-0000-00000000000000%02d' %
|
||||
x for x in range(SERVERS)]
|
||||
server_uuids = [getattr(uuids, 'instance_%d' % x)
|
||||
for x in range(SERVERS)]
|
||||
for j in range(SERVERS):
|
||||
delta = STOP - START
|
||||
# NOTE(javeme): cast seconds from float to int for clarity
|
||||
uptime = int(delta.total_seconds())
|
||||
self.assertEqual(uptime, int(servers[j]['uptime']))
|
||||
self.assertEqual(HOURS, int(servers[j]['hours']))
|
||||
self.assertIn(servers[j]['instance_id'], uuids)
|
||||
self.assertIn(servers[j]['instance_id'], server_uuids)
|
||||
|
||||
def test_verify_show_cannot_view_other_tenant(self):
|
||||
req = fakes.HTTPRequest.blank('?start=%s&end=%s' %
|
||||
|
@ -27,6 +27,7 @@ from nova import network
|
||||
from nova.objects import virtual_interface as vif_obj
|
||||
from nova import test
|
||||
from nova.tests.unit.api.openstack import fakes
|
||||
from nova.tests import uuidsentinel as uuids
|
||||
|
||||
|
||||
FAKE_UUID = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'
|
||||
@ -42,13 +43,13 @@ def _generate_fake_vifs(context):
|
||||
vif.address = '00-00-00-00-00-00'
|
||||
vif.network_id = 123
|
||||
vif.net_uuid = '22222222-2222-2222-2222-22222222222222222'
|
||||
vif.uuid = '00000000-0000-0000-0000-00000000000000000'
|
||||
vif.uuid = uuids.vif1_uuid
|
||||
fake_vifs = [vif]
|
||||
vif = vif_obj.VirtualInterface(context=context)
|
||||
vif.address = '11-11-11-11-11-11'
|
||||
vif.network_id = 456
|
||||
vif.net_uuid = '33333333-3333-3333-3333-33333333333333333'
|
||||
vif.uuid = '11111111-1111-1111-1111-11111111111111111'
|
||||
vif.uuid = uuids.vif2_uuid
|
||||
fake_vifs.append(vif)
|
||||
return fake_vifs
|
||||
|
||||
@ -66,9 +67,9 @@ class ServerVirtualInterfaceTestV21(test.NoDBTestCase):
|
||||
wsgi_api_version = None
|
||||
expected_response = {
|
||||
'virtual_interfaces': [
|
||||
{'id': '00000000-0000-0000-0000-00000000000000000',
|
||||
{'id': uuids.vif1_uuid,
|
||||
'mac_address': '00-00-00-00-00-00'},
|
||||
{'id': '11111111-1111-1111-1111-11111111111111111',
|
||||
{'id': uuids.vif2_uuid,
|
||||
'mac_address': '11-11-11-11-11-11'}]}
|
||||
|
||||
def setUp(self):
|
||||
@ -128,10 +129,10 @@ class ServerVirtualInterfaceTestV212(ServerVirtualInterfaceTestV21):
|
||||
|
||||
expected_response = {
|
||||
'virtual_interfaces': [
|
||||
{'id': '00000000-0000-0000-0000-00000000000000000',
|
||||
{'id': uuids.vif1_uuid,
|
||||
'mac_address': '00-00-00-00-00-00',
|
||||
'net_id': '22222222-2222-2222-2222-22222222222222222'},
|
||||
{'id': '11111111-1111-1111-1111-11111111111111111',
|
||||
{'id': uuids.vif2_uuid,
|
||||
'mac_address': '11-11-11-11-11-11',
|
||||
'net_id': '33333333-3333-3333-3333-33333333333333333'}]}
|
||||
|
||||
|
@ -55,6 +55,7 @@ QUOTAS = quota.QUOTAS
|
||||
|
||||
|
||||
FAKE_UUID = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'
|
||||
FAKE_PROJECT_ID = '6a6a9c9eee154e9cb8cec487b98d36ab'
|
||||
FAKE_UUIDS = {}
|
||||
|
||||
|
||||
@ -252,10 +253,13 @@ class HTTPRequest(os_wsgi.Request):
|
||||
def blank(*args, **kwargs):
|
||||
kwargs['base_url'] = 'http://localhost/v2'
|
||||
use_admin_context = kwargs.pop('use_admin_context', False)
|
||||
project_id = kwargs.pop('project_id', 'fake')
|
||||
version = kwargs.pop('version', os_wsgi.DEFAULT_API_VERSION)
|
||||
out = os_wsgi.Request.blank(*args, **kwargs)
|
||||
out.environ['nova.context'] = FakeRequestContext('fake_user', 'fake',
|
||||
is_admin=use_admin_context)
|
||||
out.environ['nova.context'] = FakeRequestContext(
|
||||
user_id='fake_user',
|
||||
project_id=project_id,
|
||||
is_admin=use_admin_context)
|
||||
out.api_version_request = api_version.APIVersionRequest(version)
|
||||
return out
|
||||
|
||||
@ -266,11 +270,14 @@ class HTTPRequestV21(os_wsgi.Request):
|
||||
def blank(*args, **kwargs):
|
||||
kwargs['base_url'] = 'http://localhost/v2'
|
||||
use_admin_context = kwargs.pop('use_admin_context', False)
|
||||
project_id = kwargs.pop('project_id', 'fake')
|
||||
version = kwargs.pop('version', os_wsgi.DEFAULT_API_VERSION)
|
||||
out = os_wsgi.Request.blank(*args, **kwargs)
|
||||
out.api_version_request = api_version.APIVersionRequest(version)
|
||||
out.environ['nova.context'] = FakeRequestContext('fake_user', 'fake',
|
||||
is_admin=use_admin_context)
|
||||
out.environ['nova.context'] = FakeRequestContext(
|
||||
user_id='fake_user',
|
||||
project_id=project_id,
|
||||
is_admin=use_admin_context)
|
||||
return out
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user