From 671be1e67fcac2507f884d119d5ac8133750f789 Mon Sep 17 00:00:00 2001 From: Corey Goodfred Date: Wed, 6 Dec 2023 08:59:24 -0500 Subject: [PATCH 1/5] Allow setting of additional info for Azure --- nise/__init__.py | 2 +- nise/generators/azure/azure_generator.py | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/nise/__init__.py b/nise/__init__.py index dcfc3b6e..d3efa6a0 100644 --- a/nise/__init__.py +++ b/nise/__init__.py @@ -1,3 +1,3 @@ -__version__ = "4.4.10" +__version__ = "4.4.11" VERSION = __version__.split(".") diff --git a/nise/generators/azure/azure_generator.py b/nise/generators/azure/azure_generator.py index 38ace7fc..42febe65 100644 --- a/nise/generators/azure/azure_generator.py +++ b/nise/generators/azure/azure_generator.py @@ -190,6 +190,7 @@ def __init__(self, start_date, end_date, currency, account_info, attributes=None self._resource_type = None self._meter_cache = {} self._billing_currency = currency + self._additional_info = None # Version 2 fields self._invoice_section_id = None self._invoice_section_name = None @@ -223,12 +224,12 @@ def _get_cached_meter_values(self, meter_id, service_meter): self._meter_cache[meter_id] = choice(service_meter) return self._meter_cache.get(meter_id) - def _get_resource_info(self, meter_id, service_meter, ex_resource, add_info, service_info): + def _get_resource_info(self, meter_id, service_meter, ex_resource, service_info): """Return resource information.""" service_tier, meter_sub, meter_name, units_of_measure = self._get_cached_meter_values(meter_id, service_meter) service_info_2 = choice(service_info) resource_group, resource_name = choice(ex_resource) - additional_info = choice(add_info) + additional_info = self._get_additional_info() if self._instance_id: self._consumed, second_part = accts_str = self._get_accts_str(self._service_name) self._resource_type = self._consumed + "/" + second_part @@ -294,6 +295,13 @@ def _get_location(self): else: location = choice(self.RESOURCE_LOCATION) return location + + def _get_additional_info(self): + """Pick additional info.""" + if self._additional_info: + return self._additional_info + else: + return choice(self.ADDITIONAL_INFO) def _add_common_usage_info(self, row, start, end, **kwargs): """Add common usage information.""" @@ -342,7 +350,7 @@ def _update_data(self, row, start, end, **kwargs): additional_info, service_info_2, ) = self._get_resource_info( - meter_id, self.SERVICE_METER, self.EXAMPLE_RESOURCE, self.ADDITIONAL_INFO, self.SERVICE_INFO_2 + meter_id, self.SERVICE_METER, self.EXAMPLE_RESOURCE, self.SERVICE_INFO_2 ) if not additional_info: additional_info = "" From 2f43b26f17ba26ebd8126fa5349db46c6dababe7 Mon Sep 17 00:00:00 2001 From: Corey Goodfred Date: Wed, 6 Dec 2023 09:03:49 -0500 Subject: [PATCH 2/5] pre-commit --- nise/generators/azure/azure_generator.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/nise/generators/azure/azure_generator.py b/nise/generators/azure/azure_generator.py index 42febe65..a48234ab 100644 --- a/nise/generators/azure/azure_generator.py +++ b/nise/generators/azure/azure_generator.py @@ -295,7 +295,7 @@ def _get_location(self): else: location = choice(self.RESOURCE_LOCATION) return location - + def _get_additional_info(self): """Pick additional info.""" if self._additional_info: @@ -349,9 +349,7 @@ def _update_data(self, row, start, end, **kwargs): units_of_measure, additional_info, service_info_2, - ) = self._get_resource_info( - meter_id, self.SERVICE_METER, self.EXAMPLE_RESOURCE, self.SERVICE_INFO_2 - ) + ) = self._get_resource_info(meter_id, self.SERVICE_METER, self.EXAMPLE_RESOURCE, self.SERVICE_INFO_2) if not additional_info: additional_info = "" if not service_info_2: From 1efbca1b53902db4476a2d9a6af6686a8e78bb43 Mon Sep 17 00:00:00 2001 From: Corey Goodfred Date: Wed, 6 Dec 2023 09:13:12 -0500 Subject: [PATCH 3/5] add unit test --- tests/test_azure_generator.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/test_azure_generator.py b/tests/test_azure_generator.py index 6b41a298..193948d3 100644 --- a/tests/test_azure_generator.py +++ b/tests/test_azure_generator.py @@ -172,6 +172,19 @@ def test_get_location(self): location = generator._get_location() self.assertIn("US East", location) + def test_get_additional_info(self): + """Test the _get_additional_info method.""" + two_hours_ago = (self.now - self.one_hour) - self.one_hour + generator = TestGenerator(two_hours_ago, self.now, self.currency, self.account_info) + add_info = generator._get_additional_info() + self.assertIsInstance(add_info, tuple) + + attributes = {} + attributes["additional_info"] = {"VCPU": "1"} + generator = TestGenerator(two_hours_ago, self.now, self.currency, self.account_info, attributes) + add_info = generator._get_additional_info + self.assertIn("VCPU", add_info) + class AzureGeneratorTestCase(TestCase): """Test Base for specific generator classes.""" From 1c6bac57472107ce13b86cc416cb3bca9b271b15 Mon Sep 17 00:00:00 2001 From: Corey Goodfred Date: Wed, 6 Dec 2023 09:18:11 -0500 Subject: [PATCH 4/5] fix test --- tests/test_azure_generator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_azure_generator.py b/tests/test_azure_generator.py index 193948d3..4ee688b0 100644 --- a/tests/test_azure_generator.py +++ b/tests/test_azure_generator.py @@ -177,7 +177,7 @@ def test_get_additional_info(self): two_hours_ago = (self.now - self.one_hour) - self.one_hour generator = TestGenerator(two_hours_ago, self.now, self.currency, self.account_info) add_info = generator._get_additional_info() - self.assertIsInstance(add_info, tuple) + self.assertIsNone(add_info) attributes = {} attributes["additional_info"] = {"VCPU": "1"} From 92c5be13a5f2b73d88aacae988d8b0e56b489de0 Mon Sep 17 00:00:00 2001 From: Corey Goodfred Date: Wed, 6 Dec 2023 09:21:31 -0500 Subject: [PATCH 5/5] fix test again --- tests/test_azure_generator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_azure_generator.py b/tests/test_azure_generator.py index 4ee688b0..8c0025d0 100644 --- a/tests/test_azure_generator.py +++ b/tests/test_azure_generator.py @@ -182,7 +182,7 @@ def test_get_additional_info(self): attributes = {} attributes["additional_info"] = {"VCPU": "1"} generator = TestGenerator(two_hours_ago, self.now, self.currency, self.account_info, attributes) - add_info = generator._get_additional_info + add_info = generator._get_additional_info() self.assertIn("VCPU", add_info)