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 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_reuse_admin_token(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' my_context = context.ContextBase('userid', 'my_tenantid', auth_token='token') with mock.patch.object(client.Client, "list_networks", side_effect=mock.Mock): with mock.patch.object(client.Client, 'get_auth_info', return_value={'auth_token': 'new_token1'}): client1 = neutronclient.get_client(my_context, True) client1.list_networks(retrieve_all=False) self.assertEqual('new_token1', 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(self): my_context = context.ContextBase('userid', 'my_tenantid') self.assertRaises(exceptions.Unauthorized, neutronclient.get_client, my_context)