-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #314 from nautobot/progala-ltm16-metric-tests
Add tests covering metric generators.
- Loading branch information
Showing
3 changed files
with
156 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
"""nautobot_device_lifecycle_mgmt test class for metrics.""" | ||
from django.db import ProgrammingError | ||
from django.test import TestCase | ||
|
||
from nautobot_device_lifecycle_mgmt.metrics import ( | ||
metrics_lcm_hw_end_of_support, | ||
metrics_lcm_validation_report_device_type, | ||
metrics_lcm_validation_report_inventory_item, | ||
) | ||
|
||
from .conftest import create_devices, create_inventory_item_hardware_notices, create_inventory_items | ||
|
||
|
||
class MetricsTest(TestCase): | ||
"""Test class for Device Lifecycle metrics.""" | ||
|
||
def setUp(self): | ||
create_inventory_items() | ||
create_inventory_item_hardware_notices() | ||
|
||
def test_metrics_lcm_validation_report_device_type(self): | ||
"""Test metric device_software_compliance_gauge.""" | ||
create_devices() | ||
# TODO: Generate DeviceSoftwareValidationResult | ||
metric_gen = metrics_lcm_validation_report_device_type() | ||
metric = next(metric_gen) | ||
|
||
expected_ts_samples = { | ||
(("device_type", "6509-E"), ("is_valid", "False")): 0, | ||
(("device_type", "6509-E"), ("is_valid", "True")): 0, | ||
} | ||
|
||
for sample in metric.samples: | ||
sample_labels = tuple(sample.labels.items()) | ||
self.assertEqual(expected_ts_samples[sample_labels], sample.value) | ||
|
||
def test_metrics_lcm_validation_report_inventory_item(self): | ||
"""Test metric inventory_item_software_compliance_gauge.""" | ||
# TODO: Generate InventoryItemSoftwareValidationResult | ||
metric_gen = metrics_lcm_validation_report_inventory_item() | ||
metric = next(metric_gen) | ||
|
||
expected_ts_samples = { | ||
(("inventory_item", "VS-S2T-10G"), ("is_valid", "False")): 0, | ||
(("inventory_item", "QSFP-100G-SR4-S"), ("is_valid", "False")): 0, | ||
(("inventory_item", "WS-X6548-GE-TX"), ("is_valid", "False")): 0, | ||
(("inventory_item", "VS-S2T-10G"), ("is_valid", "True")): 0, | ||
(("inventory_item", "QSFP-100G-SR4-S"), ("is_valid", "True")): 0, | ||
(("inventory_item", "WS-X6548-GE-TX"), ("is_valid", "True")): 0, | ||
} | ||
|
||
for sample in metric.samples: | ||
sample_labels = tuple(sample.labels.items()) | ||
self.assertEqual(expected_ts_samples[sample_labels], sample.value) | ||
|
||
def test_metrics_lcm_hw_end_of_support_does_not_error(self): | ||
"""Query providing data to hw_end_of_support_site_gauge metric should not error out. | ||
Guards against https://github.com/nautobot/nautobot-app-device-lifecycle-mgmt/issues/309 | ||
""" | ||
metric_gen = metrics_lcm_hw_end_of_support() | ||
# skip hw_end_of_support_part_number_gauge | ||
next(metric_gen) | ||
try: | ||
# Get hw_end_of_support_site_gauge | ||
next(metric_gen) | ||
except ProgrammingError: | ||
self.fail("hw_end_of_support_site_gauge query bug") | ||
|
||
def test_metrics_lcm_hw_end_of_support_part_number(self): | ||
"""Test metric hw_end_of_support_part_number_gauge.""" | ||
metric_gen = metrics_lcm_hw_end_of_support() | ||
|
||
# Get hw_end_of_support_part_number_gauge | ||
metric = next(metric_gen) | ||
|
||
expected_ts_samples = { | ||
("part_number", "6509-E"): 0, | ||
("part_number", "VS-S2T-10G"): 1, | ||
("part_number", "QSFP-100G-SR4-S"): 1, | ||
("part_number", "WS-X6548-GE-TX"): 0, | ||
} | ||
|
||
for sample in metric.samples: | ||
sample_labels = tuple(sample.labels.items())[0] | ||
self.assertEqual(expected_ts_samples[sample_labels], sample.value) | ||
|
||
def test_metrics_lcm_hw_end_of_support_site_gauge(self): | ||
"""Test metric hw_end_of_support_site_gauge.""" | ||
metric_gen = metrics_lcm_hw_end_of_support() | ||
|
||
# skip hw_end_of_support_part_number_gauge | ||
next(metric_gen) | ||
|
||
# Get hw_end_of_support_site_gauge | ||
metric = next(metric_gen) | ||
|
||
expected_ts_samples = { | ||
("site", "testsite-1"): 2, | ||
("site", "testsite-2"): 0, | ||
} | ||
|
||
for sample in metric.samples: | ||
sample_labels = tuple(sample.labels.items())[0] | ||
self.assertEqual(expected_ts_samples[sample_labels], sample.value) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters