示例#1
0
 def test_lswitch_exists(self):
     with mock.patch.object(idlutils, 'row_by_value',
                            return_value=mock.ANY):
         cmd = commands.AddLSwitchCommand(
             self.ovn_api, 'fake-lswitch', may_exist=True, foo='bar')
         cmd.run_idl(self.transaction)
         self.transaction.insert.assert_not_called()
示例#2
0
 def _test_lswitch_add(self, may_exist=True):
     with mock.patch.object(idlutils, 'row_by_value',
                            return_value=None):
         fake_lswitch = fakes.FakeOvsdbRow.create_one_ovsdb_row()
         self.transaction.insert.return_value = fake_lswitch
         cmd = commands.AddLSwitchCommand(
             self.ovn_api, 'fake-lswitch', may_exist=may_exist, foo='bar')
         cmd.run_idl(self.transaction)
         self.transaction.insert.assert_called_once_with(
             self.ovn_api.lswitch_table)
         self.assertEqual('fake-lswitch', fake_lswitch.name)
         self.assertEqual('bar', fake_lswitch.foo)
示例#3
0
    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]))
示例#4
0
 def create_lswitch(self, lswitch_name, may_exist=True, **columns):
     return cmd.AddLSwitchCommand(self, lswitch_name, may_exist, **columns)
示例#5
0
    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))