diff --git a/rally/cmd/commands/deployment.py b/rally/cmd/commands/deployment.py index ef4243453e..5c21cc2879 100644 --- a/rally/cmd/commands/deployment.py +++ b/rally/cmd/commands/deployment.py @@ -255,3 +255,12 @@ class DeploymentCommands(object): % sys.exc_info()[1]) return(1) common_cliutils.print_list(table_rows, headers) + + @cliutils.args("--deployment", type=str, dest="deployment", + help="UUID or name of the deployment") + def use(self, deployment): + """Set active deployment. Alias for "rally use deployment". + + :param deployment: UUID or name of a deployment + """ + use.UseCommands().deployment(deployment) \ No newline at end of file diff --git a/rally/cmd/commands/task.py b/rally/cmd/commands/task.py index f32cf77958..c86e2ca44c 100644 --- a/rally/cmd/commands/task.py +++ b/rally/cmd/commands/task.py @@ -621,3 +621,12 @@ class TaskCommands(object): common_cliutils.print_list(data, ("benchmark", "pos", "criterion", "status", "detail")) return failed_criteria + + @cliutils.args("--task", type=str, dest="task", required=False, + help="UUID of the task") + def use(self, task): + """Set active task. Alias for "rally use task". + + :param task: Task uuid. + """ + use.UseCommands().task(task) diff --git a/rally/cmd/commands/verify.py b/rally/cmd/commands/verify.py index d98c3efba9..0da315817f 100644 --- a/rally/cmd/commands/verify.py +++ b/rally/cmd/commands/verify.py @@ -266,3 +266,12 @@ class VerifyCommands(object): f.write(result) else: print(result) + + @cliutils.args("--verification", type=str, dest="verification", + required=False, help="UUID of the verification") + def use(self, verification): + """Set active verification. Alias for "rally use verification" + + :param verification: a UUID of verification + """ + use.UseCommands().verification(verification) \ No newline at end of file diff --git a/tests/ci/rally-verify.sh b/tests/ci/rally-verify.sh index 3d067e5b68..ac7780585a 100755 --- a/tests/ci/rally-verify.sh +++ b/tests/ci/rally-verify.sh @@ -71,26 +71,36 @@ function do_verification { gzip -9 ${RESULTS_DIR}/${1}_verify_show_detailed.txt } -do_verification 1 -do_verification 2 +function main { + do_verification 1 + do_verification 2 -rally verify list > ${RESULTS_DIR}/verify_list.txt -RESULTS+="l=$(do_status $?) " -gzip -9 ${RESULTS_DIR}/verify_list.txt + rally verify list > ${RESULTS_DIR}/verify_list.txt + RESULTS+="l=$(do_status $?) " + gzip -9 ${RESULTS_DIR}/verify_list.txt -# Compare and save results in different formats -for OUTPUT_FORMAT in "csv" "html" "json" -do - OUTPUT_FILE=${RESULTS_DIR}/compare_results.${OUTPUT_FORMAT} - rally --rally-debug verify compare --uuid-1 ${VERIFICATIONS[1]} --uuid-2 ${VERIFICATIONS[2]} --${OUTPUT_FORMAT} --output-file ${OUTPUT_FILE} - RESULTS+="c_${OUTPUT_FORMAT}=$(do_status $?) " - gzip -9 ${OUTPUT_FILE} -done + # Compare and save results in different formats + for OUTPUT_FORMAT in "csv" "html" "json" + do + OUTPUT_FILE=${RESULTS_DIR}/compare_results.${OUTPUT_FORMAT} + rally --rally-debug verify compare --uuid-1 ${VERIFICATIONS[1]} --uuid-2 ${VERIFICATIONS[2]} --${OUTPUT_FORMAT} --output-file ${OUTPUT_FILE} + RESULTS+="c_${OUTPUT_FORMAT}=$(do_status $?) " + gzip -9 ${OUTPUT_FILE} + done -python $BASE/new/rally/rally/ui/utils.py render\ - tests/ci/rally-gate/index_verify.mako ${RESULTS[*]}> ${RESULTS_DIR}/extra/index.html + python $BASE/new/rally/rally/ui/utils.py render\ + tests/ci/rally-gate/index_verify.mako ${RESULTS[*]}> ${RESULTS_DIR}/extra/index.html -if [[ ${RESULTS[*]} == *"fail"* ]] -then - return 1 -fi + if [[ ${RESULTS[*]} == *"fail"* ]] + then + return 1 + fi + + RESULT_USE=$(rally verify use --verification ${VERIFICATIONS[1]}) + if [ "$RESULT_USE" != "Verification UUID: ${VERIFICATIONS[1]}" ] + then + return 1 + fi +} + +main "$@" diff --git a/tests/functional/test_cli_deployment.py b/tests/functional/test_cli_deployment.py index 98f55b01a7..08b03be1c9 100644 --- a/tests/functional/test_cli_deployment.py +++ b/tests/functional/test_cli_deployment.py @@ -14,10 +14,12 @@ # under the License. import json +import re import unittest import mock +from rally.cmd import envutils from tests.functional import utils @@ -77,3 +79,14 @@ class DeploymentTestCase(unittest.TestCase): self.rally("deployment create --name t_create_env --fromenv") self.rally("deployment recreate --deployment t_create_env") self.assertIn("t_create_env", self.rally("deployment list")) + + def test_use(self): + with mock.patch.dict("os.environ", utils.TEST_ENV): + output = self.rally( + "deployment create --name t_create_env1 --fromenv") + uuid = re.search(r"Using deployment: (?P<uuid>[0-9a-f\-]{36})", + output).group("uuid") + self.rally("deployment create --name t_create_env2 --fromenv") + self.rally("deployment use --deployment %s" % uuid) + current_deployment = envutils.get_global("RALLY_DEPLOYMENT") + self.assertEqual(uuid, current_deployment) \ No newline at end of file diff --git a/tests/functional/test_cli_task.py b/tests/functional/test_cli_task.py index 4fb0034900..18c45b7293 100644 --- a/tests/functional/test_cli_task.py +++ b/tests/functional/test_cli_task.py @@ -473,6 +473,22 @@ class TaskTestCase(unittest.TestCase): def test_abort(self): pass + def test_use(self): + rally = utils.Rally() + with mock.patch.dict("os.environ", utils.TEST_ENV): + deployment_id = envutils.get_global("RALLY_DEPLOYMENT") + config = utils.TaskConfig(self._get_sample_task_config()) + output = rally(("task start --task %(task_file)s " + "--deployment %(deployment_id)s") % + {"task_file": config.filename, + "deployment_id": deployment_id}) + result = re.search( + r"(?P<uuid>[0-9a-f\-]{36}): started", output) + uuid = result.group("uuid") + rally("task use --task %s" % uuid) + current_task = envutils.get_global("RALLY_TASK") + self.assertEqual(uuid, current_task) + class SLATestCase(unittest.TestCase): diff --git a/tests/unit/cmd/commands/test_deployment.py b/tests/unit/cmd/commands/test_deployment.py index 61f2436d52..f532514985 100644 --- a/tests/unit/cmd/commands/test_deployment.py +++ b/tests/unit/cmd/commands/test_deployment.py @@ -202,3 +202,8 @@ class DeploymentCommandsTestCase(test.TestCase): mock_default.side_effect = exceptions.InvalidArgumentsException self.assertRaises(exceptions.InvalidArgumentsException, self.deployment.show, None) + + @mock.patch("rally.cmd.commands.use.UseCommands.deployment") + def test_use(self, mock_use_deployment): + self.deployment.use("fake_id") + mock_use_deployment.assert_called_once_with("fake_id") \ No newline at end of file diff --git a/tests/unit/cmd/commands/test_task.py b/tests/unit/cmd/commands/test_task.py index 6d7c8d26e2..33a2a728ef 100644 --- a/tests/unit/cmd/commands/test_task.py +++ b/tests/unit/cmd/commands/test_task.py @@ -595,3 +595,8 @@ class TaskCommandsTestCase(test.TestCase): self.assertEqual(1, result) mock_task_validate.assert_called_once_with("deployment", mock_load.return_value) + + @mock.patch("rally.cmd.commands.use.UseCommands.task") + def test_use(self, mock_use_task): + self.task.use("fake_id") + mock_use_task.assert_called_once_with("fake_id") diff --git a/tests/unit/cmd/commands/test_verify.py b/tests/unit/cmd/commands/test_verify.py index 1b9bc756da..ed16af1336 100644 --- a/tests/unit/cmd/commands/test_verify.py +++ b/tests/unit/cmd/commands/test_verify.py @@ -300,3 +300,8 @@ class VerifyCommandsTestCase(test.TestCase): mock_open.assert_called_once_with("results", "wb") mock_open.side_effect().write.assert_called_once_with("") + + @mock.patch("rally.cmd.commands.use.UseCommands.verification") + def test_use(self, mock_use_verification): + self.verify.use("fake_id") + mock_use_verification.assert_called_once_with("fake_id") \ No newline at end of file diff --git a/tools/rally.bash_completion b/tools/rally.bash_completion index 234a821a2e..8bb8ef0fc3 100644 --- a/tools/rally.bash_completion +++ b/tools/rally.bash_completion @@ -13,6 +13,7 @@ _rally() OPTS["deployment_list"]="" OPTS["deployment_recreate"]="--deployment" OPTS["deployment_show"]="--deployment" + OPTS["deployment_use"]="--deployment" OPTS["info_BenchmarkScenarios"]="" OPTS["info_DeployEngines"]="" OPTS["info_DeploymentEngines"]="" @@ -34,6 +35,7 @@ _rally() OPTS["task_sla_check"]="--uuid --json" OPTS["task_start"]="--deployment --task --task-args --task-args-file --tag --no-use --abort-on-sla-failure" OPTS["task_status"]="--uuid" + OPTS["task_use"]="--task" OPTS["task_validate"]="--deployment --task --task-args --task-args-file" OPTS["use_deployment"]="--deployment" OPTS["use_task"]="--uuid" @@ -44,6 +46,7 @@ _rally() OPTS["verify_results"]="--uuid --html --json --output-file" OPTS["verify_show"]="--uuid --sort-by --detailed" OPTS["verify_start"]="--deployment --set --regex --tempest-config --no-use" + OPTS["verify_use"]="--verification" for OPT in ${!OPTS[*]} ; do @@ -75,4 +78,4 @@ _rally() fi return 0 } -complete -F _rally rally \ No newline at end of file +complete -F _rally rally