Modify rally commands deployment, task, and verify
Small modifications to the rally commands 'deployment', 'task', and 'verify'. In deployment, rename the subcommand endpoint to show, and remove the pprint and json output options in subcommand config in favor of pretty-printed json output only. In task, perform the same in subcommand results as in config. In verify, perform the same in subcommand results as in config. Change-Id: I9686abf5088782e68111638da10be72c0e1135fa
This commit is contained in:
parent
a7c7cc3bb5
commit
b439b4d127
@ -19,7 +19,6 @@ from __future__ import print_function
|
||||
|
||||
import json
|
||||
import os
|
||||
import pprint
|
||||
import sys
|
||||
|
||||
import jsonschema
|
||||
@ -173,37 +172,24 @@ class DeploymentCommands(object):
|
||||
|
||||
@cliutils.args('--uuid', dest='deploy_id', type=str, required=False,
|
||||
help='UUID of a deployment.')
|
||||
@cliutils.args('--json', dest='output_json', action='store_true',
|
||||
help='Output in json format(default)')
|
||||
@cliutils.args('--pprint', dest='output_pprint', action='store_true',
|
||||
help='Output in pretty print format')
|
||||
@envutils.with_default_deploy_id
|
||||
def config(self, deploy_id=None, output_json=None, output_pprint=None):
|
||||
def config(self, deploy_id=None):
|
||||
"""Display configuration of the deployment.
|
||||
|
||||
Output can JSON or Pretty print format.
|
||||
Output is the configuration of the deployment in a
|
||||
pretty-printed JSON format.
|
||||
|
||||
:param deploy_id: a UUID of the deployment
|
||||
:param output_json: Output in json format (Default)
|
||||
:param output_pprint: Output in pretty print format
|
||||
"""
|
||||
deploy = db.deployment_get(deploy_id)
|
||||
result = deploy['config']
|
||||
if all([output_json, output_pprint]):
|
||||
print(_('Please select only one output format'))
|
||||
return 1
|
||||
elif output_pprint:
|
||||
print()
|
||||
pprint.pprint(result)
|
||||
print()
|
||||
else:
|
||||
print(json.dumps(result))
|
||||
print(json.dumps(result, sort_keys=True, indent=4))
|
||||
|
||||
@cliutils.args('--uuid', dest='deploy_id', type=str, required=False,
|
||||
help='UUID of a deployment.')
|
||||
@envutils.with_default_deploy_id
|
||||
def endpoint(self, deploy_id=None):
|
||||
"""Display all endpoints of the deployment.
|
||||
def show(self, deploy_id=None):
|
||||
"""Show the endpoints of the deployment.
|
||||
|
||||
:param deploy_id: a UUID of the deployment
|
||||
"""
|
||||
|
@ -304,19 +304,13 @@ class TaskCommands(object):
|
||||
print("\trally task results %s\n" % task["uuid"])
|
||||
|
||||
@cliutils.args('--uuid', type=str, dest='task_id', help='uuid of task')
|
||||
@cliutils.args('--pprint', action='store_true', dest='output_pprint',
|
||||
help=('Output in pretty print format'))
|
||||
@cliutils.args('--json', action='store_true', dest='output_json',
|
||||
help=('Output in json format(default)'))
|
||||
@envutils.with_default_task_id
|
||||
def results(self, task_id=None, output_pprint=None, output_json=None):
|
||||
"""Diplay raw task results.
|
||||
def results(self, task_id=None):
|
||||
"""Display raw task results.
|
||||
|
||||
This will produce a lot of output data about every iteration.
|
||||
|
||||
:param task_id: Task uuid
|
||||
:param output_pprint: Output in pretty print format
|
||||
:param output_json: Output in json format (Default)
|
||||
"""
|
||||
|
||||
results = map(lambda x: {"key": x["key"], 'result': x['data']['raw'],
|
||||
@ -324,15 +318,7 @@ class TaskCommands(object):
|
||||
db.task_result_get_all_by_uuid(task_id))
|
||||
|
||||
if results:
|
||||
if all([output_pprint, output_json]):
|
||||
print(_('Please select only one output format'))
|
||||
return 1
|
||||
elif output_pprint:
|
||||
print()
|
||||
pprint.pprint(results)
|
||||
print()
|
||||
else:
|
||||
print(json.dumps(results))
|
||||
print(json.dumps(results, sort_keys=True, indent=4))
|
||||
else:
|
||||
print(_("The task %s can not be found") % task_id)
|
||||
return(1)
|
||||
|
@ -17,7 +17,6 @@
|
||||
|
||||
import json
|
||||
import os
|
||||
import pprint
|
||||
|
||||
import six
|
||||
|
||||
@ -90,26 +89,21 @@ class VerifyCommands(object):
|
||||
@cliutils.args('--uuid', type=str, dest='verification_uuid',
|
||||
help='UUID of the verification')
|
||||
@cliutils.args('--html', action='store_true', dest='output_html',
|
||||
help=('Save results in html format to specified file'))
|
||||
help=('Results will be in html format'))
|
||||
@cliutils.args('--json', action='store_true', dest='output_json',
|
||||
help=('Save results in json format to specified file'))
|
||||
@cliutils.args('--pprint', action='store_true', dest='output_pprint',
|
||||
help=('Save results in pprint format to specified file'))
|
||||
help=('Results will be in json format'))
|
||||
@cliutils.args('--output-file', type=str, required=False,
|
||||
dest='output_file',
|
||||
help='If specified, output will be saved to given file')
|
||||
@envutils.with_default_verification_id
|
||||
def results(self, verification_uuid=None, output_file=None,
|
||||
output_html=None, output_json=None, output_pprint=None):
|
||||
output_html=None, output_json=None):
|
||||
"""Get raw results of the verification.
|
||||
|
||||
:param verification_uuid: Verification UUID
|
||||
:param output_file: If specified, output will be saved to given file
|
||||
:param output_html: Save results in html format to the specified file
|
||||
:param output_json: Save results in json format to the specified file
|
||||
(Default)
|
||||
:param output_pprint: Save results in pprint format to the
|
||||
specified file
|
||||
:param output_html: The output will be in HTML format
|
||||
:param output_json: The output will be in JSON format (Default)
|
||||
"""
|
||||
|
||||
try:
|
||||
@ -119,16 +113,12 @@ class VerifyCommands(object):
|
||||
return 1
|
||||
|
||||
result = ''
|
||||
if len(filter(lambda x: bool(x), [output_json, output_pprint,
|
||||
output_html])) > 1:
|
||||
print("Please specify only on output format")
|
||||
return 1
|
||||
elif output_pprint:
|
||||
result = pprint.pformat(results)
|
||||
if len(filter(lambda x: bool(x), [output_json, output_html])) > 1:
|
||||
print("Please specify only one output format.")
|
||||
elif output_html:
|
||||
result = json2html.main(results)
|
||||
else:
|
||||
result = json.dumps(results)
|
||||
result = json.dumps(results, sort_keys=True, indent=4)
|
||||
|
||||
if output_file:
|
||||
output_file = os.path.expanduser(output_file)
|
||||
|
@ -27,12 +27,12 @@ class DeploymentTestCase(unittest.TestCase):
|
||||
super(DeploymentTestCase, self).setUp()
|
||||
self.rally = utils.Rally()
|
||||
|
||||
def test_create_fromenv_list_endpoint(self):
|
||||
def test_create_fromenv_list_show(self):
|
||||
with mock.patch.dict("os.environ", utils.TEST_ENV):
|
||||
self.rally("deployment create --name t_create_env --fromenv")
|
||||
self.assertIn("t_create_env", self.rally("deployment list"))
|
||||
self.assertIn(utils.TEST_ENV["OS_AUTH_URL"],
|
||||
self.rally("deployment endpoint"))
|
||||
self.rally("deployment show"))
|
||||
|
||||
def test_create_fromfile(self):
|
||||
with mock.patch.dict("os.environ", utils.TEST_ENV):
|
||||
|
@ -156,32 +156,13 @@ class DeploymentCommandsTestCase(test.TestCase):
|
||||
|
||||
@mock.patch('rally.cmd.commands.deployment.db.deployment_get')
|
||||
@mock.patch('json.dumps')
|
||||
def test_config_default(self, mock_json_dumps, mock_deployment):
|
||||
def test_config(self, mock_json_dumps, mock_deployment):
|
||||
deploy_id = 'fa4a423e-f15d-4d83-971a-89574f892999'
|
||||
value = {'config': 'config'}
|
||||
mock_deployment.return_value = value
|
||||
self.deployment.config(deploy_id)
|
||||
mock_json_dumps.assert_called_once_with(value['config'])
|
||||
mock_deployment.assert_called_once_with(deploy_id)
|
||||
|
||||
@mock.patch('rally.cmd.commands.deployment.db.deployment_get')
|
||||
@mock.patch('json.dumps')
|
||||
def test_config_json(self, mock_json_dumps, mock_deployment):
|
||||
deploy_id = '25c5f6d3-56ce-4273-834c-1ae5e1c2599c'
|
||||
value = {'config': 'config'}
|
||||
mock_deployment.return_value = value
|
||||
self.deployment.config(deploy_id, output_json=True)
|
||||
mock_json_dumps.assert_called_once_with(value['config'])
|
||||
mock_deployment.assert_called_once_with(deploy_id)
|
||||
|
||||
@mock.patch('rally.cmd.commands.deployment.db.deployment_get')
|
||||
@mock.patch('pprint.pprint')
|
||||
def test_config_pprint(self, mock_pprint, mock_deployment):
|
||||
deploy_id = '840a0144-4634-46fd-8cf8-b84caa0dba67'
|
||||
value = {'config': 'config'}
|
||||
mock_deployment.return_value = value
|
||||
self.deployment.config(deploy_id, output_pprint=True)
|
||||
mock_pprint.assert_called_once_with(value['config'])
|
||||
mock_json_dumps.assert_called_once_with(value['config'],
|
||||
sort_keys=True, indent=4)
|
||||
mock_deployment.assert_called_once_with(deploy_id)
|
||||
|
||||
@mock.patch('rally.cmd.commands.deployment.envutils.get_global')
|
||||
@ -193,7 +174,7 @@ class DeploymentCommandsTestCase(test.TestCase):
|
||||
@mock.patch('rally.cmd.commands.deployment.common_cliutils.print_list')
|
||||
@mock.patch('rally.cmd.commands.deployment.utils.Struct')
|
||||
@mock.patch('rally.cmd.commands.deployment.db.deployment_get')
|
||||
def test_endpoint(self, mock_deployment, mock_struct, mock_print_list):
|
||||
def test_show(self, mock_deployment, mock_struct, mock_print_list):
|
||||
deploy_id = "b1a6153e-a314-4cb3-b63b-cf08c1a416c3"
|
||||
value = {
|
||||
"admin": {
|
||||
@ -208,7 +189,7 @@ class DeploymentCommandsTestCase(test.TestCase):
|
||||
"users": []
|
||||
}
|
||||
mock_deployment.return_value = value
|
||||
self.deployment.endpoint(deploy_id)
|
||||
self.deployment.show(deploy_id)
|
||||
mock_deployment.assert_called_once_with(deploy_id)
|
||||
|
||||
headers = ["auth_url", "username", "password", "tenant_name",
|
||||
@ -222,4 +203,4 @@ class DeploymentCommandsTestCase(test.TestCase):
|
||||
def test_deploy_no_deploy_id(self, mock_default):
|
||||
mock_default.side_effect = exceptions.InvalidArgumentsException
|
||||
self.assertRaises(exceptions.InvalidArgumentsException,
|
||||
self.deployment.endpoint, None)
|
||||
self.deployment.show, None)
|
||||
|
@ -136,7 +136,7 @@ class TaskCommandsTestCase(test.TestCase):
|
||||
|
||||
@mock.patch('rally.cmd.commands.task.db')
|
||||
@mock.patch('json.dumps')
|
||||
def test_results_default(self, mock_json, mock_db):
|
||||
def test_results(self, mock_json, mock_db):
|
||||
test_uuid = 'aa808c14-69cc-4faf-a906-97e05f5aebbd'
|
||||
value = [
|
||||
{'key': 'key', 'data': {'raw': 'raw', 'sla': []}}
|
||||
@ -146,38 +146,7 @@ class TaskCommandsTestCase(test.TestCase):
|
||||
"sla": x["data"]["sla"]}, value)
|
||||
mock_db.task_result_get_all_by_uuid.return_value = value
|
||||
self.task.results(test_uuid)
|
||||
mock_json.assert_called_once_with(result)
|
||||
mock_db.task_result_get_all_by_uuid.assert_called_once_with(test_uuid)
|
||||
|
||||
@mock.patch('rally.cmd.commands.task.db')
|
||||
@mock.patch('json.dumps')
|
||||
def test_results_json(self, mock_json, mock_db):
|
||||
test_uuid = 'e87dd629-cd3d-4a1e-b377-7b93c19226fb'
|
||||
value = [
|
||||
{'key': 'key', 'data': {'raw': 'raw', 'sla': []}}
|
||||
]
|
||||
result = map(lambda x: {"key": x["key"],
|
||||
"result": x["data"]["raw"],
|
||||
"sla": x["data"]["sla"]}, value)
|
||||
|
||||
mock_db.task_result_get_all_by_uuid.return_value = value
|
||||
self.task.results(test_uuid, output_json=True)
|
||||
mock_json.assert_called_once_with(result)
|
||||
mock_db.task_result_get_all_by_uuid.assert_called_once_with(test_uuid)
|
||||
|
||||
@mock.patch('rally.cmd.commands.task.db')
|
||||
@mock.patch('pprint.pprint')
|
||||
def test_results_pprint(self, mock_pprint, mock_db):
|
||||
test_uuid = 'c1e4bc59-a8fd-458c-9abb-c922d8df4285'
|
||||
value = [
|
||||
{'key': 'key', 'data': {'raw': 'raw', 'sla': []}}
|
||||
]
|
||||
result = map(lambda x: {"key": x["key"],
|
||||
"result": x["data"]["raw"],
|
||||
"sla": x["data"]["sla"]}, value)
|
||||
mock_db.task_result_get_all_by_uuid.return_value = value
|
||||
self.task.results(test_uuid, output_pprint=True)
|
||||
mock_pprint.assert_called_once_with(result)
|
||||
mock_json.assert_called_once_with(result, sort_keys=True, indent=4)
|
||||
mock_db.task_result_get_all_by_uuid.assert_called_once_with(test_uuid)
|
||||
|
||||
@mock.patch('rally.cmd.commands.task.db')
|
||||
|
@ -146,7 +146,7 @@ class VerifyCommandsTestCase(test.TestCase):
|
||||
self.verify.results(verification_uuid, output_json=True)
|
||||
|
||||
mock_db_result_get.assert_called_once_with(verification_uuid)
|
||||
mock_json_dumps.assert_called_once_with({})
|
||||
mock_json_dumps.assert_called_once_with({}, sort_keys=True, indent=4)
|
||||
|
||||
@mock.patch('rally.db.verification_result_get')
|
||||
def test_results_verification_not_found(self, mock_db_result_get):
|
||||
@ -171,21 +171,6 @@ class VerifyCommandsTestCase(test.TestCase):
|
||||
fake_file = mock_open.return_value.__enter__.return_value
|
||||
fake_file.write.assert_called_once_with('{}')
|
||||
|
||||
@mock.patch('rally.cmd.commands.verify.open', create=True)
|
||||
@mock.patch('rally.db.verification_result_get', return_value={'data': {}})
|
||||
def test_results_with_output_pprint_and_output_file(self,
|
||||
mock_db_result_get,
|
||||
mock_open):
|
||||
mock_open.return_value = mock.MagicMock()
|
||||
verification_uuid = 'fa882ccc-153e-4a6e-9001-91fecda6a75c'
|
||||
self.verify.results(verification_uuid, output_pprint=True,
|
||||
output_file='results')
|
||||
|
||||
mock_db_result_get.assert_called_once_with(verification_uuid)
|
||||
mock_open.assert_called_once_with('results', 'wb')
|
||||
fake_file = mock_open.return_value.__enter__.return_value
|
||||
fake_file.write.assert_called_once_with('{}')
|
||||
|
||||
@mock.patch('rally.cmd.commands.verify.open', create=True)
|
||||
@mock.patch('rally.db.verification_result_get')
|
||||
@mock.patch('rally.verification.verifiers.tempest.json2html.main',
|
||||
|
@ -17,7 +17,7 @@ _rally()
|
||||
OPTS["task_list"]=""
|
||||
OPTS["task_plot2html"]="--uuid --out --open"
|
||||
OPTS["task_report"]="--uuid --out --open"
|
||||
OPTS["task_results"]="--uuid --pprint --json"
|
||||
OPTS["task_results"]="--uuid"
|
||||
OPTS["task_sla_check"]="--uuid --json"
|
||||
OPTS["task_start"]="--deploy-id --task --tag --no-use"
|
||||
OPTS["task_status"]="--uuid"
|
||||
@ -29,16 +29,16 @@ _rally()
|
||||
OPTS["show_secgroups"]="--deploy-id"
|
||||
OPTS["verify_detailed"]="--uuid --sort-by"
|
||||
OPTS["verify_list"]=""
|
||||
OPTS["verify_results"]="--uuid --html --json --pprint --output-file"
|
||||
OPTS["verify_results"]="--uuid --html --json --output-file"
|
||||
OPTS["verify_show"]="--uuid --sort-by --detailed"
|
||||
OPTS["verify_start"]="--deploy-id --set --regex --tempest-config --no-use"
|
||||
OPTS["deployment_check"]="--uuid"
|
||||
OPTS["deployment_config"]="--uuid --json --pprint"
|
||||
OPTS["deployment_config"]="--uuid"
|
||||
OPTS["deployment_create"]="--name --fromenv --filename --no-use"
|
||||
OPTS["deployment_destroy"]="--uuid"
|
||||
OPTS["deployment_endpoint"]="--uuid"
|
||||
OPTS["deployment_list"]=""
|
||||
OPTS["deployment_recreate"]="--uuid"
|
||||
OPTS["deployment_show"]="--uuid"
|
||||
|
||||
|
||||
for OPT in ${!OPTS[*]} ; do
|
||||
|
Loading…
Reference in New Issue
Block a user