diff --git a/solumclient/solum.py b/solumclient/solum.py index 0c73ea4..9896bc2 100644 --- a/solumclient/solum.py +++ b/solumclient/solum.py @@ -43,7 +43,6 @@ import json import sys import six -import yaml from solumclient.common import cli_utils from solumclient.openstack.common import cliutils @@ -63,15 +62,7 @@ class AppCommands(cli_utils.CommandsBase): with open(args.plan_file) as definition_file: definition = definition_file.read() - # Convert yaml to json until we add yaml support in API layer. - try: - data = yaml.load(definition) - except yaml.YAMLError as exc: - print("Error in plan file: %s", str(exc)) - sys.exit(1) - - plan = self.client.plans.create(**data) - + plan = self.client.plans.create(definition) fields = ['uuid', 'name', 'description', 'uri'] data = dict([(f, getattr(plan, f, '')) for f in fields]) diff --git a/solumclient/tests/test_solum.py b/solumclient/tests/test_solum.py index 673533d..1df0a4a 100644 --- a/solumclient/tests/test_solum.py +++ b/solumclient/tests/test_solum.py @@ -23,7 +23,6 @@ import mock import six from stevedore import extension from testtools import matchers -import yaml from solumclient.openstack.common.apiclient import auth from solumclient.openstack.common import cliutils @@ -188,12 +187,12 @@ class TestSolum(base.TestCase): mock_app_create.return_value = FakeResource('foo', 'foo', 'foo', 'foo') expected_printed_dict_args = mock_app_create.return_value._asdict() - plan_data = yaml.load(plan_file_data) - mopen = mock.mock_open(read_data=plan_file_data) + plan_data = 'version: 1\nname: ex_plan1\ndescription: dsc1.' + mopen = mock.mock_open(read_data=plan_data) with mock.patch('%s.open' % solum.__name__, mopen, create=True): self.make_env() self.shell("app create /dev/null") - mock_app_create.assert_called_once_with(**plan_data) + mock_app_create.assert_called_once_with(plan_data) mock_print_dict.assert_called_once_with( expected_printed_dict_args, wrap=72) diff --git a/solumclient/tests/v1/test_plan.py b/solumclient/tests/v1/test_plan.py index 7022bdd..7fff21e 100644 --- a/solumclient/tests/v1/test_plan.py +++ b/solumclient/tests/v1/test_plan.py @@ -157,7 +157,7 @@ class PlanManagerTest(base.TestCase): fake_http_client = fake_client.FakeHTTPClient(fixtures=fixtures_create) api_client = sclient.Client(fake_http_client) mgr = plan.PlanManager(api_client) - plan_obj = mgr.create(**plan_fixture) + plan_obj = mgr.create('version: 1\nname: ex_plan1\ndescription: dsc1.') self.assert_plan_obj(plan_obj) def test_get(self): diff --git a/solumclient/v1/plan.py b/solumclient/v1/plan.py index 31970f0..5fec682 100644 --- a/solumclient/v1/plan.py +++ b/solumclient/v1/plan.py @@ -13,8 +13,10 @@ # under the License. import six +import yaml from solumclient.common import base as solum_base +from solumclient.common import exc from solumclient.openstack.common.apiclient import base as apiclient_base from solumclient.openstack.common import uuidutils @@ -83,9 +85,19 @@ class PlanManager(solum_base.CrudManager, solum_base.FindMixin): def list(self, **kwargs): return super(PlanManager, self).list(base_url="/v1", **kwargs) - def create(self, **kwargs): - return super(PlanManager, - self).create(base_url="/v1", **kwargs) + def create(self, plan, **kwargs): + kwargs = self._filter_kwargs(kwargs) + kwargs['data'] = plan + kwargs.setdefault("headers", kwargs.get("headers", {})) + kwargs['headers']['Content-Type'] = 'x-application/yaml' + resp = self.client.post( + self.build_url(base_url="/v1", **kwargs), **kwargs) + try: + resp_plan = yaml.load(resp.content) + except yaml.YAMLError: + raise exc.BaseException(message='Could not parse response ' + 'from Plan API resource.') + return self.resource_class(self, resp_plan) def get(self, **kwargs): return super(PlanManager, self).get(base_url="/v1", **kwargs)