summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2016-06-07 20:54:11 +0000
committerGerrit Code Review <review@openstack.org>2016-06-07 20:54:12 +0000
commitebbbcc6b110be9599f7c4ffbefc1ff8f1945c874 (patch)
tree9440a8aab4f4bba869000c4387ab3fe28018390e
parent7495bbeadbe61a6b96bd0f39514651d819d16189 (diff)
parentce392292353c2b289aa3247b3c401f1cf7e1506c (diff)
downloadnova-ebbbcc6b110be9599f7c4ffbefc1ff8f1945c874.tar.gz
Merge "network: Don't repopulate instance info cache from Neutron ports" into stable/liberty12.0.4
-rw-r--r--nova/network/neutronv2/api.py5
-rw-r--r--nova/tests/unit/network/test_neutronv2.py43
2 files changed, 39 insertions, 9 deletions
diff --git a/nova/network/neutronv2/api.py b/nova/network/neutronv2/api.py
index 7fb31c947b..2b0298d40f 100644
--- a/nova/network/neutronv2/api.py
+++ b/nova/network/neutronv2/api.py
@@ -1722,11 +1722,6 @@ class API(base_api.NetworkAPI):
current_neutron_port_map[current_neutron_port['id']] = (
current_neutron_port)
- # In that case we should repopulate ports from the state of
- # Neutron.
- if not port_ids:
- port_ids = current_neutron_port_map.keys()
-
for port_id in port_ids:
current_neutron_port = current_neutron_port_map.get(port_id)
if current_neutron_port:
diff --git a/nova/tests/unit/network/test_neutronv2.py b/nova/tests/unit/network/test_neutronv2.py
index 295c672909..25aca611ed 100644
--- a/nova/tests/unit/network/test_neutronv2.py
+++ b/nova/tests/unit/network/test_neutronv2.py
@@ -723,6 +723,21 @@ class TestNeutronv2(TestNeutronv2Base):
None,
None)
+ def test_get_instance_nw_info_ignores_neutron_ports_empty_cache(self):
+ # Tests that ports returned from neutron that match the same
+ # instance_id/device_id are ignored when the instance info cache is
+ # empty.
+ port_data2 = copy.copy(self.port_data2)
+
+ # set device_id on the ports to be the same.
+ port_data2[1]['device_id'] = port_data2[0]['device_id']
+ network_cache = {'info_cache': {'network_info': []}}
+
+ self._fake_get_instance_nw_info_helper(network_cache,
+ port_data2,
+ None,
+ None)
+
def _fake_get_instance_nw_info_helper(self, network_cache,
current_neutron_ports,
networks=None, port_ids=None):
@@ -762,8 +777,26 @@ class TestNeutronv2(TestNeutronv2Base):
'tenant_id': iface['network']['meta']['tenant_id']}
for iface in ifaces]
if networks is None:
- self.moxed_client.list_networks(
- id=net_ids).AndReturn({'networks': nets})
+ if ifaces:
+ self.moxed_client.list_networks(
+ id=net_ids).AndReturn({'networks': nets})
+ else:
+ non_shared_nets = [
+ {'id': iface['network']['id'],
+ 'name': iface['network']['label'],
+ 'tenant_id': iface['network']['meta']['tenant_id']}
+ for iface in ifaces if not iface['shared']]
+ shared_nets = [
+ {'id': iface['network']['id'],
+ 'name': iface['network']['label'],
+ 'tenant_id': iface['network']['meta']['tenant_id']}
+ for iface in ifaces if iface['shared']]
+ self.moxed_client.list_networks(
+ shared=False,
+ tenant_id=self.instance['project_id']
+ ).AndReturn({'networks': non_shared_nets})
+ self.moxed_client.list_networks(
+ shared=True).AndReturn({'networks': shared_nets})
else:
networks = networks + [
dict(id=iface['network']['id'],
@@ -2669,6 +2702,8 @@ class TestNeutronv2(TestNeutronv2Base):
mock_nw_info_build_network,
mock_nw_info_get_ips,
mock_nw_info_get_subnets):
+ # An empty instance info network cache should not be populated from
+ # ports found in Neutron.
api = neutronapi.API()
fake_inst = objects.Instance()
@@ -2697,7 +2732,7 @@ class TestNeutronv2(TestNeutronv2Base):
tenant_id='fake', device_id='uuid').AndReturn(
{'ports': fake_ports})
- mock_gather_port_ids_and_networks.return_value = (None, None)
+ mock_gather_port_ids_and_networks.return_value = ([], [])
mock_get_preexisting_port_ids.return_value = []
mock_nw_info_build_network.return_value = (None, None)
mock_nw_info_get_ips.return_value = []
@@ -2708,7 +2743,7 @@ class TestNeutronv2(TestNeutronv2Base):
nw_infos = api._build_network_info_model(
self.context, fake_inst)
- self.assertEqual(len(nw_infos), 1)
+ self.assertEqual(0, len(nw_infos))
def test_get_subnets_from_port(self):
api = neutronapi.API()