def _setup_rpc(self): # RPC support self.service_topics = { svc_constants.CORE: topics.PLUGIN, svc_constants.L3_ROUTER_NAT: topics.L3PLUGIN } self.rpc_context = n_context.ContextBase('neutron', 'neutron', is_admin=False) self.conn = n_rpc.create_connection(new=True) self.endpoints = [ BridgeRpcCallbacks(), securitygroups_rpc.SecurityGroupServerRpcCallback(), dhcp_rpc.DhcpRpcCallback(), l3_rpc.L3RpcCallback(), agents_db.AgentExtRpcCallback(), metadata_rpc.MetadataRpcCallback() ] for svc_topic in self.service_topics.values(): self.conn.create_consumer(svc_topic, self.endpoints, fanout=False) # Consume from all consumers in threads self.conn.consume_in_threads() self.notifier = AgentNotifierApi(topics.AGENT) self.agent_notifiers[n_const.AGENT_TYPE_DHCP] = ( dhcp_rpc_agent_api.DhcpAgentNotifyAPI()) self.agent_notifiers[n_const.AGENT_TYPE_L3] = ( l3_rpc_agent_api.L3AgentNotifyAPI())
def test_admin_token_updated(self): CONF.set_override('neutron_server_url', 'http://anyhost', group='neutron') CONF.set_override('url_timeout', 30, group='neutron') token_store = neutronclient.AdminTokenStore.get() token_store.admin_auth_token = 'new_token' tokens = [{'auth_token': 'new_token1'}, {'auth_token': 'new_token'}] my_context = context.ContextBase('userid', 'my_tenantid', auth_token='token') with contextlib.nested( mock.patch.object(client.Client, "list_networks", side_effect=mock.Mock), mock.patch.object(client.Client, 'get_auth_info', side_effect=tokens.pop), ): client1 = neutronclient.get_client(my_context, True) client1.list_networks(retrieve_all=False) self.assertEqual('new_token', token_store.admin_auth_token) client1 = neutronclient.get_client(my_context, True) client1.list_networks(retrieve_all=False) self.assertEqual('new_token1', token_store.admin_auth_token)
def test_withouttoken_keystone_connection_error(self): CONF.set_override('neutron_server_url', 'http://anyhost', group='neutron') CONF.set_override('auth_strategy', 'keystone', group='neutron') my_context = context.ContextBase('userid', 'my_tenantid') self.assertRaises(NEUTRON_CLIENT_EXCEPTION, neutronclient.get_client, my_context)
def _make_neutron_context(self, context): return neutron_context.ContextBase(context.user, context.tenant, auth_token=context.auth_token, is_admin=context.is_admin, request_id=context.request_id, user_name=context.user_name, tenant_name=context.tenant_name)
def test_withtoken(self): CONF.set_override('neutron_server_url', 'http://anyhost', group='neutron') CONF.set_override('url_timeout', 30, group='neutron') my_context = context.ContextBase('userid', 'my_tenantid', auth_token='token') cl = neutronclient.get_client(my_context) self.assertEqual(CONF.neutron.neutron_server_url, cl.httpclient.endpoint_url) self.assertEqual(my_context.auth_token, cl.httpclient.auth_token) self.assertEqual(CONF.neutron.url_timeout, cl.httpclient.timeout)
def test_withouttoken(self): my_context = context.ContextBase('userid', 'my_tenantid') self.assertRaises(exceptions.Unauthorized, neutronclient.get_client, my_context)