Repository: softlayer/softlayer-python
Pull request #1216 (2020-01-24 16:32:45)

1211 REST Issues: file replica-order fails


Patch:
diff --git a/SoftLayer/CLI/virt/detail.py b/SoftLayer/CLI/virt/detail.py
index 131117df..bf93a834 100644
--- a/SoftLayer/CLI/virt/detail.py
+++ b/SoftLayer/CLI/virt/detail.py
@@ -126,15 +126,14 @@ def cli(env, identifier, passwords=False, price=False):
 def _bw_table(bw_data):
     """Generates a bandwidth useage table"""
     table = formatting.Table(['Type', 'In GB', 'Out GB', 'Allotment'])
-    for bw_point in bw_data.get('usage'):
+    for bw_point in bw_data.get('useage'):
         bw_type = 'Private'
         allotment = 'N/A'
         if bw_point['type']['alias'] == 'PUBLIC_SERVER_BW':
             bw_type = 'Public'
-            if not bw_data.get('allotment'):
+            allotment = utils.lookup(bw_data, 'allotment', 'amount')
+            if allotment is None:
                 allotment = '-'
-            else:
-                allotment = utils.lookup(bw_data, 'allotment', 'amount')
 
         table.add_row([bw_type, bw_point['amountIn'], bw_point['amountOut'], allotment])
     return table
diff --git a/SoftLayer/managers/storage_utils.py b/SoftLayer/managers/storage_utils.py
index 7cce7671..80ec6036 100644
--- a/SoftLayer/managers/storage_utils.py
+++ b/SoftLayer/managers/storage_utils.py
@@ -660,14 +660,14 @@ def prepare_replicant_order_object(manager, snapshot_schedule, location,
     """
     # Ensure the primary volume and snapshot space are not set for cancellation
     if 'billingItem' not in volume\
-            or volume['billingItem']['cancellationDate'] != '':
+            or volume['billingItem'].get('cancellationDate'):
         raise exceptions.SoftLayerError(
             'This volume is set for cancellation; '
             'unable to order replicant volume')
 
     for child in volume['billingItem']['activeChildren']:
         if child['categoryCode'] == 'storage_snapshot_space'\
-                and child['cancellationDate'] != '':
+                and child.get('cancellationDate'):
             raise exceptions.SoftLayerError(
                 'The snapshot space for this volume is set for '
                 'cancellation; unable to order replicant volume')
diff --git a/SoftLayer/managers/vs.py b/SoftLayer/managers/vs.py
index b1391bc3..24a264b7 100644
--- a/SoftLayer/managers/vs.py
+++ b/SoftLayer/managers/vs.py
@@ -1074,10 +1074,8 @@ def get_bandwidth_allocation(self, instance_id):
         a_mask = "mask[allocation[amount]]"
         allotment = self.client.call('Virtual_Guest', 'getBandwidthAllotmentDetail', id=instance_id, mask=a_mask)
         u_mask = "mask[amountIn,amountOut,type]"
-        usage = self.client.call('Virtual_Guest', 'getBillingCycleBandwidthUsage', id=instance_id, mask=u_mask)
-        if allotment:
-            return {'allotment': allotment.get('allocation'), 'usage': usage}
-        return {'allotment': allotment, 'usage': usage}
+        useage = self.client.call('Virtual_Guest', 'getBillingCycleBandwidthUsage', id=instance_id, mask=u_mask)
+        return {'allotment': allotment.get('allocation'), 'useage': useage}
 
     # pylint: disable=inconsistent-return-statements
     def _get_price_id_for_upgrade(self, package_items, option, value, public=True):


Test patch:
diff --git a/tests/CLI/modules/vs/vs_tests.py b/tests/CLI/modules/vs/vs_tests.py
index 2c79f42b..3e57cb20 100644
--- a/tests/CLI/modules/vs/vs_tests.py
+++ b/tests/CLI/modules/vs/vs_tests.py
@@ -205,17 +205,6 @@ def test_detail_vs_empty_tag(self):
             ['example-tag'],
         )
 
-    def test_detail_vs_empty_allotment(self):
-        mock = self.set_mock('SoftLayer_Virtual_Guest', 'getBandwidthAllotmentDetail')
-        mock.return_value = None
-        result = self.run_command(['vs', 'detail', '100'])
-
-        self.assert_no_fail(result)
-        self.assertEqual(
-            json.loads(result.output)['Bandwidth'][0]['Allotment'],
-            '-',
-        )
-
     def test_detail_vs_dedicated_host_not_found(self):
         ex = SoftLayerAPIError('SoftLayer_Exception', 'Not found')
         mock = self.set_mock('SoftLayer_Virtual_DedicatedHost', 'getObject')
diff --git a/tests/managers/vs/vs_tests.py b/tests/managers/vs/vs_tests.py
index 47fcaf20..14d41966 100644
--- a/tests/managers/vs/vs_tests.py
+++ b/tests/managers/vs/vs_tests.py
@@ -902,26 +902,12 @@ def test_get_bandwidth_allocation(self):
         self.assert_called_with('SoftLayer_Virtual_Guest', 'getBandwidthAllotmentDetail', identifier=1234)
         self.assert_called_with('SoftLayer_Virtual_Guest', 'getBillingCycleBandwidthUsage', identifier=1234)
         self.assertEqual(result['allotment']['amount'], '250')
-        self.assertEqual(result['usage'][0]['amountIn'], '.448')
+        self.assertEqual(result['useage'][0]['amountIn'], '.448')
 
     def test_get_bandwidth_allocation_no_allotment(self):
         mock = self.set_mock('SoftLayer_Virtual_Guest', 'getBandwidthAllotmentDetail')
-        mock.return_value = None
+        mock.return_value = {}
 
         result = self.vs.get_bandwidth_allocation(1234)
 
         self.assertEqual(None, result['allotment'])
-
-    def test_get_bandwidth_allocation_with_allotment(self):
-        mock = self.set_mock('SoftLayer_Virtual_Guest', 'getBandwidthAllotmentDetail')
-        mock.return_value = {
-            "allocationId": 11111,
-            "id": 22222,
-            "allocation": {
-                "amount": "2000"
-            }
-        }
-
-        result = self.vs.get_bandwidth_allocation(1234)
-
-        self.assertEqual(2000, int(result['allotment']['amount']))