Python neutron_lib.plugins.directory.get_plugin() Examples

The following are 30 code examples of neutron_lib.plugins.directory.get_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_trunk_driver_v2.py    From networking-odl with Apache License 2.0 6 votes vote down vote up
def test_trunk_subports_update_status_parent_active_to_down(
            self, mock_set_subport_status, mock_get_subports_ids):
        resource = resources.PORT
        event_type = events.AFTER_UPDATE
        core_plugin = directory.get_plugin()
        port = FAKE_PARENT.copy()
        original_port = FAKE_PARENT.copy()
        port['status'] = n_const.PORT_STATUS_DOWN
        port_kwargs = {'port': port, 'original_port': original_port}

        mock_get_subports_ids.return_value = ['fake_port_id']

        self.handler.trunk_subports_update_status(resource, event_type,
                                                  mock.ANY, **port_kwargs)

        mock_set_subport_status.assert_called_once_with(
            core_plugin, mock.ANY, 'fake_port_id', n_const.PORT_STATUS_DOWN) 
Example #2
Source File: pseudo_agentdb_binding.py    From networking-odl with Apache License 2.0 6 votes vote down vote up
def _update_agents_db_row(self, host_config):
        if self.agents_db is None:
            self.agents_db = directory.get_plugin()

        # Update one row in agent db
        host_id = host_config['host-id']
        host_type = host_config['host-type']
        config = host_config['config']
        try:
            agentdb_row = self._AGENTDB_ROW.copy()
            agentdb_row['host'] = host_id
            agentdb_row['agent_type'] = host_type
            agentdb_row['configurations'] = jsonutils.loads(config)
            if (host_id, host_type) in self._old_agents:
                agentdb_row.pop('start_flag', None)
            self.agents_db.create_or_update_agent(
                context.get_admin_context(), agentdb_row)
            self._known_agents.add((host_id, host_type))
        except Exception:
            LOG.exception("Unable to update agentdb.") 
Example #3
Source File: bgp_speaker_router_insertion_db.py    From networking-midonet with Apache License 2.0 6 votes vote down vote up
def set_router_for_bgp_speaker_by_network(self, context,
                                              bgp_sp_id, net_id):
        """This method selects one router to be a bgp speaker.

        To pare down routers, only first subnet in specified external
        network is used for selection.
        REVISIT(Kengo): There may be a case where there are two subnets
        and a router is associated with the second subnet. The case is
        a restriction for user and should be improved later.
        """
        core_plugin = directory.get_plugin()
        subnets = core_plugin.get_subnets_by_network(context, net_id)
        if not subnets:
            raise bsri.NoSubnetInNetwork(network_id=net_id)
        if not subnets[0]['gateway_ip']:
            raise bsri.NoGatewayIpOnSubnet(subnet_id=subnets[0]['id'])
        filters = {'fixed_ips': {'ip_address': [subnets[0]['gateway_ip']],
                                 'subnet_id': [subnets[0]['id']]}}
        ports = core_plugin.get_ports(context, filters=filters)
        if not ports:
            raise bsri.NoGatewayIpPortOnSubnet(subnet_id=subnets[0]['id'])
        router_id = ports[0]['device_id']
        # If the router is already associated with bgp-speaker,
        # RouterInUse will be raised.
        self.set_router_for_bgp_speaker(context, bgp_sp_id, router_id) 
Example #4
Source File: bgp_db_midonet.py    From networking-midonet with Apache License 2.0 6 votes vote down vote up
def get_routes_from_extra_routes(self, context, rt_id, nexthops):
        """This method gets routes for extra routes defined on this router.

        * 'nexthop' is the IP address of the ports on this router
          that are on the same subnet as the peer IP addresses of
          the provided bgp speaker.
        * 'dests' are all the networks defined as extra routes
          on the router.
        """
        changed_extra = []
        l3plugin = directory.get_plugin(constants.L3)
        extra = l3plugin.get_router(context, rt_id,
                                    fields=['routes'])['routes']
        dest_networks = [extra_route['destination'] for extra_route in extra]
        for nexthop in nexthops:
            changed_extra += self._change_nexthop_to_router_ip(nexthop,
                                                               dest_networks)
        LOG.debug("advertised routes from extra routes: %s", changed_extra)
        return changed_extra 
Example #5
Source File: test_odl_dhcp_driver_base.py    From networking-odl with Apache License 2.0 6 votes vote down vote up
def get_network_context(self, network_id, create_network, ipv4=True):
        netwrk = 'netv4'
        if not ipv4:
            netwrk = 'netv6'
        current = {'status': 'ACTIVE',
                   'subnets': [],
                   'name': netwrk,
                   'provider:physical_network': None,
                   'admin_state_up': True,
                   'tenant_id': ODL_TENANT_ID,
                   'project_id': ODL_TENANT_ID,
                   'provider:network_type': 'local',
                   'router:external': False,
                   'shared': False,
                   'id': network_id,
                   'provider:segmentation_id': None}
        network = {'network': AttributeDict(current)}
        if create_network:
            plugin = directory.get_plugin()
            result, network_context = plugin._create_network_db(
                self.context, network)
            return [network, network_context]
        return network 
Example #6
Source File: test_bagpipe.py    From networking-bgpvpn with Apache License 2.0 6 votes vote down vote up
def setUp(self):
        cfg.CONF.set_override('mechanism_drivers',
                              ['logger', 'fake_agent'],
                              'ml2')

        super(TestBagpipeServiceDriverCallbacks, self).setUp(
            "%s.%s" % (__name__, TestCorePluginML2WithAgents.__name__))

        self.port_create_status = 'DOWN'
        self.plugin = directory.get_plugin()
        self.plugin.start_rpc_listeners()

        self.bagpipe_driver = self.bgpvpn_plugin.driver

        self.patched_driver = mock.patch.object(
            self.bgpvpn_plugin.driver,
            '_retrieve_bgpvpn_network_info_for_port',
            return_value=BGPVPN_INFO)
        self.patched_driver.start()

        # we choose an agent of type const.AGENT_TYPE_OFA
        # because this is the type used by the fake_agent mech driver
        helpers.register_ovs_agent(helpers.HOST, const.AGENT_TYPE_OFA)
        helpers.register_l3_agent() 
Example #7
Source File: bagpipe_v2.py    From networking-bgpvpn with Apache License 2.0 6 votes vote down vote up
def registry_router_interface_deleted(self, resource, event, trigger,
                                          payload=None):
        try:
            context = payload.context
            # for router_interface after_delete, in stable/newton, the
            # callback does not include the router_id directly, but we find
            # it in the port device_id
            router_id = payload.resource_id
            subnet_id = payload.metadata['subnet_id']
            # find the network for this subnet
            network_id = directory.get_plugin().get_subnet(
                context, subnet_id)['network_id']
            self.notify_router_interface_deleted(
                context, router_id, network_id)
        except Exception as e:
            _log_callback_processing_exception(
                resource, event, trigger,
                {'subnet_id': subnet_id, 'router_id': router_id}, e) 
Example #8
Source File: test_odl_dhcp_driver_base.py    From networking-odl with Apache License 2.0 6 votes vote down vote up
def get_network_and_subnet_context(self, cidr, dhcp_flag, create_subnet,
                                       create_network, ipv4=True):
        data = {}
        network_id = uuidutils.generate_uuid()
        subnet_id = uuidutils.generate_uuid()
        plugin = directory.get_plugin()
        data['network_id'] = network_id
        data['subnet_id'] = subnet_id
        data['context'] = self.context
        data['plugin'] = plugin
        network, network_context = \
            self.get_network_context(network_id, create_network, ipv4)
        if create_network:
            data['network_context'] = network_context
        data['network'] = network
        subnet, subnet_context = \
            self.get_subnet_context(network_id, subnet_id, cidr,
                                    dhcp_flag, create_subnet, ipv4)
        if create_subnet:
            data['subnet_context'] = subnet_context
        data['subnet'] = subnet
        return data 
Example #9
Source File: odl_dhcp_driver.py    From networking-odl with Apache License 2.0 6 votes vote down vote up
def handle_subnet_delete_event(self, resource, event, trigger,
                                   context=None, operation=None, row=None,
                                   **kwargs):
        subnet = kwargs['subnet']
        if event == constants.AFTER_DELETE:
            try:
                plugin = directory.get_plugin()
                network_id = subnet['network_id']
                device_id = constants.ODL_DEVICE_ID_START + '-' + subnet['id']
                filters = {
                    'network_id': [network_id],
                    'device_id': [device_id],
                    'device_owner': [n_const.DEVICE_OWNER_DHCP]
                }
                LOG.debug("Retrieving ODL DHCP port for deleted subnet %s",
                          subnet['id'])
                ports = plugin.get_ports(context, filters=filters)
                if ports:
                    self._delete_port_if_dhcp(plugin, context, ports[0])
            except Exception as e:
                LOG.error("Error while deleting %s subnet %s: %s", operation,
                          subnet['id'], e) 
Example #10
Source File: test_l3_odl_v2.py    From networking-odl with Apache License 2.0 6 votes vote down vote up
def setUp(self):
        self.cfg = self.useFixture(config_fixture.Config())
        self.cfg.config(core_plugin='neutron.plugins.ml2.plugin.Ml2Plugin')
        self.cfg.config(mechanism_drivers=[
                        'logger', 'opendaylight_v2'], group='ml2')
        self.useFixture(odl_base.OpenDaylightRestClientFixture())
        self.cfg.config(service_plugins=['odl-router_v2'])
        core_plugin = cfg.CONF.core_plugin
        service_plugins = {'l3_plugin_name': 'odl-router_v2'}
        self.useFixture(odl_base.OpenDaylightJournalThreadFixture())
        mock.patch.object(mech_driver_v2.OpenDaylightMechanismDriver,
                          '_record_in_journal').start()
        mock.patch.object(mech_driver_v2.OpenDaylightMechanismDriver,
                          'sync_from_callback_precommit').start()
        mock.patch.object(mech_driver_v2.OpenDaylightMechanismDriver,
                          'sync_from_callback_postcommit').start()
        self.useFixture(odl_base.OpenDaylightPeriodicTaskFixture())
        self.useFixture(odl_base.OpenDaylightFeaturesFixture())
        self.useFixture(odl_base.OpenDaylightPseudoAgentPrePopulateFixture())
        super(OpenDaylightL3TestCase, self).setUp(
            plugin=core_plugin, service_plugins=service_plugins)
        self.plugin = directory.get_plugin()
        self.plugin._network_is_external = mock.Mock(return_value=True)
        self.driver = directory.get_plugin(constants.L3)
        self.thread = journal.OpenDaylightJournalThread() 
Example #11
Source File: test_trunk_driver_v2.py    From networking-odl with Apache License 2.0 6 votes vote down vote up
def test_trunk_subports_update_status_parent_down_to_active(
            self, mock_set_subport_status, mock_get_subports_ids):
        resource = resources.PORT
        event_type = events.AFTER_UPDATE
        core_plugin = directory.get_plugin()
        port = FAKE_PARENT.copy()
        original_port = FAKE_PARENT.copy()
        original_port['status'] = n_const.PORT_STATUS_DOWN
        port_kwargs = {'port': port, 'original_port': original_port}

        mock_get_subports_ids.return_value = ['fake_port_id']

        self.handler.trunk_subports_update_status(resource, event_type,
                                                  mock.ANY, **port_kwargs)

        mock_set_subport_status.assert_called_once_with(
            core_plugin, mock.ANY, 'fake_port_id', n_const.PORT_STATUS_ACTIVE) 
Example #12
Source File: test_trunk_driver_v2.py    From networking-odl with Apache License 2.0 6 votes vote down vote up
def test_trunk_subports_set_status_create_parent_down(
            self, mock_set_subport_status):
        resource = resources.SUBPORTS
        event_type = events.AFTER_CREATE
        fake_payload = self._fake_trunk_payload()
        core_plugin = directory.get_plugin()

        fake_payload.subports = [models.SubPort(port_id='fake_port_id',
                                                segmentation_id=101,
                                                segmentation_type='vlan',
                                                trunk_id='fake_id')]
        parent_port = FAKE_PARENT.copy()
        parent_port['status'] = n_const.PORT_STATUS_DOWN

        with mock.patch.object(core_plugin, '_get_port') as gp:
            gp.return_value = parent_port
            self.handler.trunk_subports_set_status(resource, event_type,
                                                   mock.ANY, fake_payload)
            mock_set_subport_status.assert_called_once_with(
                core_plugin, mock.ANY, 'fake_port_id',
                n_const.PORT_STATUS_DOWN) 
Example #13
Source File: l2gateway_db.py    From networking-l2gw with Apache License 2.0 6 votes vote down vote up
def validate_l2_gateway_connection_for_create(self, context,
                                                  l2_gateway_connection):
        self._admin_check(context, 'CREATE')
        gw_connection = l2_gateway_connection[self.connection_resource]
        l2_gw_id = gw_connection.get('l2_gateway_id')
        network_id = gw_connection.get('network_id')
        plugin = directory.get_plugin()
        plugin.get_network(context, network_id)
        nw_map = {}
        nw_map['network_id'] = network_id
        nw_map['l2_gateway_id'] = l2_gw_id
        segmentation_id = ""
        if constants.SEG_ID in gw_connection:
            segmentation_id = gw_connection.get(constants.SEG_ID)
            nw_map[constants.SEG_ID] = segmentation_id
        is_vlan = self._is_vlan_configured_on_any_interface_for_l2gw(context,
                                                                     l2_gw_id)
        network_id = l2gw_validators.validate_network_mapping_list(nw_map,
                                                                   is_vlan)
        with context.session.begin(subtransactions=True):
            if self._retrieve_gateway_connections(context,
                                                  l2_gw_id,
                                                  nw_map):
                raise l2gw_exc.L2GatewayConnectionExists(mapping=nw_map,
                                                         gateway_id=l2_gw_id) 
Example #14
Source File: plugin.py    From networking-midonet with Apache License 2.0 6 votes vote down vote up
def add_gateway_network(self, context, bgp_speaker_id, network_info):
        with db_api.CONTEXT_WRITER.using(context):
            # TODO(kengo): This validation is temporary workaround
            # until upstream adds a validation for
            # existing combination of bgp speaker and gateway network.
            if self.get_router_associated_with_bgp_speaker(
                    context, bgp_speaker_id):
                raise bsri.BgpSpeakerInUse(
                    id=bgp_speaker_id,
                    reason='is already associated with router.')
            core_plugin = directory.get_plugin()
            if not core_plugin._network_is_external(
                    context, network_info['network_id']):
                raise bsri.NetworkTypeInvalid()
            info = super(MidonetBgpPlugin, self).add_gateway_network(
                context, bgp_speaker_id, network_info)
            self.set_router_for_bgp_speaker_by_network(
                context, bgp_speaker_id, network_info['network_id'])

        return info 
Example #15
Source File: test_df_qos_driver.py    From dragonflow with Apache License 2.0 6 votes vote down vote up
def setUp(self):
        if 'qos' not in self._extension_drivers:
            self._extension_drivers.append('qos')

        mock.patch('dragonflow.db.neutron.lockedobjects_db.wrap_db_lock',
                   side_effect=utils.empty_wrapper).start()
        mock.patch('dragonflow.neutron.services.qos.drivers.df_qos._driver',
                   new=None).start()
        super(TestDfQosDriver, self).setUp()
        self.qos_plugin = directory.get_plugin(service_constants.QOS)

        # Find by name
        self.qos_driver = [
            d for d in self.qos_plugin.driver_manager._drivers
            if d.name == 'df'
        ].pop() 
Example #16
Source File: driver.py    From networking-sfc with Apache License 2.0 6 votes vote down vote up
def _get_fcs_by_ids(self, fc_ids):
        flow_classifiers = []
        if not fc_ids:
            return flow_classifiers

        # Get the portchain flow classifiers
        fc_plugin = (
            directory.get_plugin(flowclassifier.FLOW_CLASSIFIER_EXT)
        )
        if not fc_plugin:
            LOG.warning("Not found the flow classifier service plugin")
            return flow_classifiers

        for fc_id in fc_ids:
            fc = fc_plugin.get_flow_classifier(self.admin_context, fc_id)
            flow_classifiers.append(fc)

        return flow_classifiers 
Example #17
Source File: port_behind_port.py    From dragonflow with Apache License 2.0 6 votes vote down vote up
def _find_nested_port_and_type(self, context, pair, port):
        try:
            ip = netaddr.IPAddress(pair['ip_address'])
        except ValueError:
            return None, None  # Skip. This is a network, not a host
        mac_address = pair.get('mac_address')
        if mac_address and mac_address == port['mac_address']:
            mac_address = None
        if ip is None and mac_address is None:
            return None, None
        filters = {}
        if ip:
            filters['fixed_ips'] = {'ip_address': [str(ip)]}
        if mac_address:
            filters['mac_address'] = [str(mac_address)]
        core_plugin = directory.get_plugin()
        ports = core_plugin.get_ports(context, filters=filters)
        if ports:
            segmentation_type = (trunk_models.TYPE_MACVLAN if mac_address
                                 else trunk_models.TYPE_IPVLAN)
            return ports[0], segmentation_type
        return None, None 
Example #18
Source File: port_status_update.py    From networking-odl with Apache License 2.0 5 votes vote down vote up
def _pull_missed_statuses(self):
        LOG.debug("starting to pull pending statuses...")
        plugin = directory.get_plugin()
        filter = {"status": [n_const.PORT_STATUS_DOWN],
                  "vif_type": ["unbound"]}
        ports = plugin.get_ports(context.get_admin_context(), filter)

        if not ports:
            LOG.debug("no down ports found, done")
            return

        port_fetch_url = utils.get_odl_url(self.PORT_PATH)
        client = odl_client.OpenDaylightRestClient.create_client(
            url=port_fetch_url)

        for port in ports:
            port_id = port["id"]
            response = client.get(port_id)
            if response.status_code != 200:
                LOG.warning("Non-200 response code %s", str(response))
                continue
            odl_status = response.json()['port'][0]['status']
            if odl_status == n_const.PORT_STATUS_ACTIVE:
                # for now we only support transition from DOWN->ACTIVE
                # See https://bugs.launchpad.net/networking-odl/+bug/1686023
                provisioning_blocks.provisioning_complete(
                    context.get_admin_context(),
                    port_id, resources.PORT,
                    provisioning_blocks.L2_AGENT_ENTITY)
        LOG.debug("done pulling pending statuses") 
Example #19
Source File: plugin.py    From networking-bgpvpn with Apache License 2.0 5 votes vote down vote up
def _validate_port(self, context, port_id):
        plugin = directory.get_plugin()
        port = plugin.get_port(context, port_id)
        return port 
Example #20
Source File: bgpvpn.py    From networking-bgpvpn with Apache License 2.0 5 votes vote down vote up
def get_resources(cls):
        plural_mappings = resource_helper.build_plural_mappings(
            {}, bgpvpn_api_def.RESOURCE_ATTRIBUTE_MAP)
        resources = resource_helper.build_resource_info(
            plural_mappings,
            bgpvpn_api_def.RESOURCE_ATTRIBUTE_MAP,
            bgpvpn_api_def.ALIAS,
            register_quota=True,
            translate_name=True)
        plugin = directory.get_plugin(bgpvpn_api_def.ALIAS)
        for collection_name in bgpvpn_api_def.SUB_RESOURCE_ATTRIBUTE_MAP:
            # Special handling needed for sub-resources with 'y' ending
            # (e.g. proxies -> proxy)
            resource_name = collection_name[:-1]
            parent = bgpvpn_api_def.SUB_RESOURCE_ATTRIBUTE_MAP[
                collection_name].get('parent')
            params = bgpvpn_api_def.SUB_RESOURCE_ATTRIBUTE_MAP[
                collection_name].get('parameters')

            controller = base.create_resource(collection_name, resource_name,
                                              plugin, params,
                                              allow_bulk=True,
                                              parent=parent,
                                              allow_pagination=True,
                                              allow_sorting=True)

            resource = extensions.ResourceExtension(
                collection_name,
                controller, parent,
                path_prefix=bgpvpn_api_def.ALIAS,
                attr_map=params)
            resources.append(resource)
        return resources 
Example #21
Source File: bgpvpn_routes_control.py    From networking-bgpvpn with Apache License 2.0 5 votes vote down vote up
def get_resources(cls):
        """Returns Ext Resources."""
        # the plugin we link this extension with is the 'bgpvpn' plugin:
        plugin = directory.get_plugin(bgpvpn_api.ALIAS)

        # The port association is the only new (sub-)resource
        # introduced by the bgpvpn-routes-control extension
        collection_name = api_def.PORT_ASSOCIATIONS

        resource_name = collection_name[:-1]
        parent = api_def.SUB_RESOURCE_ATTRIBUTE_MAP[
            collection_name].get('parent')
        params = api_def.SUB_RESOURCE_ATTRIBUTE_MAP[
            collection_name].get('parameters')

        controller = base.create_resource(collection_name, resource_name,
                                          plugin, params,
                                          allow_bulk=True,
                                          parent=parent,
                                          allow_pagination=True,
                                          allow_sorting=True)

        port_association_resource = extensions.ResourceExtension(
            collection_name,
            controller, parent,
            path_prefix='bgpvpn',
            attr_map=params)

        return [port_association_resource] 
Example #22
Source File: bgpvpn_db.py    From networking-bgpvpn with Apache License 2.0 5 votes vote down vote up
def _make_bgpvpn_dict(self, bgpvpn_db, fields=None):
        net_list = [net_assocs.network_id for net_assocs in
                    bgpvpn_db.network_associations]
        router_list = [router_assocs.router_id for router_assocs in
                       bgpvpn_db.router_associations]
        port_list = [port_assocs.port_id for port_assocs in
                     bgpvpn_db.port_associations]
        res = {
            'id': bgpvpn_db['id'],
            'tenant_id': bgpvpn_db['tenant_id'],
            'networks': net_list,
            'routers': router_list,
            'ports': port_list,
            'name': bgpvpn_db['name'],
            'type': bgpvpn_db['type'],
            'route_targets':
                utils.rtrd_str2list(bgpvpn_db['route_targets']),
            'route_distinguishers':
                utils.rtrd_str2list(bgpvpn_db['route_distinguishers']),
            'import_targets':
                utils.rtrd_str2list(bgpvpn_db['import_targets']),
            'export_targets':
                utils.rtrd_str2list(bgpvpn_db['export_targets'])
        }

        plugin = directory.get_plugin(bgpvpn_def.ALIAS)
        if utils.is_extension_supported(plugin, bgpvpn_vni_def.ALIAS):
            res[bgpvpn_vni_def.VNI] = bgpvpn_db.get(bgpvpn_vni_def.VNI)
        if utils.is_extension_supported(plugin, bgpvpn_rc_def.ALIAS):
            res[bgpvpn_rc_def.LOCAL_PREF_KEY] = bgpvpn_db.get(
                bgpvpn_rc_def.LOCAL_PREF_KEY)

        return db_utils.resource_fields(res, fields) 
Example #23
Source File: gateway_device.py    From networking-midonet with Apache License 2.0 5 votes vote down vote up
def _validate_resource_router_vtep(self, context, router_id):
        # Check specified router existence
        l3plugin = directory.get_plugin(constants.L3)

        try:
            l3plugin.get_router(context, router_id)
        except l3_exc.RouterNotFound:
            raise gw_device_ext.ResourceNotFound(resource_id=router_id)

        if self._get_gateway_device_from_resource(
                context, gw_device_ext.ROUTER_DEVICE_TYPE, router_id):
            raise gw_device_ext.DeviceInUseByGatewayDevice(
                resource_id=router_id, resource_type='router') 
Example #24
Source File: test_mechanism_odl_v2.py    From networking-odl with Apache License 2.0 5 votes vote down vote up
def _get_mock_port_operation_context(self):
        current = {'status': 'DOWN',
                   'binding:host_id': '',
                   'allowed_address_pairs': [],
                   'device_owner': 'fake_owner',
                   'binding:profile': {},
                   'fixed_ips': [{
                       'subnet_id': '72c56c48-e9b8-4dcf-b3a7-0813bb3bd839'}],
                   'id': '83d56c48-e9b8-4dcf-b3a7-0813bb3bd940',
                   'security_groups': [SECURITY_GROUP],
                   'device_id': 'fake_device',
                   'name': '',
                   'admin_state_up': True,
                   'network_id': 'd897e21a-dfd6-4331-a5dd-7524fa421c3e',
                   'tenant_id': 'test-tenant',
                   'binding:vif_details': {},
                   'binding:vnic_type': 'normal',
                   'binding:vif_type': 'unbound',
                   'mac_address': '12:34:56:78:21:b6'}
        _network = self._get_mock_network_operation_context().current
        _plugin = directory.get_plugin()
        _plugin.writer_get_security_group = mock.Mock(
            return_value=SECURITY_GROUP)
        _plugin.get_port = mock.Mock(return_value=current)
        _plugin.get_network = mock.Mock(return_value=_network)
        _plugin_context_mock = {'session': self.db_context.session}
        _network_context_mock = {'_network': _network}
        context = {'current': AttributeDict(current),
                   '_plugin': _plugin,
                   '_plugin_context': AttributeDict(_plugin_context_mock),
                   '_network_context': AttributeDict(_network_context_mock)}
        return AttributeDict(context) 
Example #25
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):
        row = self._test_get_latest_resource(helper.TEST_RESOURCE1)
        plugin = directory.get_plugin(helper.TEST_PLUGIN)
        resource = recovery.get_latest_resource(self.db_context, row)
        self.assertDictEqual(resource,
                             plugin.get_test_resource1(self.db_context, 'id')) 
Example #26
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 #27
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 #28
Source File: test_odl_dhcp_driver.py    From networking-odl with Apache License 2.0 5 votes vote down vote up
def test_subnet_delete(self):
        with self.network() as network:
            with self.subnet(network=network) as subnet:
                self.get_odl_resource(odl_const.ODL_SUBNET, subnet)
                plugin = self.get_plugin()
                port = self.get_port_data(network, subnet)
                self.assert_resource_created(odl_const.ODL_PORT, port)
                plugin.delete_subnet(
                    self.context, subnet[odl_const.ODL_SUBNET]['id'])
                resource = self.get_odl_resource(odl_const.ODL_PORT, port)
                self.assertIsNone(resource) 
Example #29
Source File: test_odl_dhcp_driver.py    From networking-odl with Apache License 2.0 5 votes vote down vote up
def test_subnet_update_from_enable_to_disable(self):
        with self.network() as network:
            with self.subnet(network=network) as subnet:
                self.get_odl_resource(odl_const.ODL_SUBNET, subnet)
                plugin = self.get_plugin()
                port = self.get_port_data(network, subnet)
                self.assert_resource_created(odl_const.ODL_PORT, port)

                subnet[odl_const.ODL_SUBNET]['enable_dhcp'] = False
                plugin.update_subnet(
                    self.context, subnet[odl_const.ODL_SUBNET]['id'], subnet)
                resource = self.get_odl_resource(odl_const.ODL_PORT, port)
                self.assertIsNone(resource) 
Example #30
Source File: test_odl_dhcp_driver.py    From networking-odl with Apache License 2.0 5 votes vote down vote up
def test_subnet_update_from_disable_to_enable(self):
        with self.network() as network:
            with self.subnet(network=network, enable_dhcp=False) as subnet:
                self.get_odl_resource(odl_const.ODL_SUBNET, subnet)
                plugin = self.get_plugin()
                port = self.get_port_data(network, subnet)
                self.assertIsNone(port)
                subnet[odl_const.ODL_SUBNET]['enable_dhcp'] = True
                plugin.update_subnet(
                    self.context, subnet[odl_const.ODL_SUBNET]['id'], subnet)
                self.get_odl_resource(odl_const.ODL_SUBNET, subnet)
                port = self.get_port_data(network, subnet)
                self.assert_resource_created(odl_const.ODL_PORT, port)