Remove ofport attribute from LogicalPort
Our apps no longer rely on ofport, so we can dispatch port events without making sure it is set. This lets us simplify _logical_port_process even further. Partial-Bug: #1690775 Change-Id: I78fd51b5b2c6b3eea2738e1282b2a99a3b8b70cc
This commit is contained in:
parent
dc80063919
commit
2825e65e16
|
@ -37,7 +37,6 @@ class MigrationApp(df_base_app.DFlowApp):
|
|||
return
|
||||
original_lport = migration_obj.lport.get_object()
|
||||
lport = self.nb_api.get(original_lport)
|
||||
port_id = lport.id
|
||||
|
||||
dest_chassis = migration_obj.dest_chassis
|
||||
if not dest_chassis:
|
||||
|
@ -46,8 +45,6 @@ class MigrationApp(df_base_app.DFlowApp):
|
|||
chassis_name = cfg.CONF.host
|
||||
if dest_chassis.id == chassis_name:
|
||||
# destination node
|
||||
ofport = self.vswitch_api.get_port_ofport_by_id(port_id)
|
||||
lport.ofport = ofport
|
||||
lport.is_local = True
|
||||
self.db_store.update(lport)
|
||||
|
||||
|
@ -66,8 +63,6 @@ class MigrationApp(df_base_app.DFlowApp):
|
|||
|
||||
# Here It could be either source node or other nodes, so
|
||||
# get ofport from chassis.
|
||||
ofport = self.vswitch_api.get_vtp_ofport(lport.lswitch.network_type)
|
||||
lport.ofport = ofport
|
||||
remote_chassis = dest_chassis.get_object()
|
||||
if not remote_chassis:
|
||||
# chassis has not been online yet.
|
||||
|
|
|
@ -36,7 +36,6 @@ from dragonflow.db import model_proxy
|
|||
from dragonflow.db.models import core
|
||||
from dragonflow.db.models import l2
|
||||
from dragonflow.db.models import mixins
|
||||
from dragonflow.db.models import trunk
|
||||
from dragonflow.db import sync
|
||||
from dragonflow.ovsdb import vswitch_impl
|
||||
|
||||
|
@ -189,22 +188,6 @@ class DfLocalController(object):
|
|||
|
||||
is_local = lport.binding.is_local
|
||||
lport.is_local = is_local
|
||||
if is_local:
|
||||
if not lport.ofport:
|
||||
lport.ofport = self.vswitch_api.get_port_ofport_by_id(lport.id)
|
||||
if not lport.ofport:
|
||||
# Not attached to the switch. Maybe it's a subport?
|
||||
lport.ofport = self._get_trunk_subport_ofport(lport)
|
||||
|
||||
if not lport.ofport and lport.is_local:
|
||||
# The tunnel port online event will update the remote logical
|
||||
# port. Log this warning first.
|
||||
LOG.warning("%(location)s logical port %(port)s"
|
||||
" was not created yet",
|
||||
{'location': "Local" if is_local else
|
||||
"Tunnel for remote",
|
||||
'port': lport})
|
||||
return
|
||||
|
||||
original_lport = self.db_store.get_one(lport)
|
||||
self.db_store.update(lport)
|
||||
|
@ -213,17 +196,6 @@ class DfLocalController(object):
|
|||
else:
|
||||
lport.emit_updated(original_lport)
|
||||
|
||||
def _get_trunk_subport_ofport(self, lport):
|
||||
try:
|
||||
cps = self.db_store.get_one(
|
||||
trunk.ChildPortSegmentation(port=lport.id),
|
||||
trunk.ChildPortSegmentation.get_index('lport_id'))
|
||||
if cps:
|
||||
return cps.parent.ofport
|
||||
except Exception:
|
||||
# Not found. Do nothing
|
||||
pass
|
||||
|
||||
def update_lport(self, lport):
|
||||
if (
|
||||
lport.binding is None or
|
||||
|
|
|
@ -213,10 +213,9 @@ class Topology(object):
|
|||
return
|
||||
|
||||
cached_lport = self.db_store.get_one(l2.LogicalPort(id=lport_id))
|
||||
if not cached_lport or not cached_lport.ofport:
|
||||
# If the logical port is not in db store or its ofport is not
|
||||
# valid. It has not been applied to dragonflow apps. We need to
|
||||
# update it in dragonflow controller.
|
||||
if not cached_lport:
|
||||
# If the logical port is not in db store it has not been applied
|
||||
# to dragonflow apps. We need to update it in dragonflow controller
|
||||
LOG.info("A local logical port(%s) is online", lport)
|
||||
try:
|
||||
self.controller.update(lport)
|
||||
|
|
|
@ -154,9 +154,8 @@ class LogicalPort(mf.ModelBase, mixins.Name, mixins.Version, mixins.Topic,
|
|||
dhcp_params = fields.EmbeddedField(DhcpParams)
|
||||
binding_vnic_type = df_fields.EnumField(portbindings.VNIC_TYPES)
|
||||
|
||||
def __init__(self, ofport=None, is_local=None, **kwargs):
|
||||
def __init__(self, is_local=None, **kwargs):
|
||||
super(LogicalPort, self).__init__(**kwargs)
|
||||
self.ofport = ofport
|
||||
self.is_local = is_local
|
||||
|
||||
@property
|
||||
|
|
|
@ -166,6 +166,9 @@ def chassis_binding(chassis):
|
|||
)
|
||||
|
||||
|
||||
_lport_index = 0
|
||||
|
||||
|
||||
def make_fake_port(id=None,
|
||||
subnets=None,
|
||||
is_local=None,
|
||||
|
@ -184,14 +187,18 @@ def make_fake_port(id=None,
|
|||
binding_vnic_type='normal',
|
||||
security_groups=['fake_security_group_id1'],
|
||||
device_id='fake_device_id',
|
||||
ofport=1,
|
||||
dhcp_params=None):
|
||||
|
||||
if binding == _DEFAULT:
|
||||
binding = chassis_binding(fake_chassis1.id)
|
||||
|
||||
if id is None:
|
||||
id = 'lport_{0}'.format(_lport_index)
|
||||
global _lport_index
|
||||
_lport_index += 1
|
||||
|
||||
fake_port = l2.LogicalPort(
|
||||
id="%s_%s" % (name, ofport) if not id else id,
|
||||
id=id,
|
||||
topic=topic,
|
||||
name=name,
|
||||
unique_key=unique_key,
|
||||
|
@ -210,7 +217,6 @@ def make_fake_port(id=None,
|
|||
dhcp_params={} if not dhcp_params else dhcp_params,
|
||||
)
|
||||
fake_port.is_local = is_local
|
||||
fake_port.ofport = ofport
|
||||
return fake_port
|
||||
|
||||
|
||||
|
@ -245,7 +251,6 @@ fake_ovs_port1 = ovs.OvsPort(
|
|||
type=constants.OVS_VM_INTERFACE,
|
||||
iface_id='fake_port1',
|
||||
attached_mac='fa:16:3e:8c:2e:b3',
|
||||
tunnel_type='vxlan',
|
||||
)
|
||||
|
||||
|
||||
|
@ -253,7 +258,6 @@ fake_local_port2 = make_fake_local_port(
|
|||
macs=['fa:16:3e:8c:2e:b4'],
|
||||
ips=['10.0.0.7'],
|
||||
id='fake_port2',
|
||||
ofport=3,
|
||||
subnets=['fake_subnet1'])
|
||||
|
||||
|
||||
|
@ -265,7 +269,6 @@ fake_ovs_port2 = ovs.OvsPort(
|
|||
type=constants.OVS_VM_INTERFACE,
|
||||
iface_id='fake_port2',
|
||||
attached_mac='fa:16:3e:8c:2e:b4',
|
||||
tunnel_type='vxlan',
|
||||
)
|
||||
|
||||
|
||||
|
@ -281,7 +284,6 @@ fake_remote_port1 = make_fake_remote_port(
|
|||
ips=['10.0.0.8'],
|
||||
binding=chassis_binding('fake_host2'),
|
||||
unique_key=5,
|
||||
ofport=1,
|
||||
subnets=['fake_subnet1'])
|
||||
|
||||
|
||||
|
|
|
@ -55,8 +55,7 @@ class TestL2App(test_app_base.DFAppTestBase):
|
|||
fake_local_port2 = test_app_base.make_fake_local_port(
|
||||
lswitch='fake_local_switch1',
|
||||
macs=['1a:0b:0c:0d:0e:0f'],
|
||||
ips=['10.0.0.12'],
|
||||
ofport=2)
|
||||
ips=['10.0.0.12'])
|
||||
self.controller.update(fake_local_port2)
|
||||
self.app.mod_flow.assert_any_call(
|
||||
inst=mock.ANY,
|
||||
|
|
|
@ -26,7 +26,6 @@ class TestLogicalNetworks(tests_base.BaseTestCase):
|
|||
fake_local_vlan_port1 = test_app_base.make_fake_local_port(
|
||||
name='fake_local_vlan_port1',
|
||||
unique_key=3,
|
||||
ofport=2,
|
||||
lswitch='fake_vlan_switch1')
|
||||
self.logical_networks.add_local_port(
|
||||
port_id=fake_local_vlan_port1.id,
|
||||
|
@ -39,7 +38,6 @@ class TestLogicalNetworks(tests_base.BaseTestCase):
|
|||
fake_local_vlan_port2 = test_app_base.make_fake_local_port(
|
||||
name='fake_local_vlan_port2',
|
||||
unique_key=4,
|
||||
ofport=3,
|
||||
lswitch='fake_vlan_switch1')
|
||||
self.logical_networks.add_local_port(
|
||||
port_id=fake_local_vlan_port2.id,
|
||||
|
@ -56,8 +54,7 @@ class TestLogicalNetworks(tests_base.BaseTestCase):
|
|||
fake_local_gre_port1 = test_app_base.make_fake_local_port(
|
||||
lswitch='fake_gre_switch1',
|
||||
name='fake_local_gre_port1',
|
||||
unique_key=5,
|
||||
ofport=4)
|
||||
unique_key=5)
|
||||
self.logical_networks.add_local_port(
|
||||
port_id=fake_local_gre_port1.id,
|
||||
network_id=2,
|
||||
|
@ -79,7 +76,6 @@ class TestLogicalNetworks(tests_base.BaseTestCase):
|
|||
fake_remote_vlan_port1 = test_app_base.make_fake_remote_port(
|
||||
name='fake_remote_vlan_port1',
|
||||
unique_key=30,
|
||||
ofport=12,
|
||||
lswitch='fake_vlan_switch1')
|
||||
self.logical_networks.add_remote_port(
|
||||
port_id=fake_remote_vlan_port1.id,
|
||||
|
@ -92,7 +88,6 @@ class TestLogicalNetworks(tests_base.BaseTestCase):
|
|||
fake_remote_vlan_port2 = test_app_base.make_fake_remote_port(
|
||||
name='fake_remote_vlan_port2',
|
||||
unique_key=4,
|
||||
ofport=3,
|
||||
lswitch='fake_vlan_switch1')
|
||||
self.logical_networks.add_remote_port(
|
||||
port_id=fake_remote_vlan_port2.id,
|
||||
|
@ -109,8 +104,7 @@ class TestLogicalNetworks(tests_base.BaseTestCase):
|
|||
fake_local_gre_port1 = test_app_base.make_fake_remote_port(
|
||||
lswitch='fake_gre_switch1',
|
||||
name='fake_remote_gre_port1',
|
||||
unique_key=5,
|
||||
ofport=4)
|
||||
unique_key=5)
|
||||
self.logical_networks.add_remote_port(
|
||||
port_id=fake_local_gre_port1.id,
|
||||
network_id=2,
|
||||
|
|
|
@ -66,8 +66,7 @@ class TestProviderNetsApp(test_app_base.DFAppTestBase):
|
|||
fake_local_vlan_port2 = make_fake_local_port(
|
||||
lswitch='fake_vlan_switch1',
|
||||
macs=['1a:0b:0c:0d:0f:0f'],
|
||||
ips=['10.0.0.112'],
|
||||
ofport=12)
|
||||
ips=['10.0.0.112'])
|
||||
self.controller.update(fake_local_vlan_port2)
|
||||
self.app.mod_flow.assert_not_called()
|
||||
self.app.mod_flow.reset_mock()
|
||||
|
|
|
@ -70,7 +70,6 @@ class TestSGApp(test_app_base.DFAppTestBase):
|
|||
port_security_enabled=True,
|
||||
device_owner='compute:None',
|
||||
device_id='fake_device_id',
|
||||
ofport=20,
|
||||
is_local=True,
|
||||
# 'binding_profile': {},
|
||||
# 'binding_vnic_type': 'normal',
|
||||
|
|
|
@ -144,7 +144,7 @@ class TestTrunkApp(test_app_base.DFAppTestBase):
|
|||
def _get_ofport_by_id(self, lport_id):
|
||||
self.assertEqual('fake_port2', lport_id,
|
||||
'Unexpected call to get_port_ofport_by_id')
|
||||
return test_app_base.fake_local_port2.ofport
|
||||
return 3
|
||||
|
||||
def test__get_classification_match(self):
|
||||
lswitch2 = self._create_2nd_lswitch()
|
||||
|
@ -159,7 +159,7 @@ class TestTrunkApp(test_app_base.DFAppTestBase):
|
|||
self._get_ofport_by_id
|
||||
match = self.app._get_classification_match(segmentation)
|
||||
match_dict = match._dict
|
||||
self.assertEqual({'in_port': test_app_base.fake_local_port2.ofport,
|
||||
self.assertEqual({'in_port': 3,
|
||||
'vlan_vid': 0x1007},
|
||||
match_dict)
|
||||
|
||||
|
|
|
@ -42,8 +42,7 @@ class TestTunnelingApp(test_app_base.DFAppTestBase):
|
|||
|
||||
def test_tunneling_for_local_port(self):
|
||||
fake_local_gre_port1 = make_fake_local_port(
|
||||
lswitch='fake_gre_switch1',
|
||||
ofport=11)
|
||||
lswitch='fake_gre_switch1')
|
||||
match = self.app.parser.OFPMatch(tunnel_id_nxm=410,
|
||||
in_port=11)
|
||||
actions = [self.app.parser.OFPActionSetField(metadata=21)]
|
||||
|
@ -62,8 +61,7 @@ class TestTunnelingApp(test_app_base.DFAppTestBase):
|
|||
fake_local_gre_port2 = make_fake_local_port(
|
||||
lswitch='fake_gre_switch1',
|
||||
macs=['1a:0b:0c:0d:0e:0f'],
|
||||
ips=['10.0.0.12'],
|
||||
ofport=2)
|
||||
ips=['10.0.0.12'])
|
||||
self.controller.update(fake_local_gre_port2)
|
||||
self.app.mod_flow.assert_not_called()
|
||||
self.app.mod_flow.reset_mock()
|
||||
|
@ -74,15 +72,14 @@ class TestTunnelingApp(test_app_base.DFAppTestBase):
|
|||
binding=test_app_base.chassis_binding('fake_host2'),
|
||||
name='fake_remote_gre_port1')
|
||||
remote_ip = fake_remote_gre_port1.binding.ip
|
||||
ofport = fake_remote_gre_port1.ofport
|
||||
match = self.app._make_bum_match(metadata=21)
|
||||
actions = [
|
||||
self.app.parser.OFPActionSetField(
|
||||
tun_ipv4_dst=remote_ip),
|
||||
self.app.parser.OFPActionSetField(
|
||||
tunnel_id_nxm=410),
|
||||
self.app.parser.OFPActionOutput(
|
||||
port=ofport)]
|
||||
self.app.parser.OFPActionOutput(port=7)]
|
||||
self.vswitch_api.get_vtp_ofport.return_value = 7
|
||||
self.controller.update(fake_remote_gre_port1)
|
||||
self.app.parser.OFPInstructionActions.assert_called_with(
|
||||
self.app.ofproto.OFPIT_APPLY_ACTIONS, actions)
|
||||
|
|
Loading…
Reference in New Issue