def check_hpssacli(): """GET local smart array status Wrap swiftlm hpssacli diag to get results """ # Needs root privileges to run results, slots = hpssacli.get_smart_array_info() if type(results) != list: # A single metric can be emitted in some cases: # <class 'swiftlm.utils.metricdata.MetricData'> # swiftlm.hp_hardware.hpssacli.smart_array failed with: \ # flock: failed to execute hpssacli: Permission denied results = [results] for slot in slots: results.extend(hpssacli.get_physical_drive_info(slot)) results.extend(hpssacli.get_logical_drive_info(slot, cache_check=True)) for result in results: # where possible change the service strings result.name = result.name.replace('swift', 'cinder') for key in result.dimensions.keys(): if key == 'service': result.dimensions[key] = 'block-storage' result.dimensions[key] = result.dimensions[key].replace( 'swift', 'cinder') # To print individual results do this... # for result in results: # print(repr(result)) return [result.metric() for result in results]
def test_get_controller_info(self): expected_base = MetricData( name=hpssacli.__name__ + ".smart_array", messages=hpssacli.BASE_RESULT.messages, dimensions={ "serial": "PACCR0M9VZ41S4Q", "model": "Smart Array P410", "slot": "1", "component": "controller", }, ) # List of tuples. # t[0] = Data set that hpssacli should return # t[1] = The failed component in the test data tests = [ (SMART_ARRAY_DATA, []), (SMART_ARRAY_CACHE_FAIL, ["cache"]), (SMART_ARRAY_BATTERY_FAIL, ["battery/capacitor"]), (SMART_ARRAY_CONTROLLER_FAIL, ["controller"]), (SMART_ARRAY_BATTERY_COUNT_FAIL, ["battery/capacitor count"]), ] for test_data, failures in tests: mock_command = mock.Mock() mock_command.return_value = CommandResult(0, test_data) with mock.patch("swiftlm.hp_hardware.hpssacli.run_cmd", mock_command): actual, actual_slots = hpssacli.get_smart_array_info() self.assertIsInstance(actual, list) self.assertEqual(len(actual), 5) expected_firmware = expected_base.child("firmware") expected_firmware.value = 6.60 actual = self.check_metrics(expected_firmware, actual) bcc = "battery/capacitor count" if bcc in failures: expected_battery_count = expected_base.child(dimensions={"sub_component": bcc, "count": "0"}) expected_battery_count.value = Severity.fail expected_battery_count.message = "no_battery" else: expected_battery_count = expected_base.child(dimensions={"sub_component": bcc, "count": "1"}) expected_battery_count.value = Severity.ok actual = self.check_metrics(expected_battery_count, actual) for submetric in ("battery/capacitor", "controller", "cache"): if submetric in failures: expected_status = expected_base.child(dimensions={"sub_component": submetric, "status": "FAIL"}) expected_status.value = Severity.fail expected_status.message = "controller_status" else: expected_status = expected_base.child(dimensions={"sub_component": submetric, "status": "OK"}) expected_status.value = Severity.ok actual = self.check_metrics(expected_status, actual) self.assertFalse(actual, "Got more metrics than expected")
def test_get_controller_slot_count(self): # Expect to get 2 slots returned, slot 1 & 3 expected_slots = ["1", "3"] test_data = SMART_ARRAY_DATA_2_CONT mock_command = mock.Mock() mock_command.return_value = CommandResult(0, test_data) with mock.patch("swiftlm.hp_hardware.hpssacli.run_cmd", mock_command): actual, actual_slots = hpssacli.get_smart_array_info() self.assertEqual(len(actual_slots), 2) self.assertEqual(expected_slots, actual_slots)
def test_get_controller_slot_count(self): # Expect to get 2 slots returned, slot 1 & 3 expected_slots = ["1", "3"] test_data = SMART_ARRAY_DATA_2_CONT mock_command = mock.Mock() mock_command.return_value = CommandResult(0, test_data) with mock.patch('swiftlm.hp_hardware.hpssacli.run_cmd', mock_command): actual, actual_slots = hpssacli.get_smart_array_info() self.assertEqual(len(actual_slots), 2) self.assertEqual(expected_slots, actual_slots)
def test_get_controller_info(self): expected_base = MetricData( name=hpssacli.__name__ + '.smart_array', messages=hpssacli.BASE_RESULT.messages, dimensions={ 'serial': 'PACCR0M9VZ41S4Q', 'model': 'Smart Array P410', 'slot': '1', 'component': 'controller', }) # List of tuples. # t[0] = Data set that hpssacli should return # t[1] = The failed component in the test data tests = [ (SMART_ARRAY_DATA, []), (SMART_ARRAY_CACHE_FAIL, ['cache']), (SMART_ARRAY_BATTERY_FAIL, ['battery/capacitor']), (SMART_ARRAY_CONTROLLER_FAIL, ['controller']), (SMART_ARRAY_BATTERY_COUNT_FAIL, ['battery/capacitor count']), ] for test_data, failures in tests: mock_command = mock.Mock() mock_command.return_value = CommandResult(0, test_data) with mock.patch('swiftlm.hp_hardware.hpssacli.run_cmd', mock_command): actual, actual_slots = hpssacli.get_smart_array_info() self.assertIsInstance(actual, list) self.assertEqual(len(actual), 5) expected_firmware = expected_base.child('firmware') expected_firmware.value = 6.60 actual = self.check_metrics(expected_firmware, actual) bcc = 'battery/capacitor count' if bcc in failures: expected_battery_count = expected_base.child(dimensions={ 'sub_component': bcc, 'count': '0'}) expected_battery_count.value = Severity.fail expected_battery_count.message = 'no_battery' else: expected_battery_count = expected_base.child(dimensions={ 'sub_component': bcc, 'count': '1'}) expected_battery_count.value = Severity.ok actual = self.check_metrics(expected_battery_count, actual) for submetric in ('battery/capacitor', 'controller', 'cache'): if submetric in failures: expected_status = expected_base.child(dimensions={ 'sub_component': submetric, 'status': 'FAIL'}) expected_status.value = Severity.fail expected_status.message = 'controller_status' else: expected_status = expected_base.child(dimensions={ 'sub_component': submetric, 'status': 'OK'}) expected_status.value = Severity.ok actual = self.check_metrics(expected_status, actual) self.assertFalse(actual, 'Got more metrics than expected')