Remove image parameter changing from merge

The merge tool originally was meant to merge somewhat different things,
and thus this was helpful in the early versions. However, at this point
we want parameters to be more stable and we don't generally merge things
that have their own image parameter.

Meanwhile this feature caused problems as we change resource names.

This is a backward incompatible change of default behavior, but the old
behavior can be had again by passing --change-image-params.

Change-Id: I78cf31f0443f3d9f274758f5471a5bca9155635d
This commit is contained in:
Clint Byrum 2014-01-31 11:05:09 -08:00
parent 6027346b9b
commit f9ef457987
5 changed files with 27 additions and 19 deletions

View File

@ -1,7 +1,7 @@
Description: examples/source2.yaml
HeatTemplateFormatVersion: '2012-12-12'
Parameters:
GenericBImage:
BImage:
Type: String
ImportantValue:
Default: a_default
@ -12,5 +12,5 @@ Resources:
my_meta: Foo
Properties:
image:
Ref: GenericBImage
Ref: BImage
Type: OS::Nova::Server

View File

@ -1,7 +1,7 @@
Description: examples/source_include_subkey.yaml
HeatTemplateFormatVersion: '2012-12-12'
Parameters:
GenericBImage:
Foo:
Type: String
Resources:
GenericB:
@ -10,5 +10,5 @@ Resources:
Ref: ImportantValue
Properties:
image:
Ref: GenericBImage
Ref: Foo
Type: OS::Nova::Server

View File

@ -1,14 +1,14 @@
Description: examples/source.yaml
HeatTemplateFormatVersion: '2012-12-12'
Parameters:
AImage: null
Default: my_image
SourceImage: null
Type: String
Resources:
A:
Properties:
image:
Ref: AImage
Ref: SourceImage
Type: OS::Nova::Server
B:
Metadata:

View File

@ -188,11 +188,17 @@ def main(argv=None):
"be copied to Prefix1Foo in the output, and value Prefix0Bar to be"
"renamed to Prefix1Bar inside that copy, or copied to Prefix1Bar "
"outside of any copy.")
parser.add_argument(
'--change-image-params', action='store_true', default=False,
help="Change parameters in templates to match resource names. This was "
" the default at one time but it causes issues when parameter "
" names need to remain stable.")
args = parser.parse_args(argv)
templates = args.templates
scaling = parse_scaling(args.scale)
merged_template = merge(templates, args.master_role, args.slave_roles,
args.included_template_dir, scaling=scaling)
args.included_template_dir, scaling=scaling,
change_image_params=args.change_image_params)
if args.output == '-':
out_file = sys.stdout
else:
@ -202,7 +208,7 @@ def main(argv=None):
def merge(templates, master_role=None, slave_roles=None,
included_template_dir=INCLUDED_TEMPLATE_DIR,
scaling=None):
scaling=None, change_image_params=None):
scaling = scaling or {}
errors = []
end_template={'HeatTemplateFormatVersion': '2012-12-12',
@ -239,11 +245,12 @@ def merge(templates, master_role=None, slave_roles=None,
new_resources = template.get('Resources', {})
for r, rbody in sorted(new_resources.items()):
if rbody['Type'] in MERGABLE_TYPES:
if 'image' in MERGABLE_TYPES[rbody['Type']]:
image_key = MERGABLE_TYPES[rbody['Type']]['image']
# XXX Assuming ImageId is always a Ref
ikey_val = end_template['Parameters'][rbody['Properties'][image_key]['Ref']]
del end_template['Parameters'][rbody['Properties'][image_key]['Ref']]
if change_image_params:
if 'image' in MERGABLE_TYPES[rbody['Type']]:
image_key = MERGABLE_TYPES[rbody['Type']]['image']
# XXX Assuming ImageId is always a Ref
ikey_val = end_template['Parameters'][rbody['Properties'][image_key]['Ref']]
del end_template['Parameters'][rbody['Properties'][image_key]['Ref']]
role = rbody.get('Metadata', {}).get('OpenStack::Role', r)
role = translate_role(role, master_role, slave_roles)
if role != r:
@ -264,10 +271,11 @@ def merge(templates, master_role=None, slave_roles=None,
if 'Resources' not in end_template:
end_template['Resources'] = {}
end_template['Resources'][role] = rbody
if 'image' in MERGABLE_TYPES[rbody['Type']]:
ikey = '%sImage' % (role)
end_template['Resources'][role]['Properties'][image_key] = {'Ref': ikey}
end_template['Parameters'][ikey] = ikey_val
if change_image_params:
if 'image' in MERGABLE_TYPES[rbody['Type']]:
ikey = '%sImage' % (role)
end_template['Resources'][role]['Properties'][image_key] = {'Ref': ikey}
end_template['Parameters'][ikey] = ikey_val
elif rbody['Type'] == 'FileInclude':
# we trust os.path.join to DTRT: if FileInclude path isn't
# absolute, join to included_template_dir (./)

View File

@ -33,7 +33,7 @@ Parameters:
Description: The password for the Heat service account, used by the Heat services.
Type: String
NoEcho: true
Image:
undercloudImage:
Default: undercloud
Type: String
NeutronPassword:
@ -165,7 +165,7 @@ Resources:
Type: OS::Nova::Server
Properties:
image:
Ref: Image
Ref: undercloudImage
flavor:
Ref: Flavor
key_name: