Пример #1
0
 def _setup_router_with_v4_and_v6(self):
     router_dict = {'name': 'test_router', 'admin_state_up': True,
                    'distributed': True}
     router = self._create_router(router_dict)
     plugin = mock.MagicMock()
     with self.network() as net_ext, self.network() as net_int:
         ext_net_id = net_ext['network']['id']
         self.core_plugin.update_network(
             self.ctx, ext_net_id,
             {'network': {'router:external': True}})
         self.mixin.update_router(
             self.ctx, router['id'],
             {'router': {'external_gateway_info':
                         {'network_id': ext_net_id}}})
         with self.subnet(
             network=net_int, cidr='20.0.0.0/24') as subnet_v4,\
             self.subnet(
                 network=net_int, cidr='fe80::/64',
                 gateway_ip='fe80::1', ip_version=6) as subnet_v6:
             self.mixin.add_router_interface(self.ctx, router['id'],
                 {'subnet_id': subnet_v4['subnet']['id']})
             self.mixin.add_router_interface(self.ctx, router['id'],
                 {'subnet_id': subnet_v6['subnet']['id']})
             directory.add_plugin(const.L3, plugin)
             return router, subnet_v4, subnet_v6
Пример #2
0
 def _test_update_arp_entry_for_dvr_service_port(
         self, device_owner, action):
     router_dict = {'name': 'test_router', 'admin_state_up': True,
                    'distributed': True}
     router = self._create_router(router_dict)
     plugin = mock.Mock()
     directory.add_plugin(plugin_constants.CORE, plugin)
     l3_notify = self.mixin.l3_rpc_notifier = mock.Mock()
     port = {
         'id': 'my_port_id',
         'fixed_ips': [
             {'subnet_id': '51edc9e0-24f9-47f2-8e1e-2a41cb691323',
              'ip_address': '10.0.0.11'},
             {'subnet_id': '2b7c8a07-6f8e-4937-8701-f1d5da1a807c',
              'ip_address': '10.0.0.21'},
             {'subnet_id': '48534187-f077-4e81-93ff-81ec4cc0ad3b',
              'ip_address': 'fd45:1515:7e0:0:f816:3eff:fe1a:1111'}],
         'mac_address': 'my_mac',
         'device_owner': device_owner
     }
     dvr_port = {
         'id': 'dvr_port_id',
         'fixed_ips': mock.ANY,
         'device_owner': const.DEVICE_OWNER_DVR_INTERFACE,
         'device_id': router['id']
     }
     plugin.get_ports.return_value = [dvr_port]
     if action == 'add':
         self.mixin.update_arp_entry_for_dvr_service_port(
             self.ctx, port)
         self.assertEqual(3, l3_notify.add_arp_entry.call_count)
     elif action == 'del':
         self.mixin.delete_arp_entry_for_dvr_service_port(
             self.ctx, port)
         self.assertEqual(3, l3_notify.del_arp_entry.call_count)
Пример #3
0
    def __init__(self, options=None, config_file=None):
        # If no options have been provided, create an empty dict
        if not options:
            options = {}

        msg = validate_pre_plugin_load()
        if msg:
            LOG.critical(msg)
            raise Exception(msg)

        # NOTE(jkoelker) Testing for the subclass with the __subclasshook__
        #                breaks tach monitoring. It has been removed
        #                intentionally to allow v2 plugins to be monitored
        #                for performance metrics.
        plugin_provider = cfg.CONF.core_plugin
        LOG.info("Loading core plugin: %s", plugin_provider)
        # NOTE(armax): keep hold of the actual plugin object
        plugin = self._get_plugin_instance(CORE_PLUGINS_NAMESPACE,
                                           plugin_provider)
        directory.add_plugin(lib_const.CORE, plugin)
        msg = validate_post_plugin_load()
        if msg:
            LOG.critical(msg)
            raise Exception(msg)

        # load services from the core plugin first
        self._load_services_from_core_plugin(plugin)
        self._load_service_plugins()
        # Used by pecan WSGI
        self.resource_plugin_mappings = {}
        self.resource_controller_mappings = {}
        self.path_prefix_resource_mappings = defaultdict(list)
Пример #4
0
    def setUp(self):
        super(ProvidernetExtensionTestCase, self).setUp()

        plugin = 'neutron.neutron_plugin_base_v2.NeutronPluginBaseV2'

        # Ensure existing ExtensionManager is not used
        extensions.PluginAwareExtensionManager._instance = None

        self.useFixture(fixture.APIDefinitionFixture())

        # Update the plugin and extensions path
        self.setup_coreplugin(plugin, load_plugins=False)
        self._plugin_patcher = mock.patch(plugin, autospec=True)
        self.plugin = self._plugin_patcher.start()
        # Ensure Quota checks never fail because of mock
        instance = self.plugin.return_value
        instance.get_networks_count.return_value = 1
        # Register mock plugin and enable the 'provider' extension
        instance.supported_extension_aliases = ["provider"]
        directory.add_plugin(constants.CORE, instance)
        ext_mgr = ProviderExtensionManager()
        self.ext_mdw = test_extensions.setup_extensions_middleware(ext_mgr)
        self.addCleanup(self._plugin_patcher.stop)
        self.api = webtest.TestApp(router.APIRouter())

        quota.QUOTAS._driver = None
        cfg.CONF.set_override('quota_driver', 'neutron.quota.ConfDriver',
                              group='QUOTAS')
Пример #5
0
    def _test_validate_log_type_for_port(self, port, expected_result):
        driver_manager = self._create_manager_with_drivers({
            'driver-A': {
                'is_loaded': True,
                'supported_logging_types': ['security_group'],
                'vif_types': [portbindings.VIF_TYPE_OVS],
                'vnic_types': [portbindings.VNIC_NORMAL]
            }
        })

        is_log_type_supported_mock = mock.Mock()
        if expected_result:
            is_log_type_supported_mock.return_value = expected_result
        log_driver = list(driver_manager.drivers)[0]
        log_driver.is_logging_type_supported = (
            is_log_type_supported_mock
        )

        class FakeLoggingPlugin(object):
            def __init__(self):
                self.driver_manager = driver_manager

        directory.add_plugin(plugin_const.LOG_API, FakeLoggingPlugin())

        self.assertEqual(
            expected_result,
            validators.validate_log_type_for_port('security_group', port))
        if expected_result:
            is_log_type_supported_mock.assert_called_once_with(
                'security_group')
        else:
            is_log_type_supported_mock.assert_not_called()
Пример #6
0
 def _helper_delete_floatingip_agent_gateway_port(self, port_host):
     ports = [{
         'id': 'my_port_id',
         portbindings.HOST_ID: 'foo_host',
         'network_id': 'ext_network_id',
         'device_owner': const.DEVICE_OWNER_ROUTER_GW
     },
             {
         'id': 'my_new_port_id',
         portbindings.HOST_ID: 'my_foo_host',
         'network_id': 'ext_network_id',
         'device_owner': const.DEVICE_OWNER_ROUTER_GW
     }]
     plugin = mock.Mock()
     directory.add_plugin(plugin_constants.CORE, plugin)
     plugin.get_ports.return_value = ports
     self.mixin.delete_floatingip_agent_gateway_port(
         self.ctx, port_host, 'ext_network_id')
     plugin.get_ports.assert_called_with(self.ctx, filters={
         'network_id': ['ext_network_id'],
         'device_owner': [const.DEVICE_OWNER_AGENT_GW]})
     if port_host:
         plugin.ipam.delete_port.assert_called_once_with(
             self.ctx, 'my_port_id')
     else:
         plugin.ipam.delete_port.assert_called_with(
             self.ctx, 'my_new_port_id')
Пример #7
0
    def setUp(self):
        super(L3SchedulerBaseTest, self).setUp(PLUGIN_NAME)

        self.l3_plugin = l3_router_plugin.L3RouterPlugin()
        directory.add_plugin(plugin_constants.L3, self.l3_plugin)
        self.adminContext = context.get_admin_context()
        self.adminContext.tenant_id = _uuid()
Пример #8
0
 def setUp(self):
     super(RpcCallbacksTestCase, self).setUp()
     self.type_manager = managers.TypeManager()
     self.notifier = plugin_rpc.AgentNotifierApi(topics.AGENT)
     self.callbacks = plugin_rpc.RpcCallbacks(self.notifier,
                                              self.type_manager)
     self.plugin = mock.MagicMock()
     directory.add_plugin(plugin_constants.CORE, self.plugin)
Пример #9
0
 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, {})
Пример #10
0
 def test_delete_network_check_disassociated_floatingips(self):
     l3_mock = mock.Mock()
     directory.add_plugin("L3_ROUTER_NAT", l3_mock)
     with self.network() as net:
         req = self.new_delete_request("networks", net["network"]["id"])
         res = req.get_response(self.api)
         self.assertEqual(exc.HTTPNoContent.code, res.status_int)
         (l3_mock.delete_disassociated_floatingips.assert_called_once_with(mock.ANY, net["network"]["id"]))
Пример #11
0
    def _setup_delete_current_gw_port_deletes_dvr_internal_ports(
        self, port=None, gw_port=True, new_network_id='ext_net_id_2'):
        router_db = {
            'name': 'foo_router',
            'admin_state_up': True,
            'distributed': True
        }
        router = self._create_router(router_db)
        if gw_port:
            with self.subnet(cidr='10.10.10.0/24') as subnet:
                port_dict = {
                    'device_id': router.id,
                    'device_owner': const.DEVICE_OWNER_ROUTER_GW,
                    'admin_state_up': True,
                    'fixed_ips': [{'subnet_id': subnet['subnet']['id'],
                                   'ip_address': '10.10.10.100'}]
                }
            net_id = subnet['subnet']['network_id']
            port_res = self.create_port(net_id, port_dict)
            port_res_dict = self.deserialize(self.fmt, port_res)
            with self.ctx.session.begin(subtransactions=True):
                port_db = self.ctx.session.query(models_v2.Port).filter_by(
                    id=port_res_dict['port']['id']).one()
                router.gw_port = port_db
                router_port = l3_models.RouterPort(
                    router_id=router.id,
                    port_id=port_db.id,
                    port_type=const.DEVICE_OWNER_ROUTER_GW
                )
                self.ctx.session.add(router)
                self.ctx.session.add(router_port)

        else:
            net_id = None

        plugin = mock.Mock()
        directory.add_plugin(plugin_constants.CORE, plugin)
        with mock.patch.object(l3_dvr_db.l3_db.L3_NAT_db_mixin,
                               'router_gw_port_has_floating_ips',
                               return_value=False),\
            mock.patch.object(
                self.mixin,
                '_get_router') as grtr,\
            mock.patch.object(
                self.mixin,
                'delete_csnat_router_interface_ports') as del_csnat_port,\
            mock.patch.object(
                self.mixin,
                'delete_floatingip_agent_gateway_port') as del_agent_gw_port,\
            mock.patch.object(
                self.mixin.l3_rpc_notifier,
                'delete_fipnamespace_for_ext_net') as del_fip:
            plugin.get_ports.return_value = port
            grtr.return_value = router
            self.mixin._delete_current_gw_port(
                self.ctx, router['id'], router, new_network_id)
            return router, plugin, net_id, del_csnat_port,\
                del_agent_gw_port, del_fip
Пример #12
0
 def test_delete_network_check_disassociated_floatingips(self):
     l3_mock = mock.Mock()
     directory.add_plugin(constants.L3, l3_mock)
     with self.network() as net:
         req = self.new_delete_request('networks', net['network']['id'])
         res = req.get_response(self.api)
         self.assertEqual(exc.HTTPNoContent.code, res.status_int)
         (l3_mock.delete_disassociated_floatingips
          .assert_called_once_with(mock.ANY, net['network']['id']))
Пример #13
0
    def setUp(self):
        super(L3AZSchedulerBaseTest, self).setUp(plugin='ml2')

        self.l3_plugin = l3_router_plugin.L3RouterPlugin()
        directory.add_plugin(plugin_constants.L3, self.l3_plugin)
        self.l3_plugin.router_scheduler = None
        directory.add_plugin(plugin_constants.L3, self.l3_plugin)
        self.adminContext = context.get_admin_context()
        self.adminContext.tenant_id = '_func_test_tenant_'
 def setUp(self):
     super(TestAristaJSONRPCWrapper, self).setUp()
     plugin_klass = importutils.import_class(
         "neutron.db.db_base_plugin_v2.NeutronDbPluginV2")
     directory.add_plugin(plugin_constants.CORE, plugin_klass())
     setup_valid_config()
     self.drv = arista_json.AristaRPCWrapperJSON()
     self.drv._server_ip = "10.11.12.13"
     self.region = 'RegionOne'
Пример #15
0
 def _test_prepare_direct_delete_dvr_internal_ports(self, port):
     plugin = mock.Mock()
     directory.add_plugin(plugin_constants.CORE, plugin)
     plugin.get_port.return_value = port
     self.mixin._router_exists = mock.Mock(return_value=True)
     self.assertRaises(exceptions.ServicePortInUse,
                       self.mixin.prevent_l3_port_deletion,
                       self.ctx,
                       port['id'])
Пример #16
0
    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])
Пример #17
0
 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'}]}
Пример #18
0
 def test__get_agent_gw_ports_exist_for_network(self):
     plugin = mock.Mock()
     directory.add_plugin(plugin_constants.CORE, plugin)
     plugin.get_ports.return_value = []
     self.mixin._get_agent_gw_ports_exist_for_network(
         self.ctx, 'network_id', 'host', 'agent_id')
     plugin.get_ports.assert_called_with(self.ctx, {
         'network_id': ['network_id'],
         'device_id': ['agent_id'],
         'device_owner': [const.DEVICE_OWNER_AGENT_GW]})
 def setUp(self):
     super(SyncServiceTest, self).setUp()
     utils.setup_arista_wrapper_config(cfg)
     plugin_klass = importutils.import_class(
         "neutron.db.db_base_plugin_v2.NeutronDbPluginV2")
     directory.add_plugin(plugin_constants.CORE, plugin_klass())
     utils.setup_scenario()
     self.mech_queue = queue.LightQueue()
     self.sync_service = arista_sync.AristaSyncWorker(self.mech_queue)
     self.sync_service._rpc = utils.MockCvx('region')
Пример #20
0
    def setUp(self, plugin=None):
        super(TestNovaNotify, self).setUp()

        class FakePlugin(object):
            def get_port(self, context, port_id):
                device_id = '32102d7b-1cf4-404d-b50a-97aae1f55f87'
                return {'device_id': device_id,
                        'device_owner': DEVICE_OWNER_COMPUTE}

        self.nova_notifier = nova.Notifier()
        directory.add_plugin(n_const.CORE, FakePlugin())
Пример #21
0
    def _load_services_from_core_plugin(self, plugin):
        """Puts core plugin in service_plugins for supported services."""
        LOG.debug("Loading services supported by the core plugin")

        # supported service types are derived from supported extensions
        for ext_alias in getattr(plugin, "supported_extension_aliases", []):
            if ext_alias in constants.EXT_TO_SERVICE_MAPPING:
                service_type = constants.EXT_TO_SERVICE_MAPPING[ext_alias]
                directory.add_plugin(service_type, plugin)
                LOG.info("Service %s is supported by the core plugin",
                         service_type)
Пример #22
0
 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))
Пример #23
0
 def __init__(self):
     config.register_nsxv_azs(cfg.CONF, cfg.CONF.nsxv.availability_zones)
     self.context = neutron_context.get_admin_context()
     self.filters = get_plugin_filters(self.context)
     super(NsxVPluginWrapper, self).__init__()
     # Make this the core plugin
     directory.add_plugin('CORE', self)
     # finish the plugin initialization
     # (with md-proxy config, but without housekeeping)
     with mock.patch("vmware_nsx.plugins.common.housekeeper."
                     "housekeeper.NsxHousekeeper"):
         self.init_complete(0, 0, 0)
Пример #24
0
    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'])
Пример #25
0
 def test_can_be_trunked_returns_false(self):
     # need to trigger a driver registration
     fakes.FakeDriverCanTrunkBoundPort.create()
     self.trunk_plugin = trunk_plugin.TrunkPlugin()
     directory.add_plugin('trunk', self.trunk_plugin)
     with self.port() as port:
         core_plugin = directory.get_plugin()
         port['port']['binding:host_id'] = 'host'
         core_plugin.update_port(self.context, port['port']['id'], port)
         validator = rules.TrunkPortValidator(port['port']['id'])
         # port cannot be trunked because of binding mismatch
         self.assertFalse(validator.can_be_trunked(self.context))
Пример #26
0
 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)
Пример #27
0
 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())
Пример #28
0
    def setUp(self, plugin=None):
        super(TestNovaNotify, self).setUp()
        self.ctx = n_ctx.get_admin_context()
        self.port_uuid = uuidutils.generate_uuid()

        class FakePlugin(object):
            def get_port(self, context, port_id):
                device_id = '32102d7b-1cf4-404d-b50a-97aae1f55f87'
                return {'device_id': device_id,
                        'device_owner': DEVICE_OWNER_COMPUTE,
                        'id': port_id}

        self.nova_notifier = nova.Notifier()
        directory.add_plugin(plugin_constants.CORE, FakePlugin())
Пример #29
0
 def test_can_be_trunked_returns_true(self):
     # need to trigger a driver registration
     fakes.FakeDriverCanTrunkBoundPort.create()
     self.trunk_plugin = trunk_plugin.TrunkPlugin()
     directory.add_plugin('trunk', self.trunk_plugin)
     with self.port() as port, \
             mock.patch.object(trunk_utils, "is_driver_compatible",
                               return_value=True) as g:
         core_plugin = directory.get_plugin()
         port['port']['binding:host_id'] = 'host'
         core_plugin.update_port(self.context, port['port']['id'], port)
         validator = rules.TrunkPortValidator(port['port']['id'])
         self.assertTrue(validator.can_be_trunked(self.context))
         self.assertTrue(g.call_count)
Пример #30
0
 def setUp(self):
     super(TestDhcpRpcCallback, self).setUp()
     self.plugin = mock.MagicMock()
     directory.add_plugin(plugin_constants.CORE, self.plugin)
     self.callbacks = dhcp_rpc.DhcpRpcCallback()
     self.log_p = mock.patch('neutron.api.rpc.handlers.dhcp_rpc.LOG')
     self.log = self.log_p.start()
     set_dirty_p = mock.patch('neutron.quota.resource_registry.'
                              'set_resources_dirty')
     self.mock_set_dirty = set_dirty_p.start()
     self.utils_p = mock.patch('neutron.plugins.common.utils.create_port')
     self.utils = self.utils_p.start()
     self.segment_plugin = mock.MagicMock()
     directory.add_plugin('segments', self.segment_plugin)
Пример #31
0
    def _load_service_plugins(self):
        """Loads service plugins.

        Starts from the core plugin and checks if it supports
        advanced services then loads classes provided in configuration.
        """
        plugin_providers = cfg.CONF.service_plugins
        plugin_providers.extend(self._get_default_service_plugins())
        LOG.debug("Loading service plugins: %s", plugin_providers)
        for provider in plugin_providers:
            if provider == '':
                continue

            LOG.info("Loading Plugin: %s", provider)
            plugin_inst = self._get_plugin_instance('neutron.service_plugins',
                                                    provider)

            # only one implementation of svc_type allowed
            # specifying more than one plugin
            # for the same type is a fatal exception
            # TODO(armax): simplify this by moving the conditional into the
            # directory itself.
            plugin_type = plugin_inst.get_plugin_type()
            if directory.get_plugin(plugin_type):
                raise ValueError(
                    _("Multiple plugins for service "
                      "%s were configured") % plugin_type)
            # import pdb; pdb.set_trace()

            directory.add_plugin(plugin_type, plugin_inst)

            # search for possible agent notifiers declared in service plugin
            # (needed by agent management extension)
            plugin = directory.get_plugin()
            if (hasattr(plugin, 'agent_notifiers')
                    and hasattr(plugin_inst, 'agent_notifiers')):
                plugin.agent_notifiers.update(plugin_inst.agent_notifiers)

            LOG.debug(
                "Successfully loaded %(type)s plugin. "
                "Description: %(desc)s", {
                    "type": plugin_type,
                    "desc": plugin_inst.get_plugin_description()
                })
Пример #32
0
    def setUp(self, maintenance_worker=False):
        ml2_config.cfg.CONF.set_override('extension_drivers',
                                         self._extension_drivers,
                                         group='ml2')
        ml2_config.cfg.CONF.set_override('tenant_network_types', ['geneve'],
                                         group='ml2')
        ml2_config.cfg.CONF.set_override('vni_ranges', ['1:65536'],
                                         group='ml2_type_geneve')
        ovn_conf.cfg.CONF.set_override('dns_servers', ['10.10.10.10'],
                                       group='ovn')
        ovn_conf.cfg.CONF.set_override('api_workers', 1)

        self.addCleanup(exts.PluginAwareExtensionManager.clear_instance)
        self.ovsdb_server_mgr = None
        super(TestOVNFunctionalBase, self).setUp()
        self.test_log_dir = os.path.join(DEFAULT_LOG_DIR, self.id())
        base.setup_test_logging(cfg.CONF, self.test_log_dir, "testrun.txt")

        mm = directory.get_plugin().mechanism_manager
        self.mech_driver = mm.mech_drivers['ovn'].obj
        self.l3_plugin = directory.get_plugin(constants.L3)
        self.segments_plugin = directory.get_plugin('segments')
        # OVN does not use RPC: disable it for port-forwarding tests
        self.pf_plugin = manager.NeutronManager.load_class_for_provider(
            'neutron.service_plugins', 'port_forwarding')()
        self.pf_plugin._rpc_notifications_required = False
        self.log_plugin = directory.get_plugin(constants.LOG_API)
        if not self.log_plugin:
            self.log_plugin = manager.NeutronManager.load_class_for_provider(
                'neutron.service_plugins', 'log')()
            directory.add_plugin(constants.LOG_API, self.log_plugin)
            self.log_plugin.driver_manager.register_driver(
                self.mech_driver.log_driver)
        self.mech_driver.log_driver.plugin_driver = self.mech_driver
        self.mech_driver.log_driver._log_plugin_property = None
        self.ovn_northd_mgr = None
        self.maintenance_worker = maintenance_worker
        mock.patch('neutron.plugins.ml2.drivers.ovn.mech_driver.ovsdb.'
                   'maintenance.MaintenanceThread').start()
        mock.patch('neutron.plugins.ml2.drivers.ovn.mech_driver.ovsdb.'
                   'maintenance.HashRingHealthCheckPeriodics').start()
        self._start_idls()
        self._start_ovn_northd()
        self.addCleanup(self._reset_agent_cache_singleton)
Пример #33
0
    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()
Пример #34
0
    def setUp(self):
        super(NeutronPolicyTestCase, self).setUp()
        policy.refresh()
        # Add Fake resources to RESOURCE_ATTRIBUTE_MAP
        attributes.RESOURCE_ATTRIBUTE_MAP.update(FAKE_RESOURCES)
        self._set_rules()

        def remove_fake_resource():
            del attributes.RESOURCE_ATTRIBUTE_MAP["%ss" % FAKE_RESOURCE_NAME]

        self.patcher = mock.patch.object(neutron.policy,
                                         'init',
                                         new=self.fakepolicyinit)
        self.patcher.start()
        self.addCleanup(remove_fake_resource)
        self.context = context.Context('fake', 'fake', roles=['user'])
        plugin_klass = importutils.import_class(
            "neutron.db.db_base_plugin_v2.NeutronDbPluginV2")
        directory.add_plugin(constants.CORE, plugin_klass())
Пример #35
0
 def _test_update_arp_entry_for_dvr_service_port(self, device_owner,
                                                 action):
     router_dict = {
         'name': 'test_router',
         'admin_state_up': True,
         'distributed': True
     }
     router = self._create_router(router_dict)
     plugin = mock.Mock()
     directory.add_plugin(plugin_constants.CORE, plugin)
     l3_notify = self.mixin.l3_rpc_notifier = mock.Mock()
     port = {
         'id':
         'my_port_id',
         'fixed_ips': [{
             'subnet_id': '51edc9e0-24f9-47f2-8e1e-2a41cb691323',
             'ip_address': '10.0.0.11'
         }, {
             'subnet_id': '2b7c8a07-6f8e-4937-8701-f1d5da1a807c',
             'ip_address': '10.0.0.21'
         }, {
             'subnet_id': '48534187-f077-4e81-93ff-81ec4cc0ad3b',
             'ip_address': 'fd45:1515:7e0:0:f816:3eff:fe1a:1111'
         }],
         'mac_address':
         'my_mac',
         'device_owner':
         device_owner
     }
     dvr_port = {
         'id': 'dvr_port_id',
         'fixed_ips': mock.ANY,
         'device_owner': const.DEVICE_OWNER_DVR_INTERFACE,
         'device_id': router['id']
     }
     plugin.get_ports.return_value = [dvr_port]
     if action == 'add':
         self.mixin.update_arp_entry_for_dvr_service_port(self.ctx, port)
         self.assertEqual(3, l3_notify.add_arp_entry.call_count)
     elif action == 'del':
         self.mixin.delete_arp_entry_for_dvr_service_port(self.ctx, port)
         self.assertEqual(3, l3_notify.del_arp_entry.call_count)
Пример #36
0
    def test_all_plugins_checked(self):
        plugin1 = mock.Mock()
        plugin2 = mock.Mock()
        plugins = {'plugin1': plugin1, 'plugin2': plugin2}

        for name, plugin in plugins.items():
            plugin.get_floatingips_count.side_effect = NotImplementedError
            plugin.get_floatingips.side_effect = NotImplementedError
            directory.add_plugin(name, plugin)

        context = mock.Mock()
        collection_name = 'floatingips'
        project_id = 'fakeid'
        self.assertRaises(NotImplementedError, resource._count_resource,
                          context, collection_name, project_id)

        for plugin in plugins.values():
            for func in (plugin.get_floatingips_count, plugin.get_floatingips):
                func.assert_called_with(context,
                                        filters={'project_id': [project_id]})
Пример #37
0
    def _create_and_add_service_plugin(self, provider):
        plugin_inst = self._get_plugin_instance('neutron.service_plugins',
                                                provider)
        plugin_type = plugin_inst.get_plugin_type()
        directory.add_plugin(plugin_type, plugin_inst)

        # search for possible agent notifiers declared in service plugin
        # (needed by agent management extension)
        plugin = directory.get_plugin()
        if (hasattr(plugin, 'agent_notifiers') and
                hasattr(plugin_inst, 'agent_notifiers')):
            plugin.agent_notifiers.update(plugin_inst.agent_notifiers)

        # disable incompatible extensions in core plugin if any
        utils.disable_extension_by_service_plugin(plugin, plugin_inst)

        LOG.debug("Successfully loaded %(type)s plugin. "
                  "Description: %(desc)s",
                  {"type": plugin_type,
                   "desc": plugin_inst.get_plugin_description()})
Пример #38
0
    def setUp(self):
        super(TestCiscoIPsecDriver, self).setUp()
        mock.patch('neutron.common.rpc.create_connection').start()
        self._fake_vpn_router_id = _uuid()
        service_plugin = mock.Mock()
        service_plugin._get_vpnservice.return_value = {
            'router_id': self._fake_vpn_router_id
        }

        l3_plugin = mock.Mock()
        directory.add_plugin(lib_const.L3, l3_plugin)

        l3_plugin.get_host_for_router.return_value = FAKE_HOST
        l3_agent = mock.Mock()
        l3_agent.host = 'some-host'
        l3_plugin.get_l3_agents_hosting_routers.return_value = [l3_agent]

        self.driver = ipsec_driver.CiscoCsrIPsecVPNDriver(service_plugin)
        mock.patch.object(csr_db, 'create_tunnel_mapping').start()
        self.context = n_ctx.Context('some_user', 'some_tenant')
Пример #39
0
 def test__notify_agents_cast_required_with_scheduling_segment(self):
     network_id = 'foo_network_id'
     segment_id = 'foo_segment_id'
     subnet = {'subnet': {'segment_id': segment_id}}
     segment = {
         'id': segment_id,
         'network_id': network_id,
         'hosts': ['host-a']
     }
     self.notifier.plugin.get_network.return_value = {'id': network_id}
     segment_sp = mock.Mock()
     segment_sp.get_segment.return_value = segment
     directory.add_plugin('segments', segment_sp)
     self._test__notify_agents('subnet_create_end',
                               expected_scheduling=1,
                               expected_casts=1,
                               payload=subnet)
     get_agents = self.notifier.plugin.get_dhcp_agents_hosting_networks
     get_agents.assert_called_once_with(mock.ANY, [network_id],
                                        hosts=segment['hosts'])
Пример #40
0
    def _setup_delete_current_gw_port_deletes_dvr_internal_ports(
            self, port=None, gw_port=True, new_network_id='ext_net_id_2'):
        router = mock.MagicMock()
        router.extra_attributes.distributed = True
        if gw_port:
            gw_port_db = {
                'id': 'my_gw_id',
                'network_id': 'ext_net_id',
                'device_owner': const.DEVICE_OWNER_ROUTER_GW,
                'fixed_ips': [{
                    'ip_address': '1.2.3.4'
                }]
            }
            router.gw_port = gw_port_db
        else:
            router.gw_port = None

        plugin = mock.Mock()
        directory.add_plugin(plugin_constants.CORE, plugin)
        with mock.patch.object(l3_dvr_db.l3_db.L3_NAT_db_mixin,
                               'router_gw_port_has_floating_ips',
                               return_value=False),\
            mock.patch.object(l3_dvr_db.l3_db.L3_NAT_db_mixin,
                              '_delete_router_gw_port_db'),\
            mock.patch.object(
                self.mixin,
                '_get_router') as grtr,\
            mock.patch.object(
                self.mixin,
                'delete_csnat_router_interface_ports') as del_csnat_port,\
            mock.patch.object(
                self.mixin,
                'delete_floatingip_agent_gateway_port') as del_agent_gw_port,\
            mock.patch.object(
                self.mixin.l3_rpc_notifier,
                'delete_fipnamespace_for_ext_net') as del_fip:
            plugin.get_ports.return_value = port
            grtr.return_value = router
            self.mixin._delete_current_gw_port(self.ctx, router['id'], router,
                                               new_network_id)
            return router, plugin, del_csnat_port, del_agent_gw_port, del_fip
Пример #41
0
 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, 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)
Пример #42
0
 def setUp(self, *args, **kwargs):
     super(L3TestCase, self).setUp(plugin='ml2')
     self.core_plugin = directory.get_plugin()
     self.ctx = context.get_admin_context()
     self.mixin = FakeL3Plugin()
     directory.add_plugin(plugin_constants.L3, self.mixin)
     self.network = self.create_network()
     self.subnets = []
     self.subnets.append(self.create_subnet(self.network, '1.1.1.1',
                                            '1.1.1.0/24'))
     self.subnets.append(self.create_subnet(self.network, '1.1.2.1',
                                            '1.1.2.0/24'))
     router = {'router': {'name': 'foo_router', 'admin_state_up': True,
                          'tenant_id': 'foo_tenant'}}
     self.router = self.create_router(router)
     self.ports = []
     for subnet in self.subnets:
         ipa = str(netaddr.IPNetwork(subnet['subnet']['cidr']).ip + 10)
         fixed_ips = [{'subnet_id': subnet['subnet']['id'],
                       'ip_address': ipa}]
         self.ports.append(self.create_port(
             self.network['network']['id'], {'fixed_ips': fixed_ips}))
     self.addCleanup(self._clean_objs)
Пример #43
0
 def test__flavor_plugin(self):
     directory.add_plugin(p_cons.FLAVORS, mock.Mock())
     _dc = driver_controller.DriverController(self.fake_l3)
     self.assertEqual(directory.get_plugin(p_cons.FLAVORS),
                      _dc._flavor_plugin)
 def setUp(self):
     super(PortSecurityDbMixinTestCase, self).setUp()
     self.plugin = FakePlugin()
     directory.add_plugin(constants.CORE, self.plugin)
Пример #45
0
 def test_fixture(self):
     directory.add_plugin('foo', 'foo')
     self.assertTrue(self.directory.add_plugin.called)
Пример #46
0
 def __exit__(self, exc_type, exc_value, traceback):
     directory.add_plugin(plugin_constants.CORE, None)
Пример #47
0
 def __enter__(self):
     directory.add_plugin(plugin_constants.CORE, self)
     return self
 def _setUp(self):
     super(OpenDaylightAgentDBFixture, self)._setUp()
     fake_agents_db = mock.MagicMock()
     fake_agents_db.create_or_update_agent = mock.MagicMock()
     directory.add_plugin(plugin_constants.CORE, fake_agents_db)
Пример #49
0
 def setUp(self):
     super(TestExtraRouteDb, self).setUp()
     self._plugin = _Plugin()
     directory.add_plugin(constants.CORE, self._plugin)
Пример #50
0
 def __enter__(self):
     directory.add_plugin(const.CORE, self)
     return self
Пример #51
0
 def test_get_unique_plugins(self):
     directory.add_plugin('foo1', fake_plugin)
     directory.add_plugin('foo2', fake_plugin)
     self.assertEqual(1, len(directory.get_unique_plugins()))
Пример #52
0
 def test_get_plugins(self):
     directory.add_plugin('CORE', fake_plugin)
     self.assertIsNotNone(directory.get_plugins())
Пример #53
0
 def test_get_plugin_alias(self):
     directory.add_plugin('foo', fake_plugin)
     self.assertIsNotNone(directory.get_plugin('foo'))
Пример #54
0
 def test_add_plugin(self):
     directory.add_plugin('foo', fake_plugin)
     self.assertIn('foo', directory.get_plugins())
Пример #55
0
 def setUp(self):
     super(PortForwardingTestCaseBase, self).setUp()
     self.pf_plugin = pf_plugin.PortForwardingPlugin()
     directory.add_plugin(plugin_constants.PORTFORWARDING, self.pf_plugin)
Пример #56
0
 def setUp(self):
     super(DbLibTest, self).setUp()
     plugin_klass = importutils.import_class(
         "neutron.db.db_base_plugin_v2.NeutronDbPluginV2")
     directory.add_plugin(plugin_constants.CORE, plugin_klass())
Пример #57
0
 def test_is_loaded(self):
     self.assertFalse(directory.is_loaded())
     directory.add_plugin('foo1', fake_plugin)
     self.assertTrue(directory.is_loaded())
Пример #58
0
 def setUp(self):
     super(L3DvrTestCase, self).setUp(plugin='ml2')
     self.core_plugin = directory.get_plugin()
     self.ctx = context.get_admin_context()
     self.mixin = FakeL3Plugin()
     directory.add_plugin(plugin_constants.L3, self.mixin)
Пример #59
0
    def _setup_delete_current_gw_port_deletes_dvr_internal_ports(
            self, port=None, gw_port=True, new_network_id='ext_net_id_2'):
        router_db = {
            'name': 'foo_router',
            'admin_state_up': True,
            'distributed': True
        }
        router = self._create_router(router_db)
        if gw_port:
            with self.subnet(cidr='10.10.10.0/24') as subnet:
                port_dict = {
                    'device_id':
                    router.id,
                    'device_owner':
                    const.DEVICE_OWNER_ROUTER_GW,
                    'admin_state_up':
                    True,
                    'fixed_ips': [{
                        'subnet_id': subnet['subnet']['id'],
                        'ip_address': '10.10.10.100'
                    }]
                }
            net_id = subnet['subnet']['network_id']
            port_res = self.create_port(net_id, port_dict)
            port_res_dict = self.deserialize(self.fmt, port_res)
            with self.ctx.session.begin(subtransactions=True):
                port_db = self.ctx.session.query(models_v2.Port).filter_by(
                    id=port_res_dict['port']['id']).one()
                router.gw_port = port_db
                router_port = l3_models.RouterPort(
                    router_id=router.id,
                    port_id=port_db.id,
                    port_type=const.DEVICE_OWNER_ROUTER_GW)
                self.ctx.session.add(router)
                self.ctx.session.add(router_port)

        else:
            net_id = None

        plugin = mock.Mock()
        directory.add_plugin(plugin_constants.CORE, plugin)
        with mock.patch.object(l3_dvr_db.l3_db.L3_NAT_db_mixin,
                               'router_gw_port_has_floating_ips',
                               return_value=False),\
            mock.patch.object(
                self.mixin,
                '_get_router') as grtr,\
            mock.patch.object(
                self.mixin,
                'delete_csnat_router_interface_ports') as del_csnat_port,\
            mock.patch.object(
                self.mixin,
                'delete_floatingip_agent_gateway_port') as del_agent_gw_port,\
            mock.patch.object(
                self.mixin.l3_rpc_notifier,
                'delete_fipnamespace_for_ext_net') as del_fip:
            plugin.get_ports.return_value = port
            grtr.return_value = router
            self.mixin._delete_current_gw_port(self.ctx, router['id'], router,
                                               new_network_id)
            return router, plugin, net_id, del_csnat_port,\
                del_agent_gw_port, del_fip
 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)