summaryrefslogtreecommitdiffstats
path: root/nova/tests
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2011-11-11 21:27:27 +0000
committerGerrit Code Review <review@openstack.org>2011-11-11 21:27:27 +0000
commit615c4df3201fce7ae95c1b50bcec7f212cfc2aa6 (patch)
tree48c2cf2bb2d51f2a621d3175154b8636ebddaf55 /nova/tests
parentf492fced12078733c8a84e69d222ec52c2fce609 (diff)
parent6bd44ccb3a4bf8536f6bca9b81517d2b24c31f14 (diff)
Merge "Converting fixed ip calls to use instance objects"
Diffstat (limited to 'nova/tests')
-rw-r--r--nova/tests/api/openstack/contrib/test_multinic_xs.py26
-rw-r--r--nova/tests/test_compute.py7
2 files changed, 23 insertions, 10 deletions
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 d74c96757..bf3c1ea59 100644
--- a/nova/tests/test_compute.py
+++ b/nova/tests/test_compute.py
@@ -1875,3 +1875,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)