summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2017-06-15 14:04:26 +0000
committerGerrit Code Review <review@openstack.org>2017-06-15 14:04:26 +0000
commitd217fb1be49db9209c7e7421a0c4b72c4292ef22 (patch)
treef006005b0e6cb392e167a53fe15961fe5d73250e
parent6084277a51d4587dc961ae24500c42f4abb83588 (diff)
parent6061585fc1e095c233a62d46f1e877496e7cebc8 (diff)
Merge "Minor changes to object version-related code"
-rw-r--r--ironic/objects/base.py67
1 files changed, 38 insertions, 29 deletions
diff --git a/ironic/objects/base.py b/ironic/objects/base.py
index 0103197..55f90a7 100644
--- a/ironic/objects/base.py
+++ b/ironic/objects/base.py
@@ -120,24 +120,26 @@ class IronicObject(object_base.VersionedObject):
120 :raises: ovo_exception.IncompatibleObjectVersion 120 :raises: ovo_exception.IncompatibleObjectVersion
121 """ 121 """
122 pin = CONF.pin_release_version 122 pin = CONF.pin_release_version
123 if pin: 123 if not pin:
124 version_manifest = versions.RELEASE_MAPPING[pin]['objects'] 124 return self.__class__.VERSION
125 pinned_version = version_manifest.get(self.obj_name()) 125
126 if pinned_version: 126 version_manifest = versions.RELEASE_MAPPING[pin]['objects']
127 if not versionutils.is_compatible(pinned_version, 127 pinned_version = version_manifest.get(self.obj_name())
128 self.__class__.VERSION): 128 if pinned_version:
129 LOG.error( 129 if not versionutils.is_compatible(pinned_version,
130 'For object "%(objname)s", the target version ' 130 self.__class__.VERSION):
131 '"%(target)s" is not compatible with its supported ' 131 LOG.error(
132 'version "%(support)s". The value ("%(pin)s") of the ' 132 'For object "%(objname)s", the target version '
133 '"pin_release_version" configuration option may be ' 133 '"%(target)s" is not compatible with its supported '
134 'incorrect.', 134 'version "%(support)s". The value ("%(pin)s") of the '
135 {'objname': self.obj_name(), 'target': pinned_version, 135 '"pin_release_version" configuration option may be '
136 'support': self.__class__.VERSION, 'pin': pin}) 136 'incorrect.',
137 raise ovo_exception.IncompatibleObjectVersion( 137 {'objname': self.obj_name(), 'target': pinned_version,
138 objname=self.obj_name(), objver=pinned_version, 138 'support': self.__class__.VERSION, 'pin': pin})
139 supported=self.__class__.VERSION) 139 raise ovo_exception.IncompatibleObjectVersion(
140 return pinned_version 140 objname=self.obj_name(), objver=pinned_version,
141 supported=self.__class__.VERSION)
142 return pinned_version
141 143
142 return self.__class__.VERSION 144 return self.__class__.VERSION
143 145
@@ -185,6 +187,14 @@ class IronicObject(object_base.VersionedObject):
185 obj[field] = db_object[field] 187 obj[field] = db_object[field]
186 188
187 obj._context = context 189 obj._context = context
190
191 # NOTE(rloo). We now have obj, a versioned object that corresponds to
192 # its DB representation. A versioned object has an internal attribute
193 # ._changed_fields; this is a list of changed fields -- used, e.g.,
194 # when saving the object to the DB (only those changed fields are
195 # saved to the DB). The obj.obj_reset_changes() clears this list
196 # since we didn't actually make any modifications to the object that
197 # we want saved later.
188 obj.obj_reset_changes() 198 obj.obj_reset_changes()
189 199
190 if db_version != obj.__class__.VERSION: 200 if db_version != obj.__class__.VERSION:
@@ -217,30 +227,29 @@ class IronicObject(object_base.VersionedObject):
217 for db_obj in db_objects] 227 for db_obj in db_objects]
218 228
219 def do_version_changes_for_db(self): 229 def do_version_changes_for_db(self):
220 """Do any changes to the object before saving it in the DB. 230 """Change the object to the version needed for the database.
221 231
222 This determines which version of the object should be saved to the 232 If needed, this changes the object (modifies object fields) to be in
223 database, and if needed, updates the object (fields) to correspond to 233 the correct version for saving to the database.
224 the desired version.
225 234
226 The version used to save the object is determined as follows: 235 The version used to save the object in the DB is determined as follows:
227 236
228 * If the object is pinned, we save the object in the pinned version. 237 * If the object is pinned, we save the object in the pinned version.
229 Since it is pinned, we don't want to save in a newer version, in case 238 Since it is pinned, we must not save in a newer version, in case
230 a rolling upgrade is happening and some services are still using the 239 a rolling upgrade is happening and some services are still using the
231 older version of ironic, with no knowledge of this newer version. 240 older version of ironic, with no knowledge of this newer version.
232 * If the object isn't pinned, we save the object in the latest version. 241 * If the object isn't pinned, we save the object in the latest version.
233 242
234 Because the object may be converted to a different object version, 243 Because the object may be converted to a different object version, this
235 this method should only be called just before saving the object to 244 method must only be called just before saving the object to the DB.
236 the DB.
237 245
238 :returns: a dictionary of changed fields and their new values 246 :returns: a dictionary of changed fields and their new values
239 (could be an empty dictionary). 247 (could be an empty dictionary). These are the fields/values
248 of the object that would be saved to the DB.
240 """ 249 """
241 target_version = self.get_target_version() 250 target_version = self.get_target_version()
242 251
243 if (target_version != self.VERSION): 252 if target_version != self.VERSION:
244 # Convert the object so we can save it in the target version. 253 # Convert the object so we can save it in the target version.
245 self.convert_to_version(target_version) 254 self.convert_to_version(target_version)
246 db_version = target_version 255 db_version = target_version