Skip to content

Commit 1848340

Browse files
Merge pull request #941 from camporter/fix_metric_tracking_id_error
Carefully check for the metric tracking id on virtual guests
2 parents 97d3f1d + 39b57b8 commit 1848340

File tree

2 files changed

+29
-12
lines changed

2 files changed

+29
-12
lines changed

SoftLayer/CLI/report/bandwidth.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,12 @@ def _get_virtual_bandwidth(env, start, end):
143143
label='Calculating for virtual',
144144
file=sys.stderr) as vms:
145145
for instance in vms:
146+
metric_tracking_id = utils.lookup(instance,
147+
'metricTrackingObjectId')
148+
149+
if metric_tracking_id is None:
150+
continue
151+
146152
pool_name = None
147153
if utils.lookup(instance,
148154
'virtualRack',
@@ -161,7 +167,7 @@ def _get_virtual_bandwidth(env, start, end):
161167
end.strftime('%Y-%m-%d %H:%M:%S %Z'),
162168
types,
163169
3600,
164-
id=instance['metricTrackingObjectId'],
170+
id=metric_tracking_id,
165171
),
166172
}
167173

tests/CLI/modules/report_tests.py

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ def test_bandwidth_report(self):
4141
}, {
4242
'id': 2,
4343
'name': 'pool2',
44-
'metricTrackingObjectId': 2,
44+
}, {
45+
'id': 3,
46+
'name': 'pool3',
47+
'metricTrackingObjectId': 3,
4548
}]
4649
hardware = self.set_mock('SoftLayer_Account', 'getHardware')
4750
hardware.return_value = [{
@@ -50,8 +53,12 @@ def test_bandwidth_report(self):
5053
'hostname': 'host1',
5154
}, {
5255
'id': 102,
53-
'metricTrackingObject': {'id': 102},
54-
'hostname': 'host1',
56+
'hostname': 'host2',
57+
'virtualRack': {'id': 1, 'bandwidthAllotmentTypeId': 2},
58+
}, {
59+
'id': 103,
60+
'metricTrackingObject': {'id': 103},
61+
'hostname': 'host3',
5562
'virtualRack': {'id': 1, 'bandwidthAllotmentTypeId': 2},
5663
}]
5764
guests = self.set_mock('SoftLayer_Account', 'getVirtualGuests')
@@ -61,8 +68,12 @@ def test_bandwidth_report(self):
6168
'hostname': 'host1',
6269
}, {
6370
'id': 202,
64-
'metricTrackingObjectId': 202,
65-
'hostname': 'host1',
71+
'hostname': 'host2',
72+
'virtualRack': {'id': 2, 'bandwidthAllotmentTypeId': 2},
73+
}, {
74+
'id': 203,
75+
'metricTrackingObjectId': 203,
76+
'hostname': 'host3',
6677
'virtualRack': {'id': 2, 'bandwidthAllotmentTypeId': 2},
6778
}]
6879
summary_data = self.set_mock('SoftLayer_Metric_Tracking_Object',
@@ -93,7 +104,7 @@ def test_bandwidth_report(self):
93104
'public_out': 20,
94105
'type': 'pool',
95106
}, {
96-
'name': 'pool2',
107+
'name': 'pool3',
97108
'pool': None,
98109
'private_in': 30,
99110
'private_out': 40,
@@ -109,7 +120,7 @@ def test_bandwidth_report(self):
109120
'public_out': 20,
110121
'type': 'virtual',
111122
}, {
112-
'name': 'host1',
123+
'name': 'host3',
113124
'pool': 2,
114125
'private_in': 30,
115126
'private_out': 40,
@@ -125,7 +136,7 @@ def test_bandwidth_report(self):
125136
'public_out': 20,
126137
'type': 'hardware',
127138
}, {
128-
'name': 'host1',
139+
'name': 'host3',
129140
'pool': None,
130141
'private_in': 30,
131142
'private_out': 40,
@@ -145,19 +156,19 @@ def test_bandwidth_report(self):
145156
identifier=1)
146157
self.assert_called_with('SoftLayer_Metric_Tracking_Object',
147158
'getSummaryData',
148-
identifier=2)
159+
identifier=3)
149160
self.assert_called_with('SoftLayer_Metric_Tracking_Object',
150161
'getSummaryData',
151162
identifier=101)
152163
self.assert_called_with('SoftLayer_Metric_Tracking_Object',
153164
'getSummaryData',
154-
identifier=102)
165+
identifier=103)
155166
self.assert_called_with('SoftLayer_Metric_Tracking_Object',
156167
'getSummaryData',
157168
identifier=201)
158169
self.assert_called_with('SoftLayer_Metric_Tracking_Object',
159170
'getSummaryData',
160-
identifier=202)
171+
identifier=203)
161172
call = self.calls('SoftLayer_Metric_Tracking_Object', 'getSummaryData',
162173
identifier=1)[0]
163174
expected_args = (

0 commit comments

Comments
 (0)