summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2014-03-06 12:29:04 +0000
committerGerrit Code Review <review@openstack.org>2014-03-06 12:29:04 +0000
commit1b790cc59720edd0cc77b3b5fb2114ce4c56b1ce (patch)
tree802190b2337aa25935f3f1dcb55763c4c49cbe79
parent6aaf436891efc340914b50d9c1069aeb4c076d22 (diff)
parentd3c8757dfc59a30ca4a8bf2ab8c1d610b4fd8a2a (diff)
downloadnova-1b790cc59720edd0cc77b3b5fb2114ce4c56b1ce.tar.gz
Merge "Remove unneeded call to conductor in network interface" into stable/havana
-rw-r--r--nova/network/neutronv2/api.py22
-rw-r--r--nova/tests/network/test_neutronv2.py39
2 files changed, 26 insertions, 35 deletions
diff --git a/nova/network/neutronv2/api.py b/nova/network/neutronv2/api.py
index 61476ae02c..3efe77ec6b 100644
--- a/nova/network/neutronv2/api.py
+++ b/nova/network/neutronv2/api.py
@@ -20,6 +20,7 @@ import time
from neutronclient.common import exceptions as neutron_client_exc
from oslo.config import cfg
+import six
from nova.compute import flavors
from nova import conductor
@@ -991,12 +992,15 @@ class API(base.Base):
data = client.list_ports(**search_opts)
ports = data.get('ports', [])
nw_info = network_model.NetworkInfo()
+
+ # Unfortunately, this is sometimes in unicode and sometimes not
+ if isinstance(instance['info_cache']['network_info'], six.text_type):
+ ifaces = jsonutils.loads(instance['info_cache']['network_info'])
+ else:
+ ifaces = instance['info_cache']['network_info']
+
if networks is None:
- # retrieve networks from info_cache to get correct nic order
- network_cache = self.conductor_api.instance_get_by_uuid(
- context, instance['uuid'])['info_cache']['network_info']
- network_cache = jsonutils.loads(network_cache)
- net_ids = [iface['network']['id'] for iface in network_cache]
+ net_ids = [iface['network']['id'] for iface in ifaces]
networks = self._get_available_networks(context,
instance['project_id'],
net_ids)
@@ -1004,14 +1008,6 @@ class API(base.Base):
# ensure ports are in preferred network order, and filter out
# those not attached to one of the provided list of networks
else:
-
- # Unfortunately, this is sometimes in unicode and sometimes not
- if isinstance(instance['info_cache']['network_info'], unicode):
- ifaces = jsonutils.loads(
- instance['info_cache']['network_info'])
- else:
- ifaces = instance['info_cache']['network_info']
-
# Include existing interfaces so they are not removed from the db.
# Needed when interfaces are added to existing instances.
for iface in ifaces:
diff --git a/nova/tests/network/test_neutronv2.py b/nova/tests/network/test_neutronv2.py
index 04ec25de70..a6d150b5c6 100644
--- a/nova/tests/network/test_neutronv2.py
+++ b/nova/tests/network/test_neutronv2.py
@@ -15,12 +15,14 @@
#
# vim: tabstop=4 shiftwidth=4 softtabstop=4
+import copy
import uuid
import mox
from neutronclient.common import exceptions
from neutronclient.v2_0 import client
from oslo.config import cfg
+import six
from nova.compute import flavors
from nova.conductor import api as conductor_api
@@ -401,18 +403,14 @@ class TestNeutronv2Base(test.TestCase):
self.instance['uuid'],
mox.IgnoreArg())
port_data = number == 1 and self.port_data1 or self.port_data2
- nets = number == 1 and self.nets1 or self.nets2
- self.mox.StubOutWithMock(conductor_api.API,
- 'instance_get_by_uuid')
-
net_info_cache = []
for port in port_data:
net_info_cache.append({"network": {"id": port['network_id']}})
- info_cache = {'info_cache': {'network_info':
- jsonutils.dumps(net_info_cache)}}
+ instance = copy.copy(self.instance)
+ # This line here does not wrap net_info_cache in jsonutils.dumps()
+ # intentionally to test the other code path when it's not unicode.
+ instance['info_cache'] = {'network_info': net_info_cache}
- api.conductor_api.instance_get_by_uuid(
- mox.IgnoreArg(), mox.IgnoreArg()).AndReturn(info_cache)
self.moxed_client.list_ports(
tenant_id=self.instance['project_id'],
device_id=self.instance['uuid']).AndReturn(
@@ -439,7 +437,7 @@ class TestNeutronv2Base(test.TestCase):
device_owner='network:dhcp').AndReturn(
{'ports': []})
self.mox.ReplayAll()
- nw_inf = api.get_instance_nw_info(self.context, self.instance)
+ nw_inf = api.get_instance_nw_info(self.context, instance)
for i in xrange(0, number):
self._verify_nw_info(nw_inf, i)
@@ -579,16 +577,15 @@ class TestNeutronv2(TestNeutronv2Base):
net_info_cache = []
for port in self.port_data3:
net_info_cache.append({"network": {"id": port['network_id']}})
- info_cache = {'info_cache': {'network_info':
- jsonutils.dumps(net_info_cache)}}
-
- api.conductor_api.instance_get_by_uuid(
- mox.IgnoreArg(), mox.IgnoreArg()).AndReturn(info_cache)
+ instance = copy.copy(self.instance)
+ instance['info_cache'] = {'network_info':
+ six.text_type(
+ jsonutils.dumps(net_info_cache))}
self.mox.ReplayAll()
nw_inf = api.get_instance_nw_info(self.context,
- self.instance)
+ instance)
id_suffix = 3
self.assertEquals(0, len(nw_inf.fixed_ips()))
@@ -890,17 +887,15 @@ class TestNeutronv2(TestNeutronv2Base):
port_data = number == 1 and self.port_data1 or self.port_data2
nets = number == 1 and self.nets1 or self.nets2
self.moxed_client.delete_port(port_data[0]['id'])
- self.mox.StubOutWithMock(conductor_api.API,
- 'instance_get_by_uuid')
net_info_cache = []
for port in port_data:
net_info_cache.append({"network": {"id": port['network_id']}})
- info_cache = {'info_cache': {'network_info':
- jsonutils.dumps(net_info_cache)}}
+ instance = copy.copy(self.instance)
+ instance['info_cache'] = {'network_info':
+ six.text_type(
+ jsonutils.dumps(net_info_cache))}
api = neutronapi.API()
- api.conductor_api.instance_get_by_uuid(
- mox.IgnoreArg(), mox.IgnoreArg()).AndReturn(info_cache)
neutronv2.get_client(mox.IgnoreArg(), admin=True).AndReturn(
self.moxed_client)
self.moxed_client.list_ports(
@@ -924,7 +919,7 @@ class TestNeutronv2(TestNeutronv2Base):
self.mox.ReplayAll()
- nwinfo = api.deallocate_port_for_instance(self.context, self.instance,
+ nwinfo = api.deallocate_port_for_instance(self.context, instance,
port_data[0]['id'])
self.assertEqual(len(nwinfo), len(port_data[1:]))
if len(port_data) > 1: