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
This commit is contained in:
Xiao Chen 2014-03-06 18:13:46 +08:00
parent 834f776973
commit df03a9b9b7
2 changed files with 25 additions and 1 deletions

View 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())

View 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