Merge "Rolling Upgrades: Fix VolumeAttachment"
This commit is contained in:
commit
356f4a50ee
@ -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):
|
||||
|
@ -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')
|
||||
|
Loading…
x
Reference in New Issue
Block a user