def setUp(self): # We need a L3 service plugin l3_plugin = ('neutron.tests.unit.test_l3_plugin.' 'TestL3NatServicePlugin') service_plugins = {'l3_plugin_name': l3_plugin} # Enable the test mechanism driver to ensure that # we can successfully call through to all mechanism # driver apis. config.cfg.CONF.set_override('mechanism_drivers', self._mechanism_drivers, group='ml2') self.physnet = 'physnet1' self.vlan_range = '1:100' self.vlan_range2 = '200:300' self.physnet2 = 'physnet2' self.phys_vrange = ':'.join([self.physnet, self.vlan_range]) self.phys2_vrange = ':'.join([self.physnet2, self.vlan_range2]) config.cfg.CONF.set_override('network_vlan_ranges', [self.phys_vrange, self.phys2_vrange], group='ml2_type_vlan') super(Ml2PluginV2TestCase, self).setUp(PLUGIN_NAME, service_plugins=service_plugins) self.port_create_status = 'DOWN' self.driver = ml2_plugin.Ml2Plugin() self.context = context.get_admin_context()
def test_get_worker(self): workers = ml2_plugin.Ml2Plugin().get_workers() self.assertTrue( any( isinstance(worker, pseudo_agentdb_binding.PseudoAgentDBBindingWorker) for worker in workers))
def _create_plugin_for_create_update_port(self, new_host_port): plugin = ml2_plugin.Ml2Plugin() plugin.extension_manager = mock.Mock() plugin.type_manager = mock.Mock() plugin.mechanism_manager = mock.Mock() plugin.notifier = mock.Mock() plugin._get_host_port_if_changed = mock.Mock( return_value=new_host_port) plugin._notify_l3_agent_new_port = mock.Mock() plugin._notify_l3_agent_new_port.side_effect = ( lambda c, p: self._ensure_transaction_is_closed()) return plugin
def setUp(self): super(NetworkRBACTestCase, self).setUp() cfg.CONF.set_override('notify_nova_on_port_status_changes', False) DB_PLUGIN_KLASS = 'neutron.plugins.ml2.plugin.Ml2Plugin' self.setup_coreplugin(DB_PLUGIN_KLASS) self.plugin = ml2_plugin.Ml2Plugin() self.cxt = context.Context(user_id=None, tenant_id=None, is_admin=True, overwrite=False) self.tenant_1 = uuidutils.generate_uuid() self.tenant_2 = uuidutils.generate_uuid() self.network_id = uuidutils.generate_uuid() self.subnet_1_id = uuidutils.generate_uuid() self.subnet_2_id = uuidutils.generate_uuid() self.port_id = uuidutils.generate_uuid()
def test_simple_sync_all_with_HTTPError_not_found(self): self.given_back_end.out_of_sync = True ml2_plugin = plugin.Ml2Plugin() port_mock = mock.MagicMock(port_binding=models.PortBinding()) response = mock.Mock(status_code=requests.codes.not_found) fake_exception = requests.exceptions.HTTPError('Test', response=response) def side_eff(*args, **kwargs): # HTTP ERROR exception with 404 status code will be raised when use # sendjson to get the object in ODL DB if args[0] == 'get': raise fake_exception with mock.patch.object(client.OpenDaylightRestClient, 'sendjson', side_effect=side_eff), \ mock.patch.object(plugin.Ml2Plugin, 'get_networks', return_value=[FAKE_NETWORK.copy()]), \ mock.patch.object(plugin.Ml2Plugin, 'get_network', return_value=FAKE_NETWORK.copy()), \ mock.patch.object(plugin.Ml2Plugin, 'get_subnets', return_value=[FAKE_SUBNET.copy()]), \ mock.patch.object(plugin.Ml2Plugin, '_get_port', return_value=port_mock), \ mock.patch.object(plugin.Ml2Plugin, 'get_ports', return_value=[FAKE_PORT.copy()]), \ mock.patch.object(plugin.Ml2Plugin, 'get_security_groups', return_value=[FAKE_SECURITY_GROUP.copy()]), \ mock.patch.object(plugin.Ml2Plugin, 'get_security_group_rules', return_value=[FAKE_SECURITY_GROUP_RULE.copy()]): self.given_back_end.sync_full(ml2_plugin) sync_id_list = [FAKE_SECURITY_GROUP['id'], FAKE_SECURITY_GROUP_RULE['id'], FAKE_NETWORK['id'], FAKE_SUBNET['id'], FAKE_PORT['id']] act = [] for args, kwargs in \ client.OpenDaylightRestClient.sendjson.call_args_list: if args[0] == 'post': for key in args[2]: act.append(args[2][key][0]['id']) self.assertEqual(act, sync_id_list)
def setUp(self): super(NetworkRBACTestCase, self).setUp() cfg.CONF.set_override('notify_nova_on_port_status_changes', False) DB_PLUGIN_KLASS = 'neutron.plugins.ml2.plugin.Ml2Plugin' self.setup_coreplugin(DB_PLUGIN_KLASS) self.plugin = ml2_plugin.Ml2Plugin() self.cxt = context.Context(user_id=None, tenant_id=None, is_admin=True, overwrite=False) self.tenant_1 = uuidutils.generate_uuid() self.tenant_2 = uuidutils.generate_uuid() self.network_id = uuidutils.generate_uuid() self.subnet_1_id = uuidutils.generate_uuid() self.subnet_2_id = uuidutils.generate_uuid() self.port_id = uuidutils.generate_uuid() make_res = mock.patch.object(quota.QuotaEngine, 'make_reservation') self.mock_quota_make_res = make_res.start() commit_res = mock.patch.object(quota.QuotaEngine, 'commit_reservation') self.mock_quota_commit_res = commit_res.start()
def test_simple_sync_all_with_all_synced(self): self.given_back_end.out_of_sync = True ml2_plugin = plugin.Ml2Plugin() with mock.patch.object(client.OpenDaylightRestClient, 'sendjson', return_value=None), \ mock.patch.object(plugin.Ml2Plugin, 'get_networks', return_value=[FAKE_NETWORK.copy()]), \ mock.patch.object(plugin.Ml2Plugin, 'get_subnets', return_value=[FAKE_SUBNET.copy()]), \ mock.patch.object(plugin.Ml2Plugin, 'get_ports', return_value=[FAKE_PORT.copy()]), \ mock.patch.object(plugin.Ml2Plugin, 'get_security_groups', return_value=[FAKE_SECURITY_GROUP.copy()]), \ mock.patch.object(plugin.Ml2Plugin, 'get_security_group_rules', return_value=[FAKE_SECURITY_GROUP_RULE.copy()]): self.given_back_end.sync_full(ml2_plugin) # it's only called for GET, there is no call for PUT # 5 = network, subnet, port, security_group, security_group_rule self.assertEqual(5, client.OpenDaylightRestClient.sendjson.call_count)
def test_valid_config(self): self._set_config() plugin.Ml2Plugin()