예제 #1
0
    def test_all_services_running(self):
        server_types = dict(proxy=True,
                            object=True,
                            container=True,
                            account=True)
        expected_services = list(s for s in swift_services.SERVICES
                                 if s.startswith(tuple(server_types.keys())))
        create_fake_process_entries(self.testdir, expected_services)
        with mock.patch('swiftlm.utils.metricdata.timestamp',
                        lambda *args: self.fake_time):
            with mock.patch('swiftlm.swift.swift_services.server_type',
                            lambda *args: server_types):
                with mock.patch('swiftlm.swift.swift_services.PROC_DIR',
                                self.testdir):
                    results = swift_services.main()

        self.assertEqual(len(expected_services), len(results))
        for r in results:
            metric = r.metric()
            actual_service = metric['dimensions']['component']
            self.assertTrue(actual_service in expected_services)

            expected_services.remove(actual_service)
            expected_dimensions = dict(self.expected_dimensions_base)
            expected_dimensions.update(dict(component=actual_service))
            expected_value_meta = dict(msg=actual_service + ' is running')
            expected_metric = dict(self.expected_metric_base)
            expected_metric.update(dict(dimensions=expected_dimensions,
                                        value=Severity.ok,
                                        value_meta=expected_value_meta))
            self.assertEqual(expected_metric, metric)
        # sanity check - all expected services found in actual metrics
        self.assertFalse(expected_services)
예제 #2
0
    def test_all_services_running(self):
        server_types = dict(proxy=True,
                            object=True,
                            container=True,
                            account=True)
        expected_services = list(s for s in swift_services.SERVICES
                                 if s.startswith(tuple(server_types.keys())))
        create_fake_process_entries(self.testdir, expected_services)
        with mock.patch('swiftlm.utils.metricdata.timestamp',
                        lambda *args: self.fake_time):
            with mock.patch('swiftlm.swift.swift_services.server_type',
                            lambda *args: server_types):
                with mock.patch('swiftlm.swift.swift_services.PROC_DIR',
                                self.testdir):
                    results = swift_services.main()

        self.assertEqual(len(expected_services), len(results))
        for r in results:
            metric = r.metric()
            actual_service = metric['dimensions']['component']
            self.assertTrue(actual_service in expected_services)

            expected_services.remove(actual_service)
            expected_dimensions = dict(self.expected_dimensions_base)
            expected_dimensions.update(dict(component=actual_service))
            expected_value_meta = dict(msg=actual_service + ' is running')
            expected_metric = dict(self.expected_metric_base)
            expected_metric.update(
                dict(dimensions=expected_dimensions,
                     value=Severity.ok,
                     value_meta=expected_value_meta))
            self.assertEqual(expected_metric, metric)
        # sanity check - all expected services found in actual metrics
        self.assertFalse(expected_services)
예제 #3
0
    def test_no_server_conf_found(self):
        server_types = dict(proxy=False,
                            object=False,
                            container=False,
                            account=False)
        with mock.patch('swiftlm.utils.metricdata.timestamp',
                        lambda *args: self.fake_time):
            with mock.patch('swiftlm.swift.swift_services.server_type',
                            lambda *args: server_types):
                with mock.patch('swiftlm.swift.swift_services.PROC_DIR',
                                self.testdir):
                    results = swift_services.main()

        # results should be a single MetricData instance
        metric = results.metric()
        expected_dimensions = dict(self.expected_dimensions_base)
        expected_metric = dict(self.expected_metric_base)
        expected_value_meta = dict(msg='no swift services running')
        expected_metric.update(dict(dimensions=expected_dimensions,
                                    value=Severity.unknown,
                                    value_meta=expected_value_meta))
        self.assertEqual(expected_metric, metric)
예제 #4
0
    def test_no_server_conf_found(self):
        server_types = dict(proxy=False,
                            object=False,
                            container=False,
                            account=False)
        with mock.patch('swiftlm.utils.metricdata.timestamp',
                        lambda *args: self.fake_time):
            with mock.patch('swiftlm.swift.swift_services.server_type',
                            lambda *args: server_types):
                with mock.patch('swiftlm.swift.swift_services.PROC_DIR',
                                self.testdir):
                    results = swift_services.main()

        # results should be a single MetricData instance
        metric = results.metric()
        expected_dimensions = dict(self.expected_dimensions_base)
        expected_metric = dict(self.expected_metric_base)
        expected_value_meta = dict(msg='no swift services running')
        expected_metric.update(
            dict(dimensions=expected_dimensions,
                 value=Severity.unknown,
                 value_meta=expected_value_meta))
        self.assertEqual(expected_metric, metric)