Add support for creating a Glance client

os-cloud-config can almost do everything to set up a nascent cloud
for deploying baremetal machines except uploading the kernel and
ramdisk using Glance, which is still performed by setup-baremetal.
To enact the plan to put setup-baremetal on a radical diet, add
support for creating a Glance client.

Change-Id: I765e0ac89d1bf196255ea9217f877952b3617bad
This commit is contained in:
Steve Kowalik 2015-01-13 15:53:10 +13:00
parent 0d14c19285
commit e3abc1c269
5 changed files with 63 additions and 0 deletions

View File

@ -45,3 +45,7 @@ def get_keystone_v3_client():
def get_neutron_client():
return clients.get_neutron_client(*_get_client_args())
def get_glance_client():
return clients.get_glance_client(*_get_client_args())

View File

@ -85,3 +85,24 @@ class CMDClientsTest(base.TestCase):
auth_url=environ["OS_AUTH_URL"],
tenant_name=environ["OS_TENANT_NAME"],
ca_cert=environ.get("OS_CACERT"))
@mock.patch('os.environ')
@mock.patch('keystoneclient.session.Session')
@mock.patch('keystoneclient.auth.identity.v2.Password')
@mock.patch('glanceclient.Client')
def test_get_glance_client(self, client_mock, password_mock, session_mock,
environ):
clients.get_glance_client()
tenant_name = environ["OS_TENANT_NAME"]
password_mock.assert_called_once_with(auth_url=environ["OS_AUTH_URL"],
username=environ["OS_USERNAME"],
password=environ["OS_PASSWORD"],
tenant_name=tenant_name)
session_mock.assert_called_once_with(auth=password_mock.return_value)
session_mock.return_value.get_endpoint.assert_called_once_with(
service_type='image', interface='public', region_name='regionOne')
session_mock.return_value.get_token.assert_called_once_with()
client_mock.assert_called_once_with(
'1', endpoint=session_mock.return_value.get_endpoint.return_value,
token=session_mock.return_value.get_token.return_value,
cacert=environ.get('OS_CACERT'))

View File

@ -15,7 +15,10 @@
import logging
import glanceclient
from ironicclient import client as ironicclient
from keystoneclient.auth.identity import v2
from keystoneclient import session
from keystoneclient.v2_0 import client as ksclient
from keystoneclient.v3 import client as ks3client
from neutronclient.neutron import client as neutronclient
@ -95,3 +98,18 @@ def get_neutron_client(username,
neutron = neutronclient.Client('2.0', **kwargs)
neutron.format = 'json'
return neutron
def get_glance_client(username, password, tenant_name, auth_url, cacert=None,
region_name='regionOne'):
LOG.debug('Creating Keystone session to fetch Glance endpoint.')
auth = v2.Password(auth_url=auth_url, username=username, password=password,
tenant_name=tenant_name)
ks_session = session.Session(auth=auth)
endpoint = ks_session.get_endpoint(service_type='image',
interface='public',
region_name=region_name)
token = ks_session.get_token()
LOG.debug('Creating glance client.')
return glanceclient.Client('1', endpoint=endpoint, token=token,
cacert=cacert)

View File

@ -86,3 +86,22 @@ class ClientsTest(base.TestCase):
auth_url='auth_url',
tenant_name='tenant_name',
ca_cert=None)
@mock.patch('keystoneclient.session.Session')
@mock.patch('keystoneclient.auth.identity.v2.Password')
@mock.patch('glanceclient.Client')
def test_get_glance_client(self, client_mock, password_mock, session_mock):
clients.get_glance_client('username', 'password', 'tenant_name',
'auth_url')
password_mock.assert_called_once_with(auth_url='auth_url',
username='username',
password='password',
tenant_name='tenant_name')
session_mock.assert_called_once_with(auth=password_mock.return_value)
session_mock.return_value.get_endpoint.assert_called_once_with(
service_type='image', interface='public', region_name='regionOne')
session_mock.return_value.get_token.assert_called_once_with()
client_mock.assert_called_once_with(
'1', endpoint=session_mock.return_value.get_endpoint.return_value,
token=session_mock.return_value.get_token.return_value,
cacert=None)

View File

@ -5,6 +5,7 @@ pbr>=0.6,!=0.7,<1.0
argparse
Babel>=1.3
python-glanceclient>=0.15.0
python-ironicclient>=0.2.1
python-keystoneclient>=0.11.1
python-neutronclient>=2.3.6,<3