Example #1
0
    def test_get_logical_drive_info(self):
        # Test that normal output and bugged output give exactly
        # the same results
        mock_command = mock.Mock()
        test_slot = "1"
        mock_command.return_value = CommandResult(0, LOGICAL_DRIVE_DATA)
        with mock.patch("swiftlm.hp_hardware.hpssacli.run_cmd", mock_command):
            data_1 = hpssacli.get_logical_drive_info(test_slot)

        self.assertIsInstance(data_1, list)
        self.assertTrue(len(data_1), 3)

        mock_command = mock.Mock()
        mock_command.return_value = CommandResult(0, LOGICAL_DRIVE_DATA_BUGGED)
        with mock.patch("swiftlm.hp_hardware.hpssacli.run_cmd", mock_command):
            data_2 = hpssacli.get_logical_drive_info(test_slot)

        self.assertIsInstance(data_2, list)
        self.assertTrue(len(data_2), 3)

        # Check the data is the same for both
        for d in data_1:
            data_2 = self.check_metrics(d, data_2)

        # Check data is as expected.
        expected_lun = MetricData.single(
            hpssacli.__name__ + ".logical_drive",
            Severity.ok,
            "OK",
            {
                "component": "logical_drive",
                "sub_component": "lun_status",
                "status": "OK",
                "logical_drive": "L",
                "caching": "Enabled",
            },
        )
        data_1 = self.check_metrics(expected_lun, data_1)

        expected_cache = MetricData.single(
            hpssacli.__name__ + ".logical_drive",
            Severity.ok,
            "OK",
            {
                "component": "logical_drive",
                "sub_component": "cache_status",
                "status": "OK",
                "logical_drive": "L",
                "caching": "Enabled",
            },
        )
        data_1 = self.check_metrics(expected_cache, data_1)

        self.assertFalse(data_1, "Got more metrics than expected with" "LOGICAL_DRIVE_DATA")
        self.assertFalse(data_2, "Got more metrics than expected with" "LOGICAL_DRIVE_DATA_BUGGED")
Example #2
0
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]
Example #3
0
    def test_get_logical_drive_info(self):
        # Test that normal output and bugged output give exactly
        # the same results
        mock_command = mock.Mock()
        test_slot = "1"
        mock_command.return_value = CommandResult(0, LOGICAL_DRIVE_DATA)
        with mock.patch('swiftlm.hp_hardware.hpssacli.run_cmd',
                        mock_command):
            data_1 = hpssacli.get_logical_drive_info(test_slot)

        self.assertIsInstance(data_1, list)
        self.assertTrue(len(data_1), 3)

        mock_command = mock.Mock()
        mock_command.return_value = CommandResult(0, LOGICAL_DRIVE_DATA_BUGGED)
        with mock.patch('swiftlm.hp_hardware.hpssacli.run_cmd',
                        mock_command):
            data_2 = hpssacli.get_logical_drive_info(test_slot)

        self.assertIsInstance(data_2, list)
        self.assertTrue(len(data_2), 3)

        # Check the data is the same for both
        for d in data_1:
            data_2 = self.check_metrics(d, data_2)

        # Check data is as expected.
        expected_lun = MetricData.single(
            hpssacli.__name__ + '.logical_drive',
            Severity.ok, 'OK',
            {'component': 'logical_drive', 'sub_component': 'lun_status',
             'status': "OK", 'logical_drive': 'L', 'caching': 'Enabled'})
        data_1 = self.check_metrics(expected_lun, data_1)

        expected_cache = MetricData.single(
            hpssacli.__name__ + '.logical_drive',
            Severity.ok, 'OK',
            {'component': 'logical_drive', 'sub_component': 'cache_status',
             'status': "OK", 'logical_drive': 'L', 'caching': 'Enabled'})
        data_1 = self.check_metrics(expected_cache, data_1)

        self.assertFalse(data_1, 'Got more metrics than expected with'
                         'LOGICAL_DRIVE_DATA')
        self.assertFalse(data_2, 'Got more metrics than expected with'
                         'LOGICAL_DRIVE_DATA_BUGGED')
Example #4
0
    def test_get_logical_drive_info_failures(self):
        tests = [(LOGICAL_DRIVE_LUN_FAIL, "lun_status"), (LOGICAL_DRIVE_CACHE_FAIL, "cache_status")]

        test_slot = "1"
        for test_data, failed_component 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 = hpssacli.get_logical_drive_info(test_slot)

            expected_lun = MetricData.single(
                hpssacli.__name__ + ".logical_drive",
                Severity.ok,
                "OK",
                {
                    "component": "logical_drive",
                    "logical_drive": "L",
                    "sub_component": "lun_status",
                    "caching": "Enabled",
                    "status": "OK",
                },
            )

            expected_cache = MetricData.single(
                hpssacli.__name__ + ".logical_drive",
                Severity.ok,
                "OK",
                {
                    "component": "logical_drive",
                    "logical_drive": "L",
                    "sub_component": "cache_status",
                    "caching": "Enabled",
                    "status": "OK",
                },
            )

            if expected_lun["sub_component"] == failed_component:
                expected_lun.value = Severity.fail
                expected_lun["status"] = "Fail"
                expected_lun._message = hpssacli.BASE_RESULT.messages["l_drive"]

            if expected_cache["sub_component"] == failed_component:
                expected_lun["caching"] = "Disabled"

            actual = self.check_metrics(expected_lun, actual)

            if expected_cache["sub_component"] == failed_component:
                expected_cache.value = Severity.fail
                expected_cache["caching"] = "Disabled"
                expected_cache._message = hpssacli.BASE_RESULT.messages["l_cache"]

            if expected_lun["sub_component"] == failed_component:
                expected_cache["status"] = "Fail"

            actual = self.check_metrics(expected_cache, actual)

            self.assertFalse(actual, "Got more metrics than expected")
Example #5
0
    def test_get_logical_drive_info_failures(self):
        tests = [
            (LOGICAL_DRIVE_LUN_FAIL, 'lun_status'),
            (LOGICAL_DRIVE_CACHE_FAIL, 'cache_status')
        ]

        test_slot = "1"
        for test_data, failed_component 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 = hpssacli.get_logical_drive_info(test_slot)

            expected_lun = MetricData.single(
                hpssacli.__name__ + '.logical_drive',
                Severity.ok, 'OK',
                {'component': 'logical_drive',
                 'logical_drive': 'L',
                 'sub_component': 'lun_status',
                 'caching': 'Enabled',
                 'status': "OK"})

            expected_cache = MetricData.single(
                hpssacli.__name__ + '.logical_drive',
                Severity.ok, 'OK',
                {'component': 'logical_drive',
                 'logical_drive': 'L',
                 'sub_component': 'cache_status',
                 'caching': 'Enabled',
                 'status': "OK"})

            if expected_lun['sub_component'] == failed_component:
                expected_lun.value = Severity.fail
                expected_lun['status'] = 'Fail'
                expected_lun._message = (hpssacli.BASE_RESULT.messages
                                         ['l_drive'])

            if expected_cache['sub_component'] == failed_component:
                expected_lun['caching'] = 'Disabled'

            actual = self.check_metrics(expected_lun, actual)

            if expected_cache['sub_component'] == failed_component:
                expected_cache.value = Severity.fail
                expected_cache['caching'] = 'Disabled'
                expected_cache._message = (hpssacli.BASE_RESULT.messages
                                           ['l_cache'])

            if expected_lun['sub_component'] == failed_component:
                expected_cache['status'] = 'Fail'

            actual = self.check_metrics(expected_cache, actual)

            self.assertFalse(actual, 'Got more metrics than expected')