[cli]remove deprecated rally show command

rally show command deprecated from Rally 0.2.0
relatednote:
http://rally.readthedocs.io/en/0.7.0/cli/cli_reference.html#category-show

Change-Id: I54b907d0b6a88a9ed42847ade2f7ac091241837c
This commit is contained in:
haishi 2016-12-21 20:11:04 +08:00
parent 1508e90db4
commit f2fc3015be
9 changed files with 17 additions and 493 deletions

View File

@ -28,11 +28,6 @@ _rally()
OPTS["deployment_use"]="--deployment"
OPTS["plugin_list"]="--name --namespace"
OPTS["plugin_show"]="--name --namespace"
OPTS["show_flavors"]="--deployment"
OPTS["show_images"]="--deployment"
OPTS["show_keypairs"]="--deployment"
OPTS["show_networks"]="--deployment"
OPTS["show_secgroups"]="--deployment"
OPTS["task_abort"]="--uuid --soft"
OPTS["task_delete"]="--force --uuid"
OPTS["task_detailed"]="--uuid --iterations-data"

View File

@ -970,7 +970,8 @@ class API(object):
"Failed to read configuration file(s): %s") % cfg_files)
plugin_paths = plugin_paths or []
plugin_paths.extend(CONF.get("plugin_paths") or [])
if "plugin_paths" in CONF:
plugin_paths.extend(CONF.get("plugin_paths") or [])
for path in plugin_paths:
discover.load_plugins(path)

View File

@ -1,186 +0,0 @@
# Copyright 2014: The Rally team
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""Rally command: show"""
from __future__ import print_function
from rally.cli import cliutils
from rally.cli import envutils
from rally.common.i18n import _
from rally.common import objects
from rally.common import utils
from rally import osclients
class ShowCommands(object):
"""[Deprecated since 0.2.0] Show resources.
Set of commands that allow you to view resources, provided by OpenStack
cloud represented by deployment.
"""
def _print_header(self, resource_name, credentials):
print(_("\n%(resource)s for user `%(user)s` in tenant `%(tenant)s`:")
% {"resource": resource_name,
"user": credentials["username"],
"tenant": credentials["tenant_name"]})
@staticmethod
def _get_credentials(api, deployment):
deployment = api.deployment.get(deployment)
# NOTE(andreykurilin): it is a bad practise to access to inner db_obj,
# but we can do it here, since we are planning to deprecate and remove
# this command at all.
admin = deployment.deployment.get("admin")
credentials = [admin] if admin else []
return credentials + deployment.deployment.get("users", [])
@cliutils.args("--deployment", dest="deployment", type=str,
metavar="<uuid>", required=False,
help="UUID or name of a deployment.")
@envutils.with_default_deployment(cli_arg_name="deployment")
@cliutils.process_keystone_exc
def images(self, api, deployment=None):
"""Display available images.
:param deployment: UUID or name of a deployment
"""
headers = ["UUID", "Name", "Size (B)"]
mixed_case_fields = ["UUID", "Name"]
float_cols = ["Size (B)"]
formatters = dict(zip(float_cols,
[cliutils.pretty_float_formatter(col)
for col in float_cols]))
for credential_dict in self._get_credentials(api, deployment):
self._print_header("Images", credential_dict)
table_rows = []
clients = osclients.Clients(objects.Credential(**credential_dict))
glance_client = clients.glance()
for image in glance_client.images.list():
data = [image.id, image.name, image.size]
table_rows.append(utils.Struct(**dict(zip(headers, data))))
cliutils.print_list(table_rows,
fields=headers,
formatters=formatters,
mixed_case_fields=mixed_case_fields)
@cliutils.args("--deployment", dest="deployment", type=str,
metavar="<uuid>", required=False,
help="UUID or name of a deployment.")
@envutils.with_default_deployment(cli_arg_name="deployment")
@cliutils.process_keystone_exc
def flavors(self, api, deployment=None):
"""Display available flavors.
:param deployment: UUID or name of a deployment
"""
headers = ["ID", "Name", "vCPUs", "RAM (MB)", "Swap (MB)", "Disk (GB)"]
mixed_case_fields = ["ID", "Name", "vCPUs"]
float_cols = ["RAM (MB)", "Swap (MB)", "Disk (GB)"]
formatters = dict(zip(float_cols,
[cliutils.pretty_float_formatter(col)
for col in float_cols]))
for credential_dict in self._get_credentials(api, deployment):
self._print_header("Flavors", credential_dict)
table_rows = []
clients = osclients.Clients(objects.Credential(**credential_dict))
nova_client = clients.nova()
for flavor in nova_client.flavors.list():
data = [flavor.id, flavor.name, flavor.vcpus,
flavor.ram, flavor.swap, flavor.disk]
table_rows.append(utils.Struct(**dict(zip(headers, data))))
cliutils.print_list(table_rows,
fields=headers,
formatters=formatters,
mixed_case_fields=mixed_case_fields)
@cliutils.args("--deployment", dest="deployment", type=str,
metavar="<uuid>", required=False,
help="UUID or name of a deployment.")
@envutils.with_default_deployment(cli_arg_name="deployment")
@cliutils.process_keystone_exc
def networks(self, api, deployment=None):
"""Display configured networks."""
headers = ["ID", "Label", "CIDR"]
mixed_case_fields = ["ID", "Label", "CIDR"]
for credential_dict in self._get_credentials(api, deployment):
self._print_header("Networks", credential_dict)
table_rows = []
clients = osclients.Clients(objects.Credential(**credential_dict))
nova_client = clients.nova()
for network in nova_client.networks.list():
data = [network.id, network.label, network.cidr]
table_rows.append(utils.Struct(**dict(zip(headers, data))))
cliutils.print_list(table_rows,
fields=headers,
mixed_case_fields=mixed_case_fields)
@cliutils.args("--deployment", dest="deployment", type=str,
metavar="<uuid>", required=False,
help="UUID or name of a deployment.")
@envutils.with_default_deployment(cli_arg_name="deployment")
@cliutils.process_keystone_exc
def secgroups(self, api, deployment=None):
"""Display security groups."""
headers = ["ID", "Name", "Description"]
mixed_case_fields = ["ID", "Name", "Description"]
for credential_dict in self._get_credentials(api, deployment):
self._print_header("Security groups", credential_dict)
table_rows = []
clients = osclients.Clients(objects.Credential(**credential_dict))
nova_client = clients.nova()
for secgroup in nova_client.security_groups.list():
data = [secgroup.id, secgroup.name,
secgroup.description]
table_rows.append(utils.Struct(**dict(zip(headers,
data))))
cliutils.print_list(
table_rows,
fields=headers,
mixed_case_fields=mixed_case_fields)
@cliutils.args("--deployment", dest="deployment", type=str,
metavar="<uuid>", required=False,
help="UUID or name of a deployment.")
@envutils.with_default_deployment(cli_arg_name="deployment")
@cliutils.process_keystone_exc
def keypairs(self, api, deployment=None):
"""Display available ssh keypairs."""
headers = ["Name", "Fingerprint"]
mixed_case_fields = ["Name", "Fingerprint"]
for credential_dict in self._get_credentials(api, deployment):
self._print_header("Keypairs", credential_dict)
table_rows = []
clients = osclients.Clients(objects.Credential(**credential_dict))
nova_client = clients.nova()
for keypair in nova_client.keypairs.list():
data = [keypair.name, keypair.fingerprint]
table_rows.append(utils.Struct(**dict(zip(headers, data))))
cliutils.print_list(table_rows,
fields=headers,
mixed_case_fields=mixed_case_fields)

View File

@ -22,7 +22,6 @@ import sys
from rally.cli import cliutils
from rally.cli.commands import deployment
from rally.cli.commands import plugin
from rally.cli.commands import show
from rally.cli.commands import task
from rally.cli.commands import verify
@ -30,7 +29,6 @@ from rally.cli.commands import verify
categories = {
"deployment": deployment.DeploymentCommands,
"plugin": plugin.PluginCommands,
"show": show.ShowCommands,
"task": task.TaskCommands,
"verify": verify.VerifyCommands
}

View File

@ -1,49 +0,0 @@
# Copyright 2013: Mirantis Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import unittest
from tests.functional import utils
class ShowTestCase(unittest.TestCase):
def setUp(self):
super(ShowTestCase, self).setUp()
self.rally = utils.Rally()
def test_show_images(self):
res = self.rally("show images")
cirros = "cirros" in res
testvm = "TestVM" in res
self.assertTrue(cirros or testvm)
def test_show_flavors(self):
res = self.rally("show flavors")
self.assertIn("m1.tiny", res)
def test_show_networks(self):
res = self.rally("show networks")
private = "private" in res
novanetwork = "novanetwork" in res
self.assertTrue(private or novanetwork)
def test_show_secgroups(self):
res = self.rally("show secgroups")
self.assertIn("default", res)
def test_show_keypairs(self):
self.rally("show keypairs")

View File

@ -548,8 +548,7 @@ def check_objects_imports_in_cli(logical_line, physical_line, filename):
N361
"""
if (not filename.startswith("./rally/cli")
or filename == "./rally/cli/commands/show.py"):
if not filename.startswith("./rally/cli"):
return
if re_objects_import.search(logical_line):
yield (0, "N361 CLI modules do not allow to work with "

View File

@ -1,232 +0,0 @@
# Copyright 2014: The Rally team
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import mock
from rally.cli.commands import show
from rally.common import objects
from tests.unit import fakes
from tests.unit import test
class ShowCommandsTestCase(test.TestCase):
def setUp(self):
super(ShowCommandsTestCase, self).setUp()
self.show = show.ShowCommands()
self.admin_credential = {
"username": "admin",
"password": "admin",
"tenant_name": "admin",
"auth_url": "http://fake.auth.url"
}
self.user_credentials = {
"username": "user1",
"password": "user2",
"tenant_name": "user3",
"auth_url": "http://fake.auth.url"
}
self.fake_deployment_id = "7f6e88e0-897e-45c0-947c-595ce2437bee"
self.fake_clients = fakes.FakeClients()
self.fake_glance_client = fakes.FakeGlanceClient()
self.fake_nova_client = fakes.FakeNovaClient()
self.fake_api = fakes.FakeAPI()
@mock.patch("rally.cli.commands.show.print", create=True)
@mock.patch("rally.cli.commands.show.cliutils.print_list")
@mock.patch("rally.cli.commands.show.cliutils.pretty_float_formatter")
@mock.patch("rally.cli.commands.show.utils.Struct")
@mock.patch("rally.osclients.Glance.create_client")
def test_images(self, mock_glance_create_client,
mock_struct, mock_pretty_float_formatter,
mock_print_list, mock_print):
self.fake_glance_client.images.create("image", None, None, None)
fake_image = list(self.fake_glance_client.images.cache.values())[0]
fake_image.size = 1
mock_glance_create_client.return_value = self.fake_glance_client
self.fake_api.deployment.get.return_value = objects.Deployment({
"admin": self.admin_credential,
"users": [self.user_credentials, self.user_credentials]
})
self.show.images(self.fake_api, self.fake_deployment_id)
self.fake_api.deployment.get.assert_called_once_with(
self.fake_deployment_id)
mock_glance_create_client.assert_has_calls([mock.call()] * 3)
self.assertEqual(3, mock_glance_create_client.call_count)
headers = ["UUID", "Name", "Size (B)"]
fake_data = dict(
zip(headers, [fake_image.id, fake_image.name, fake_image.size])
)
mock_struct.assert_has_calls([mock.call(**fake_data)] * 3)
fake_formatters = {"Size (B)": mock_pretty_float_formatter()}
mixed_case_fields = ["UUID", "Name"]
mock_print_list.assert_has_calls([mock.call(
[mock_struct()],
fields=headers,
formatters=fake_formatters,
mixed_case_fields=mixed_case_fields
)] * 3)
self.assertEqual(3, mock_print.call_count)
@mock.patch("rally.cli.commands.show.cliutils.print_list")
@mock.patch("rally.cli.commands.show.cliutils.pretty_float_formatter")
@mock.patch("rally.cli.commands.show.utils.Struct")
@mock.patch("rally.osclients.Nova.create_client")
def test_flavors(self, mock_nova_create_client,
mock_struct, mock_pretty_float_formatter,
mock_print_list):
self.fake_nova_client.flavors.create()
fake_flavor = list(self.fake_nova_client.flavors.cache.values())[0]
fake_flavor.id, fake_flavor.name, fake_flavor.vcpus = 1, "m1.fake", 1
fake_flavor.ram, fake_flavor.swap, fake_flavor.disk = 1024, 128, 10
mock_nova_create_client.return_value = self.fake_nova_client
self.fake_api.deployment.get.return_value = objects.Deployment({
"admin": self.admin_credential,
"users": [self.user_credentials, self.user_credentials]
})
self.show.flavors(self.fake_api, self.fake_deployment_id)
self.fake_api.deployment.get.assert_called_once_with(
self.fake_deployment_id)
mock_nova_create_client.assert_has_calls([mock.call()] * 3)
self.assertEqual(3, mock_nova_create_client.call_count)
headers = ["ID", "Name", "vCPUs", "RAM (MB)", "Swap (MB)", "Disk (GB)"]
fake_data = dict(
zip(headers,
[fake_flavor.id, fake_flavor.name, fake_flavor.vcpus,
fake_flavor.ram, fake_flavor.swap, fake_flavor.disk])
)
mock_struct.assert_has_calls([mock.call(**fake_data)] * 3)
fake_formatters = {"RAM (MB)": mock_pretty_float_formatter(),
"Swap (MB)": mock_pretty_float_formatter(),
"Disk (GB)": mock_pretty_float_formatter()}
mixed_case_fields = ["ID", "Name", "vCPUs"]
mock_print_list.assert_has_calls([mock.call(
[mock_struct()],
fields=headers,
formatters=fake_formatters,
mixed_case_fields=mixed_case_fields
)] * 3)
@mock.patch("rally.cli.commands.show.cliutils.print_list")
@mock.patch("rally.cli.commands.show.utils.Struct")
@mock.patch("rally.osclients.Nova.create_client")
def test_networks(self, mock_nova_create_client,
mock_struct, mock_print_list):
self.fake_nova_client.networks.create(1234)
fake_network = list(self.fake_nova_client.networks.cache.values())[0]
fake_network.label = "fakenet"
fake_network.cidr = "10.0.0.0/24"
mock_nova_create_client.return_value = self.fake_nova_client
self.fake_api.deployment.get.return_value = objects.Deployment({
"admin": self.admin_credential,
"users": [self.user_credentials, self.user_credentials]
})
self.show.networks(self.fake_api, self.fake_deployment_id)
self.fake_api.deployment.get.assert_called_once_with(
self.fake_deployment_id)
mock_nova_create_client.assert_has_calls([mock.call()] * 3)
self.assertEqual(3, mock_nova_create_client.call_count)
headers = ["ID", "Label", "CIDR"]
fake_data = dict(
zip(headers,
[fake_network.id, fake_network.label, fake_network.cidr])
)
mock_struct.assert_has_calls([mock.call(**fake_data)] * 3)
mixed_case_fields = ["ID", "Label", "CIDR"]
mock_print_list.assert_has_calls([mock.call(
[mock_struct()],
fields=headers,
mixed_case_fields=mixed_case_fields
)] * 3)
@mock.patch("rally.cli.commands.show.cliutils.print_list")
@mock.patch("rally.cli.commands.show.utils.Struct")
@mock.patch("rally.osclients.Nova.create_client")
def test_secgroups(self, mock_nova_create_client,
mock_struct, mock_print_list):
self.fake_nova_client.security_groups.create("othersg")
fake_secgroup = list(
self.fake_nova_client.security_groups.cache.values())[0]
fake_secgroup.id = 0
fake_secgroup2 = list(
self.fake_nova_client.security_groups.cache.values())[1]
fake_secgroup2.id = 1
mock_nova_create_client.return_value = self.fake_nova_client
self.fake_api.deployment.get.return_value = objects.Deployment({
"admin": self.admin_credential,
"users": [self.user_credentials]
})
self.show.secgroups(self.fake_api, self.fake_deployment_id)
self.fake_api.deployment.get.assert_called_once_with(
self.fake_deployment_id)
mock_nova_create_client.assert_has_calls([mock.call()] * 2)
self.assertEqual(2, mock_nova_create_client.call_count)
headers = ["ID", "Name", "Description"]
fake_data = [fake_secgroup.id, fake_secgroup.name, ""]
fake_data2 = [fake_secgroup2.id, fake_secgroup2.name, ""]
calls = [mock.call(**dict(zip(headers, fake_data2))),
mock.call(**dict(zip(headers, fake_data)))]
mock_struct.assert_has_calls(calls * 2, any_order=True)
mixed_case_fields = ["ID", "Name", "Description"]
mock_print_list.assert_has_calls([mock.call(
[mock_struct(), mock_struct()],
fields=headers,
mixed_case_fields=mixed_case_fields
)] * 2)
@mock.patch("rally.cli.commands.show.cliutils.print_list")
@mock.patch("rally.cli.commands.show.utils.Struct")
@mock.patch("rally.osclients.Nova.create_client")
def test_keypairs(self, mock_nova_create_client,
mock_struct, mock_print_list):
self.fake_nova_client.keypairs.create("keypair")
fake_keypair = list(self.fake_nova_client.keypairs.cache.values())[0]
fake_keypair.fingerprint = "84:87:58"
mock_nova_create_client.return_value = self.fake_nova_client
self.fake_api.deployment.get.return_value = objects.Deployment({
"admin": self.admin_credential,
"users": [self.user_credentials, self.user_credentials]
})
self.show.keypairs(self.fake_api, self.fake_deployment_id)
self.fake_api.deployment.get.assert_called_once_with(
self.fake_deployment_id)
mock_nova_create_client.assert_has_calls([mock.call()] * 3)
self.assertEqual(3, mock_nova_create_client.call_count)
headers = ["Name", "Fingerprint"]
fake_data = dict(
zip(headers,
[fake_keypair.name, fake_keypair.fingerprint])
)
mock_struct.assert_has_calls([mock.call(**fake_data)] * 3)
mixed_case_fields = ["Name", "Fingerprint"]
mock_print_list.assert_has_calls([mock.call(
[mock_struct()],
fields=headers,
mixed_case_fields=mixed_case_fields
)] * 3)

View File

@ -22,7 +22,6 @@ import sqlalchemy.exc
from rally.cli import cliutils
from rally.cli.commands import deployment
from rally.cli.commands import show
from rally.cli.commands import task
from rally.cli.commands import verify
from rally import exceptions
@ -40,7 +39,6 @@ class CliUtilsTestCase(test.TestCase):
super(CliUtilsTestCase, self).setUp()
self.categories = {
"deployment": deployment.DeploymentCommands,
"show": show.ShowCommands,
"task": task.TaskCommands,
"verify": verify.VerifyCommands
}
@ -165,14 +163,6 @@ class CliUtilsTestCase(test.TestCase):
)
CONF.unregister_opt(category_opt)
@mock.patch("rally.api.API",
side_effect=exceptions.RallyException("config_file"))
def test_run_fails(self, mock_rally_api_api):
ret = cliutils.run(["rally", "show", "flavors"], self.categories)
self.assertEqual(ret, 2)
mock_rally_api_api.assert_called_once_with(
config_args=["show", "flavors"])
def test_run_version(self):
ret = cliutils.run(["rally", "version"], self.categories)
self.assertEqual(ret, 0)
@ -181,10 +171,6 @@ class CliUtilsTestCase(test.TestCase):
ret = cliutils.run(["rally", "bash-completion"], self.categories)
self.assertEqual(ret, 0)
def test_run_show(self):
ret = cliutils.run(["rally", "show", "keypairs"], self.categories)
self.assertEqual(ret, 1)
@mock.patch("rally.common.db.task_get",
side_effect=exceptions.TaskNotFound(uuid=FAKE_TASK_UUID))
def test_run_task_not_found(self, mock_task_get):
@ -195,8 +181,9 @@ class CliUtilsTestCase(test.TestCase):
@mock.patch("rally.cli.cliutils.validate_args",
side_effect=cliutils.MissingArgs("missing"))
def test_run_show_fails(self, mock_validate_args):
ret = cliutils.run(["rally", "show", "keypairs"], self.categories)
def test_run_task_failed(self, mock_validate_args):
ret = cliutils.run(["rally", "task", "status", "%s" % FAKE_TASK_UUID],
self.categories)
self.assertTrue(mock_validate_args.called)
self.assertEqual(ret, 1)
@ -837,3 +824,13 @@ class ValidateArgsTest(test.TestCase):
cmd_name = "test-command"
wrapped = cliutils.alias(cmd_name)
self.assertEqual(wrapped(alias_fn).alias, cmd_name)
class CategoryParserTestCase(test.TestCase):
def setUp(self):
super(CategoryParserTestCase, self).setUp()
self.categoryParser = cliutils.CategoryParser()
def test_format_help(self):
self.assertIsNotNone(self.categoryParser.format_help())

View File

@ -534,6 +534,7 @@ class APITestCase(test.TestCase):
@mock.patch("rally.api.CONF", spec=cfg.CONF)
def test_init_plugin_path(self, mock_conf, mock_version_string,
mock_load_plugins, mock_isfile):
mock_conf.__contains__.return_value = True
mock_conf.get.side_effect = (
lambda a: ["/path/from/args"] if a == "plugin_paths" else None)
api.API(plugin_paths=["/my/path"])