def _pseudo_parameters(self, stack_identifier): stack_id = (stack_identifier.arn() if stack_identifier is not None else 'None') stack_name = stack_identifier and stack_identifier.stack_name yield parameters.Parameter( self.PARAM_STACK_ID, parameters.Schema(parameters.Schema.STRING, _('Stack ID'), default=str(stack_id))) if stack_name: yield parameters.Parameter( self.PARAM_STACK_NAME, parameters.Schema(parameters.Schema.STRING, _('Stack Name'), default=stack_name)) yield parameters.Parameter( self.PARAM_REGION, parameters.Schema(parameters.Schema.STRING, default='ap-southeast-1', constraints=[ constr.AllowedValues([ 'us-east-1', 'us-west-1', 'us-west-2', 'sa-east-1', 'eu-west-1', 'ap-southeast-1', 'ap-northeast-1' ]) ]))
def _pseudo_parameters(self, stack_identifier): stack_id = getattr(stack_identifier, 'stack_id', '') stack_name = getattr(stack_identifier, 'stack_name', '') yield parameters.Parameter( self.PARAM_STACK_ID, parameters.Schema(parameters.Schema.STRING, _('Stack ID'), default=str(stack_id))) if stack_name: yield parameters.Parameter( self.PARAM_STACK_NAME, parameters.Schema(parameters.Schema.STRING, _('Stack Name'), default=stack_name))
def test_merge_envs_with_zeros(self): env1 = {'parameter_defaults': {'value1': 1}} env2 = {'parameter_defaults': {'value1': 0}} files = {'env_1': json.dumps(env1), 'env_2': json.dumps(env2)} environment_files = ['env_1', 'env_2'] param_schemata = { 'value1': parameters.Schema(parameters.Schema.NUMBER) } env_util.merge_environments(environment_files, files, self.params, param_schemata) self.assertEqual({'value1': 0}, self.params['parameter_defaults'])
def test_merge_envs_with_zeros_in_maps(self): env1 = {'parameter_defaults': {'value1': {'foo': 1}}} env2 = { 'parameter_defaults': { 'value1': { 'foo': 0 } }, 'parameter_merge_strategies': { 'value1': 'deep_merge' } } files = {'env_1': json.dumps(env1), 'env_2': json.dumps(env2)} environment_files = ['env_1', 'env_2'] param_schemata = {'value1': parameters.Schema(parameters.Schema.MAP)} env_util.merge_environments(environment_files, files, self.params, param_schemata) self.assertEqual({'value1': { 'foo': 0 }}, self.params['parameter_defaults'])
def setUp(self): super(TestMergeEnvironments, self).setUp() self.ctx = utils.dummy_context(tenant_id='stack_service_test_tenant') # Setup self.params = { 'parameters': {}, 'resource_registry': {}, 'parameter_defaults': {} } self.env_1 = { 'parameters': { 'str_value1': "string1", 'str_value2': "string2", 'del_lst_value1': '1,2', 'del_lst_value2': '3,4', 'lst_value1': [1, 2], 'json_value1': { "1": ["str1", "str2"] }, 'json_value2': { "2": ["test1", "test2"] } }, 'resource_registry': { 'test::R1': "OS::Heat::RandomString", 'test::R2': "BROKEN" }, 'parameter_defaults': { 'lst_value2': [3, 4] } } self.env_2 = { 'parameters': { 'str_value1': "string3", 'str_value2': "string4", 'del_lst_value1': '5,6', 'del_lst_value2': '7,8', 'lst_value1': [5, 6], 'json_value1': { "3": ["str3", "str4"] }, 'json_value2': { "4": ["test3", "test4"] } }, 'resource_registry': { 'test::R2': "OS::Heat::None" }, 'parameter_defaults': { 'lst_value2': [7, 8] } } self.env_3 = { 'parameters': { 'lst_value1': [9, 10], 'json_value1': { "5": ["str5"] } } } self.env_4 = {'parameter_defaults': {'lst_value2': [9, 10]}} self.param_schemata = { 'str_value1': parameters.Schema(parameters.Schema.STRING), 'str_value2': parameters.Schema(parameters.Schema.STRING), 'del_lst_value1': parameters.Schema(parameters.Schema.LIST), 'del_lst_value2': parameters.Schema(parameters.Schema.LIST), 'lst_value1': parameters.Schema(parameters.Schema.LIST, default=[7]), 'lst_value2': parameters.Schema(parameters.Schema.LIST), 'json_value1': parameters.Schema(parameters.Schema.MAP), 'json_value2': parameters.Schema(parameters.Schema.MAP) }