def _parse_stack_configs(self, config_dict, transform_context): """ Create a StackConfig Object for each stack defined in config :param config_dict: dict :return: dict(stack_name: StackConfig) """ stacks_dict = TransformDict({}, transform_context) for key, value in config_dict.get("stacks", {}).items(): try: stacks_dict[key] = StackConfig( value, working_dir=self.working_dir, default_tags=self.default_tags, default_package_bucket=self.default_package_bucket, default_timeout=self.default_timeout, default_service_role=self.default_service_role, default_stack_policy_url=self.default_stack_policy_url, default_failure_action=self.default_failure_action, default_disable_rollback=self.default_disable_rollback) except InvalidConfigException as e: raise InvalidConfigException( "Invalid config for stack {0}: {1}".format(key, e)) return stacks_dict
def test_resolve_parameter_values_calls_convert_list_to_string_on_list_value( self, convert_list_to_string_mock): stack_config = Mock() stack_config.parameters = TransformDict({'foo': ['a', 'b']}, {}) ParameterResolver(self.cfn_mock).resolve_parameter_values( 'foo', stack_config) convert_list_to_string_mock.assert_called_once_with(['a', 'b'])
def __init__(self, stack_config_dict, working_dir=None, default_tags=None, default_timeout=600, default_service_role=None, default_stack_policy_url=None, default_failure_action="ROLLBACK", default_disable_rollback=False): # unit testing constructs this directly which means we have to wrap it here. if not isinstance(stack_config_dict, TransformDict): stack_config_dict = TransformDict(stack_config_dict, {}) if not stack_config_dict: raise InvalidConfigException( "Stack configuration must not be empty") if default_tags is None: default_tags = {} self.parameters = stack_config_dict.get("parameters", {}) self.template_url = stack_config_dict.get("template-url") self.tags = {} self.tags.update(default_tags) self.tags.update(stack_config_dict.get("tags", {})) self.service_role = stack_config_dict.get("service-role", default_service_role) self.stack_policy_url = stack_config_dict.get( "stack-policy-url", default_stack_policy_url) self.timeout = stack_config_dict.get("timeout", default_timeout) self.failure_action = stack_config_dict.get("on_failure", default_failure_action) self.disable_rollback = stack_config_dict.get( "disable_rollback", default_disable_rollback) self.working_dir = working_dir self._stack_config_dict = stack_config_dict self._validate()
def test_resolve_parameter_values_returns_ref_list_value( self, get_output_value_mock): self.cfn_mock.get_stacks_outputs = MagicMock(return_value=None) get_output_value_mock.return_value = 'bar' stack_config = Mock() stack_config.parameters = TransformDict( {'foo': ['|Ref|stack.output', '|Ref|stack.output']}, {}) result = ParameterResolver(self.cfn_mock).resolve_parameter_values( 'foo', stack_config) get_output_value_mock.assert_called_with(None, "stack", "output") self.assertEqual({'foo': 'bar,bar'}, result)
def _read_config_file(config_file, transform_context, path): try: with open(config_file, "r") as f: context = merge_includes(transform_context, path) config_dict = TransformDict(yaml.safe_load(f.read()), context) if not isinstance(config_dict, TransformDict): raise InvalidConfigException( "Config file {0} has invalid content, top level element must be a dict" .format(config_file)) return config_dict except ScannerError as e: raise InvalidConfigException("Could not parse {0}: {1} {2}".format( config_file, e.problem, e.problem_mark)) except Exception as e: raise InvalidConfigException( "Could not read yaml file {0}: {1}".format(config_file, e))