Create instance_extra entry if it doesn't update
When updating an instance, if there is no instance_extra, for older
instances, we make sure we create one if there is not one already.
This keeps flavor data migrations (ie system_metadata ->
instance_extra) from failing when the system_metadata entries are soft
deleted but an instance_extra entry is not created because it was
"updated" assuming an instance_extra entry already existed, leaving
the instance with no flavor data.
Closes-Bug: #1459758
Change-Id: I715217d98729c6c5ac45d64d8bacaaca745ff3d7
(cherry picked from commit e776d6fddf
)
This commit is contained in:
parent
aaa8ce07fc
commit
a0f093a266
|
@ -2661,9 +2661,16 @@ def _instance_extra_create(context, values):
|
|||
|
||||
|
||||
def instance_extra_update_by_uuid(context, instance_uuid, values):
|
||||
return model_query(context, models.InstanceExtra).\
|
||||
rows_updated = model_query(context, models.InstanceExtra).\
|
||||
filter_by(instance_uuid=instance_uuid).\
|
||||
update(values)
|
||||
if not rows_updated:
|
||||
LOG.debug("Created instance_extra for %s" % instance_uuid)
|
||||
create_values = copy.copy(values)
|
||||
create_values["instance_uuid"] = instance_uuid
|
||||
_instance_extra_create(context, create_values)
|
||||
rows_updated = 1
|
||||
return rows_updated
|
||||
|
||||
|
||||
def instance_extra_get_by_instance_uuid(context, instance_uuid,
|
||||
|
|
|
@ -2748,6 +2748,21 @@ class InstanceExtraTestCase(test.TestCase):
|
|||
self.ctxt, self.instance['uuid'])
|
||||
self.assertEqual('changed', inst_extra.numa_topology)
|
||||
|
||||
def test_instance_extra_update_by_uuid_and_create(self):
|
||||
sqlalchemy_api.model_query(self.ctxt, models.InstanceExtra).\
|
||||
filter_by(instance_uuid=self.instance['uuid']).\
|
||||
delete()
|
||||
inst_extra = db.instance_extra_get_by_instance_uuid(
|
||||
self.ctxt, self.instance['uuid'])
|
||||
self.assertIsNone(inst_extra)
|
||||
|
||||
db.instance_extra_update_by_uuid(self.ctxt, self.instance['uuid'],
|
||||
{'numa_topology': 'changed'})
|
||||
|
||||
inst_extra = db.instance_extra_get_by_instance_uuid(
|
||||
self.ctxt, self.instance['uuid'])
|
||||
self.assertEqual('changed', inst_extra.numa_topology)
|
||||
|
||||
def test_instance_extra_get_with_columns(self):
|
||||
extra = db.instance_extra_get_by_instance_uuid(
|
||||
self.ctxt, self.instance['uuid'],
|
||||
|
|
Loading…
Reference in New Issue