From 7617a7d30a7b3eeaf8e688bc1072f0a55db5a91a Mon Sep 17 00:00:00 2001 From: Ramakrishnan G Date: Tue, 28 Oct 2014 04:34:42 +0000 Subject: [PATCH] HPSSA: Fixes for issue found during functional testing This commit fixes the issues found adding functional tests. This fixes the following: - hpssacli logicaldrive delete shouldn't be called when there are no RAID arrays (results in failure otherwise) - trim down the wwn returned to 8-byte hex so that it is same as the one returned by lsblk. Change-Id: Ic4e2983a34fa6b3fcf576f9dd46c9d5b66a47848 --- proliantutils/hpssa/manager.py | 5 ++++- proliantutils/hpssa/objects.py | 8 +++++++- proliantutils/tests/hpssa/test_manager.py | 15 ++++++++++++--- proliantutils/tests/hpssa/test_objects.py | 4 ++-- 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/proliantutils/hpssa/manager.py b/proliantutils/hpssa/manager.py index 611c7d7..660dc9d 100644 --- a/proliantutils/hpssa/manager.py +++ b/proliantutils/hpssa/manager.py @@ -156,7 +156,10 @@ def delete_configuration(): """Delete a RAID configuration on this server.""" server = objects.Server() for controller in server.controllers: - controller.delete_all_logical_drives() + # Trigger delete only if there is some RAID array, otherwise + # hpssacli will fail saying "no logical drives found." + if controller.raid_arrays: + controller.delete_all_logical_drives() def get_configuration(): diff --git a/proliantutils/hpssa/objects.py b/proliantutils/hpssa/objects.py index 34d23be..43ed775 100644 --- a/proliantutils/hpssa/objects.py +++ b/proliantutils/hpssa/objects.py @@ -383,9 +383,15 @@ class LogicalDrive(object): # TODO(rameshg87): Check if size is always reported in GB self.size_gb = int(float(self.properties['Size'].rstrip(' GB'))) self.raid_level = self.properties.get('Fault Tolerance') - self.wwn = self.properties.get('Unique Identifier') self.volume_name = self.properties.get('Logical Drive Label') + # Trim down the WWN to 16 digits (8 bytes) so that it matches + # lsblk output in Linux. + wwn = self.properties.get('Unique Identifier') + if wwn: + wwn = '0x' + wwn[:16].lower() + self.wwn = wwn + def get_property(self, prop): if not self.properties: return None diff --git a/proliantutils/tests/hpssa/test_manager.py b/proliantutils/tests/hpssa/test_manager.py index 9ce9e75..03aa331 100644 --- a/proliantutils/tests/hpssa/test_manager.py +++ b/proliantutils/tests/hpssa/test_manager.py @@ -129,9 +129,9 @@ class ManagerTestCases(testtools.TestCase): if x['raid_level'] == '1'][0] ld2_ret = [x for x in current_config['logical_disks'] if x['raid_level'] == '5'][0] - self.assertEqual('600508B1001CC42CDF101F06E5563967', + self.assertEqual('0x600508b1001cc42c', ld2_ret['root_device_hint']['wwn']) - self.assertEqual('600508B1001CE1E18302A8702C6AB008', + self.assertEqual('0x600508b1001ce1e1', ld1_ret['root_device_hint']['wwn']) @mock.patch.object(objects.Controller, 'execute_cmd') @@ -165,6 +165,15 @@ class ManagerTestCases(testtools.TestCase): "delete", "forced") + @mock.patch.object(objects.Controller, 'execute_cmd') + def test_delete_configuration_no_arrays( + self, controller_exec_cmd_mock, get_all_details_mock): + + get_all_details_mock.return_value = raid_constants.HPSSA_NO_DRIVES + + manager.delete_configuration() + self.assertFalse(controller_exec_cmd_mock.called) + def test_get_configuration(self, get_all_details_mock): get_all_details_mock.return_value = raid_constants.HPSSA_ONE_DRIVE @@ -178,7 +187,7 @@ class ManagerTestCases(testtools.TestCase): '5I:1:2'], 'volume_name': '01F42227PDVTF0BRH5T0MOAB64', 'root_device_hint': { - 'wwn': '600508B1001C321CCA06EB7CD847939D'}} + 'wwn': '0x600508b1001c321c'}} # NOTE(rameshg87: Cannot directly compare because # of 'physical_disks' key. diff --git a/proliantutils/tests/hpssa/test_objects.py b/proliantutils/tests/hpssa/test_objects.py index 422c358..86878c9 100644 --- a/proliantutils/tests/hpssa/test_objects.py +++ b/proliantutils/tests/hpssa/test_objects.py @@ -130,7 +130,7 @@ class ServerTest(testtools.TestCase): get_all_details_mock.return_value = two_drives server = objects.Server() - wwn = '600508B1001CC42CDF101F06E5563967' + wwn = '0x600508b1001cc42c' ld_ret = server.get_logical_drive_by_wwn(wwn) raid_arrays = server.controllers[0].raid_arrays ld_exp = [x.logical_drives[0] for x in raid_arrays @@ -257,7 +257,7 @@ class LogicalDriveTest(testtools.TestCase): ret = logical_drive.get_logical_drive_dict() self.assertEqual(558, ret['size_gb']) self.assertEqual('1', ret['raid_level']) - self.assertEqual('600508B1001C321CCA06EB7CD847939D', + self.assertEqual('0x600508b1001c321c', ret['root_device_hint']['wwn']) self.assertEqual('Smart Array P822 in Slot 2', ret['controller'])