summaryrefslogtreecommitdiffstats
path: root/nova/tests
diff options
context:
space:
mode:
authorTrey Morris <treyemorris@gmail.com>2012-06-15 16:35:31 -0500
committerTrey Morris <treyemorris@gmail.com>2012-06-18 13:31:56 -0500
commit82599c77346bbefd550ea4ee6c0b13a3df4950af (patch)
tree5178e194b41705fc264eca182cebe42535ff83a7 /nova/tests
parent4d9545260509d238e7ba809d39b3a4e602f5777b (diff)
moved update cache functionality to the network api
previously the network manager get_instance_nw_info was responsible for updating the cache. This is to prevent calling that function in a confusing way. part 2 of this patch was fixing bug997763 floating_ip_associate was removed from the compute api. network api associate is now called directly. network api floating_ip functions now require instance as an argument in order to update cache. Change-Id: Ie8daa017b99e48769afbac4862696ef0a8eb1067
Diffstat (limited to 'nova/tests')
-rw-r--r--nova/tests/api/ec2/test_cloud.py9
-rw-r--r--nova/tests/api/openstack/compute/contrib/test_floating_ips.py16
-rw-r--r--nova/tests/compute/test_compute.py43
-rw-r--r--nova/tests/network/test_manager.py4
4 files changed, 21 insertions, 51 deletions
diff --git a/nova/tests/api/ec2/test_cloud.py b/nova/tests/api/ec2/test_cloud.py
index afb906f45..41818de1b 100644
--- a/nova/tests/api/ec2/test_cloud.py
+++ b/nova/tests/api/ec2/test_cloud.py
@@ -39,6 +39,7 @@ from nova import flags
from nova.image import fake
from nova.image import s3
from nova import log as logging
+from nova.network import api as network_api
from nova import rpc
from nova import test
from nova import utils
@@ -233,8 +234,14 @@ class CloudTestCase(test.TestCase):
project_id=project_id)
fixed_ips = nw_info.fixed_ips()
-
ec2_id = ec2utils.id_to_ec2_id(inst['id'])
+
+ self.stubs.Set(ec2utils, 'get_ip_info_for_instance',
+ lambda *args: {'fixed_ips': ['10.0.0.1'],
+ 'fixed_ip6s': [],
+ 'floating_ips': []})
+ self.stubs.Set(network_api.API, 'get_instance_id_by_floating_address',
+ lambda *args: 1)
self.cloud.associate_address(self.context,
instance_id=ec2_id,
public_ip=address)
diff --git a/nova/tests/api/openstack/compute/contrib/test_floating_ips.py b/nova/tests/api/openstack/compute/contrib/test_floating_ips.py
index 9a3a72d55..b1f87c6df 100644
--- a/nova/tests/api/openstack/compute/contrib/test_floating_ips.py
+++ b/nova/tests/api/openstack/compute/contrib/test_floating_ips.py
@@ -19,6 +19,7 @@ import webob
from nova.api.openstack.compute.contrib import floating_ips
from nova import compute
+from nova.compute import utils as compute_utils
from nova import context
from nova import db
from nova import exception
@@ -56,7 +57,7 @@ def network_api_get_floating_ips_by_project(self, context):
{'id': 2,
'pool': 'nova', 'interface': 'eth0',
'address': '10.10.10.11',
- 'fixed_ip_id': None}]
+ 'fixed_ip_id': None}]
def compute_api_get(self, context, instance_id):
@@ -79,7 +80,7 @@ def network_api_associate(self, context, floating_address, fixed_address):
pass
-def network_api_disassociate(self, context, floating_address):
+def network_api_disassociate(self, context, instance, floating_address):
pass
@@ -92,6 +93,12 @@ def fake_instance_get(context, instance_id):
"project_id": '123'}
+def stub_nw_info(stubs):
+ def get_nw_info_for_instance(instance):
+ return fake_network.fake_get_instance_nw_info(stubs, spectacular=True)
+ return get_nw_info_for_instance
+
+
class FloatingIpTest(test.TestCase):
floating_ip = "10.10.10.10"
@@ -122,9 +129,8 @@ class FloatingIpTest(test.TestCase):
network_api_release)
self.stubs.Set(network.api.API, "disassociate_floating_ip",
network_api_disassociate)
-
- fake_network.fake_get_instance_nw_info(self.stubs, 1, 1,
- spectacular=True)
+ self.stubs.Set(compute_utils, "get_nw_info_for_instance",
+ stub_nw_info(self.stubs))
fake_network.stub_out_nw_api_get_instance_nw_info(self.stubs,
spectacular=True)
diff --git a/nova/tests/compute/test_compute.py b/nova/tests/compute/test_compute.py
index 92e5d193c..35fa6de23 100644
--- a/nova/tests/compute/test_compute.py
+++ b/nova/tests/compute/test_compute.py
@@ -2875,49 +2875,6 @@ class ComputeAPITestCase(BaseTestCase):
finally:
self.compute.terminate_instance(context, instance['uuid'])
- def test_associate_floating_ip(self):
- """Ensure we can associate a floating ip with an instance"""
- called = {'associate': False}
-
- def fake_associate_ip_network_api(self, ctxt, floating_address,
- fixed_address):
- called['associate'] = True
-
- self.stubs.Set(nova.network.API, 'associate_floating_ip',
- fake_associate_ip_network_api)
-
- instance = self._create_fake_instance()
- instance_uuid = instance['uuid']
- address = '0.1.2.3'
-
- self.compute.run_instance(self.context, instance_uuid)
- self.compute_api.associate_floating_ip(self.context,
- instance,
- address)
- self.assertTrue(called['associate'])
- self.compute.terminate_instance(self.context, instance_uuid)
-
- def test_associate_floating_ip_no_fixed_ip(self):
- """Should fail if instance has no fixed ip."""
-
- def fake_get_nw_info(self, ctxt, instance):
- return []
-
- self.stubs.Set(nova.network.API, 'get_instance_nw_info',
- fake_get_nw_info)
-
- instance = self._create_fake_instance()
- instance_uuid = instance['uuid']
- address = '0.1.2.3'
-
- self.compute.run_instance(self.context, instance_uuid)
- self.assertRaises(exception.FixedIpNotFoundForInstance,
- self.compute_api.associate_floating_ip,
- self.context,
- instance,
- address)
- self.compute.terminate_instance(self.context, instance_uuid)
-
def test_get(self):
"""Test get instance"""
c = context.get_admin_context()
diff --git a/nova/tests/network/test_manager.py b/nova/tests/network/test_manager.py
index 15dc68396..817b7271d 100644
--- a/nova/tests/network/test_manager.py
+++ b/nova/tests/network/test_manager.py
@@ -699,7 +699,7 @@ class VlanNetworkTestCase(test.TestCase):
self.local = True
self.stubs.Set(self.network.db, 'fixed_ip_get_by_address', fake4)
self.stubs.Set(self.network.db, 'network_get', fake4_network)
- self.stubs.Set(rpc, 'cast', fake6)
+ self.stubs.Set(rpc, 'call', fake6)
self.network.associate_floating_ip(ctxt, mox.IgnoreArg(),
mox.IgnoreArg())
self.assertFalse(self.local)
@@ -817,7 +817,7 @@ class VlanNetworkTestCase(test.TestCase):
self.local = True
self.stubs.Set(self.network.db, 'fixed_ip_get', fake4)
self.stubs.Set(self.network.db, 'network_get', fake4_network)
- self.stubs.Set(rpc, 'cast', fake6)
+ self.stubs.Set(rpc, 'call', fake6)
self.network.disassociate_floating_ip(ctxt, mox.IgnoreArg())
self.assertFalse(self.local)