Python neutron_lib.context.get_admin_context() Examples
The following are 30
code examples of neutron_lib.context.get_admin_context().
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.context
, or try the search function
.
![](https://www.programcreek.com/common/static/images/search.png)
Example #1
Source File: test_sfc.py From networking-sfc with Apache License 2.0 | 6 votes |
def setUp(self): super(SfcAgentExtensionTestCase, self).setUp() conn_patcher = mock.patch('neutron.agent.ovsdb.impl_idl._connection') conn_patcher.start() self.addCleanup(conn_patcher.stop) self.sfc_ext = sfc.SfcAgentExtension() self.context = context.get_admin_context() self.connection = mock.Mock() os_ken_app = mock.Mock() self.agent_api = ovs_ext_api.OVSAgentExtensionAPI( ovs_bridge.OVSAgentBridge('br-int', os_ken_app=os_ken_app), ovs_bridge.OVSAgentBridge('br-tun', os_ken_app=os_ken_app)) self.sfc_ext.consume_api(self.agent_api) # Don't rely on used driver mock.patch( 'neutron.manager.NeutronManager.load_class_for_provider', return_value=lambda: mock.Mock(spec=sfc.SfcAgentDriver) ).start() self.sfc_ext.initialize( self.connection, constants.EXTENSION_DRIVER_TYPE)
Example #2
Source File: bgp_plugin.py From dragonflow with Apache License 2.0 | 6 votes |
def router_port_callback(self, resource, event, trigger, **kwargs): if 'payload' in kwargs: # TODO(boden): remove shim once all events use payloads gw_network = kwargs['payload'].metadata.get('network_id') else: gw_network = kwargs['network_id'] # NOTE(xiaohhui) Not all events have context in kwargs(e.g router # gw after create event), just get a admin context here. admin_ctx = n_context.get_admin_context() speakers = self._bgp_speakers_for_gateway_network(admin_ctx, gw_network) for speaker in speakers: self._update_bgp_speaker_tenant_network_routes(admin_ctx, speaker.id, speaker.project_id)
Example #3
Source File: test_midonet_plugin_ml2.py From networking-midonet with Apache License 2.0 | 6 votes |
def test_add_router_interface_by_port_failure(self): class _MyException(Exception): pass with self.port() as port, self.router() as router: ctx = context.get_admin_context() plugin = directory.get_plugin() l3_plugin = directory.get_plugin(plugin_constants.L3) router_id = router['router']['id'] port_id = port['port']['id'] interface_info = { 'port_id': port_id, } with mock.patch.object(l3_plugin.client, 'add_router_interface_postcommit', auto_spec=True, side_effect=_MyException), \ testtools.ExpectedException(_MyException): l3_plugin.add_router_interface(ctx, router_id, interface_info) port2 = plugin.get_port(ctx, port_id) self.assertEqual(port_id, port2['id'])
Example #4
Source File: pseudo_agentdb_binding.py From networking-odl with Apache License 2.0 | 6 votes |
def delete_agents_db_row(self, host_id, host_type): """Delete agent row.""" try: filters = {'agent_type': [host_type], 'host': [host_id]} # TODO(rsood): get_agent can be used here agent = self.agents_db.get_agents_db( context.get_admin_context(), filters=filters) if not agent: return LOG.debug("Deleting Agent with Agent id: %s", agent[0]['id']) self.agents_db.delete_agent( context.get_admin_context(), agent[0]['id']) self._known_agents.remove((host_id, host_type)) except Exception: LOG.exception("Unable to delete from agentdb.")
Example #5
Source File: pseudo_agentdb_binding.py From networking-odl with Apache License 2.0 | 6 votes |
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 #6
Source File: port_status_update.py From networking-odl with Apache License 2.0 | 6 votes |
def _process_websocket_recv(self, payload, reconnect): # Callback for websocket notification LOG.debug("Websocket notification for port status update") for event in odl_ws_client.EventDataParser.get_item(payload): operation, path, data = event.get_fields() if ((operation in [event.OPERATION_UPDATE, event.OPERATION_CREATE])): port_id = event.extract_field(path, "neutron:uuid") port_id = str(port_id).strip("'") status_field = data.get('status') if status_field is not None: status = status_field.get('content') LOG.debug("Update port for port id %s %s", port_id, status) # for now we only support transition from DOWN->ACTIVE # https://bugs.launchpad.net/networking-odl/+bug/1686023 if status == n_const.PORT_STATUS_ACTIVE: provisioning_blocks.provisioning_complete( context.get_admin_context(), port_id, resources.PORT, provisioning_blocks.L2_AGENT_ENTITY) if operation == event.OPERATION_DELETE: LOG.debug("PortStatus: Ignoring delete operation")
Example #7
Source File: periodic_task.py From networking-odl with Apache License 2.0 | 6 votes |
def execute_ops(self, forced=False): LOG.info("Starting %s periodic task.", self.task) context = neutron_context.get_admin_context() # Lock make sure that periodic task is executed only after # specified interval. It makes sure that maintenance tasks # are not executed back to back. if not forced and self.task_already_executed_recently(context): LOG.info("Periodic %s task executed after periodic interval " "Skipping execution.", self.task) return if not self._lock_task(context): LOG.info("Periodic %s task already running task", self.task) return try: for phase in self.phases: self._execute_op(phase, context) finally: self._clear_and_unlock_task(context) LOG.info("%s task has been finished", self.task)
Example #8
Source File: test_agent_scheduler.py From networking-l2gw with Apache License 2.0 | 6 votes |
def setUp(self): super(TestAgentScheduler, self).setUp() cfg.CONF.set_override('core_plugin', "neutron.plugins.ml2.plugin.Ml2Plugin") self.plugin = FakePlugin() self.agent_rpc = agent_api.L2gatewayAgentApi( l2gw_topics.L2GATEWAY_AGENT, cfg.CONF.host) self.context = neutron_context.get_admin_context() cfg.CONF.set_override('agent_down_time', 10) cfg.CONF.set_override('periodic_monitoring_interval', 5) self.agentsch = agent_scheduler.L2GatewayAgentScheduler(self.agent_rpc, cfg.CONF) self.agentsch._plugin = self.plugin self.agentsch.context = self.context self.agentsch.agent_ext_support = True self.LOG = agent_scheduler.LOG
Example #9
Source File: test_rpc_l2gw.py From networking-l2gw with Apache License 2.0 | 6 votes |
def test_create_l2gateway_connection_with_invalid_device(self, phy_switch): self.db_context = ctx.get_admin_context() fake_l2gw_conn_dict = {'l2_gateway_connection': { 'id': 'fake_id', 'network_id': 'fake_network_id', 'l2_gateway_id': 'fake_l2gw_id'}} fake_device = {'devices': [{'device_name': 'fake_device', 'interfaces': [{'name': 'fake_interface'}]}]} fake_physical_switch = None phy_switch.return_value = fake_physical_switch with mock.patch.object(self.service_plugin, '_admin_check', return_value=True), \ mock.patch.object(self.service_plugin, 'get_l2_gateway', return_value=fake_device), \ mock.patch.object(self.service_plugin, '_get_network', return_value=True), \ mock.patch.object(self.service_plugin, '_get_l2_gateway', return_value=True): self.assertRaises(l2gw_exc.L2GatewayDeviceNotFound, self.plugin.create_l2_gateway_connection, self.db_context, fake_l2gw_conn_dict)
Example #10
Source File: agent_scheduler.py From networking-l2gw with Apache License 2.0 | 6 votes |
def monitor_agent_state(self): """Represents L2gateway agent scheduler thread. Maintains list of active and inactive agents based on the heartbeat recorded. """ context = neutron_context.get_admin_context() try: all_agents = self.plugin.get_agents( context, filters={'agent_type': [srv_const.AGENT_TYPE_L2GATEWAY]}) except Exception: LOG.exception("Unable to get the agent list. Continuing...") return # Reset the agents that will be processed for selecting the # Monitor agent agents_to_process = [] for agent in all_agents: if not utils.is_agent_down(agent['heartbeat_timestamp']): agents_to_process.append(agent) if agents_to_process: self._select_agent_type(context, agents_to_process) return
Example #11
Source File: bgp_plugin.py From neutron-dynamic-routing with Apache License 2.0 | 6 votes |
def _handle_router_gateway_after_create(self, payload): ctx = context.get_admin_context() gw_network = payload.metadata.get('network_id') router_id = payload.resource_id with ctx.session.begin(subtransactions=True): speakers = self._bgp_speakers_for_gateway_network(ctx, gw_network) next_hops = self._next_hops_from_gateway_ips( payload.metadata.get('gateway_ips')) for speaker in speakers: if speaker.ip_version in next_hops: next_hop = next_hops[speaker.ip_version] prefixes = self._tenant_prefixes_by_router(ctx, router_id, speaker.id) routes = self._route_list_from_prefixes_and_next_hop( prefixes, next_hop) self.start_route_advertisements(ctx, self._bgp_rpc, speaker.id, routes)
Example #12
Source File: bgp_plugin.py From neutron-dynamic-routing with Apache License 2.0 | 6 votes |
def router_gateway_callback(self, resource, event, trigger, payload=None): if event == events.AFTER_CREATE: self._handle_router_gateway_after_create(payload) if event == events.AFTER_DELETE: gw_network = payload.metadata.get('network_id') router_id = payload.resource_id next_hops = self._next_hops_from_gateway_ips( payload.metadata.get('gateway_ips')) ctx = context.get_admin_context() speakers = self._bgp_speakers_for_gateway_network(ctx, gw_network) for speaker in speakers: if speaker.ip_version in next_hops: next_hop = next_hops[speaker.ip_version] prefixes = self._tenant_prefixes_by_router(ctx, router_id, speaker.id) routes = self._route_list_from_prefixes_and_next_hop( prefixes, next_hop) self._handle_router_interface_after_delete(gw_network, routes)
Example #13
Source File: bgp_plugin.py From neutron-dynamic-routing with Apache License 2.0 | 6 votes |
def _handle_router_interface_after_create(self, **kwargs): gw_network = kwargs['network_id'] if not gw_network: return ctx = context.get_admin_context() with ctx.session.begin(subtransactions=True): speakers = self._bgp_speakers_for_gateway_network(ctx, gw_network) next_hops = self._next_hops_from_gateway_ips( kwargs['gateway_ips']) for speaker in speakers: prefixes = self._tenant_prefixes_by_router( ctx, kwargs['router_id'], speaker.id) next_hop = next_hops.get(speaker.ip_version) if next_hop: rl = self._route_list_from_prefixes_and_next_hop(prefixes, next_hop) self.start_route_advertisements(ctx, self._bgp_rpc, speaker.id, rl)
Example #14
Source File: test_plugin.py From neutron-vpnaas with Apache License 2.0 | 6 votes |
def setUp(self): super(TestVPNDriverPluginMultipleDrivers, self).setUp() vpnaas_providers = [ {'service_type': p_constants.VPN, 'name': 'ipsec', 'driver': IPSEC_SERVICE_DRIVER, 'default': True}, {'service_type': p_constants.VPN, 'name': 'dummy', 'driver': DUMMY_IPSEC_SERVICE_DRIVER, 'default': False}] self.service_providers = ( mock.patch.object(st_db.ServiceTypeManager, 'get_service_providers').start()) self.service_providers.return_value = vpnaas_providers self.adminContext = context.get_admin_context()
Example #15
Source File: test_ipsec.py From neutron-vpnaas with Apache License 2.0 | 6 votes |
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 #16
Source File: plugin.py From neutron-vpnaas with Apache License 2.0 | 5 votes |
def _check_orphan_vpnservice_associations(self): context = ncontext.get_admin_context() vpnservices = self.get_vpnservices(context) vpnservice_ids = [vpnservice['id'] for vpnservice in vpnservices] stm = self.service_type_manager provider_names = stm.get_provider_names_by_resource_ids( context, vpnservice_ids) lost_providers = set() lost_vpnservices = [] for vpnservice_id, provider in provider_names.items(): if provider not in self.drivers: lost_providers.add(provider) lost_vpnservices.append(vpnservice_id) if lost_providers or lost_vpnservices: # Provider are kept internally, we need to inform users about # the related VPN services. msg = ( "Delete associated vpnservices %(vpnservices)s before " "removing providers %(providers)s." ) % {'vpnservices': lost_vpnservices, 'providers': list(lost_providers)} LOG.exception(msg) raise SystemExit(msg) # Deal with upgrade. Associate existing VPN services to default # provider. unasso_vpnservices = [ vpnservice_id for vpnservice_id in vpnservice_ids if vpnservice_id not in provider_names] if unasso_vpnservices: LOG.info( ("Associating VPN services %(unasso_vpnservices)s to " "default provider %(default_provider)s."), {'unasso_vpnservices': unasso_vpnservices, 'default_provider': self.default_provider}) for vpnservice_id in unasso_vpnservices: stm.add_resource_association( context, constants.VPN, self.default_provider, vpnservice_id)
Example #17
Source File: test_vpn_db.py From neutron-vpnaas with Apache License 2.0 | 5 votes |
def _set_active(self, model, resource_id): service_plugin = directory.get_plugin(nconstants.VPN) adminContext = context.get_admin_context() with adminContext.session.begin(subtransactions=True): resource_db = service_plugin._get_resource( adminContext, model, resource_id) resource_db.status = lib_constants.ACTIVE
Example #18
Source File: test_l2gw_db.py From networking-l2gw with Apache License 2.0 | 5 votes |
def setUp(self): super(L2GWTestCase, self).setUp() self.ctx = context.get_admin_context() self.mixin = l2gateway_db.L2GatewayMixin() self.gw_resource = constants.L2_GATEWAYS self.con_resource = constants.CONNECTION_RESOURCE_NAME self.plugin = importutils.import_object(DB_PLUGIN_KLASS)
Example #19
Source File: trunk_driver_v2.py From networking-odl with Apache License 2.0 | 5 votes |
def trunk_subports_set_status(self, resource, event, trunk_plugin, payload): core_plugin = directory.get_plugin() admin_context = context.get_admin_context() if event == events.AFTER_DELETE: status = n_const.PORT_STATUS_DOWN else: parent_id = payload.current_trunk.port_id parent_port = core_plugin._get_port(admin_context, parent_id) status = parent_port['status'] for subport in payload.subports: self._set_subport_status(core_plugin, admin_context, subport.port_id, status)
Example #20
Source File: trunk_driver_v2.py From networking-odl with Apache License 2.0 | 5 votes |
def trunk_subports_update_status(self, resource, event, trigger, **kwargs): core_plugin = directory.get_plugin() admin_context = context.get_admin_context() port = kwargs['port'] original_port = kwargs['original_port'] if port['status'] == original_port['status']: return for subport_id in self._get_subports_ids(port['id']): self._set_subport_status(core_plugin, admin_context, subport_id, port['status'])
Example #21
Source File: trunk_driver_v2.py From networking-odl with Apache License 2.0 | 5 votes |
def _get_subports_ids(self, port_id): trunk_plugin = directory.get_plugin('trunk') filters = {'port_id': port_id} trunks = trunk_plugin.get_trunks(context.get_admin_context(), filters=filters) if not trunks: return () trunk = trunks[0] return (subport['port_id'] for subport in trunk['sub_ports'])
Example #22
Source File: journal.py From networking-odl with Apache License 2.0 | 5 votes |
def sync_pending_entries(self): LOG.debug("Start processing journal entries") context = nl_context.get_admin_context() entry = db.get_oldest_pending_db_row_with_lock(context) if entry is None: LOG.debug("No journal entries to process") return while entry is not None: stop_processing = self._sync_entry(context, entry) if stop_processing: break entry = db.get_oldest_pending_db_row_with_lock(context) LOG.debug("Finished processing journal entries")
Example #23
Source File: test_plugin.py From neutron-vpnaas with Apache License 2.0 | 5 votes |
def setUp(self): driver_cls_p = mock.patch( 'neutron_vpnaas.services.vpn.' 'service_drivers.ipsec.IPsecVPNDriver') driver_cls = driver_cls_p.start() self.driver = mock.Mock() self.driver.service_type = ipsec_driver.IPSEC self.driver.validator = driver_validator.VpnDriverValidator( self.driver) driver_cls.return_value = self.driver super(TestVPNDriverPlugin, self).setUp( vpnaas_plugin=VPN_DRIVER_CLASS) # Note: Context must be created after BaseTestCase.setUp() so that # config for policy is set. self.adminContext = context.get_admin_context()
Example #24
Source File: port_status_update.py From networking-odl with Apache License 2.0 | 5 votes |
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 #25
Source File: test_data.py From networking-l2gw with Apache License 2.0 | 5 votes |
def setUp(self): super(TestOVSDBData, self).setUp() self.context = context.get_admin_context() self.ovsdb_identifier = 'fake_ovsdb_id' mock.patch.object(directory, 'get_plugin').start() mock.patch.object(managers, 'TypeManager').start() self.ovsdb_data = data.OVSDBData(self.ovsdb_identifier)
Example #26
Source File: test_driver.py From networking-sfc with Apache License 2.0 | 5 votes |
def setUp(self): flowclassifier_plugin = ( test_flowclassifier_db.DB_FLOWCLASSIFIER_PLUGIN_CLASS) service_plugins = { flowclassifier.FLOW_CLASSIFIER_EXT: flowclassifier_plugin } fdb.FlowClassifierDbPlugin.supported_extension_aliases = [ flowclassifier.FLOW_CLASSIFIER_EXT] fdb.FlowClassifierDbPlugin.path_prefix = ( flowclassifier.FLOW_CLASSIFIER_PREFIX ) super(OVSFlowClassifierDriverTestCase, self).setUp( ext_mgr=None, plugin=None, service_plugins=service_plugins ) self.flowclassifier_plugin = importutils.import_object( flowclassifier_plugin) ext_mgr = api_ext.PluginAwareExtensionManager( test_flowclassifier_db.extensions_path, { flowclassifier.FLOW_CLASSIFIER_EXT: self.flowclassifier_plugin } ) app = config.load_paste_app('extensions_test_app') self.ext_api = api_ext.ExtensionMiddleware(app, ext_mgr=ext_mgr) self.ctx = context.get_admin_context() self.driver = driver.OVSFlowClassifierDriver() self.driver.initialize()
Example #27
Source File: test_db.py From networking-bgpvpn with Apache License 2.0 | 5 votes |
def setUp(self, service_provider=None): super(BgpvpnDBTestCase, self).setUp(service_provider) self.ctx = context.get_admin_context() self.plugin_db = BGPVPNPluginDb()
Example #28
Source File: nb_api_neutron_notifier.py From dragonflow with Apache License 2.0 | 5 votes |
def _neutron_server_update_core_plugin(table, key, action, value, topic=None): if l2.LogicalPort.table_name == table and 'update' == action: LOG.info("Process port %s status update event", key) core_plugin = directory.get_plugin() core_plugin.update_port_status(n_context.get_admin_context(), key, value)
Example #29
Source File: test_fc_driver.py From dragonflow with Apache License 2.0 | 5 votes |
def setUp(self): flowclassifier_plugin = ( test_flowclassifier_db.DB_FLOWCLASSIFIER_PLUGIN_CLASS) service_plugins = { flowclassifier.FLOW_CLASSIFIER_EXT: flowclassifier_plugin } fdb.FlowClassifierDbPlugin.supported_extension_aliases = [ flowclassifier.FLOW_CLASSIFIER_EXT] fdb.FlowClassifierDbPlugin.path_prefix = ( flowclassifier.FLOW_CLASSIFIER_PREFIX ) super(TestDfFcDriver, self).setUp( ext_mgr=None, plugin=None, service_plugins=service_plugins ) self.flowclassifier_plugin = importutils.import_object( flowclassifier_plugin) ext_mgr = api_ext.PluginAwareExtensionManager( test_flowclassifier_db.extensions_path, { flowclassifier.FLOW_CLASSIFIER_EXT: self.flowclassifier_plugin } ) app = config.load_paste_app('extensions_test_app') self.ext_api = api_ext.ExtensionMiddleware(app, ext_mgr=ext_mgr) self.ctx = context.get_admin_context() self.driver = driver.DfFlowClassifierDriver() self.driver.initialize() self.driver._nb_api = mock.Mock()
Example #30
Source File: driver.py From dragonflow with Apache License 2.0 | 5 votes |
def _update_subport_statuses(self, parent_id, subports): core_plugin = directory.get_plugin() admin_context = context.get_admin_context() parent = core_plugin.get_port(admin_context, parent_id) if parent['status'] == n_constants.PORT_STATUS_ACTIVE: for subport in subports: core_plugin.update_port_status(admin_context, subport.port_id, n_constants.PORT_STATUS_ACTIVE)