Skip to content

Commit acf4071

Browse files
Merge pull request #1186 from FernandoOjeda/fo_cdn_detail_usage
Fix cdn detail usage.
2 parents bafc580 + 141cd23 commit acf4071

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

SoftLayer/managers/cdn.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ class CDNManager(utils.IdentifierMixin, object):
2121

2222
def __init__(self, client):
2323
self.client = client
24+
self._start_date = None
25+
self._end_date = None
2426
self.cdn_configuration = self.client['Network_CdnMarketplace_Configuration_Mapping']
2527
self.cdn_path = self.client['SoftLayer_Network_CdnMarketplace_Configuration_Mapping_Path']
2628
self.cdn_metrics = self.client['Network_CdnMarketplace_Metrics']
@@ -151,10 +153,20 @@ def get_usage_metrics(self, unique_id, history=30, frequency="aggregate"):
151153
_start = utils.days_to_datetime(history)
152154
_end = utils.days_to_datetime(0)
153155

154-
_start_date = utils.timestamp(_start)
155-
_end_date = utils.timestamp(_end)
156+
self._start_date = utils.timestamp(_start)
157+
self._end_date = utils.timestamp(_end)
156158

157-
usage = self.cdn_metrics.getMappingUsageMetrics(unique_id, _start_date, _end_date, frequency)
159+
usage = self.cdn_metrics.getMappingUsageMetrics(unique_id, self._start_date, self._end_date, frequency)
158160

159161
# The method getMappingUsageMetrics() returns an array but there is only 1 object
160162
return usage[0]
163+
164+
@property
165+
def start_data(self):
166+
"""Retrieve the cdn usage metric start date."""
167+
return self._start_date
168+
169+
@property
170+
def end_date(self):
171+
"""Retrieve the cdn usage metric end date."""
172+
return self._end_date

tests/managers/cdn_tests.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
from SoftLayer.managers import cdn
99
from SoftLayer import testing
10-
from SoftLayer import utils
1110

1211

1312
class CDNTests(testing.TestCase):
@@ -31,15 +30,9 @@ def test_detail_cdn(self):
3130
def test_detail_usage_metric(self):
3231
self.cdn_client.get_usage_metrics(12345, history=30, frequency="aggregate")
3332

34-
_start = utils.days_to_datetime(30)
35-
_end = utils.days_to_datetime(0)
36-
37-
_start_date = utils.timestamp(_start)
38-
_end_date = utils.timestamp(_end)
39-
4033
args = (12345,
41-
_start_date,
42-
_end_date,
34+
self.cdn_client.start_data,
35+
self.cdn_client.end_date,
4336
"aggregate")
4437
self.assert_called_with('SoftLayer_Network_CdnMarketplace_Metrics',
4538
'getMappingUsageMetrics',

0 commit comments

Comments
 (0)