Custom variables

On creating a solum app, user can upload custom
variables via --param-file option.

Change-Id: I653aec30881759f9a7fbe20b54abd39e343a61b5
This commit is contained in:
James Li
2014-10-29 21:26:44 +00:00
parent 5a5f7a6b3a
commit ffb653096b
2 changed files with 24 additions and 7 deletions

View File

@@ -48,6 +48,7 @@ import sys
import six import six
from solumclient.common import cli_utils from solumclient.common import cli_utils
from solumclient.common import yamlutils
from solumclient.openstack.common import cliutils from solumclient.openstack.common import cliutils
from solumclient.openstack.common import strutils from solumclient.openstack.common import strutils
from solumclient.v1 import assembly as cli_assem from solumclient.v1 import assembly as cli_assem
@@ -61,12 +62,25 @@ class AppCommands(cli_utils.CommandsBase):
def create(self): def create(self):
"""Create an application.""" """Create an application."""
self.parser.add_argument('plan_file', self.parser.add_argument('plan_file',
help="Plan file") help="A yaml file that defines an app,"
" check out solum repo for examples")
self.parser.add_argument('--param-file',
dest='param_file',
help="A yaml file containing custom"
" parameters to be used in the"
" application, check out solum repo for"
" examples")
args = self.parser.parse_args() args = self.parser.parse_args()
with open(args.plan_file) as definition_file: with open(args.plan_file) as definition_file:
definition = definition_file.read() plan_definition = definition_file.read()
definition = yamlutils.load(plan_definition)
plan = self.client.plans.create(definition) if args.param_file:
with open(args.param_file) as param_f:
param_definition = param_f.read()
definition['parameters'] = yamlutils.load(param_definition)
plan = self.client.plans.create(yamlutils.dump(definition))
fields = ['uuid', 'name', 'description', 'uri', 'artifacts'] fields = ['uuid', 'name', 'description', 'uri', 'artifacts']
data = dict([(f, getattr(plan, f, '')) data = dict([(f, getattr(plan, f, ''))
for f in fields]) for f in fields])

View File

@@ -25,6 +25,7 @@ from stevedore import extension
from testtools import matchers from testtools import matchers
from solumclient.builder.v1 import image from solumclient.builder.v1 import image
from solumclient.common import yamlutils
from solumclient.openstack.common.apiclient import auth from solumclient.openstack.common.apiclient import auth
from solumclient.openstack.common import cliutils from solumclient.openstack.common import cliutils
from solumclient import solum from solumclient import solum
@@ -260,8 +261,9 @@ class TestSolum(base.TestCase):
mock_app_create.return_value = FakeResource('foo', 'foo', 'foo', 'foo') mock_app_create.return_value = FakeResource('foo', 'foo', 'foo', 'foo')
expected_printed_dict_args = mock_app_create.return_value._asdict() expected_printed_dict_args = mock_app_create.return_value._asdict()
plan_data = 'version: 1\nname: ex_plan1\ndescription: dsc1.' raw_data = 'version: 1\nname: ex_plan1\ndescription: dsc1.'
mopen = mock.mock_open(read_data=plan_data) plan_data = yamlutils.dump(yamlutils.load(raw_data))
mopen = mock.mock_open(read_data=raw_data)
with mock.patch('%s.open' % solum.__name__, mopen, create=True): with mock.patch('%s.open' % solum.__name__, mopen, create=True):
self.make_env() self.make_env()
self.shell("app create /dev/null") self.shell("app create /dev/null")
@@ -284,8 +286,9 @@ class TestSolum(base.TestCase):
expected_printed_dict_args = mock_app_create.return_value._asdict() expected_printed_dict_args = mock_app_create.return_value._asdict()
expected_printed_dict_args.pop('artifacts') expected_printed_dict_args.pop('artifacts')
expected_show_pub_keys_args = 'artifacts' expected_show_pub_keys_args = 'artifacts'
plan_data = 'version: 1\nname: ex_plan1\ndescription: dsc1.' raw_data = 'version: 1\nname: ex_plan1\ndescription: dsc1.'
mopen = mock.mock_open(read_data=plan_data) plan_data = yamlutils.dump(yamlutils.load(raw_data))
mopen = mock.mock_open(read_data=raw_data)
with mock.patch('%s.open' % solum.__name__, mopen, create=True): with mock.patch('%s.open' % solum.__name__, mopen, create=True):
self.make_env() self.make_env()
self.shell("app create /dev/null") self.shell("app create /dev/null")