diff --git a/SoftLayer/CLI/report/bandwidth.py b/SoftLayer/CLI/report/bandwidth.py index 5eccdea85..47f9fdbc1 100644 --- a/SoftLayer/CLI/report/bandwidth.py +++ b/SoftLayer/CLI/report/bandwidth.py @@ -143,6 +143,12 @@ def _get_virtual_bandwidth(env, start, end): label='Calculating for virtual', file=sys.stderr) as vms: for instance in vms: + metric_tracking_id = utils.lookup(instance, + 'metricTrackingObjectId') + + if metric_tracking_id is None: + continue + pool_name = None if utils.lookup(instance, 'virtualRack', @@ -161,7 +167,7 @@ def _get_virtual_bandwidth(env, start, end): end.strftime('%Y-%m-%d %H:%M:%S %Z'), types, 3600, - id=instance['metricTrackingObjectId'], + id=metric_tracking_id, ), } diff --git a/tests/CLI/modules/report_tests.py b/tests/CLI/modules/report_tests.py index a8b742d3d..f57d87120 100644 --- a/tests/CLI/modules/report_tests.py +++ b/tests/CLI/modules/report_tests.py @@ -41,7 +41,10 @@ def test_bandwidth_report(self): }, { 'id': 2, 'name': 'pool2', - 'metricTrackingObjectId': 2, + }, { + 'id': 3, + 'name': 'pool3', + 'metricTrackingObjectId': 3, }] hardware = self.set_mock('SoftLayer_Account', 'getHardware') hardware.return_value = [{ @@ -50,8 +53,12 @@ def test_bandwidth_report(self): 'hostname': 'host1', }, { 'id': 102, - 'metricTrackingObject': {'id': 102}, - 'hostname': 'host1', + 'hostname': 'host2', + 'virtualRack': {'id': 1, 'bandwidthAllotmentTypeId': 2}, + }, { + 'id': 103, + 'metricTrackingObject': {'id': 103}, + 'hostname': 'host3', 'virtualRack': {'id': 1, 'bandwidthAllotmentTypeId': 2}, }] guests = self.set_mock('SoftLayer_Account', 'getVirtualGuests') @@ -61,8 +68,12 @@ def test_bandwidth_report(self): 'hostname': 'host1', }, { 'id': 202, - 'metricTrackingObjectId': 202, - 'hostname': 'host1', + 'hostname': 'host2', + 'virtualRack': {'id': 2, 'bandwidthAllotmentTypeId': 2}, + }, { + 'id': 203, + 'metricTrackingObjectId': 203, + 'hostname': 'host3', 'virtualRack': {'id': 2, 'bandwidthAllotmentTypeId': 2}, }] summary_data = self.set_mock('SoftLayer_Metric_Tracking_Object', @@ -93,7 +104,7 @@ def test_bandwidth_report(self): 'public_out': 20, 'type': 'pool', }, { - 'name': 'pool2', + 'name': 'pool3', 'pool': None, 'private_in': 30, 'private_out': 40, @@ -109,7 +120,7 @@ def test_bandwidth_report(self): 'public_out': 20, 'type': 'virtual', }, { - 'name': 'host1', + 'name': 'host3', 'pool': 2, 'private_in': 30, 'private_out': 40, @@ -125,7 +136,7 @@ def test_bandwidth_report(self): 'public_out': 20, 'type': 'hardware', }, { - 'name': 'host1', + 'name': 'host3', 'pool': None, 'private_in': 30, 'private_out': 40, @@ -145,19 +156,19 @@ def test_bandwidth_report(self): identifier=1) self.assert_called_with('SoftLayer_Metric_Tracking_Object', 'getSummaryData', - identifier=2) + identifier=3) self.assert_called_with('SoftLayer_Metric_Tracking_Object', 'getSummaryData', identifier=101) self.assert_called_with('SoftLayer_Metric_Tracking_Object', 'getSummaryData', - identifier=102) + identifier=103) self.assert_called_with('SoftLayer_Metric_Tracking_Object', 'getSummaryData', identifier=201) self.assert_called_with('SoftLayer_Metric_Tracking_Object', 'getSummaryData', - identifier=202) + identifier=203) call = self.calls('SoftLayer_Metric_Tracking_Object', 'getSummaryData', identifier=1)[0] expected_args = (