CLI changes for supporting custom language packs
- Added 'solum languagepack build' command. - Added code to invoke the builder client. https://review.openstack.org/#/c/103689/11 Change-Id: I0480f074bf409d58a6de1b6e1232f858bd5f80f3
This commit is contained in:
@@ -34,3 +34,30 @@ def Client(version, **kwargs):
|
|||||||
endpoint=kwargs.get('endpoint'))
|
endpoint=kwargs.get('endpoint'))
|
||||||
http_client = client.HTTPClient(keystone_auth)
|
http_client = client.HTTPClient(keystone_auth)
|
||||||
return client_class(http_client)
|
return client_class(http_client)
|
||||||
|
|
||||||
|
|
||||||
|
def get_client(api_version, **kwargs):
|
||||||
|
"""Get an authtenticated client.
|
||||||
|
|
||||||
|
This is based on the credentials in the keyword args.
|
||||||
|
|
||||||
|
:param api_version: the API version to use
|
||||||
|
:param kwargs: keyword args containing credentials, either:
|
||||||
|
* os_auth_token: pre-existing token to re-use
|
||||||
|
* endpoint: solum API endpoint
|
||||||
|
or:
|
||||||
|
* os_username: name of user
|
||||||
|
* os_password: user's password
|
||||||
|
* os_auth_url: endpoint to authenticate against
|
||||||
|
* os_tenant_name: name of tenant
|
||||||
|
"""
|
||||||
|
cli_kwargs = {
|
||||||
|
'username': kwargs.get('os_username'),
|
||||||
|
'password': kwargs.get('os_password'),
|
||||||
|
'tenant_name': kwargs.get('os_tenant_name'),
|
||||||
|
'token': kwargs.get('os_auth_token'),
|
||||||
|
'auth_url': kwargs.get('os_auth_url'),
|
||||||
|
'endpoint': kwargs.get('solum_url')
|
||||||
|
}
|
||||||
|
|
||||||
|
return Client(api_version, **cli_kwargs)
|
||||||
|
@@ -17,6 +17,7 @@ import os
|
|||||||
|
|
||||||
from keystoneclient.openstack.common.apiclient import exceptions as ks_exc
|
from keystoneclient.openstack.common.apiclient import exceptions as ks_exc
|
||||||
|
|
||||||
|
from solumclient.builder import client as builder_client
|
||||||
from solumclient import client as solum_client
|
from solumclient import client as solum_client
|
||||||
from solumclient.common import exc
|
from solumclient.common import exc
|
||||||
from solumclient.openstack.common.apiclient import exceptions
|
from solumclient.openstack.common.apiclient import exceptions
|
||||||
@@ -104,6 +105,11 @@ class CommandsBase(object):
|
|||||||
client_args['endpoint'] = client_args['solum_url']
|
client_args['endpoint'] = client_args['solum_url']
|
||||||
|
|
||||||
del client_args['solum_url']
|
del client_args['solum_url']
|
||||||
|
|
||||||
|
if client_args['action'] == 'build':
|
||||||
|
self.client = builder_client.get_client(parsed.solum_api_version,
|
||||||
|
**client_args)
|
||||||
|
else:
|
||||||
self.client = solum_client.get_client(parsed.solum_api_version,
|
self.client = solum_client.get_client(parsed.solum_api_version,
|
||||||
**client_args)
|
**client_args)
|
||||||
|
|
||||||
|
@@ -284,6 +284,21 @@ class LanguagePackCommands(cli_utils.CommandsBase):
|
|||||||
for f in fields])
|
for f in fields])
|
||||||
cliutils.print_dict(data, wrap=72)
|
cliutils.print_dict(data, wrap=72)
|
||||||
|
|
||||||
|
def build(self):
|
||||||
|
"""Build a custom language pack."""
|
||||||
|
self.parser.add_argument('name',
|
||||||
|
help="Language pack name.")
|
||||||
|
self.parser.add_argument('git_url',
|
||||||
|
help=("Github url of custom "
|
||||||
|
"language pack repository."))
|
||||||
|
args = self.parser.parse_args()
|
||||||
|
response = self.client.images.create(name=args.name,
|
||||||
|
source_uri=args.git_url)
|
||||||
|
fields = ['uuid', 'name']
|
||||||
|
data = dict([(f, getattr(response, f, ''))
|
||||||
|
for f in fields])
|
||||||
|
cliutils.print_dict(data, wrap=72)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
"""Basically the entry point."""
|
"""Basically the entry point."""
|
||||||
|
@@ -12,6 +12,7 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
from solumclient.builder.v1 import image
|
||||||
from solumclient.openstack.common.apiclient import fake_client
|
from solumclient.openstack.common.apiclient import fake_client
|
||||||
from solumclient.tests import base
|
from solumclient.tests import base
|
||||||
from solumclient.v1 import client as sclient
|
from solumclient.v1 import client as sclient
|
||||||
@@ -92,6 +93,20 @@ fixtures_create = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
image_fixture = {
|
||||||
|
'name': 'lp1',
|
||||||
|
'source_uri': 'github.com/test'
|
||||||
|
}
|
||||||
|
|
||||||
|
fixtures_build = {
|
||||||
|
'/v1/images': {
|
||||||
|
'POST': (
|
||||||
|
{},
|
||||||
|
image_fixture
|
||||||
|
),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class LanguagePackManagerTest(base.TestCase):
|
class LanguagePackManagerTest(base.TestCase):
|
||||||
|
|
||||||
@@ -128,3 +143,15 @@ class LanguagePackManagerTest(base.TestCase):
|
|||||||
mgr = languagepack.LanguagePackManager(api_client)
|
mgr = languagepack.LanguagePackManager(api_client)
|
||||||
languagepack_obj = mgr.get(lp_id='x1')
|
languagepack_obj = mgr.get(lp_id='x1')
|
||||||
self.assert_lp_object(languagepack_obj)
|
self.assert_lp_object(languagepack_obj)
|
||||||
|
|
||||||
|
def test_build(self):
|
||||||
|
fake_http_client = fake_client.FakeHTTPClient(fixtures=fixtures_build)
|
||||||
|
api_client = sclient.Client(fake_http_client)
|
||||||
|
mgr = image.ImageManager(api_client)
|
||||||
|
image_obj = mgr.create(name='lp1', source_uri='github.com/test')
|
||||||
|
self.assert_image_object(image_obj)
|
||||||
|
|
||||||
|
def assert_image_object(self, image_obj):
|
||||||
|
self.assertIn('Image', repr(image_obj))
|
||||||
|
self.assertEqual(image_fixture['source_uri'], image_obj.source_uri)
|
||||||
|
self.assertEqual(image_fixture['name'], image_obj.name)
|
||||||
|
Reference in New Issue
Block a user