Repository: softlayer/softlayer-python
Pull request #1237 (2020-03-09 22:54:05)

Fix order place bare metal capacity restriction.
Fix order place bare metal capacity restriction https://github.com/softlayer/softlayer-python/issues/1236.


Patch:
diff --git a/SoftLayer/managers/ordering.py b/SoftLayer/managers/ordering.py
index e86679f6..7e4e81db 100644
--- a/SoftLayer/managers/ordering.py
+++ b/SoftLayer/managers/ordering.py
@@ -351,7 +351,7 @@ def get_price_id_list(self, package_keyname, item_keynames, core=None):
                   keynames in the given package
 
         """
-        mask = 'id, capacity, itemCategory, keyName, prices[categories]'
+        mask = 'id, description, capacity, itemCategory, keyName, prices[categories]'
         items = self.list_items(package_keyname, mask=mask)
         item_capacity = self.get_item_capacity(items, item_keynames)
 
@@ -422,6 +422,11 @@ def get_item_capacity(self, items, item_keynames):
                     if "TIER" in item["keyName"]:
                         item_capacity = item['capacity']
                         break
+                    if "INTEL" in item["keyName"]:
+                        item_split = item['description'].split("(")
+                        item_core = item_split[1].split(" ")
+                        item_capacity = item_core[0]
+                        break
         return item_capacity
 
     def get_preset_prices(self, preset):


Test patch:
diff --git a/tests/managers/ordering_tests.py b/tests/managers/ordering_tests.py
index 045517cd..39caa72f 100644
--- a/tests/managers/ordering_tests.py
+++ b/tests/managers/ordering_tests.py
@@ -309,7 +309,7 @@ def test_get_price_id_list(self):
 
             prices = self.ordering.get_price_id_list('PACKAGE_KEYNAME', ['ITEM1', 'ITEM2'], "8")
 
-        list_mock.assert_called_once_with('PACKAGE_KEYNAME', mask='id, capacity, itemCategory, keyName, '
+        list_mock.assert_called_once_with('PACKAGE_KEYNAME', mask='id, description, capacity, itemCategory, keyName, '
                                                                   'prices[categories]')
         self.assertEqual([price1['id'], price2['id']], prices)
 
@@ -327,7 +327,7 @@ def test_get_price_id_list_no_core(self):
 
             prices = self.ordering.get_price_id_list('PACKAGE_KEYNAME', ['ITEM1', 'ITEM2'], None)
 
-        list_mock.assert_called_once_with('PACKAGE_KEYNAME', mask='id, capacity, itemCategory, keyName, '
+        list_mock.assert_called_once_with('PACKAGE_KEYNAME', mask='id, description, capacity, itemCategory, keyName, '
                                                                   'prices[categories]')
         self.assertEqual([price1['id'], price2['id']], prices)
 
@@ -342,7 +342,7 @@ def test_get_price_id_list_item_not_found(self):
             exc = self.assertRaises(exceptions.SoftLayerError,
                                     self.ordering.get_price_id_list,
                                     'PACKAGE_KEYNAME', ['ITEM2'], "8")
-        list_mock.assert_called_once_with('PACKAGE_KEYNAME', mask='id, capacity, itemCategory, keyName, '
+        list_mock.assert_called_once_with('PACKAGE_KEYNAME', mask='id, description, capacity, itemCategory, keyName, '
                                                                   'prices[categories]')
         self.assertEqual("Item ITEM2 does not exist for package PACKAGE_KEYNAME", str(exc))
 
@@ -357,8 +357,8 @@ def test_get_price_id_list_gpu_items_with_two_categories(self):
 
             prices = self.ordering.get_price_id_list('PACKAGE_KEYNAME', ['ITEM1', 'ITEM1'], "8")
 
-            list_mock.assert_called_once_with('PACKAGE_KEYNAME', mask='id, capacity, itemCategory, keyName, '
-                                                                      'prices[categories]')
+            list_mock.assert_called_once_with('PACKAGE_KEYNAME', mask='id, description, capacity, itemCategory, '
+                                                                      'keyName, ' 'prices[categories]')
             self.assertEqual([price2['id'], price1['id']], prices)
 
     def test_generate_no_complex_type(self):
@@ -608,7 +608,7 @@ def test_location_group_id_none(self):
 
             prices = self.ordering.get_price_id_list('PACKAGE_KEYNAME', ['ITEM1', 'ITEM2'], "8")
 
-        list_mock.assert_called_once_with('PACKAGE_KEYNAME', mask='id, capacity, itemCategory, keyName, '
+        list_mock.assert_called_once_with('PACKAGE_KEYNAME', mask='id, description, capacity, itemCategory, keyName, '
                                                                   'prices[categories]')
         self.assertEqual([price1['id'], price2['id']], prices)
 
@@ -626,7 +626,7 @@ def test_location_groud_id_empty(self):
 
             prices = self.ordering.get_price_id_list('PACKAGE_KEYNAME', ['ITEM1', 'ITEM2'], "8")
 
-        list_mock.assert_called_once_with('PACKAGE_KEYNAME', mask='id, capacity, itemCategory, keyName, '
+        list_mock.assert_called_once_with('PACKAGE_KEYNAME', mask='id, description, capacity, itemCategory, keyName, '
                                                                   'prices[categories]')
         self.assertEqual([price1['id'], price2['id']], prices)
 
@@ -673,11 +673,10 @@ def test_issues1067(self):
             {
                 'id': 10453,
                 'itemCategory': {'categoryCode': 'server'},
+                "description": "Dual Intel Xeon Silver 4110 (16 Cores, 2.10 GHz)",
                 'keyName': 'INTEL_INTEL_XEON_4110_2_10',
                 'prices': [
                     {
-                        'capacityRestrictionMaximum': '2',
-                        'capacityRestrictionMinimum': '2',
                         'capacityRestrictionType': 'PROCESSOR',
                         'categories': [{'categoryCode': 'os'}],
                         'id': 201161,
@@ -744,3 +743,21 @@ def test_get_item_capacity_storage(self):
         item_capacity = self.ordering.get_item_capacity(items, ['READHEAVY_TIER', 'STORAGE_SPACE_FOR_2_IOPS_PER_GB'])
 
         self.assertEqual(1, int(item_capacity))
+
+    def test_get_item_capacity_intel(self):
+
+        items = [{
+            "capacity": "1",
+            "id": 6131,
+            "description": "Dual Intel Xeon E5-2690 v3 (24 Cores, 2.60 GHz)",
+            "keyName": "INTEL_XEON_2690_2_60",
+        },
+            {
+                "capacity": "1",
+                "id": 10201,
+                "keyName": "GUEST_CORE_1_DEDICATED",
+        }]
+
+        item_capacity = self.ordering.get_item_capacity(items, ['INTEL_XEON_2690_2_60', 'BANDWIDTH_20000_GB'])
+
+        self.assertEqual(24, int(item_capacity))