Merge "Make CLI outputs consistent with other OpenStack clients"

This commit is contained in:
Jenkins 2016-02-16 23:33:10 +00:00 committed by Gerrit Code Review
commit c2935117fe
4 changed files with 64 additions and 32 deletions

View File

@ -484,7 +484,7 @@ class PackageMuranoSanityClientTest(utils.CLIUtilsTestPackagesBase):
self.dummy_app_path, self.dummy_app_path,
'--exists-action', 's' '--exists-action', 's'
) )
skip_package = self.import_package( updated_package = self.import_package(
self.app_name, self.app_name,
self.dummy_app_path, self.dummy_app_path,
'--exists-action', 's' '--exists-action', 's'
@ -492,7 +492,7 @@ class PackageMuranoSanityClientTest(utils.CLIUtilsTestPackagesBase):
package_list = self.listing("package-list") package_list = self.listing("package-list")
self.assertIn(package, package_list) self.assertIn(package, package_list)
self.assertEqual(package, skip_package) self.assertIsNone(updated_package)
def test_package_import_abort(self): def test_package_import_abort(self):
"""Test scenario: """Test scenario:

View File

@ -535,11 +535,19 @@ class ShellCommandTest(ShellTest):
self.register_keystone_discovery_fixture(m_requests) self.register_keystone_discovery_fixture(m_requests)
self.register_keystone_token_fixture(m_requests) self.register_keystone_token_fixture(m_requests)
self.shell('env-template-create env-name') self.shell('env-template-create env-name')
self.client.env_templates.create.assert_called_once_with(
{'name': 'env-name', 'is_public': False})
@mock.patch('muranoclient.v1.templates.EnvTemplateManager')
@requests_mock.mock()
def test_env_template_create_public(self, mock_manager, m_requests):
self.client.env_templates = mock_manager()
self.make_env()
self.register_keystone_discovery_fixture(m_requests)
self.register_keystone_token_fixture(m_requests)
self.shell('env-template-create --is-public env-name') self.shell('env-template-create --is-public env-name')
self.client.env_templates.create.assert_has_calls([ self.client.env_templates.create.assert_called_once_with(
mock.call({'name': 'env-name', 'is_public': False}), {'name': 'env-name', 'is_public': True})
mock.call({'name': 'env-name', 'is_public': True})
])
@mock.patch('muranoclient.v1.templates.EnvTemplateManager') @mock.patch('muranoclient.v1.templates.EnvTemplateManager')
@requests_mock.mock() @requests_mock.mock()

View File

@ -47,6 +47,10 @@ def do_environment_list(mc, args=None):
args = {} args = {}
all_tenants = getattr(args, 'all_tenants', False) all_tenants = getattr(args, 'all_tenants', False)
environments = mc.environments.list(all_tenants) environments = mc.environments.list(all_tenants)
_print_environment_list(environments)
def _print_environment_list(environments):
field_labels = ['ID', 'Name', 'Status', 'Created', 'Updated'] field_labels = ['ID', 'Name', 'Status', 'Created', 'Updated']
fields = ['id', 'name', 'status', 'created', 'updated'] fields = ['id', 'name', 'status', 'created', 'updated']
utils.print_list(environments, fields, field_labels, sortby=0) utils.print_list(environments, fields, field_labels, sortby=0)
@ -86,8 +90,8 @@ def do_environment_create(mc, args):
if args.join_net_id or args.join_subnet_id: if args.join_net_id or args.join_subnet_id:
body.update(_generate_join_existing_net( body.update(_generate_join_existing_net(
args.join_net_id, args.join_subnet_id)) args.join_net_id, args.join_subnet_id))
mc.environments.create(body) environment = mc.environments.create(body)
do_environment_list(mc) _print_environment_list([environment])
@utils.arg("id", metavar="<NAME or ID>", @utils.arg("id", metavar="<NAME or ID>",
@ -121,11 +125,11 @@ def do_environment_rename(mc, args):
"""Rename an environment.""" """Rename an environment."""
try: try:
environment = utils.find_resource(mc.environments, args.id) environment = utils.find_resource(mc.environments, args.id)
mc.environments.update(environment.id, args.name) environment = mc.environments.update(environment.id, args.name)
except exceptions.NotFound: except exceptions.NotFound:
raise exceptions.CommandError("Environment %s not found" % args.id) raise exceptions.CommandError("Environment %s not found" % args.id)
else: else:
do_environment_list(mc) _print_environment_list([environment])
@utils.arg("id", metavar="<NAME or ID>", @utils.arg("id", metavar="<NAME or ID>",
@ -270,6 +274,10 @@ def do_env_template_list(mc, args=None):
if args is None: if args is None:
args = {} args = {}
env_templates = mc.env_templates.list() env_templates = mc.env_templates.list()
_print_env_template_list(env_templates)
def _print_env_template_list(env_templates):
field_labels = ['ID', 'Name', 'Created', 'Updated', 'Is public'] field_labels = ['ID', 'Name', 'Created', 'Updated', 'Is public']
fields = ['id', 'name', 'created', 'updated', 'is_public'] fields = ['id', 'name', 'created', 'updated', 'is_public']
utils.print_list(env_templates, fields, field_labels, sortby=0) utils.print_list(env_templates, fields, field_labels, sortby=0)
@ -281,8 +289,9 @@ def do_env_template_list(mc, args=None):
help='Make the template available for users from other tenants.') help='Make the template available for users from other tenants.')
def do_env_template_create(mc, args): def do_env_template_create(mc, args):
"""Create an environment template.""" """Create an environment template."""
mc.env_templates.create({"name": args.name, "is_public": args.is_public}) env_template = mc.env_templates.create(
do_env_template_list(mc) {"name": args.name, "is_public": args.is_public})
_print_env_template_list([env_template])
@utils.arg("id", metavar="<ID>", @utils.arg("id", metavar="<ID>",
@ -334,7 +343,7 @@ def do_env_template_add_app(mc, args):
with open(args.app_template_file, "r") as app_file: with open(args.app_template_file, "r") as app_file:
app_template = json.load(app_file) app_template = json.load(app_file)
mc.env_templates.create_app(args.id, app_template) mc.env_templates.create_app(args.id, app_template)
do_env_template_list(mc) do_env_template_show(mc, args)
@utils.arg("id", metavar="<ENV_TEMPLATE_ID>", @utils.arg("id", metavar="<ENV_TEMPLATE_ID>",
@ -343,8 +352,8 @@ def do_env_template_add_app(mc, args):
help="Application ID.") help="Application ID.")
def do_env_template_del_app(mc, args): def do_env_template_del_app(mc, args):
"""Delete application from the environment template.""" """Delete application from the environment template."""
mc.env_templates.delete_app(args.name, args.app_id) mc.env_templates.delete_app(args.id, args.app_id)
do_env_template_list(mc) do_env_template_show(mc, args)
@utils.arg("id", metavar="<ID>", @utils.arg("id", metavar="<ID>",
@ -353,8 +362,8 @@ def do_env_template_del_app(mc, args):
help="Environment template name.") help="Environment template name.")
def do_env_template_update(mc, args): def do_env_template_update(mc, args):
"""Update an environment template.""" """Update an environment template."""
mc.env_templates.update(args.id, args.name) env_template = mc.env_templates.update(args.id, args.name)
do_env_template_list(mc) _print_env_template_list([env_template])
@utils.arg("id", metavar="<ID>", @utils.arg("id", metavar="<ID>",
@ -467,6 +476,10 @@ def do_package_list(mc, args=None):
filter_args['tag'] = args.tag filter_args['tag'] = args.tag
packages = mc.packages.filter(**filter_args) packages = mc.packages.filter(**filter_args)
_print_package_list(packages)
def _print_package_list(packages):
field_labels = ["ID", "Name", "FQN", "Author", "Active", field_labels = ["ID", "Name", "FQN", "Author", "Active",
"Is Public", "Type"] "Is Public", "Type"]
fields = ["id", "name", "fully_qualified_name", "author", fields = ["id", "name", "fully_qualified_name", "author",
@ -542,7 +555,6 @@ def do_package_delete(mc, args):
mc.packages.delete(package_id) mc.packages.delete(package_id)
print("Deleted package '{0}'".format(package_id)) print("Deleted package '{0}'".format(package_id))
except exceptions.NotFound: except exceptions.NotFound:
raise exceptions.CommandError("Package %s not found" % package_id)
failure_count += 1 failure_count += 1
print("Failed to delete '{0}'; package not found". print("Failed to delete '{0}'; package not found".
format(package_id)) format(package_id))
@ -574,7 +586,7 @@ def _handle_package_exists(mc, data, package, exists_action):
break break
if res == 's': if res == 's':
print("Skipping.") print("Skipping.")
return return None
elif res == 'a': elif res == 'a':
print("Exiting.") print("Exiting.")
sys.exit() sys.exit()
@ -631,8 +643,6 @@ def do_package_import(mc, args):
if args.categories: if args.categories:
data["categories"] = args.categories data["categories"] = args.categories
should_do_list = False
total_reqs = {} total_reqs = {}
for filename in args.filename: for filename in args.filename:
if os.path.isfile(filename): if os.path.isfile(filename):
@ -653,9 +663,10 @@ def do_package_import(mc, args):
print("Failed to create package for '{0}', reason: {1}".format( print("Failed to create package for '{0}', reason: {1}".format(
filename, e)) filename, e))
continue continue
should_do_list = True
total_reqs.update(package.requirements(base_url=args.murano_repo_url)) total_reqs.update(package.requirements(base_url=args.murano_repo_url))
imported_list = []
for name, package in six.iteritems(total_reqs): for name, package in six.iteritems(total_reqs):
image_specs = package.images() image_specs = package.images()
if image_specs: if image_specs:
@ -673,13 +684,16 @@ def do_package_import(mc, args):
print("Error {0} occurred while installing " print("Error {0} occurred while installing "
"images for {1}".format(e, name)) "images for {1}".format(e, name))
try: try:
_handle_package_exists(mc, data, package, args.exists_action) imported_package = _handle_package_exists(
mc, data, package, args.exists_action)
if imported_package:
imported_list.append(imported_package)
except Exception as e: except Exception as e:
print("Error {0} occurred while installing package {1}".format( print("Error {0} occurred while installing package {1}".format(
e, name)) e, name))
if should_do_list: if imported_list:
do_package_list(mc) _print_package_list(imported_list)
@utils.arg("id", metavar="<ID>", @utils.arg("id", metavar="<ID>",
@ -722,7 +736,6 @@ def do_bundle_import(mc, args):
file names, relative to location of the bundle file. Requirements file names, relative to location of the bundle file. Requirements
are first searched in the same directory. are first searched in the same directory.
""" """
should_do_list = False
total_reqs = {} total_reqs = {}
for filename in args.filename: for filename in args.filename:
local_path = None local_path = None
@ -746,7 +759,6 @@ def do_bundle_import(mc, args):
filename, e)) filename, e))
continue continue
should_do_list = True
data = {"is_public": args.is_public} data = {"is_public": args.is_public}
for package in bundle_file.packages( for package in bundle_file.packages(
@ -758,6 +770,8 @@ def do_bundle_import(mc, args):
) )
total_reqs.update(requirements) total_reqs.update(requirements)
imported_list = []
for name, dep_package in six.iteritems(total_reqs): for name, dep_package in six.iteritems(total_reqs):
image_specs = dep_package.images() image_specs = dep_package.images()
if image_specs: if image_specs:
@ -776,15 +790,17 @@ def do_bundle_import(mc, args):
print("Error {0} occurred while installing " print("Error {0} occurred while installing "
"images for {1}".format(e, name)) "images for {1}".format(e, name))
try: try:
_handle_package_exists( imported_package = _handle_package_exists(
mc, data, dep_package, args.exists_action) mc, data, dep_package, args.exists_action)
if imported_package:
imported_list.append(imported_package)
except exceptions.CommandError: except exceptions.CommandError:
raise raise
except Exception as e: except Exception as e:
print("Error {0} occurred while " print("Error {0} occurred while "
"installing package {1}".format(e, name)) "installing package {1}".format(e, name))
if should_do_list: if imported_list:
do_package_list(mc) _print_package_list(imported_list)
def _handle_save_packages(packages, dst, base_url, no_images): def _handle_save_packages(packages, dst, base_url, no_images):
@ -1027,6 +1043,10 @@ def do_category_list(mc, args=None):
if args is None: if args is None:
args = {} args = {}
categories = mc.categories.list() categories = mc.categories.list()
_print_category_list(categories)
def _print_category_list(categories):
field_labels = ["ID", "Name"] field_labels = ["ID", "Name"]
fields = ["id", "name"] fields = ["id", "name"]
utils.print_list(categories, fields, field_labels) utils.print_list(categories, fields, field_labels)
@ -1048,8 +1068,8 @@ def do_category_show(mc, args):
help="Category name.") help="Category name.")
def do_category_create(mc, args): def do_category_create(mc, args):
"""Create a category.""" """Create a category."""
mc.categories.add({"name": args.name}) category = mc.categories.add({"name": args.name})
do_category_list(mc) _print_category_list([category])
@utils.arg("id", metavar="<ID>", @utils.arg("id", metavar="<ID>",

View File

@ -0,0 +1,4 @@
---
fixes:
- Changed murano-client CLI outputs to show only items affected
by current operation instead of full item list.