From 1c0e67996375e91878bf433877aab80d7227bf28 Mon Sep 17 00:00:00 2001 From: John Griffith Date: Sun, 13 Sep 2015 08:52:53 -0600 Subject: [PATCH] Check for empty attributes on SF volume 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 | 22 ++++++++++++++++++++++ cinder/volume/drivers/solidfire.py | 4 +++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/cinder/tests/unit/test_solidfire.py b/cinder/tests/unit/test_solidfire.py index c3cda4d28..f505eadd2 100644 --- a/cinder/tests/unit/test_solidfire.py +++ b/cinder/tests/unit/test_solidfire.py @@ -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']) diff --git a/cinder/volume/drivers/solidfire.py b/cinder/volume/drivers/solidfire.py index 97b8dd56b..a43afba1f 100644 --- a/cinder/volume/drivers/solidfire.py +++ b/cinder/volume/drivers/solidfire.py @@ -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 -- 2.45.2