Merge "Fix for 'ofport' query retries during neutron agent start"

This commit is contained in:
Jenkins 2016-05-20 14:59:15 +00:00 committed by Gerrit Code Review
commit 1debc902ff
3 changed files with 91 additions and 35 deletions

View File

@ -1148,13 +1148,14 @@ class OVSNeutronAgent(sg_rpc.SecurityGroupAgentRpcCallbackMixin,
# Setup int_br to physical bridge patches. If they already
# exist we leave them alone, otherwise we create them but don't
# connect them until after the drop rules are in place.
int_ofport = self.int_br.get_port_ofport(int_if_name)
if int_ofport == ovs_lib.INVALID_OFPORT:
if self.int_br.port_exists(int_if_name):
int_ofport = self.int_br.get_port_ofport(int_if_name)
else:
int_ofport = self.int_br.add_patch_port(
int_if_name, constants.NONEXISTENT_PEER)
phys_ofport = br.get_port_ofport(phys_if_name)
if phys_ofport == ovs_lib.INVALID_OFPORT:
if br.port_exists(phys_if_name):
phys_ofport = br.get_port_ofport(phys_if_name)
else:
phys_ofport = br.add_patch_port(
phys_if_name, constants.NONEXISTENT_PEER)

View File

@ -1090,7 +1090,7 @@ class TestOvsNeutronAgent(object):
self.assertFalse(int_br.set_db_attribute.called)
self.assertFalse(int_br.drop_port.called)
def test_setup_physical_bridges(self):
def _test_setup_physical_bridges(self, port_exists=False):
with mock.patch.object(ip_lib.IPDevice, "exists") as devex_fn,\
mock.patch.object(sys, "exit"),\
mock.patch.object(utils, "execute"),\
@ -1102,10 +1102,14 @@ class TestOvsNeutronAgent(object):
parent.attach_mock(phys_br_cls, 'phys_br_cls')
parent.attach_mock(phys_br, 'phys_br')
parent.attach_mock(int_br, 'int_br')
phys_br.add_patch_port.return_value = "phy_ofport"
int_br.add_patch_port.return_value = "int_ofport"
phys_br.get_port_ofport.return_value = ovs_lib.INVALID_OFPORT
int_br.get_port_ofport.return_value = ovs_lib.INVALID_OFPORT
if port_exists:
phys_br.get_port_ofport.return_value = "phy_ofport"
int_br.get_port_ofport.return_value = "int_ofport"
else:
phys_br.add_patch_port.return_value = "phy_ofport"
int_br.add_patch_port.return_value = "int_ofport"
phys_br.port_exists.return_value = port_exists
int_br.port_exists.return_value = port_exists
self.agent.setup_physical_bridges({"physnet1": "br-eth"})
expected_calls = [
mock.call.phys_br_cls('br-eth'),
@ -1117,12 +1121,30 @@ class TestOvsNeutronAgent(object):
# Have to use __getattr__ here to avoid mock._Call.__eq__
# method being called
mock.call.int_br.db_get_val().__getattr__('__eq__')('veth'),
mock.call.int_br.get_port_ofport('int-br-eth'),
mock.call.int_br.add_patch_port('int-br-eth',
constants.NONEXISTENT_PEER),
mock.call.phys_br.get_port_ofport('phy-br-eth'),
mock.call.phys_br.add_patch_port('phy-br-eth',
constants.NONEXISTENT_PEER),
mock.call.int_br.port_exists('int-br-eth'),
]
if port_exists:
expected_calls += [
mock.call.int_br.get_port_ofport('int-br-eth'),
]
else:
expected_calls += [
mock.call.int_br.add_patch_port(
'int-br-eth', constants.NONEXISTENT_PEER),
]
expected_calls += [
mock.call.phys_br.port_exists('phy-br-eth'),
]
if port_exists:
expected_calls += [
mock.call.phys_br.get_port_ofport('phy-br-eth'),
]
else:
expected_calls += [
mock.call.phys_br.add_patch_port(
'phy-br-eth', constants.NONEXISTENT_PEER),
]
expected_calls += [
mock.call.int_br.drop_port(in_port='int_ofport'),
mock.call.phys_br.drop_port(in_port='phy_ofport'),
mock.call.int_br.set_db_attribute('Interface', 'int-br-eth',
@ -1138,6 +1160,12 @@ class TestOvsNeutronAgent(object):
self.assertEqual("phy_ofport",
self.agent.phys_ofports["physnet1"])
def test_setup_physical_bridges(self):
self._test_setup_physical_bridges()
def test_setup_physical_bridges_port_exists(self):
self._test_setup_physical_bridges(port_exists=True)
def test_setup_physical_bridges_using_veth_interconnection(self):
self.agent.use_veth_interconnection = True
with mock.patch.object(ip_lib.IPDevice, "exists") as devex_fn,\
@ -1175,7 +1203,8 @@ class TestOvsNeutronAgent(object):
self.assertEqual("phys_veth_ofport",
self.agent.phys_ofports["physnet1"])
def test_setup_physical_bridges_change_from_veth_to_patch_conf(self):
def _test_setup_physical_bridges_change_from_veth_to_patch_conf(
self, port_exists=False):
with mock.patch.object(sys, "exit"),\
mock.patch.object(utils, "execute"),\
mock.patch.object(self.agent, 'br_phys_cls') as phys_br_cls,\
@ -1187,10 +1216,14 @@ class TestOvsNeutronAgent(object):
parent.attach_mock(phys_br_cls, 'phys_br_cls')
parent.attach_mock(phys_br, 'phys_br')
parent.attach_mock(int_br, 'int_br')
phys_br.add_patch_port.return_value = "phy_ofport"
int_br.add_patch_port.return_value = "int_ofport"
phys_br.get_port_ofport.return_value = ovs_lib.INVALID_OFPORT
int_br.get_port_ofport.return_value = ovs_lib.INVALID_OFPORT
if port_exists:
phys_br.get_port_ofport.return_value = "phy_ofport"
int_br.get_port_ofport.return_value = "int_ofport"
else:
phys_br.add_patch_port.return_value = "phy_ofport"
int_br.add_patch_port.return_value = "int_ofport"
phys_br.port_exists.return_value = port_exists
int_br.port_exists.return_value = port_exists
self.agent.setup_physical_bridges({"physnet1": "br-eth"})
expected_calls = [
mock.call.phys_br_cls('br-eth'),
@ -1199,12 +1232,30 @@ class TestOvsNeutronAgent(object):
mock.call.phys_br.setup_default_table(),
mock.call.int_br.delete_port('int-br-eth'),
mock.call.phys_br.delete_port('phy-br-eth'),
mock.call.int_br.get_port_ofport('int-br-eth'),
mock.call.int_br.add_patch_port('int-br-eth',
constants.NONEXISTENT_PEER),
mock.call.phys_br.get_port_ofport('phy-br-eth'),
mock.call.phys_br.add_patch_port('phy-br-eth',
constants.NONEXISTENT_PEER),
mock.call.int_br.port_exists('int-br-eth'),
]
if port_exists:
expected_calls += [
mock.call.int_br.get_port_ofport('int-br-eth'),
]
else:
expected_calls += [
mock.call.int_br.add_patch_port(
'int-br-eth', constants.NONEXISTENT_PEER),
]
expected_calls += [
mock.call.phys_br.port_exists('phy-br-eth'),
]
if port_exists:
expected_calls += [
mock.call.phys_br.get_port_ofport('phy-br-eth'),
]
else:
expected_calls += [
mock.call.phys_br.add_patch_port(
'phy-br-eth', constants.NONEXISTENT_PEER),
]
expected_calls += [
mock.call.int_br.drop_port(in_port='int_ofport'),
mock.call.phys_br.drop_port(in_port='phy_ofport'),
mock.call.int_br.set_db_attribute('Interface', 'int-br-eth',
@ -1220,6 +1271,14 @@ class TestOvsNeutronAgent(object):
self.assertEqual("phy_ofport",
self.agent.phys_ofports["physnet1"])
def test_setup_physical_bridges_change_from_veth_to_patch_conf(self):
self._test_setup_physical_bridges_change_from_veth_to_patch_conf()
def test_setup_physical_bridges_change_from_veth_to_patch_conf_port_exists(
self):
self._test_setup_physical_bridges_change_from_veth_to_patch_conf(
port_exists=True)
def test_setup_tunnel_br(self):
self.tun_br = mock.Mock()
with mock.patch.object(self.agent.int_br,

View File

@ -139,8 +139,7 @@ class TunnelTest(object):
self.mock_int_bridge.add_port.return_value = self.MAP_TUN_INT_OFPORT
self.mock_int_bridge.add_patch_port.side_effect = (
lambda tap, peer: self.ovs_int_ofports[tap])
self.mock_int_bridge.get_port_ofport.return_value = (
ovs_lib.INVALID_OFPORT)
self.mock_int_bridge.port_exists.return_value = False
self.mock_int_bridge.get_vif_ports.return_value = []
self.mock_int_bridge.get_ports_attributes.return_value = []
self.mock_int_bridge.db_get_val.return_value = {}
@ -151,8 +150,7 @@ class TunnelTest(object):
self.MAP_TUN_PHY_OFPORT)
self.mock_map_tun_bridge.add_patch_port.return_value = (
self.MAP_TUN_PHY_OFPORT)
self.mock_map_tun_bridge.get_port_ofport.return_value = (
ovs_lib.INVALID_OFPORT)
self.mock_map_tun_bridge.port_exists.return_value = False
self.mock_tun_bridge = self.ovs_bridges[self.TUN_BRIDGE]
self.mock_tun_bridge.add_port.return_value = self.INT_OFPORT
@ -206,14 +204,14 @@ class TunnelTest(object):
mock.call.create(),
mock.call.setup_controllers(mock.ANY),
mock.call.setup_default_table(),
mock.call.get_port_ofport('phy-%s' % self.MAP_TUN_BRIDGE),
mock.call.port_exists('phy-%s' % self.MAP_TUN_BRIDGE),
mock.call.add_patch_port('phy-%s' % self.MAP_TUN_BRIDGE,
constants.NONEXISTENT_PEER),
]
self.mock_int_bridge_expected += [
mock.call.db_get_val('Interface', 'int-%s' % self.MAP_TUN_BRIDGE,
'type', log_errors=False),
mock.call.get_port_ofport('int-%s' % self.MAP_TUN_BRIDGE),
mock.call.port_exists('int-%s' % self.MAP_TUN_BRIDGE),
mock.call.add_patch_port('int-%s' % self.MAP_TUN_BRIDGE,
constants.NONEXISTENT_PEER),
]
@ -244,7 +242,6 @@ class TunnelTest(object):
]
self.mock_int_bridge_expected += [
mock.call.port_exists('patch-tun'),
nonzero(mock.call.port_exists()),
mock.call.add_patch_port('patch-tun', 'patch-int'),
]
self.mock_int_bridge_expected += [
@ -692,7 +689,6 @@ class TunnelTestUseVethInterco(TunnelTest):
]
self.mock_int_bridge_expected += [
mock.call.port_exists('patch-tun'),
nonzero(mock.call.port_exists()),
mock.call.add_patch_port('patch-tun', 'patch-int')
]
self.mock_int_bridge_expected += [