def test_timeout(self): """Tests a timeout with an IP where no HMC is sitting.""" cred_dict = {"hmc": "192.168.0.0", "userid": "user", "password": "******"} session = zhmc_prometheus_exporter.create_session( cred_dict, "filename") with self.assertRaises(zhmcclient.ConnectionError): zhmc_prometheus_exporter.create_metrics_context( session, {}, '2.14')
def test_timeout(self): """Tests a timeout with an IP where no HMC is sitting. Omitting this test improves test time by three orders of magnitude. """ cred_dict = {"hmc": "192.168.0.0", "userid": "user", "password": "******"} session = zhmc_prometheus_exporter.create_session(cred_dict) with self.assertRaises(zhmc_prometheus_exporter.ConnectionError): zhmc_prometheus_exporter.create_metrics_context( session, {}, "filename", '2.14')
def test_collect(self): """Test ZHMCUsageCollector.collect""" session = zhmcclient_mock.FakedSession("fake-host", "fake-hmc", "2.13.1", "1.8") yaml_metric_groups = {"metric-group": {"prefix": "pre", "fetch": True}} context = (zhmc_prometheus_exporter.create_metrics_context( session, yaml_metric_groups, "filename")) yaml_metrics = { "metric-group": { "metric": { "percent": True, "exporter_name": "metric", "exporter_desc": "metric" } } } my_zhmc_usage_collector = (zhmc_prometheus_exporter.ZHMCUsageCollector( context, yaml_metric_groups, yaml_metrics, "filename")) collected = list(my_zhmc_usage_collector.collect()) self.assertEqual(len(collected), 1) self.assertEqual(type(collected[0]), prometheus_client.core.GaugeMetricFamily) self.assertEqual(collected[0].name, "zhmc_pre_metric") self.assertEqual(collected[0].documentation, "metric") self.assertEqual(collected[0].type, "gauge") self.assertEqual(collected[0].samples, []) self.assertEqual(collected[0]._labelnames, ("resource", ))
def test_init(self): """Tests ZHMCUsageCollector.__init__.""" cred_dict = {"hmc": "192.168.0.0", "userid": "user", "password": "******"} session = zhmcclient_mock.FakedSession("fake-host", "fake-hmc", "2.13.1", "1.8") yaml_metric_groups = {"metric-group": {"prefix": "pre", "fetch": True}} context = (zhmc_prometheus_exporter.create_metrics_context( session, yaml_metric_groups, "filename")) yaml_metrics = { "metric-group": { "metric": { "percent": True, "exporter_name": "metric", "exporter_desc": "metric" } } } my_zhmc_usage_collector = (zhmc_prometheus_exporter.ZHMCUsageCollector( cred_dict, session, context, yaml_metric_groups, yaml_metrics, "filename", "filename")) self.assertEqual(my_zhmc_usage_collector.yaml_creds, cred_dict) self.assertEqual(my_zhmc_usage_collector.session, session) self.assertEqual(my_zhmc_usage_collector.context, context) self.assertEqual(my_zhmc_usage_collector.yaml_metric_groups, yaml_metric_groups) self.assertEqual(my_zhmc_usage_collector.yaml_metrics, yaml_metrics) self.assertEqual(my_zhmc_usage_collector.filename_metrics, "filename") self.assertEqual(my_zhmc_usage_collector.filename_creds, "filename")
def test_init(self): """Tests ZHMCUsageCollector.__init__.""" cred_dict = {"hmc": "192.168.0.0", "userid": "user", "password": "******"} session = setup_faked_session() yaml_metric_groups = { "dpm-system-usage-overview": { "prefix": "pre", "fetch": True } } context, resources = zhmc_prometheus_exporter.create_metrics_context( session, yaml_metric_groups, '2.14') yaml_metrics = { "dpm-system-usage-overview": { "processor-usage": { "percent": True, "exporter_name": "processor_usage", "exporter_desc": "processor_usage description" } } } extra_labels = {} my_zhmc_usage_collector = zhmc_prometheus_exporter.ZHMCUsageCollector( cred_dict, session, context, resources, yaml_metric_groups, yaml_metrics, extra_labels, "filename", "filename", None, '2.14') self.assertEqual(my_zhmc_usage_collector.yaml_creds, cred_dict) self.assertEqual(my_zhmc_usage_collector.session, session) self.assertEqual(my_zhmc_usage_collector.context, context) self.assertEqual(my_zhmc_usage_collector.yaml_metric_groups, yaml_metric_groups) self.assertEqual(my_zhmc_usage_collector.yaml_metrics, yaml_metrics) self.assertEqual(my_zhmc_usage_collector.filename_metrics, "filename") self.assertEqual(my_zhmc_usage_collector.filename_creds, "filename")
def test_normal_input(self): """Tests normal input with a generic metric group.""" session = zhmcclient_mock.FakedSession("fake-host", "fake-hmc", "2.13.1", "1.8") context = (zhmc_prometheus_exporter.create_metrics_context( session, {"metric-group": { "prefix": "pre", "fetch": True }}, "filename")) self.assertEqual(type(context), zhmcclient._metrics.MetricsContext) context.delete() session.logoff()
def test_normal_input(self): """Tests normal input with a generic metric group.""" session = zhmcclient_mock.FakedSession("fake-host", "fake-hmc", "2.13.1", "1.8") context, _ = zhmc_prometheus_exporter.create_metrics_context( session, {"dpm-system-usage-overview": { "prefix": "pre", "fetch": True }}, '2.14') # pylint: disable=protected-access self.assertEqual(type(context), zhmcclient._metrics.MetricsContext) context.delete() session.logoff()
def test_collect(self): """Test ZHMCUsageCollector.collect""" cred_dict = {"hmc": "192.168.0.0", "userid": "user", "password": "******"} session = setup_faked_session() yaml_metric_groups = { "dpm-system-usage-overview": { "prefix": "pre", "fetch": True } } context, resources = zhmc_prometheus_exporter.create_metrics_context( session, yaml_metric_groups, '2.14') yaml_metrics = { "dpm-system-usage-overview": { "processor-usage": { "percent": True, "exporter_name": "processor_usage", "exporter_desc": "processor_usage description" } } } extra_labels = {} my_zhmc_usage_collector = zhmc_prometheus_exporter.ZHMCUsageCollector( cred_dict, session, context, resources, yaml_metric_groups, yaml_metrics, extra_labels, "filename", "filename", None, '2.14') collected = list(my_zhmc_usage_collector.collect()) self.assertEqual(len(collected), 1) self.assertEqual(type(collected[0]), prometheus_client.core.GaugeMetricFamily) self.assertEqual(collected[0].name, "zhmc_pre_processor_usage") self.assertEqual(collected[0].documentation, "processor_usage description") self.assertEqual(collected[0].type, "gauge") sample1 = prometheus_client.samples.Sample( name='zhmc_pre_processor_usage', labels={'resource': 'cpc_1'}, value=0.01) self.assertEqual(collected[0].samples, [sample1]) # pylint: disable=protected-access self.assertEqual(collected[0]._labelnames, ("resource", ))