When performing an obj_clone on an Instance object, it relies on the
base obj_clone's deep copy method which just goes through all of the
fields and duplicates them on the clone. However, the Instance object
has internal tracking attributes for metadata and system_metadata that
keep track of which keys have changed. Since these don't get copied
over on the deep copy, these will show up as having changed on the
cloned Instance (if they had metadata set originally) and on a save
on this cloned object will end up updating the metadata in the db
which if these have stale information will wipe out other changes.
Such a scenario to this is occurring during build_instance where the
Claim constructor is saving off a clone of the Instance object
so that it will have the current copy. In the case of a failure
during the build_instance, the claim will use this current copy
to then set the value of the host on the instance to None. Since
the clone reflects that the system_metadata has changed, it will
as part of the save try to update the system_metadata in the db,
which since it is stale will wipe out changes made.
In the case of the issue being fixed here, the value in the
system_metdata being wiped out is the network_allocated=True
attribute. By this being wiped out then reschedules of that
build_instance fail in cases where the IP address has been
assigned to the instance.
Change-Id: Ie49a90993fb9643c04d75402dbaaa933c6b5222e
Closes-Bug: #1639230
(cherry picked from commit 9345ed40e85e291d2f9e9aac24d468f40140ae0e)
Reviewed: https:/ /review. openstack. org/396782 /git.openstack. org/cgit/ openstack/ nova/commit/ ?id=bc620681ff2 d7aa6c40c961da7 6d598c9f23281d
Committed: https:/
Submitter: Jenkins
Branch: stable/newton
commit bc620681ff2d7aa 6c40c961da76d59 8c9f23281d
Author: Brent Tang <email address hidden>
Date: Fri Nov 4 07:35:25 2016 -0700
Instance obj_clone leaves metadata as changed
When performing an obj_clone on an Instance object, it relies on the
base obj_clone's deep copy method which just goes through all of the
fields and duplicates them on the clone. However, the Instance object
has internal tracking attributes for metadata and system_metadata that
keep track of which keys have changed. Since these don't get copied
over on the deep copy, these will show up as having changed on the
cloned Instance (if they had metadata set originally) and on a save
on this cloned object will end up updating the metadata in the db
which if these have stale information will wipe out other changes.
Such a scenario to this is occurring during build_instance where the
Claim constructor is saving off a clone of the Instance object
so that it will have the current copy. In the case of a failure
during the build_instance, the claim will use this current copy
to then set the value of the host on the instance to None. Since
the clone reflects that the system_metadata has changed, it will
as part of the save try to update the system_metadata in the db,
which since it is stale will wipe out changes made.
In the case of the issue being fixed here, the value in the allocated= True
system_metdata being wiped out is the network_
attribute. By this being wiped out then reschedules of that
build_instance fail in cases where the IP address has been
assigned to the instance.
Change-Id: Ie49a90993fb964 3c04d75402dbaaa 933c6b5222e d2f9e9aac24d468 f40140ae0e)
Closes-Bug: #1639230
(cherry picked from commit 9345ed40e85e291