From df03a9b9b7025a0e13d9387a74c304875dec0918 Mon Sep 17 00:00:00 2001 From: Xiao Chen Date: Thu, 6 Mar 2014 18:13:46 +0800 Subject: [PATCH] resolve KeyError for IBM Storwize/SVC driver 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 | 24 +++++++++++++++++++ .../drivers/ibm/storwize_svc/helpers.py | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/cinder/tests/test_storwize_svc.py b/cinder/tests/test_storwize_svc.py index 35a3f8f76..79f9b9423 100644 --- a/cinder/tests/test_storwize_svc.py +++ b/cinder/tests/test_storwize_svc.py @@ -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()) diff --git a/cinder/volume/drivers/ibm/storwize_svc/helpers.py b/cinder/volume/drivers/ibm/storwize_svc/helpers.py index 8b65154cb..860382991 100644 --- a/cinder/volume/drivers/ibm/storwize_svc/helpers.py +++ b/cinder/volume/drivers/ibm/storwize_svc/helpers.py @@ -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 -- 2.45.2