]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Fix retyping volume that has volume type None
authorgit-harry <git-harry@live.co.uk>
Thu, 8 May 2014 11:38:41 +0000 (12:38 +0100)
committergit-harry <git-harry@live.co.uk>
Thu, 8 May 2014 11:38:41 +0000 (12:38 +0100)
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

cinder/tests/test_volume_types.py
cinder/volume/volume_types.py

index 8b464cd1f28e2febe56aaafb48be62d0f34c7cc2..8dad322e02836d51041fc603fd0845fa34977862 100644 (file)
@@ -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')})
index 7486f5df02434685251c11c70a7f74b16da8fde2..2e69fcb6258275e172995a82e50dd6b31f2e0e45 100644 (file)
@@ -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