def test_check_dead_swift_processes(self, mock_running, mock_type): mock_type.return_value = self.server_type mock_running.return_value = False results = swift_services.check_swift_processes() self.assertEqual(len(SERVICES), len(results)) for r in results: self.assertEqual(Severity.fail, r.value)
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()))) mock_cmdline = iter( list([('None'), [ '/opt/stack/venv/swift-20160808T211047Z/bin' '/python2', '/opt/stack/service/swift-' + s + '/venv/bin/swift-' + s, '/opt/stack/' 'service/swift-' + s + '-20160808T211047Z/etc/' 'proxy-server.conf' ]] for s in expected_services)) mock_get_all_proc_and_cmdlines = mock.Mock() mock_get_all_proc_and_cmdlines.return_value = mock_cmdline 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.' 'get_all_proc_and_cmdlines', mock_get_all_proc_and_cmdlines): results = swift_services.check_swift_processes() 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)
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): results = swift_services.check_swift_processes() # 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)
def test_no_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()))) mock_cmdline = [(fake_rsync_process(), ['', ''])] mock_get_all_proc_and_cmdlines = mock.Mock() mock_get_all_proc_and_cmdlines.return_value = mock_cmdline 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.' 'get_all_proc_and_cmdlines', mock_get_all_proc_and_cmdlines): results = swift_services.check_swift_processes() 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 not running') expected_metric = dict(self.expected_metric_base) expected_metric.update( dict(dimensions=expected_dimensions, value=Severity.fail, value_meta=expected_value_meta)) self.assertEqual(expected_metric, metric) # sanity check - all expected services found in actual metrics self.assertFalse(expected_services)