]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Check for empty attributes on SF volume
authorJohn Griffith <john.griffith8@gmail.com>
Sun, 13 Sep 2015 14:52:53 +0000 (08:52 -0600)
committerJohn Griffith <john.griffith8@gmail.com>
Mon, 14 Sep 2015 13:51:07 +0000 (07:51 -0600)
This should not happen, but; we should be more strict
about our dict reading/checking and always make sure
the key item actually comes back and exists.

In the case of volume['attributes'] we were always
assuming this to be present which should be "ok", but
it's better to verify if rather than assuming, so this
patch adds a simple verification step before trying to
fetch on volume['attributes'].

Change-Id: I37a134a735aaf043aed1230d57fe458bb3a60240
Closes-Bug: #1495247

cinder/tests/unit/test_solidfire.py
cinder/volume/drivers/solidfire.py

index c3cda4d28a4a2a423f22d9aa379feec555e6ce23..f505eadd240aa69f46100b51ee692ac4060fedce 100644 (file)
@@ -1099,3 +1099,25 @@ class SolidFireVolumeTestCase(test.TestCase):
 
             self.assertEqual('1 99 None', snapshot_updates[0]['provider_id'])
             self.assertEqual(1, len(snapshot_updates))
+
+    def test_get_sf_volume_missing_attributes(self):
+        sfv = solidfire.SolidFireDriver(configuration=self.configuration)
+        test_name = "existing_volume"
+        fake_response = {'result': {
+            'volumes': [{'volumeID': 5,
+                         'name': test_name,
+                         'accountID': 8,
+                         'sliceCount': 1,
+                         'totalSize': 1 * units.Gi,
+                         'enable512e': True,
+                         'access': "readWrite",
+                         'status': "active",
+                         'qos': None,
+                         'iqn': test_name}]}}
+
+        def _fake_issue_api_req(method, params, version=0):
+            return fake_response
+
+        with mock.patch.object(
+                sfv, '_issue_api_request', side_effect=_fake_issue_api_req):
+            self.assertEqual(5, sfv._get_sf_volume(test_name, 8)['volumeID'])
index 97b8dd56b594d2c24cea29ab44145a33426f797d..a43afba1fd60e4f4d4858f938e0a2b8bdb9bebdc 100644 (file)
@@ -602,7 +602,9 @@ class SolidFireDriver(san.SanISCSIDriver):
             # update that on manage/import, so we use
             # the uuid attribute
             meta = v.get('attributes')
-            alt_id = meta.get('uuid', 'empty')
+            alt_id = ''
+            if meta:
+                alt_id = meta.get('uuid', '')
 
             if uuid in v['name'] or uuid in alt_id:
                 found_count += 1