diff --git a/mistralclient/commands/v2/environments.py b/mistralclient/commands/v2/environments.py index 54022aa9..956efd4e 100644 --- a/mistralclient/commands/v2/environments.py +++ b/mistralclient/commands/v2/environments.py @@ -106,12 +106,32 @@ class Get(command.ShowOne): help='Environment name' ) + parser.add_argument( + '--export', + default=False, + action='store_true', + help='Export the environment suitable for import' + ) + return parser def take_action(self, parsed_args): mistral_client = self.app.client_manager.workflow_engine environment = mistral_client.environments.get(parsed_args.environment) + if parsed_args.export: + columns = ('name', + 'description', + 'scope', + 'variables') + + data = (environment.name, + environment.description, + environment.scope, + json.dumps(environment.variables)) + + return columns, data + return format(environment) diff --git a/mistralclient/tests/functional/cli/v2/cli_tests_v2.py b/mistralclient/tests/functional/cli/v2/cli_tests_v2.py index 02997053..54abd6f3 100644 --- a/mistralclient/tests/functional/cli/v2/cli_tests_v2.py +++ b/mistralclient/tests/functional/cli/v2/cli_tests_v2.py @@ -1530,6 +1530,22 @@ class EnvironmentCLITests(base_v2.MistralClientTestBase): self.assertEqual(env_name, fetched_env_name) self.assertEqual(env_desc, fetched_env_desc) + def test_environment_get_export(self): + env = self.environment_create('env.yaml') + + env_name = self.get_field_value(env, 'Name') + env_desc = self.get_field_value(env, 'Description') + + env = self.mistral_admin('environment-get', + params='--export {0}'.format(env_name)) + + fetched_env_name = self.get_field_value(env, 'name') + fetched_env_desc = self.get_field_value(env, 'description') + + self.assertTableStruct(env, ['Field', 'Value']) + self.assertEqual(env_name, fetched_env_name) + self.assertEqual(env_desc, fetched_env_desc) + class ActionExecutionCLITests(base_v2.MistralClientTestBase): """Test suite checks commands to work with action executions.""" diff --git a/mistralclient/tests/unit/v2/test_cli_environments.py b/mistralclient/tests/unit/v2/test_cli_environments.py index 4c24618e..539a075e 100644 --- a/mistralclient/tests/unit/v2/test_cli_environments.py +++ b/mistralclient/tests/unit/v2/test_cli_environments.py @@ -48,6 +48,11 @@ EXPECTED_RESULT = (ENVIRONMENT_DICT['name'], ENVIRONMENT_DICT['created_at'], ENVIRONMENT_DICT['updated_at']) +EXPECTED_EXPORT_RESULT = (ENVIRONMENT_DICT['name'], + ENVIRONMENT_DICT['description'], + ENVIRONMENT_DICT['scope'], + json.dumps(ENVIRONMENT_DICT['variables'])) + class TestCLIEnvironmentsV2(base.BaseCommandTest): @@ -110,6 +115,13 @@ class TestCLIEnvironmentsV2(base.BaseCommandTest): self.assertEqual(EXPECTED_RESULT, result[1]) + def test_get_with_export(self): + self.client.environments.get.return_value = ENVIRONMENT + + result = self.call(environment_cmd.Get, app_args=['--export', 'name']) + + self.assertEqual(EXPECTED_EXPORT_RESULT, result[1]) + def test_delete(self): self.call(environment_cmd.Delete, app_args=['name'])