]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
resolve KeyError for IBM Storwize/SVC driver
authorXiao Chen <chenxiao@cn.ibm.com>
Thu, 6 Mar 2014 10:13:46 +0000 (18:13 +0800)
committerXiao Chen <chenxiao@cn.ibm.com>
Tue, 18 Mar 2014 01:26:34 +0000 (09:26 +0800)
When using iSCSI protocol to conenct IBM v7000, and compression
is not enabled for the system, KeyError may occur because of the response
item's lack of 'license_compression_enclosures'. So add a check to
resolve it.

Change-Id: Ie53631ea5b047650897313ad5614f6e1df5377f2
Closes-Bug: #1288645

cinder/tests/test_storwize_svc.py
cinder/volume/drivers/ibm/storwize_svc/helpers.py

index 35a3f8f76407a5e1889a5d773d66e6a3a2a3841f..79f9b94236604fc056c549a84cd01332a04f6de7 100644 (file)
@@ -34,6 +34,7 @@ from cinder import units
 from cinder import utils
 from cinder.volume import configuration as conf
 from cinder.volume.drivers.ibm import storwize_svc
+from cinder.volume.drivers.ibm.storwize_svc import helpers
 from cinder.volume.drivers.ibm.storwize_svc import ssh
 from cinder.volume import volume_types
 
@@ -2700,3 +2701,26 @@ port_speed!8Gb
         self.assertEqual(list(resp.select('port_id', 'port_status')),
                          [('500507680210C744', 'active'),
                           ('500507680240C744', 'inactive')])
+
+
+class StorwizeHelpersTestCase(test.TestCase):
+    def setUp(self):
+        super(StorwizeHelpersTestCase, self).setUp()
+        self.helpers = helpers.StorwizeHelpers(None)
+
+    def test_compression_enabled(self):
+        fake_license_without_keys = {}
+        fake_license = {
+            'license_compression_enclosures': '1',
+            'license_compression_capacity': '1'
+        }
+
+        # Check when keys of return licenses do not contain
+        # 'license_compression_enclosures' and 'license_compression_capacity'
+        with mock.patch.object(ssh.StorwizeSSH, 'lslicense') as lslicense:
+            lslicense.return_value = fake_license_without_keys
+            self.assertFalse(self.helpers.compression_enabled())
+
+        with mock.patch.object(ssh.StorwizeSSH, 'lslicense') as lslicense:
+            lslicense.return_value = fake_license
+            self.assertTrue(self.helpers.compression_enabled())
index 8b65154cb3c86ade815cef796c890f9138bae454..86038299106d58b8fbd5ae67eb4ba9ed425486b3 100644 (file)
@@ -51,7 +51,7 @@ class StorwizeHelpers(object):
         keys = ['license_compression_enclosures',
                 'license_compression_capacity']
         for key in keys:
-            if resp[key] != '0':
+            if resp.get(key, '0') != '0':
                 return True
         return False