def delete_lswitch(self, lswitch_name=None, ext_id=None, if_exists=True): if lswitch_name is not None: return cmd.DelLSwitchCommand(self, lswitch_name, if_exists) else: raise RuntimeError( _("Currently only supports delete " "by lswitch-name"))
def test_lswitch_del(self): fake_lswitch = fakes.FakeOvsdbRow.create_one_ovsdb_row() self.ovn_api.lswitch_table.rows[fake_lswitch.uuid] = fake_lswitch with mock.patch.object(idlutils, 'row_by_value', return_value=fake_lswitch): cmd = commands.DelLSwitchCommand( self.ovn_api, fake_lswitch.name, if_exists=True) cmd.run_idl(self.transaction) fake_lswitch.delete.assert_called_once_with()
def _test_lswitch_del_no_exist(self, if_exists=True): with mock.patch.object(idlutils, 'row_by_value', side_effect=idlutils.RowNotFound): cmd = commands.DelLSwitchCommand( self.ovn_api, 'fake-lswitch', if_exists=if_exists) if if_exists: cmd.run_idl(self.transaction) else: self.assertRaises(RuntimeError, cmd.run_idl, self.transaction)
def _modify_resources_in_nb_db(self): fake_api = mock.MagicMock() fake_api.idl = self.monitor_nb_db_idl fake_api._tables = self.monitor_nb_db_idl.tables with self.nb_idl_transaction(fake_api, check_error=True) as txn: for lswitch_name in self.create_lswitches: external_ids = { ovn_const.OVN_NETWORK_NAME_EXT_ID_KEY: lswitch_name } txn.add( cmd.AddLSwitchCommand(fake_api, lswitch_name, True, external_ids=external_ids)) for lswitch_name in self.delete_lswitches: txn.add(cmd.DelLSwitchCommand(fake_api, lswitch_name, True)) for lport_name, lswitch_name in self.create_lswitch_ports: external_ids = {ovn_const.OVN_PORT_NAME_EXT_ID_KEY: lport_name} txn.add( cmd.AddLSwitchPortCommand(fake_api, lport_name, lswitch_name, True, external_ids=external_ids)) for lport_name, lswitch_name in self.delete_lswitch_ports: txn.add( cmd.DelLSwitchPortCommand(fake_api, lport_name, lswitch_name, True)) for lrouter_name in self.create_lrouters: external_ids = { ovn_const.OVN_ROUTER_NAME_EXT_ID_KEY: lrouter_name } txn.add( cmd.AddLRouterCommand(fake_api, lrouter_name, True, external_ids=external_ids)) for lrouter_name in self.delete_lrouters: txn.add(cmd.DelLRouterCommand(fake_api, lrouter_name, True)) for lrport, lrouter_name in self.create_lrouter_ports: txn.add( cmd.AddLRouterPortCommand(fake_api, lrport, lrouter_name)) for lrport, lrouter_name, networks in self.update_lrouter_ports: txn.add( cmd.UpdateLRouterPortCommand(fake_api, lrport, lrouter_name, True, **{'networks': [networks]})) for lrport, lrouter_name in self.delete_lrouter_ports: txn.add( cmd.DelLRouterPortCommand(fake_api, lrport, lrouter_name, True)) for lrouter_name, ip_prefix, nexthop in self.create_lrouter_routes: txn.add( cmd.AddStaticRouteCommand(fake_api, lrouter_name, ip_prefix=ip_prefix, nexthop=nexthop)) for lrouter_name, ip_prefix, nexthop in self.delete_lrouter_routes: txn.add( cmd.DelStaticRouteCommand(fake_api, lrouter_name, ip_prefix, nexthop, True)) for acl in self.create_acls: txn.add(cmd.AddACLCommand(fake_api, **acl)) for lport_name, lswitch_name in self.delete_acls: txn.add( cmd.DelACLCommand(fake_api, lswitch_name, lport_name, True)) for name, ip_version in self.create_address_sets: ovn_name = utils.ovn_addrset_name(name, ip_version) external_ids = {ovn_const.OVN_SG_NAME_EXT_ID_KEY: name} txn.add( cmd.AddAddrSetCommand(fake_api, ovn_name, True, external_ids=external_ids)) for name, ip_version in self.delete_address_sets: ovn_name = utils.ovn_addrset_name(name, ip_version) txn.add(cmd.DelAddrSetCommand(fake_api, ovn_name, True)) for name, ip_version, ip_adds, ip_dels in self.update_address_sets: ovn_name = utils.ovn_addrset_name(name, ip_version) txn.add( cmd.UpdateAddrSetCommand(fake_api, ovn_name, ip_adds, ip_dels, True)) for lport_name in self.reset_lport_dhcpv4_options: txn.add( cmd.SetLSwitchPortCommand(fake_api, lport_name, True, dhcpv4_options=[])) for dhcp_opts in self.stale_lport_dhcpv4_options: txn.add( cmd.AddDHCPOptionsCommand( fake_api, dhcp_opts['subnet_id'], port_id=dhcp_opts['port_id'], cidr=dhcp_opts['cidr'], options=dhcp_opts['options'], external_ids=dhcp_opts['external_ids'])) for row_uuid in self.missed_dhcpv4_options: txn.add(cmd.DelDHCPOptionsCommand(fake_api, row_uuid)) for dhcp_opts in self.dirty_dhcpv4_options: txn.add( cmd.AddDHCPOptionsCommand(fake_api, dhcp_opts['subnet_id'], port_id=dhcp_opts.get('port_id'), external_ids={ 'subnet_id': dhcp_opts['subnet_id'], 'port_id': dhcp_opts.get('port_id') }, options={'foo': 'bar'})) for port_id in self.lport_dhcpv4_disabled: txn.add( cmd.SetLSwitchPortCommand( fake_api, port_id, True, dhcpv4_options=[self.lport_dhcpv4_disabled[port_id]])) with self.nb_idl_transaction(fake_api, check_error=True) as txn: for dhcp_opts in self.stale_lport_dhcpv4_options: if dhcp_opts['port_id'] in self.orphaned_lport_dhcpv4_options: continue uuid = self.mech_driver._nb_ovn.get_port_dhcp_options( dhcp_opts['subnet_id'], dhcp_opts['port_id'])['uuid'] txn.add( cmd.SetLSwitchPortCommand(fake_api, lport_name, True, dhcpv4_options=[uuid]))
def _modify_resources_in_nb_db(self): fake_api = mock.MagicMock() fake_api.idl = self.monitor_nb_db_idl fake_api._tables = self.monitor_nb_db_idl.tables with self.idl_transaction(fake_api, check_error=True) as txn: for lswitch_name in self.create_lswitches: external_ids = { ovn_const.OVN_NETWORK_NAME_EXT_ID_KEY: lswitch_name } txn.add( cmd.AddLSwitchCommand(fake_api, lswitch_name, True, external_ids=external_ids)) for lswitch_name in self.delete_lswitches: txn.add(cmd.DelLSwitchCommand(fake_api, lswitch_name, True)) for lport_name, lswitch_name in self.create_lswitch_ports: external_ids = {ovn_const.OVN_PORT_NAME_EXT_ID_KEY: lport_name} txn.add( cmd.AddLSwitchPortCommand(fake_api, lport_name, lswitch_name, True, external_ids=external_ids)) for lport_name, lswitch_name in self.delete_lswitch_ports: txn.add( cmd.DelLSwitchPortCommand(fake_api, lport_name, lswitch_name, True)) for lrouter_name in self.create_lrouters: external_ids = { ovn_const.OVN_ROUTER_NAME_EXT_ID_KEY: lrouter_name } txn.add( cmd.AddLRouterCommand(fake_api, lrouter_name, True, external_ids=external_ids)) for lrouter_name in self.delete_lrouters: txn.add(cmd.DelLRouterCommand(fake_api, lrouter_name, True)) for lrport, lrouter_name in self.create_lrouter_ports: txn.add( cmd.AddLRouterPortCommand(fake_api, lrport, lrouter_name)) for lrport, lrouter_name in self.delete_lrouter_ports: txn.add( cmd.DelLRouterPortCommand(fake_api, lrport, lrouter_name, True)) for lrouter_name, ip_prefix, nexthop in self.create_lrouter_routes: txn.add( cmd.AddStaticRouteCommand(fake_api, lrouter_name, ip_prefix=ip_prefix, nexthop=nexthop)) for lrouter_name, ip_prefix, nexthop in self.delete_lrouter_routes: txn.add( cmd.DelStaticRouteCommand(fake_api, lrouter_name, ip_prefix, nexthop, True)) for acl in self.create_acls: txn.add(cmd.AddACLCommand(fake_api, **acl)) for lport_name, lswitch_name in self.delete_acls: txn.add( cmd.DelACLCommand(fake_api, lswitch_name, lport_name, True))