Fix cluster templates update
This change fixes the following issues:
* Remove _appy_defaults for cluster template fields on update
Fields that are not specified should not be given default values
on update like they are on creation. If a field is not specified,
it should be left alone
* Do not delete node groups if the cluster template update does
specify a node_group field
Closes-Bug: #1438077
Change-Id: I65dd15e02871f9c7227d2b51acedd6e06cb04950
(cherry picked from commit 196f72f18e
)
This commit is contained in:
parent
ebdc87cfa6
commit
2495f1af85
|
@ -258,7 +258,6 @@ class ConductorManager(db_base.Base):
|
|||
ignore_default=False):
|
||||
"""Update a cluster_template from the values dictionary."""
|
||||
values = copy.deepcopy(values)
|
||||
values = _apply_defaults(values, CLUSTER_DEFAULTS)
|
||||
values['tenant_id'] = context.tenant_id
|
||||
values['id'] = id
|
||||
|
||||
|
|
|
@ -542,13 +542,19 @@ def cluster_template_update(context, values, ignore_default=False):
|
|||
)
|
||||
cluster_template.update(values)
|
||||
|
||||
model_query(m.TemplatesRelation, context).filter_by(
|
||||
cluster_template_id=cluster_template_id).delete()
|
||||
for ng in node_groups:
|
||||
node_group = m.TemplatesRelation()
|
||||
node_group.update(ng)
|
||||
node_group.update({"cluster_template_id": cluster_template_id})
|
||||
node_group.save(session=session)
|
||||
# If node_groups has not been specified, then we are
|
||||
# keeping the old ones so don't delete!
|
||||
if node_groups:
|
||||
model_query(m.TemplatesRelation,
|
||||
context, session=session).filter_by(
|
||||
cluster_template_id=cluster_template_id).delete()
|
||||
|
||||
for ng in node_groups:
|
||||
node_group = m.TemplatesRelation()
|
||||
node_group.update(ng)
|
||||
node_group.update({"cluster_template_id":
|
||||
cluster_template_id})
|
||||
session.add(node_group)
|
||||
|
||||
return cluster_template
|
||||
|
||||
|
|
|
@ -340,6 +340,7 @@ class ClusterTemplates(test_base.ConductorManagerTestCase):
|
|||
|
||||
updated_clt = self.api.cluster_template_get(ctx, clt_id)
|
||||
self.assertEqual(UPDATE_NAME, updated_clt["name"])
|
||||
self.assertEqual(clt["node_groups"], updated_clt["node_groups"])
|
||||
|
||||
# check duplicate name handling
|
||||
clt = self.api.cluster_template_create(ctx, SAMPLE_CLT)
|
||||
|
|
Loading…
Reference in New Issue