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:
parent
18e7a1882a
commit
fa1758fb8c
|
@ -13,6 +13,7 @@
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
from oslo_serialization import jsonutils
|
from oslo_serialization import jsonutils
|
||||||
|
from oslo_utils import versionutils
|
||||||
from oslo_versionedobjects import fields
|
from oslo_versionedobjects import fields
|
||||||
|
|
||||||
from cinder import db
|
from cinder import db
|
||||||
|
@ -64,6 +65,14 @@ class VolumeAttachment(base.CinderPersistentObject, base.CinderObject,
|
||||||
def _get_expected_attrs(cls, context, *args, **kwargs):
|
def _get_expected_attrs(cls, context, *args, **kwargs):
|
||||||
return ['volume']
|
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
|
@classmethod
|
||||||
def _from_db_object(cls, context, attachment, db_attachment,
|
def _from_db_object(cls, context, attachment, db_attachment,
|
||||||
expected_attrs=None):
|
expected_attrs=None):
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
import ddt
|
||||||
import mock
|
import mock
|
||||||
import six
|
import six
|
||||||
|
|
||||||
|
@ -22,6 +23,7 @@ from cinder.tests.unit import fake_volume
|
||||||
from cinder.tests.unit import objects as test_objects
|
from cinder.tests.unit import objects as test_objects
|
||||||
|
|
||||||
|
|
||||||
|
@ddt.ddt
|
||||||
class TestVolumeAttachment(test_objects.BaseObjectsTestCase):
|
class TestVolumeAttachment(test_objects.BaseObjectsTestCase):
|
||||||
|
|
||||||
@mock.patch('cinder.db.sqlalchemy.api.volume_attachment_get')
|
@mock.patch('cinder.db.sqlalchemy.api.volume_attachment_get')
|
||||||
|
@ -96,6 +98,21 @@ class TestVolumeAttachment(test_objects.BaseObjectsTestCase):
|
||||||
self.assertEqual(fields.VolumeAttachStatus.ATTACHED,
|
self.assertEqual(fields.VolumeAttachStatus.ATTACHED,
|
||||||
attachment.attach_status)
|
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):
|
class TestVolumeAttachmentList(test_objects.BaseObjectsTestCase):
|
||||||
@mock.patch('cinder.db.volume_attachment_get_all_by_volume_id')
|
@mock.patch('cinder.db.volume_attachment_get_all_by_volume_id')
|
||||||
|
|
Loading…
Reference in New Issue