Rolling Upgrades: Fix Group OVO
On commit 325f99a64a
we bumped group
version to 1.1 when we added 3 new fields but we didn't add backward
compatibility code to version 1.0, which means that we'll break rolling
upgrades if this information is passed between services.
TrivialFix
Change-Id: I855f63073950bd9a6f1e847666cae1d444ee0067
This commit is contained in:
parent
63433278a4
commit
db4855a564
|
@ -12,13 +12,15 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from oslo_utils import versionutils
|
||||
from oslo_versionedobjects import fields
|
||||
|
||||
from cinder import db
|
||||
from cinder import exception
|
||||
from cinder.i18n import _
|
||||
from cinder import objects
|
||||
from cinder.objects import base
|
||||
from cinder.objects import fields as c_fields
|
||||
from oslo_versionedobjects import fields
|
||||
|
||||
|
||||
@base.CinderObjectRegistry.register
|
||||
|
@ -52,6 +54,15 @@ class Group(base.CinderPersistentObject, base.CinderObject,
|
|||
nullable=True),
|
||||
}
|
||||
|
||||
def obj_make_compatible(self, primitive, target_version):
|
||||
"""Make an object representation compatible with target version."""
|
||||
super(Group, self).obj_make_compatible(primitive, target_version)
|
||||
target_version = versionutils.convert_version_to_tuple(target_version)
|
||||
if target_version < (1, 1):
|
||||
for key in ('group_snapshot_id', 'source_group_id',
|
||||
'group_snapshots'):
|
||||
primitive.pop(key, None)
|
||||
|
||||
@staticmethod
|
||||
def _from_db_object(context, group, db_group,
|
||||
expected_attrs=None):
|
||||
|
|
|
@ -12,11 +12,13 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import ddt
|
||||
import mock
|
||||
import six
|
||||
|
||||
from cinder import exception
|
||||
from cinder import objects
|
||||
from cinder.objects import base as ovo_base
|
||||
from cinder.objects import fields
|
||||
from cinder.tests.unit import fake_constants as fake
|
||||
from cinder.tests.unit import fake_volume
|
||||
|
@ -35,6 +37,7 @@ fake_group = {
|
|||
}
|
||||
|
||||
|
||||
@ddt.ddt
|
||||
class TestGroup(test_objects.BaseObjectsTestCase):
|
||||
|
||||
@mock.patch('cinder.db.sqlalchemy.api.group_get',
|
||||
|
@ -160,6 +163,22 @@ class TestGroup(test_objects.BaseObjectsTestCase):
|
|||
self.assertEqual(len(db_volumes), len(group.volumes))
|
||||
self._compare(self, db_volumes[0], group.volumes[0])
|
||||
|
||||
@ddt.data('1.10', '1.11')
|
||||
def test_obj_make_compatible(self, version):
|
||||
extra_data = {'group_snapshot_id': fake.GROUP_SNAPSHOT_ID,
|
||||
'source_group_id': fake.GROUP_ID,
|
||||
'group_snapshots': objects.GroupSnapshotList()}
|
||||
group = objects.Group(self.context, name='name', **extra_data)
|
||||
|
||||
serializer = ovo_base.CinderObjectSerializer(version)
|
||||
primitive = serializer.serialize_entity(self.context, group)
|
||||
|
||||
converted_group = objects.Group.obj_from_primitive(primitive)
|
||||
is_set = version == '1.11'
|
||||
for key in extra_data:
|
||||
self.assertEqual(is_set, converted_group.obj_attr_is_set(key))
|
||||
self.assertEqual('name', converted_group.name)
|
||||
|
||||
|
||||
class TestGroupList(test_objects.BaseObjectsTestCase):
|
||||
@mock.patch('cinder.db.group_get_all',
|
||||
|
|
Loading…
Reference in New Issue