Rolling Upgrades: Fix VolumeAttachment

When we added `connection_info` to the VolumeAttachment on
Idbc1049e8adf1d5b955bda01d58bb6b89fc6c5c7 we didn't add backporting
code, so rolling upgrades will break if a VolumeAttachment OVO is passed
between Cinder Services with different versions during an upgrade.

TrivialFix

Change-Id: I07101a2adfcbc81687a62d1d19bb97971d12a42d
This commit is contained in:
Gorka Eguileor 2017-05-19 11:55:29 +02:00
parent 18e7a1882a
commit fa1758fb8c
2 changed files with 26 additions and 0 deletions

View File

@ -13,6 +13,7 @@
# under the License.
from oslo_serialization import jsonutils
from oslo_utils import versionutils
from oslo_versionedobjects import fields
from cinder import db
@ -64,6 +65,14 @@ class VolumeAttachment(base.CinderPersistentObject, base.CinderObject,
def _get_expected_attrs(cls, context, *args, **kwargs):
return ['volume']
def obj_make_compatible(self, primitive, target_version):
"""Make a object representation compatible with target version."""
super(VolumeAttachment, self).obj_make_compatible(primitive,
target_version)
target_version = versionutils.convert_version_to_tuple(target_version)
if target_version < (1, 2):
primitive.pop('connection_info', None)
@classmethod
def _from_db_object(cls, context, attachment, db_attachment,
expected_attrs=None):

View File

@ -12,6 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import ddt
import mock
import six
@ -22,6 +23,7 @@ from cinder.tests.unit import fake_volume
from cinder.tests.unit import objects as test_objects
@ddt.ddt
class TestVolumeAttachment(test_objects.BaseObjectsTestCase):
@mock.patch('cinder.db.sqlalchemy.api.volume_attachment_get')
@ -96,6 +98,21 @@ class TestVolumeAttachment(test_objects.BaseObjectsTestCase):
self.assertEqual(fields.VolumeAttachStatus.ATTACHED,
attachment.attach_status)
@ddt.data('1.0', '1.1', '1.2')
def test_obj_make_compatible(self, version):
connection_info = {'field': 'value'}
vol_attach = objects.VolumeAttachment(self.context,
connection_info=connection_info)
primitive = vol_attach.obj_to_primitive(version)
converted_vol_attach = objects.VolumeAttachment.obj_from_primitive(
primitive)
if version == '1.2':
self.assertEqual(connection_info,
converted_vol_attach.connection_info)
else:
self.assertFalse(converted_vol_attach.obj_attr_is_set(
'connection_info'))
class TestVolumeAttachmentList(test_objects.BaseObjectsTestCase):
@mock.patch('cinder.db.volume_attachment_get_all_by_volume_id')