From: git-harry Date: Thu, 8 May 2014 11:38:41 +0000 (+0100) Subject: Fix retyping volume that has volume type None X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=8ce85e4fd40e9def337daadfdc92aca7b064efff;p=openstack-build%2Fcinder-build.git Fix retyping volume that has volume type None Modified volume_types_diff to work when one volume type is None. Fixed _fix_encryption_specs so that the new dictionary is returned. Change-Id: Iaba3032317f4d0649c917fb92403c4e9146fe3e9 Closes-Bug: #1311058 --- diff --git a/cinder/tests/test_volume_types.py b/cinder/tests/test_volume_types.py index 8b464cd1f..8dad322e0 100644 --- a/cinder/tests/test_volume_types.py +++ b/cinder/tests/test_volume_types.py @@ -298,3 +298,21 @@ class VolumeTypeTestCase(test.TestCase): self.assertEqual(diff['extra_specs']['key1'], ('val1', 'val1')) self.assertEqual(diff['qos_specs']['k1'], ('v1', 'v1')) self.assertEqual(diff['encryption']['key_size'], (256, 128)) + + # Check diff equals type specs when one type is None + diff, same = volume_types.volume_types_diff(self.ctxt, None, + type_ref1['id']) + self.assertEqual(same, False) + self.assertEqual(diff['extra_specs'], + {'key1': (None, 'val1'), 'key2': (None, 'val2')}) + self.assertEqual(diff['qos_specs'], + {'consumer': (None, 'back-end'), + 'k1': (None, 'v1'), + 'k2': (None, 'v2'), + 'k3': (None, 'v3')}) + self.assertEqual(diff['encryption'], + {'cipher': (None, 'c1'), + 'control_location': (None, 'front-end'), + 'deleted': (None, False), + 'key_size': (None, 256), + 'provider': (None, 'p1')}) diff --git a/cinder/volume/volume_types.py b/cinder/volume/volume_types.py index 7486f5df0..2e69fcb62 100644 --- a/cinder/volume/volume_types.py +++ b/cinder/volume/volume_types.py @@ -192,11 +192,12 @@ def volume_types_diff(context, vol_type_id1, vol_type_id2): qos_specs.update(qos_specs.pop('specs', {})) def _fix_encryption_specs(encryption): - if encryption1: + if encryption: encryption = dict(encryption) for param in ['volume_type_id', 'created_at', 'updated_at', 'deleted_at']: encryption.pop(param, None) + return encryption def _dict_diff(dict1, dict2): res = {} @@ -217,28 +218,34 @@ def volume_types_diff(context, vol_type_id1, vol_type_id2): all_equal = True diff = {} - vol_type1 = get_volume_type(context, vol_type_id1) - vol_type2 = get_volume_type(context, vol_type_id2) - - extra_specs1 = vol_type1.get('extra_specs') - extra_specs2 = vol_type2.get('extra_specs') - diff['extra_specs'], equal = _dict_diff(extra_specs1, extra_specs2) + vol_type_data = [] + for vol_type_id in (vol_type_id1, vol_type_id2): + if vol_type_id is None: + specs = {'extra_specs': None, + 'qos_specs': None, + 'encryption': None} + else: + specs = {} + vol_type = get_volume_type(context, vol_type_id) + specs['extra_specs'] = vol_type.get('extra_specs') + qos_specs = get_volume_type_qos_specs(vol_type_id) + specs['qos_specs'] = qos_specs.get('qos_specs') + _fix_qos_specs(specs['qos_specs']) + specs['encryption'] = get_volume_type_encryption(context, + vol_type_id) + specs['encryption'] = _fix_encryption_specs(specs['encryption']) + vol_type_data.append(specs) + + diff['extra_specs'], equal = _dict_diff(vol_type_data[0]['extra_specs'], + vol_type_data[1]['extra_specs']) if not equal: all_equal = False - - qos_specs1 = get_volume_type_qos_specs(vol_type_id1).get('qos_specs') - _fix_qos_specs(qos_specs1) - qos_specs2 = get_volume_type_qos_specs(vol_type_id2).get('qos_specs') - _fix_qos_specs(qos_specs2) - diff['qos_specs'], equal = _dict_diff(qos_specs1, qos_specs2) + diff['qos_specs'], equal = _dict_diff(vol_type_data[0]['qos_specs'], + vol_type_data[1]['qos_specs']) if not equal: all_equal = False - - encryption1 = get_volume_type_encryption(context, vol_type_id1) - _fix_encryption_specs(encryption1) - encryption2 = get_volume_type_encryption(context, vol_type_id2) - _fix_encryption_specs(encryption2) - diff['encryption'], equal = _dict_diff(encryption1, encryption2) + diff['encryption'], equal = _dict_diff(vol_type_data[0]['encryption'], + vol_type_data[1]['encryption']) if not equal: all_equal = False