def _port_from_idl_row(row): res = switch.SwitchPort( id=str(row.uuid), name=row.name, type=_get_interface_type(row), ) if row.ofport: res.port_num = int(row.ofport[0]) if row.mac_in_use: res.mac_in_use = row.mac_in_use[0] if row.admin_state: res.admin_state = row.admin_state[0] if res.type == constants.SWITCH_PATCH_INTERFACE: res.peer = row.options['peer'] if res.type == constants.SWITCH_TUNNEL_INTERFACE: res.tunnel_type = row.type external_ids = row.external_ids lport_id = external_ids.get('iface-id') if lport_id is not None: res.lport = lport_id attached_mac = external_ids.get('attached-mac') if attached_mac is not None: res.attached_mac = attached_mac return res
def test_port_update_no_ofport(self): self.assertFalse( impl_idl._is_ovsport_update_valid( 'set', switch.SwitchPort( name='tap-uuid', ), ), )
def test_metadata_interface_online(self): with mock.patch.object(self.meta_app, '_add_tap_metadata_port') as mock_func: # Device without mac will not trigger update flow self.controller.update( switch.SwitchPort( id='fake_switch_port', port_num=1, name=self.meta_app._interface, )) mock_func.assert_not_called() mock_func.reset_mock() # Other device update will not trigger update flow self.controller.update( switch.SwitchPort( id='fake_switch_port', port_num=1, name='no-interface', mac_in_use='aa:bb:cc:dd:ee:ff', )) mock_func.assert_not_called() mock_func.reset_mock() # Device with mac will trigger update flow self.controller.update( switch.SwitchPort( id='fake_switch_port', port_num=1, name=self.meta_app._interface, mac_in_use='aa:bb:cc:dd:ee:ff', )) mock_func.assert_called_once_with(1, "aa:bb:cc:dd:ee:ff") mock_func.reset_mock() # Duplicated updated will not trigger update flow self.controller.update( switch.SwitchPort( id='fake_switch_port1', port_num=1, name=self.meta_app._interface, mac_in_use='aa:bb:cc:dd:ee:ff', )) mock_func.assert_not_called()
def test_port_update_qg(self): self.assertFalse( impl_idl._is_ovsport_update_valid( 'set', switch.SwitchPort( port_num=1, name='qg-some-uuid', ), ), )
def test_port_update_missing_lport(self): self.assertFalse( impl_idl._is_ovsport_update_valid( 'set', switch.SwitchPort( port_num=1, type=constants.SWITCH_COMPUTE_INTERFACE, name='tap-uuid', ), ), )
def get_virtual_tunnel_ports(self): ifaces = self.ovsdb.db_find( 'Interface', ('options', '=', {'remote_ip': 'flow'}), columns=['uuid', 'name', 'type']).execute() tunnel_ports = [] for iface in ifaces: if (self.integration_bridge != self._get_bridge_for_iface(iface['name'])): continue tunnel_ports.append( switch.SwitchPort( id=str(iface['uuid']), name=iface['name'], tunnel_type=iface['type'], ), ) return tunnel_ports
def test_provider_bridge(self): self.app.int_ofports['phynet'] = 1 self.app.bridge_macs['phynet'] = '00:12:23:34:45:56' self.app.reverse_bridge_mappings['private'] = 'phynet' fake_local_vlan_port = make_fake_local_port( lswitch='fake_vlan_switch1') self.controller.update(fake_local_vlan_port) self.app.mod_flow.reset_mock() switch_port = switch.SwitchPort( id='fake_switch_port', lport=fake_local_vlan_port.id, port_num=1, admin_state='up', name='private', mac_in_use='00:00:00:00:00:01', type=constants.SWITCH_COMPUTE_INTERFACE) self.controller.update(switch_port) call_list = [ mock.call( command=self.app.ofproto.OFPFC_DELETE, table_id=const.EGRESS_EXTERNAL_TABLE, priority=const.PRIORITY_HIGH, match=self.app.parser.OFPMatch()), mock.call( table_id=const.EGRESS_EXTERNAL_TABLE, priority=const.PRIORITY_HIGH, match=self.app.parser.OFPMatch(), inst=[self.app.parser.OFPInstructionActions()] )] self.assertEqual(len(call_list), self.app.mod_flow.call_count) self.app.mod_flow.assert_has_calls(call_list) self.app.mod_flow.reset_mock() self.controller.delete(switch_port) self.app.mod_flow.assert_called_with( command=self.app.ofproto.OFPFC_DELETE, table_id=const.EGRESS_EXTERNAL_TABLE, priority=const.PRIORITY_HIGH, match=self.app.parser.OFPMatch())
def test_classifier_for_vlan_port(self): fake_local_vlan_port = make_fake_local_port( lswitch='fake_vlan_switch1') self.controller.update(fake_local_vlan_port) self.app.mod_flow.assert_not_called() switch_port = switch.SwitchPort( id='fake_switch_port', lport=fake_local_vlan_port.id, port_num=1, admin_state='up', type=constants.SWITCH_COMPUTE_INTERFACE) self.controller.update(switch_port) port_key = fake_local_vlan_port.unique_key match = self.app.parser.OFPMatch(reg7=port_key) self.app.mod_flow.assert_called_with( inst=mock.ANY, table_id=const.INGRESS_DISPATCH_TABLE, priority=const.PRIORITY_MEDIUM, match=match) self.app.mod_flow.reset_mock() port_num = switch_port.port_num match = self.app.parser.OFPMatch(in_port=port_num) if self.order == SCENARIO_ORDER_DELETE_LPORT_FIRST: self.controller.delete(fake_local_vlan_port) self.controller.delete(switch_port) elif self.order == SCENARIO_ORDER_DELETE_SWITCH_PORT_FIRST: self.controller.delete(switch_port) self.controller.delete(fake_local_vlan_port) else: self.fail("Bad order") self.app.mod_flow.assert_called_with( table_id=const.INGRESS_CLASSIFICATION_DISPATCH_TABLE, command=self.datapath.ofproto.OFPFC_DELETE, priority=const.PRIORITY_MEDIUM, match=match) self.app.mod_flow.reset_mock()
fake_dhcp_params = { constants.DHCP_SIADDR: "10.0.0.1", "opts": fake_local_port1_dhcp_opts } fake_local_port1 = make_fake_local_port(macs=['fa:16:3e:8c:2e:b3'], ips=['10.0.0.6', '2222:2222::3'], subnets=['fake_subnet1'], id='fake_port1', dhcp_params=fake_dhcp_params) fake_switch_port1 = switch.SwitchPort( id='fake_switch_port1', port_num=2, name='tap-fake_port1', admin_state='up', type=constants.SWITCH_COMPUTE_INTERFACE, lport='fake_port1', attached_mac='fa:16:3e:8c:2e:b3', ) fake_local_port2 = make_fake_local_port(macs=['fa:16:3e:8c:2e:b4'], ips=['10.0.0.7'], id='fake_port2', subnets=['fake_subnet1']) fake_switch_port2 = switch.SwitchPort( id='fake_switch_port2', port_num=3, name='tap-fake_port2', admin_state='up',