예제 #1
0
    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")
예제 #2
0
    def test_response_child(self):
        r = MetricData(name='name', messages={'a': 'b'})
        r['test'] = 'test'

        c = r.child(dimensions={'test2': 'test2'})
        self.assertIn('test', c)
        self.assertIn('test2', c)
        self.assertDictEqual({'a': 'b'}, c.messages)
        self.assertEqual('swiftlm.name', c.name)

        c = r.child()
        self.assertIn('test', c)
        self.assertNotIn('test2', c)
예제 #3
0
    def test_response_child(self):
        r = MetricData(name='name', messages={'a': 'b'})
        r['test'] = 'test'

        c = r.child(dimensions={'test2': 'test2'})
        self.assertIn('test', c)
        self.assertIn('test2', c)
        self.assertDictEqual({'a': 'b'}, c.messages)
        self.assertEqual('swiftlm.name', c.name)

        c = r.child()
        self.assertIn('test', c)
        self.assertNotIn('test2', c)
예제 #4
0
    def test_child_msgkeys(self):
        r = MetricData(name='name',
                       messages={
                           'ok': 'test message',
                           'test':
                           'test with meta {test_value} and {test_value2}',
                       })

        c = r.child(dimensions={'test_value': '123'},
                    msgkeys={'test_value2': '456'})
        c.message = 'test'

        self.assertEqual('test with meta 123 and 456', str(c))
예제 #5
0
    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')