Add --export option to environment-get
Use --export to give output suitable for importing via environment-update. The other 'get-definition' commands will be deprecated in favor of a --export option to 'get' and 'show' Change-Id: I1bf9b621b498b6978d6fa5903db58c1474b31c93 Closes-Bug: #1769491
This commit is contained in:
parent
2f06ab41fb
commit
4dd1c2a444
@ -106,12 +106,32 @@ class Get(command.ShowOne):
|
|||||||
help='Environment name'
|
help='Environment name'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
parser.add_argument(
|
||||||
|
'--export',
|
||||||
|
default=False,
|
||||||
|
action='store_true',
|
||||||
|
help='Export the environment suitable for import'
|
||||||
|
)
|
||||||
|
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
mistral_client = self.app.client_manager.workflow_engine
|
mistral_client = self.app.client_manager.workflow_engine
|
||||||
environment = mistral_client.environments.get(parsed_args.environment)
|
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)
|
return format(environment)
|
||||||
|
|
||||||
|
|
||||||
|
@ -1530,6 +1530,22 @@ class EnvironmentCLITests(base_v2.MistralClientTestBase):
|
|||||||
self.assertEqual(env_name, fetched_env_name)
|
self.assertEqual(env_name, fetched_env_name)
|
||||||
self.assertEqual(env_desc, fetched_env_desc)
|
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):
|
class ActionExecutionCLITests(base_v2.MistralClientTestBase):
|
||||||
"""Test suite checks commands to work with action executions."""
|
"""Test suite checks commands to work with action executions."""
|
||||||
|
@ -48,6 +48,11 @@ EXPECTED_RESULT = (ENVIRONMENT_DICT['name'],
|
|||||||
ENVIRONMENT_DICT['created_at'],
|
ENVIRONMENT_DICT['created_at'],
|
||||||
ENVIRONMENT_DICT['updated_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):
|
class TestCLIEnvironmentsV2(base.BaseCommandTest):
|
||||||
|
|
||||||
@ -110,6 +115,13 @@ class TestCLIEnvironmentsV2(base.BaseCommandTest):
|
|||||||
|
|
||||||
self.assertEqual(EXPECTED_RESULT, result[1])
|
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):
|
def test_delete(self):
|
||||||
self.call(environment_cmd.Delete, app_args=['name'])
|
self.call(environment_cmd.Delete, app_args=['name'])
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user