From 1d4c407fc53ed2b57377095f0f5d99079afcf51f Mon Sep 17 00:00:00 2001 From: Mark Vanderwiel Date: Fri, 4 Mar 2016 14:36:13 -0600 Subject: [PATCH] OSC plugin for orchestration template validate This change implements "openstack orchestration template validate" command Based from the existing heat commands: heat template-validate This is different from the stack create/update --dry-run which used the preview api, this uses the validate api. Change-Id: Icf5794ad6bb35574a060f095d7ef10e6a46ca2fe Blueprint: heat-support-python-openstackclient --- heatclient/common/http.py | 13 +++ heatclient/osc/v1/stack.py | 15 +--- heatclient/osc/v1/template.py | 83 +++++++++++++++++++ heatclient/tests/unit/osc/v1/test_stack.py | 2 - heatclient/tests/unit/osc/v1/test_template.py | 73 ++++++++++++++++ heatclient/v1/shell.py | 23 ++--- setup.cfg | 1 + 7 files changed, 178 insertions(+), 32 deletions(-) diff --git a/heatclient/common/http.py b/heatclient/common/http.py index 4b46c71d..8a799b69 100644 --- a/heatclient/common/http.py +++ b/heatclient/common/http.py @@ -39,6 +39,19 @@ SENSITIVE_HEADERS = ('X-Auth-Token',) osprofiler_web = importutils.try_import("osprofiler.web") +def authenticated_fetcher(hc): + """A wrapper around the heat client object to fetch a template.""" + + def _do(*args, **kwargs): + if isinstance(hc.http_client, SessionClient): + method, url = args + return hc.http_client.request(url, method, **kwargs).content + else: + return hc.http_client.raw_request(*args, **kwargs).content + + return _do + + def get_system_ca_file(): """Return path to system default CA file.""" # Standard CA file locations for Debian/Ubuntu, RedHat/Fedora, diff --git a/heatclient/osc/v1/stack.py b/heatclient/osc/v1/stack.py index e60b6e20..e9059df8 100644 --- a/heatclient/osc/v1/stack.py +++ b/heatclient/osc/v1/stack.py @@ -37,17 +37,6 @@ from heatclient.openstack.common._i18n import _ from heatclient.openstack.common._i18n import _LI -def _authenticated_fetcher(client): - def _do(*args, **kwargs): - if isinstance(client.http_client, http.SessionClient): - method, url = args - return client.http_client.request(url, method, **kwargs).content - else: - return client.http_client.raw_request(*args, **kwargs).content - - return _do - - class CreateStack(show.ShowOne): """Create a stack.""" @@ -136,7 +125,7 @@ class CreateStack(show.ShowOne): tpl_files, template = template_utils.process_template_path( parsed_args.template, - object_request=_authenticated_fetcher(client)) + object_request=http.authenticated_fetcher(client)) env_files, env = ( template_utils.process_multiple_environments_and_files( @@ -297,7 +286,7 @@ class UpdateStack(show.ShowOne): tpl_files, template = template_utils.process_template_path( parsed_args.template, - object_request=_authenticated_fetcher(client), + object_request=http.authenticated_fetcher(client), existing=parsed_args.existing) env_files, env = ( diff --git a/heatclient/osc/v1/template.py b/heatclient/osc/v1/template.py index 28a3f5b1..2d3d7d1a 100644 --- a/heatclient/osc/v1/template.py +++ b/heatclient/osc/v1/template.py @@ -13,10 +13,16 @@ # Copyright 2015 IBM Corp. import logging +import six + from cliff import lister from openstackclient.common import utils +from heatclient.common import format_utils +from heatclient.common import http +from heatclient.common import template_utils +from heatclient.common import utils as heat_utils from heatclient import exc from heatclient.openstack.common._i18n import _ @@ -72,3 +78,80 @@ class FunctionList(lister.Lister): fields, (utils.get_item_properties(s, fields) for s in functions) ) + + +class Validate(format_utils.YamlFormat): + """Validate a template""" + + log = logging.getLogger(__name__ + ".Validate") + + def get_parser(self, prog_name): + parser = super(Validate, self).get_parser(prog_name) + parser.add_argument( + '-t', '--template', + metavar='