Add post Plan in YAML
the API now supports Post of plan in YAML format, so this patch updates the client post method according to the api changes. Change-Id: I6763ff3bb82625a56c86b5f2a5c71ade4dc76594 Related-Bug: #1309493
This commit is contained in:
@@ -43,7 +43,6 @@ import json
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
import six
|
import six
|
||||||
import yaml
|
|
||||||
|
|
||||||
from solumclient.common import cli_utils
|
from solumclient.common import cli_utils
|
||||||
from solumclient.openstack.common import cliutils
|
from solumclient.openstack.common import cliutils
|
||||||
@@ -63,15 +62,7 @@ class AppCommands(cli_utils.CommandsBase):
|
|||||||
with open(args.plan_file) as definition_file:
|
with open(args.plan_file) as definition_file:
|
||||||
definition = definition_file.read()
|
definition = definition_file.read()
|
||||||
|
|
||||||
# Convert yaml to json until we add yaml support in API layer.
|
plan = self.client.plans.create(definition)
|
||||||
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)
|
|
||||||
|
|
||||||
fields = ['uuid', 'name', 'description', 'uri']
|
fields = ['uuid', 'name', 'description', 'uri']
|
||||||
data = dict([(f, getattr(plan, f, ''))
|
data = dict([(f, getattr(plan, f, ''))
|
||||||
for f in fields])
|
for f in fields])
|
||||||
|
@@ -23,7 +23,6 @@ import mock
|
|||||||
import six
|
import six
|
||||||
from stevedore import extension
|
from stevedore import extension
|
||||||
from testtools import matchers
|
from testtools import matchers
|
||||||
import yaml
|
|
||||||
|
|
||||||
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
|
||||||
@@ -188,12 +187,12 @@ 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 = yaml.load(plan_file_data)
|
plan_data = 'version: 1\nname: ex_plan1\ndescription: dsc1.'
|
||||||
mopen = mock.mock_open(read_data=plan_file_data)
|
mopen = mock.mock_open(read_data=plan_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")
|
||||||
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(
|
mock_print_dict.assert_called_once_with(
|
||||||
expected_printed_dict_args,
|
expected_printed_dict_args,
|
||||||
wrap=72)
|
wrap=72)
|
||||||
|
@@ -157,7 +157,7 @@ class PlanManagerTest(base.TestCase):
|
|||||||
fake_http_client = fake_client.FakeHTTPClient(fixtures=fixtures_create)
|
fake_http_client = fake_client.FakeHTTPClient(fixtures=fixtures_create)
|
||||||
api_client = sclient.Client(fake_http_client)
|
api_client = sclient.Client(fake_http_client)
|
||||||
mgr = plan.PlanManager(api_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)
|
self.assert_plan_obj(plan_obj)
|
||||||
|
|
||||||
def test_get(self):
|
def test_get(self):
|
||||||
|
@@ -13,8 +13,10 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import six
|
import six
|
||||||
|
import yaml
|
||||||
|
|
||||||
from solumclient.common import base as solum_base
|
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.apiclient import base as apiclient_base
|
||||||
from solumclient.openstack.common import uuidutils
|
from solumclient.openstack.common import uuidutils
|
||||||
|
|
||||||
@@ -83,9 +85,19 @@ class PlanManager(solum_base.CrudManager, solum_base.FindMixin):
|
|||||||
def list(self, **kwargs):
|
def list(self, **kwargs):
|
||||||
return super(PlanManager, self).list(base_url="/v1", **kwargs)
|
return super(PlanManager, self).list(base_url="/v1", **kwargs)
|
||||||
|
|
||||||
def create(self, **kwargs):
|
def create(self, plan, **kwargs):
|
||||||
return super(PlanManager,
|
kwargs = self._filter_kwargs(kwargs)
|
||||||
self).create(base_url="/v1", **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):
|
def get(self, **kwargs):
|
||||||
return super(PlanManager, self).get(base_url="/v1", **kwargs)
|
return super(PlanManager, self).get(base_url="/v1", **kwargs)
|
||||||
|
Reference in New Issue
Block a user