[envs] Add --only-spec option to pring spec
Change-Id: I41b9c386af2c6e89dca4f2b8dc8884eca9c2e01e
This commit is contained in:
parent
a3fd27e5a1
commit
094391610c
@ -38,7 +38,7 @@ _rally()
|
||||
OPTS["env_destroy"]="--env --skip-cleanup --json --detailed"
|
||||
OPTS["env_info"]="--env --json"
|
||||
OPTS["env_list"]="--json"
|
||||
OPTS["env_show"]="--env --json"
|
||||
OPTS["env_show"]="--env --json --only-spec"
|
||||
OPTS["env_use"]="--env --json"
|
||||
OPTS["plugin_list"]="--name --platform --plugin-base"
|
||||
OPTS["plugin_show"]="--name --platform"
|
||||
|
@ -98,7 +98,7 @@ class EnvCommands(object):
|
||||
|
||||
if do_use:
|
||||
self._use(env.uuid, to_json)
|
||||
self._show(env.data, to_json)
|
||||
self._show(env.data, to_json=to_json, only_spec=False)
|
||||
return 0
|
||||
|
||||
@cliutils.args("--env", dest="env", type=str,
|
||||
@ -167,8 +167,10 @@ class EnvCommands(object):
|
||||
table.align = "l"
|
||||
print(table.get_string())
|
||||
|
||||
def _show(self, env_data, to_json):
|
||||
if to_json:
|
||||
def _show(self, env_data, to_json, only_spec):
|
||||
if only_spec:
|
||||
print(json.dumps(env_data["spec"], indent=2))
|
||||
elif to_json:
|
||||
print(json.dumps(env_data, indent=2))
|
||||
else:
|
||||
table = prettytable.PrettyTable()
|
||||
@ -189,11 +191,13 @@ class EnvCommands(object):
|
||||
help="UUID or name of the env.")
|
||||
@cliutils.args("--json", action="store_true", dest="to_json",
|
||||
help="Format output as JSON.")
|
||||
@cliutils.args("--only-spec", action="store_true", dest="only_spec",
|
||||
help="Print only a spec for the environment.")
|
||||
@cliutils.suppress_warnings
|
||||
@envutils.with_default_env()
|
||||
def show(self, api, env=None, to_json=False):
|
||||
def show(self, api, env=None, to_json=False, only_spec=False):
|
||||
env_data = env_mgr.EnvManager.get(env).data
|
||||
self._show(env_data, to_json)
|
||||
self._show(env_data, to_json=to_json, only_spec=only_spec)
|
||||
|
||||
@cliutils.args("--env", dest="env", type=str,
|
||||
metavar="<uuid>", required=False,
|
||||
|
@ -68,7 +68,8 @@ class EnvCommandsTestCase(test.TestCase):
|
||||
mock_env_manager_create.assert_called_once_with(
|
||||
"test_name", {}, description="test_description", extras=None)
|
||||
mock_env_commands__show.assert_called_once_with(
|
||||
mock_env_manager_create.return_value.data, False)
|
||||
mock_env_manager_create.return_value.data,
|
||||
to_json=False, only_spec=False)
|
||||
|
||||
@mock.patch("rally.env.env_mgr.EnvManager.create")
|
||||
@mock.patch("rally.cli.commands.env.open", create=True)
|
||||
@ -245,7 +246,7 @@ class EnvCommandsTestCase(test.TestCase):
|
||||
name="my best env",
|
||||
description="description")
|
||||
env_data["platforms"] = {}
|
||||
self.env._show(env_data, False)
|
||||
self.env._show(env_data, False, False)
|
||||
mock_print.assert_called_once_with(
|
||||
"+-------------+--------------------------------------+\n"
|
||||
"| uuid | a77004a6-7fe5-4b75-a278-009c3c5f6b20 |\n"
|
||||
@ -259,7 +260,12 @@ class EnvCommandsTestCase(test.TestCase):
|
||||
|
||||
@mock.patch("rally.cli.commands.env.print")
|
||||
def test__show_to_json(self, mock_print):
|
||||
self.env._show("data", True)
|
||||
self.env._show("data", to_json=True, only_spec=False)
|
||||
mock_print.assert_called_once_with("\"data\"")
|
||||
|
||||
@mock.patch("rally.cli.commands.env.print")
|
||||
def test__show_only_spec(self, mock_print):
|
||||
self.env._show({"spec": "data"}, to_json=False, only_spec=True)
|
||||
mock_print.assert_called_once_with("\"data\"")
|
||||
|
||||
@mock.patch("rally.env.env_mgr.EnvManager.get")
|
||||
@ -269,11 +275,13 @@ class EnvCommandsTestCase(test.TestCase):
|
||||
self.env.show(self.api, env_)
|
||||
mock_env_manager_get.assert_called_once_with(env_)
|
||||
mock__show.assert_called_once_with(
|
||||
mock_env_manager_get.return_value.data, False)
|
||||
mock_env_manager_get.return_value.data, to_json=False,
|
||||
only_spec=False)
|
||||
mock__show.reset_mock()
|
||||
self.env.show(self.api, env_, to_json=True)
|
||||
mock__show.assert_called_once_with(
|
||||
mock_env_manager_get.return_value.data, True)
|
||||
mock_env_manager_get.return_value.data, to_json=True,
|
||||
only_spec=False)
|
||||
|
||||
@mock.patch("rally.env.env_mgr.EnvManager.get")
|
||||
@mock.patch("rally.cli.commands.env.print")
|
||||
|
Loading…
Reference in New Issue
Block a user