From 6bd44ccb3a4bf8536f6bca9b81517d2b24c31f14 Mon Sep 17 00:00:00 2001 From: Brian Waldon Date: Thu, 10 Nov 2011 20:45:55 -0500 Subject: Converting fixed ip calls to use instance objects Related to blueprint internal-uuids Change-Id: Ifad7a6ac39b0455f77602d9744f64425ebb3f49c --- .../api/openstack/contrib/test_multinic_xs.py | 26 +++++++++++++--------- nova/tests/test_compute.py | 7 ++++++ 2 files changed, 23 insertions(+), 10 deletions(-) (limited to 'nova/tests') diff --git a/nova/tests/api/openstack/contrib/test_multinic_xs.py b/nova/tests/api/openstack/contrib/test_multinic_xs.py index cecc4af4f..90999a384 100644 --- a/nova/tests/api/openstack/contrib/test_multinic_xs.py +++ b/nova/tests/api/openstack/contrib/test_multinic_xs.py @@ -23,20 +23,25 @@ from nova import test from nova.tests.api.openstack import fakes +UUID = '70f6db34-de8d-4fbd-aafb-4065bdfa6114' last_add_fixed_ip = (None, None) last_remove_fixed_ip = (None, None) -def compute_api_add_fixed_ip(self, context, instance_id, network_id): +def compute_api_add_fixed_ip(self, context, instance, network_id): global last_add_fixed_ip - last_add_fixed_ip = (instance_id, network_id) + last_add_fixed_ip = (instance['uuid'], network_id) -def compute_api_remove_fixed_ip(self, context, instance_id, address): +def compute_api_remove_fixed_ip(self, context, instance, address): global last_remove_fixed_ip - last_remove_fixed_ip = (instance_id, address) + last_remove_fixed_ip = (instance['uuid'], address) + + +def compute_api_get(self, context, instance_id): + return {'id': 1, 'uuid': instance_id} class FixedIpTest(test.TestCase): @@ -48,6 +53,7 @@ class FixedIpTest(test.TestCase): compute_api_add_fixed_ip) self.stubs.Set(compute.api.API, "remove_fixed_ip", compute_api_remove_fixed_ip) + self.stubs.Set(compute.api.API, 'get', compute_api_get) self.context = context.get_admin_context() def test_add_fixed_ip(self): @@ -55,21 +61,21 @@ class FixedIpTest(test.TestCase): last_add_fixed_ip = (None, None) body = dict(addFixedIp=dict(networkId='test_net')) - req = webob.Request.blank('/v1.1/123/servers/test_inst/action') + req = webob.Request.blank('/v1.1/123/servers/%s/action' % UUID) req.method = 'POST' req.body = json.dumps(body) req.headers['content-type'] = 'application/json' resp = req.get_response(fakes.wsgi_app()) self.assertEqual(resp.status_int, 202) - self.assertEqual(last_add_fixed_ip, ('test_inst', 'test_net')) + self.assertEqual(last_add_fixed_ip, (UUID, 'test_net')) def test_add_fixed_ip_no_network(self): global last_add_fixed_ip last_add_fixed_ip = (None, None) body = dict(addFixedIp=dict()) - req = webob.Request.blank('/v1.1/123/servers/test_inst/action') + req = webob.Request.blank('/v1.1/123/servers/%s/action' % UUID) req.method = 'POST' req.body = json.dumps(body) req.headers['content-type'] = 'application/json' @@ -83,21 +89,21 @@ class FixedIpTest(test.TestCase): last_remove_fixed_ip = (None, None) body = dict(removeFixedIp=dict(address='10.10.10.1')) - req = webob.Request.blank('/v1.1/123/servers/test_inst/action') + req = webob.Request.blank('/v1.1/123/servers/%s/action' % UUID) req.method = 'POST' req.body = json.dumps(body) req.headers['content-type'] = 'application/json' resp = req.get_response(fakes.wsgi_app()) self.assertEqual(resp.status_int, 202) - self.assertEqual(last_remove_fixed_ip, ('test_inst', '10.10.10.1')) + self.assertEqual(last_remove_fixed_ip, (UUID, '10.10.10.1')) def test_remove_fixed_ip_no_address(self): global last_remove_fixed_ip last_remove_fixed_ip = (None, None) body = dict(removeFixedIp=dict()) - req = webob.Request.blank('/v1.1/123/servers/test_inst/action') + req = webob.Request.blank('/v1.1/123/servers/%s/action' % UUID) req.method = 'POST' req.body = json.dumps(body) req.headers['content-type'] = 'application/json' diff --git a/nova/tests/test_compute.py b/nova/tests/test_compute.py index 9cf580b1f..a4d86deec 100644 --- a/nova/tests/test_compute.py +++ b/nova/tests/test_compute.py @@ -1833,3 +1833,10 @@ class ComputeAPITestCase(BaseTestCase): i_ref = db.instance_get(self.context, instance_id) self.assertEqual(i_ref['name'], i_ref['uuid']) db.instance_destroy(self.context, i_ref['id']) + + def test_add_remove_fixed_ip(self): + instance_id = self._create_instance() + instance = self.compute_api.get(self.context, instance_id) + self.compute_api.add_fixed_ip(self.context, instance, '1') + self.compute_api.remove_fixed_ip(self.context, instance, '192.168.1.1') + self.compute_api.delete(self.context, instance) -- cgit