Python neutron_lib.plugins.directory.add_plugin() Examples

The following are 28 code examples of neutron_lib.plugins.directory.add_plugin(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module neutron_lib.plugins.directory , or try the search function .
Example #1
Source File: test_plugin.py    From neutron-vpnaas with Apache License 2.0 6 votes vote down vote up
def test_get_provider_for_flavor_id_provider_not_found(self):
        FLAVOR_ID = _uuid()
        FAKE_FLAVOR = {'id': FLAVOR_ID,
                       'service_type': p_constants.VPN,
                       'enabled': True}
        PROVIDERS = [{'provider': 'SOME_PROVIDER'}]
        directory.add_plugin(p_constants.FLAVORS,
                             flavors_plugin.FlavorsPlugin())
        mock.patch(
            'neutron.services.flavors.flavors_plugin.FlavorsPlugin.get_flavor',
            return_value=FAKE_FLAVOR).start()
        mock.patch(
            'neutron.services.flavors.flavors_plugin.'
            'FlavorsPlugin.get_flavor_next_provider',
            return_value=PROVIDERS).start()
        with self.vpnservices_providers_set():
            driver_plugin = vpn_plugin.VPNDriverPlugin()
            self.assertRaises(
                vpn_flavors.NoProviderFoundForFlavor,
                driver_plugin._get_provider_for_flavor,
                self.adminContext,
                FLAVOR_ID) 
Example #2
Source File: test_plugin.py    From neutron-vpnaas with Apache License 2.0 6 votes vote down vote up
def test_get_provider_for_flavor_id(self):
        FLAVOR_ID = _uuid()
        FAKE_FLAVOR = {'id': FLAVOR_ID,
                       'service_type': p_constants.VPN,
                       'enabled': True}
        PROVIDERS = [{'provider': 'dummy'}]
        directory.add_plugin(p_constants.FLAVORS,
                             flavors_plugin.FlavorsPlugin())
        mock.patch(
            'neutron.services.flavors.flavors_plugin.FlavorsPlugin.get_flavor',
            return_value=FAKE_FLAVOR).start()
        mock.patch(
            'neutron.services.flavors.flavors_plugin.'
            'FlavorsPlugin.get_flavor_next_provider',
            return_value=PROVIDERS).start()
        with self.vpnservices_providers_set():
            driver_plugin = vpn_plugin.VPNDriverPlugin()
            self.assertEqual(
                'dummy',
                driver_plugin._get_provider_for_flavor(
                    self.adminContext, FLAVOR_ID)) 
Example #3
Source File: test_trunk_driver.py    From dragonflow with Apache License 2.0 6 votes vote down vote up
def setUp(self):
        self._extension_drivers.append('qos')
        super(TestDFTrunkDriver, self).setUp()
        drivers_patch = mock.patch.object(trunk_drivers, 'register')
        self.addCleanup(drivers_patch.stop)
        drivers_patch.start()

        compat_patch = mock.patch.object(
            trunk_plugin.TrunkPlugin, 'check_compatibility')
        self.addCleanup(compat_patch.stop)
        compat_patch.start()

        self.trunk_plugin = trunk_plugin.TrunkPlugin()
        self.trunk_plugin.add_segmentation_type('vlan', lambda x: True)
        cfg.CONF.set_override('mechanism_drivers', 'df', group='ml2')
        directory.add_plugin('trunk', self.trunk_plugin)
        self.df_driver = self.mech_driver.trunk_driver 
Example #4
Source File: test_full_sync.py    From networking-odl with Apache License 2.0 6 votes vote down vote up
def _mock_l2_resources(self):
        expected_journal = {odl_const.ODL_NETWORK: '1',
                            odl_const.ODL_SUBNET: '2',
                            odl_const.ODL_PORT: '3'}
        network_id = expected_journal[odl_const.ODL_NETWORK]
        plugin = mock.Mock()
        plugin.get_networks.return_value = [{'id': network_id}]
        plugin.get_subnets.return_value = [
            {'id': expected_journal[odl_const.ODL_SUBNET],
             'network_id': network_id}]
        port = {'id': expected_journal[odl_const.ODL_PORT],
                odl_const.ODL_SGS: None,
                'tenant_id': '123',
                'fixed_ips': [],
                'network_id': network_id}
        plugin.get_ports.side_effect = ([port], [])
        directory.add_plugin(constants.CORE, plugin)
        return expected_journal 
Example #5
Source File: test_ipsec.py    From neutron-vpnaas with Apache License 2.0 6 votes vote down vote up
def setUp(self):
        super(TestIPsecDriver, self).setUp()
        mock.patch('neutron_lib.rpc.Connection').start()

        l3_agent = mock.Mock()
        l3_agent.host = FAKE_HOST
        plugin = mock.Mock()
        plugin.get_l3_agents_hosting_routers.return_value = [l3_agent]
        directory.add_plugin(constants.CORE, plugin)
        directory.add_plugin(constants.L3, plugin)
        self.svc_plugin = mock.Mock()
        self.svc_plugin.get_l3_agents_hosting_routers.return_value = [l3_agent]
        self._fake_vpn_router_id = _uuid()
        self.svc_plugin._get_vpnservice.return_value = {
            'router_id': self._fake_vpn_router_id
        }
        self.driver = ipsec_driver.IPsecVPNDriver(self.svc_plugin)
        self.validator = ipsec_validator.IpsecVpnValidator(self.driver)
        self.context = n_ctx.get_admin_context() 
Example #6
Source File: test_full_sync.py    From networking-odl with Apache License 2.0 5 votes vote down vote up
def _add_side_effect(self):
        plugins = self._get_all_plugins()
        resources = self._get_all_resources()
        for resource_type, plugin_name in resources:
            name = self._get_name(resource_type)
            setattr(plugins[plugin_name][0], "get_%s" % name[12:],
                    getattr(self, name))

            if directory.get_plugin(plugin_name) is None:
                directory.add_plugin(plugin_name, plugins[plugin_name][0]) 
Example #7
Source File: test_directory.py    From neutron-lib with Apache License 2.0 5 votes vote down vote up
def test_add_plugin(self):
        self.plugin_directory.add_plugin('foo', 'bar')
        self.assertEqual(1, len(self.plugin_directory._plugins)) 
Example #8
Source File: test_directory.py    From neutron-lib with Apache License 2.0 5 votes vote down vote up
def test_is_loaded(self):
        self.assertFalse(directory.is_loaded())
        directory.add_plugin('foo1', fake_plugin)
        self.assertTrue(directory.is_loaded()) 
Example #9
Source File: test_directory.py    From neutron-lib with Apache License 2.0 5 votes vote down vote up
def test_get_plugins(self):
        directory.add_plugin('CORE', fake_plugin)
        self.assertIsNotNone(directory.get_plugins()) 
Example #10
Source File: test_directory.py    From neutron-lib with Apache License 2.0 5 votes vote down vote up
def test_get_plugin_alias(self):
        directory.add_plugin('foo', fake_plugin)
        self.assertIsNotNone(directory.get_plugin('foo')) 
Example #11
Source File: test_directory.py    From neutron-lib with Apache License 2.0 5 votes vote down vote up
def test_get_plugin_core(self):
        directory.add_plugin('CORE', fake_plugin)
        self.assertIsNotNone(directory.get_plugin()) 
Example #12
Source File: test_directory.py    From neutron-lib with Apache License 2.0 5 votes vote down vote up
def test_add_plugin(self):
        directory.add_plugin('foo', fake_plugin)
        self.assertIn('foo', directory.get_plugins()) 
Example #13
Source File: test_fixture.py    From neutron-lib with Apache License 2.0 5 votes vote down vote up
def test_fixture(self):
        directory.add_plugin('foo', 'foo')
        self.assertTrue(self.directory.add_plugin.called) 
Example #14
Source File: test_pseudo_agentdb_binding.py    From networking-odl with Apache License 2.0 5 votes vote down vote up
def _setUp(self):
        super(OpenDaylightAgentDBFixture, self)._setUp()
        fake_agents_db = mock.MagicMock()
        fake_agents_db.create_or_update_agent = mock.MagicMock()
        self.useFixture(fixture.PluginDirectoryFixture())
        directory.add_plugin(plugin_constants.CORE, fake_agents_db) 
Example #15
Source File: test_base_driver.py    From networking-odl with Apache License 2.0 5 votes vote down vote up
def setUp(self):
        super(BaseDriverTestCase, self).setUp()
        self.test_driver = helper.TestDriver()
        self.plugin = helper.TestPlugin()
        directory.add_plugin(helper.TEST_PLUGIN, self.plugin)
        self.addCleanup(directory.add_plugin, helper.TEST_PLUGIN, None) 
Example #16
Source File: test_recovery.py    From networking-odl with Apache License 2.0 5 votes vote down vote up
def _test_get_latest_resource(self, resource_type):
        # Drivers needs to be initialized to register resources for recovery
        # and full sync mechasnim.
        helper.TestDriver()
        directory.add_plugin(helper.TEST_PLUGIN, helper.TestPlugin())
        self.addCleanup(directory.add_plugin, helper.TEST_PLUGIN, None)
        return db.create_pending_row(self.db_context, resource_type,
                                     'id', odl_const.ODL_DELETE, {}) 
Example #17
Source File: test_full_sync.py    From networking-odl with Apache License 2.0 5 votes vote down vote up
def test_sync_resources(self):
        self._register_resources()
        plugin = helper.TestPlugin()
        self.add_plugin(helper.TEST_PLUGIN, plugin)
        resources = plugin.get_test_resource1s(self.db_context)
        full_sync.sync_resources(self.db_context,
                                 helper.TEST_RESOURCE1)
        entries = [entry.data for entry in db.get_all_db_rows(self.db_context)]
        for resource in resources:
            self.assertIn(resource, entries)
        self.assertEqual(len(resources), len(entries)) 
Example #18
Source File: test_full_sync.py    From networking-odl with Apache License 2.0 5 votes vote down vote up
def test_plugin_not_registered(self):
        self._register_resources()
        # NOTE(rajivk): workaround, as we don't have delete method for plugin
        plugin = directory.get_plugin(helper.TEST_PLUGIN)
        directory.add_plugin(helper.TEST_PLUGIN, None)
        self.addCleanup(self.add_plugin, helper.TEST_PLUGIN, plugin)
        self.assertRaises(exceptions.PluginMethodNotFound,
                          full_sync.sync_resources,
                          self.db_context,
                          helper.TEST_RESOURCE1)
        self.assertEqual([], db.get_all_db_rows(self.db_context)) 
Example #19
Source File: test_full_sync.py    From networking-odl with Apache License 2.0 5 votes vote down vote up
def _test_full_sync_resources(self, expected_journal):
        self._mock_canary_missing()
        directory.add_plugin(constants.CORE, mock.Mock())
        full_sync.full_sync(self.db_context)

        rows = self._assert_canary_created()
        rows = self._filter_out_canary(rows)
        self.assertItemsEqual(expected_journal.keys(),
                              [row['object_type'] for row in rows])
        for row in rows:
            self.assertEqual(expected_journal[row['object_type']],
                             row['object_uuid']) 
Example #20
Source File: test_full_sync.py    From networking-odl with Apache License 2.0 5 votes vote down vote up
def _clean_registered_plugins(self):
        for plugin_type in self._get_all_plugins().keys():
            directory.add_plugin(plugin_type, None) 
Example #21
Source File: test_qos.py    From networking-odl with Apache License 2.0 5 votes vote down vote up
def setUp(self):
        self.useFixture(nlib_fixture.PluginDirectoryFixture())
        super(QoSDriverTests, self).setUp()
        self.qos_plug = qos_plugin.QoSPlugin()
        directory.add_plugin('QOS', self.qos_plug)
        ext_mgr = QoSTestExtensionManager()
        self.resource_prefix_map = {'policies': '/qos'}
        self.ext_api = test_extensions.setup_extensions_middleware(ext_mgr)
        tenant_id = uuidutils.generate_uuid()
        self.policy_data = {
            'policy': {'name': 'test-policy', 'tenant_id': tenant_id}} 
Example #22
Source File: test_l2gw_db.py    From networking-l2gw with Apache License 2.0 5 votes vote down vote up
def test_l2gw_callback_delete_port(self):
        service_plugin = mock.Mock()
        directory.add_plugin(constants.L2GW, service_plugin)
        fake_context = mock.Mock()
        fake_port = mock.Mock()
        fake_kwargs = {'context': fake_context,
                       'port': fake_port}
        l2gateway_db.l2gw_callback(resources.PORT,
                                   events.AFTER_DELETE,
                                   mock.Mock(),
                                   **fake_kwargs)
        self.assertTrue(service_plugin.delete_port_mac.called) 
Example #23
Source File: test_l2gw_db.py    From networking-l2gw with Apache License 2.0 5 votes vote down vote up
def test_l2gw_callback_update_port(self):
        service_plugin = mock.Mock()
        directory.add_plugin(constants.L2GW, service_plugin)
        fake_context = mock.Mock()
        fake_port = mock.Mock()
        fake_kwargs = {'context': fake_context,
                       'port': fake_port}
        l2gateway_db.l2gw_callback(resources.PORT,
                                   events.AFTER_UPDATE,
                                   mock.Mock(),
                                   **fake_kwargs)
        self.assertTrue(service_plugin.add_port_mac.called) 
Example #24
Source File: test_l2gw_db.py    From networking-l2gw with Apache License 2.0 5 votes vote down vote up
def test_l2gateway_con_create_with_invalid_net_id(self):
        """Test l2 gateway connection create with invalid net id."""
        name = "l2gw_con2"
        device_name = "device_name2"
        data_l2gw = self._get_l2_gateway_data(name,
                                              device_name)
        gw = self._create_l2gateway(data_l2gw)
        net_id = 'invalid_net_id'
        l2gw_id = gw['id']
        data_con = {self.con_resource: {'l2_gateway_id': l2gw_id,
                                        'network_id': net_id}}
        directory.add_plugin('CORE', self.plugin)
        self.assertRaises(exc.NetworkNotFound,
                          self._validate_l2_gateway_connection_for_create,
                          data_con) 
Example #25
Source File: test_bgp_speaker_rpc.py    From neutron-dynamic-routing with Apache License 2.0 5 votes vote down vote up
def setUp(self):
        super(TestBgpSpeakerRpcCallback, self).setUp()
        self.plugin = mock.Mock()
        directory.add_plugin(bgp_ext.BGP_EXT_ALIAS, self.plugin)
        self.callback = bgp_speaker_rpc.BgpSpeakerRpcCallback() 
Example #26
Source File: test_vpn_validator.py    From neutron-vpnaas with Apache License 2.0 5 votes vote down vote up
def setUp(self):
        super(TestVpnValidation, self).setUp()
        self.l3_plugin = mock.Mock()
        self.core_plugin = mock.Mock()
        directory.add_plugin(nconstants.CORE, self.core_plugin)
        directory.add_plugin(nconstants.L3, self.l3_plugin)
        self.context = n_ctx.Context('some_user', 'some_tenant')
        self.validator = vpn_validator.VpnReferenceValidator()
        self.router = mock.Mock()
        self.router.gw_port = {'fixed_ips': [{'ip_address': '10.0.0.99'}]} 
Example #27
Source File: test_plugin.py    From neutron-vpnaas with Apache License 2.0 5 votes vote down vote up
def test_get_provider_for_flavor_id_flavor_disabled(self):
        FAKE_FLAVOR = {'service_type': p_constants.VPN,
                       'enabled': False}
        directory.add_plugin(p_constants.FLAVORS,
                             flavors_plugin.FlavorsPlugin())
        mock.patch(
            'neutron.services.flavors.flavors_plugin.FlavorsPlugin.get_flavor',
            return_value=FAKE_FLAVOR).start()
        with self.vpnservices_providers_set():
            driver_plugin = vpn_plugin.VPNDriverPlugin()
            self.assertRaises(
                flav_exc.FlavorDisabled,
                driver_plugin._get_provider_for_flavor,
                self.adminContext,
                _uuid()) 
Example #28
Source File: test_plugin.py    From neutron-vpnaas with Apache License 2.0 5 votes vote down vote up
def test_get_provider_for_flavor_id_invalid_type(self):
        FAKE_FLAVOR = {'service_type': 'NOT_VPN'}
        directory.add_plugin(p_constants.FLAVORS,
                             flavors_plugin.FlavorsPlugin())
        mock.patch(
            'neutron.services.flavors.flavors_plugin.FlavorsPlugin.get_flavor',
            return_value=FAKE_FLAVOR).start()
        with self.vpnservices_providers_set():
            driver_plugin = vpn_plugin.VPNDriverPlugin()
            self.assertRaises(
                lib_exc.InvalidServiceType,
                driver_plugin._get_provider_for_flavor,
                self.adminContext,
                _uuid())