Add support for creating Keystone v3 clients

Due to the Keystone v2 client not supporting domains, we should add
support for using the Keystone v3 client for some operations. This
branch does not change any of the existing Keystone callsites, merely
adds support for creating the client.

Drive-by correcting the method name for the Neutron client tests.

Change-Id: Ifd94b73684df99e3a2ef9ced9b8b4a748ac18416
This commit is contained in:
Steve Kowalik 2014-11-12 15:47:42 +11:00
parent 39caf69313
commit f811472c5f
4 changed files with 49 additions and 2 deletions

View File

@ -40,6 +40,13 @@ def get_keystone_client():
os.environ["OS_AUTH_URL"])
def get_keystone_v3_client():
return clients.get_keystone_v3_client(os.environ["OS_USERNAME"],
os.environ["OS_PASSWORD"],
os.environ["OS_TENANT_NAME"],
os.environ["OS_AUTH_URL"])
def get_neutron_client():
return clients.get_neutron_client(os.environ["OS_USERNAME"],
os.environ["OS_PASSWORD"],

View File

@ -51,9 +51,19 @@ class CMDClientsTest(base.TestCase):
auth_url=environ["OS_AUTH_URL"],
tenant_name=environ["OS_TENANT_NAME"])
@mock.patch('os.environ')
@mock.patch('keystoneclient.v3.client.Client')
def test_get_keystone_v3_client(self, client_mock, environ):
clients.get_keystone_v3_client()
client_mock.assert_called_once_with(
username=environ["OS_USERNAME"],
password=environ["OS_PASSWORD"],
auth_url=environ["OS_AUTH_URL"].replace('v2.0', 'v3'),
tenant_name=environ["OS_TENANT_NAME"])
@mock.patch('os.environ')
@mock.patch('neutronclient.neutron.client.Client')
def test_get_client(self, client_mock, environ):
def test_get_neutron_client(self, client_mock, environ):
clients.get_neutron_client()
client_mock.assert_called_once_with(
'2.0', username=environ["OS_USERNAME"],

View File

@ -17,6 +17,7 @@ import logging
from ironicclient import client as ironicclient
from keystoneclient.v2_0 import client as ksclient
from keystoneclient.v3 import client as ks3client
from neutronclient.neutron import client as neutronclient
from novaclient.extension import Extension
from novaclient.v1_1 import client as novav11client
@ -53,6 +54,15 @@ def get_keystone_client(username, password, tenant_name, auth_url):
return ksclient.Client(**kwargs)
def get_keystone_v3_client(username, password, tenant_name, auth_url):
LOG.debug('Creating keystone v3 client.')
kwargs = {'username': username,
'password': password,
'tenant_name': tenant_name,
'auth_url': auth_url.replace('v2.0', 'v3')}
return ks3client.Client(**kwargs)
def get_neutron_client(username, password, tenant_name, auth_url):
LOG.debug('Creating neutron client.')
kwargs = {'username': username,

View File

@ -51,8 +51,28 @@ class ClientsTest(base.TestCase):
auth_url='auth_url',
tenant_name='tenant_name')
@mock.patch('keystoneclient.v3.client.Client')
def test_get_keystone_v3_client_with_v2_url(self, client_mock):
clients.get_keystone_v3_client('username', 'password', 'tenant_name',
'auth_url/v2.0')
client_mock.assert_called_once_with(
username='username',
password='password',
auth_url='auth_url/v3',
tenant_name='tenant_name')
@mock.patch('keystoneclient.v3.client.Client')
def test_get_keystone_v3_client_with_v3_url(self, client_mock):
clients.get_keystone_v3_client('username', 'password', 'tenant_name',
'auth_url/v3')
client_mock.assert_called_once_with(
username='username',
password='password',
auth_url='auth_url/v3',
tenant_name='tenant_name')
@mock.patch('neutronclient.neutron.client.Client')
def test_get_client(self, client_mock):
def test_get_neutron_client(self, client_mock):
clients.get_neutron_client('username', 'password', 'tenant_name',
'auth_url')
client_mock.assert_called_once_with(