def validate_plan(self, plan_name): """Validate Plan This private method provides validations to ensure a plan meets the proper criteria before allowed to persist in storage. :param plan_files: The files to import into the container. :type plan_files: dict :returns boolean """ plan = self.get_plan(plan_name) # there can only be up to one root-template file in metadata rt = {k: v for (k, v) in plan.files.items() if v.get('meta', {}).get('file-type') == 'root-template'} if len(rt) > 1: raise exception.TooManyRootTemplatesError() # the plan needs to be validated with heat to ensure it conforms template, environment, files = templates.process_plan_data(plan.files) try: self.heatclient.stacks.validate( template=template, files=files, environment=environment, show_nested=True) except heatexceptions.HTTPBadRequest as exc: LOG.exception("Error validating the plan.") six.raise_from(exception.HeatValidationFailedError(msg=exc), exc) # no validation issues found return True
def validate_plan(self, plan_name): """Validate Plan This private method provides validations to ensure a plan meets the proper criteria before allowed to persist in storage. :param plan_files: The files to import into the container. :type plan_files: dict :returns boolean """ plan = self.get_plan(plan_name) # there can only be up to one root-template file in metadata rt = { k: v for (k, v) in plan.files.items() if v.get('meta', {}).get('file-type') == 'root-template' } if len(rt) > 1: raise exception.TooManyRootTemplatesError() # the plan needs to be validated with heat to ensure it conforms template, environment, files = templates.process_plan_data(plan.files) try: self.heatclient.stacks.validate(template=template, files=files, environment=environment, show_nested=True) except heatexceptions.HTTPBadRequest as exc: LOG.exception("Error validating the plan.") six.raise_from(exception.HeatValidationFailedError(msg=exc), exc) # no validation issues found return True
def get_deployment_parameters(self, plan_name): """Determine available deployment parameters :param plan_name: The name of the plan and container name """ plan = self.get_plan(plan_name) template, environment, files = templates.process_plan_data(plan.files) try: params = self.heatclient.stacks.validate(template=template, files=files, environment=environment, show_nested=True) except heatexceptions.HTTPBadRequest as exc: six.raise_from(exception.HeatValidationFailedError(msg=exc), exc) return params
def get_deployment_parameters(self, plan_name): """Determine available deployment parameters :param plan_name: The name of the plan and container name """ plan = self.get_plan(plan_name) template, environment, files = templates.process_plan_data(plan.files) try: params = self.heatclient.stacks.validate( template=template, files=files, environment=environment, show_nested=True) except heatexceptions.HTTPBadRequest as exc: six.raise_from(exception.HeatValidationFailedError(msg=exc), exc) return params
def update_deployment_parameters(self, plan_name, deployment_parameters): """Update the deployment parameters :param plan_name: The name of the plan and container name :type plan_name: str :param deployment_parameters: dictionary of deployment parameters :type deployment_parameters: dict """ plan = self.get_plan(plan_name) deployment_params_file = 'environments/deployment_parameters.yaml' # Make sure the dict has the expected environment file format. if not deployment_parameters.get('parameter_defaults'): deployment_parameters = { 'parameter_defaults': deployment_parameters } # pop the deployment params temporary environment file from the plan # so it's not included in the validation call. If the stack is valid # the deployment params temporary environment file is overwritten if deployment_params_file in plan.files: plan.files.pop(deployment_params_file) # Update deployment params and validate through heat API. template, environment, files = templates.process_plan_data(plan.files) environment = templates.deep_update(environment, deployment_parameters) try: self.heatclient.stacks.validate( template=template, files=files, environment=environment, show_nested=True) except heatexceptions.HTTPBadRequest as exc: six.raise_from(exception.HeatValidationFailedError(msg=exc), exc) env = yaml.dump(deployment_parameters, default_flow_style=False) plan.files[deployment_params_file] = { 'contents': env, 'meta': { 'file-type': 'temp-environment', } } self.update_plan(plan_name, plan.files)
def update_deployment_parameters(self, plan_name, deployment_parameters): """Update the deployment parameters :param plan_name: The name of the plan and container name :type plan_name: str :param deployment_parameters: dictionary of deployment parameters :type deployment_parameters: dict """ plan = self.get_plan(plan_name) deployment_params_file = 'environments/deployment_parameters.yaml' # Make sure the dict has the expected environment file format. if not deployment_parameters.get('parameter_defaults'): deployment_parameters = { 'parameter_defaults': deployment_parameters } # pop the deployment params temporary environment file from the plan # so it's not included in the validation call. If the stack is valid # the deployment params temporary environment file is overwritten if deployment_params_file in plan.files: plan.files.pop(deployment_params_file) # Update deployment params and validate through heat API. template, environment, files = templates.process_plan_data(plan.files) environment = templates.deep_update(environment, deployment_parameters) try: self.heatclient.stacks.validate(template=template, files=files, environment=environment, show_nested=True) except heatexceptions.HTTPBadRequest as exc: six.raise_from(exception.HeatValidationFailedError(msg=exc), exc) env = yaml.safe_dump(deployment_parameters, default_flow_style=False) plan.files[deployment_params_file] = { 'contents': env, 'meta': { 'file-type': 'temp-environment', } } self.update_plan(plan_name, plan.files)
def setUp(self): super(UtilsTemplatesTest, self).setUp() self.tpl, self.env, self.files = process_plan_data(PLAN_DATA) print(self.files)