Skip to content

Commit ac2aa71

Browse files
author
seolmin
committed
fix: add strip method to string values and change validation logic of cost and usage_quantity
Signed-off-by: seolmin <seolmin@megazone.com>
1 parent 58f1fb6 commit ac2aa71

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

src/cloudforet/cost_analysis/manager/cost_manager.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def _make_cost_data(self, results):
3636
costs_data = []
3737
for result in results:
3838
result = self._apply_strip_to_dict_keys(result)
39+
result = self._apply_strip_to_dict_values(result)
3940

4041
if self.http_file_connector.field_mapper:
4142
result = self._change_result_by_field_mapper(result)
@@ -89,6 +90,13 @@ def _apply_strip_to_dict_keys(result):
8990
del result[key]
9091
return result
9192

93+
@staticmethod
94+
def _apply_strip_to_dict_values(result):
95+
for key, value in result.items():
96+
if isinstance(value, str):
97+
result[key] = value.strip()
98+
return result
99+
92100
def _change_result_by_field_mapper(self, result):
93101
for origin_field, actual_field in self.http_file_connector.field_mapper.items():
94102
if isinstance(actual_field, str):
@@ -149,7 +157,9 @@ def _convert_cost_and_usage_quantity_types(result):
149157

150158
@staticmethod
151159
def _exist_cost_and_usage_quantity(result):
152-
if result['cost'] and result.get('usage_quantity'):
160+
if result['cost'] or result['cost'] == float(0):
161+
return True
162+
elif result['usage_quantity'] or result['usage_quantity'] == float(0):
153163
return True
154164
else:
155165
_LOGGER.error(f'[_exist_cost_and_usage_quantity] cost or usage quantity are empty: {result}')

0 commit comments

Comments
 (0)