Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Test cases implementation, pep8 compatible and slight code modifications
  • Loading branch information
Swapnil Khanapurkar committed Mar 24, 2014
commit e4da33999a5172f4e291d5a939b52cd7e100302e
30 changes: 26 additions & 4 deletions SoftLayer/CLI/modules/cci.py
Original file line number Diff line number Diff line change
Expand Up @@ -1072,19 +1072,41 @@ def execute(self, args):
"This action will incur charges on your account. "
"Continue?"):
item_id = []
import pdb;pdb.set_trace()
try:
package_items = cci.get_package_items_for_virtual_guest()
if data['cpus']:
item_id.append({'id': cci.get_item_id_for_upgrade(
item_id.append({'id': self.get_item_id_for_upgrade(
package_items, 'cpus', data['cpus'])})
if data['memory']:
item_id.append({'id': cci.get_item_id_for_upgrade(
item_id.append({'id': self.get_item_id_for_upgrade(
package_items, 'memory', data['memory'])})
if data['nic_speed']:
item_id.append({'id': cci.get_item_id_for_upgrade(
item_id.append({'id': self.get_item_id_for_upgrade(
package_items, 'nic_speed',
data['nic_speed'])})
cci.upgrade(instance_id, item_id)
except:
raise CLIAbort('CCI Upgrade Failed')

def get_item_id_for_upgrade(self, package_items, option, value):
"""
Find the item ids for the parameters you want to upgrade to.
:param list package_items: Contains all the items related to an CCI
:param string option: Describes type of paramter to be upgraded
:param int value: The value of the parameter to be upgraded
"""
id = {'memory': 3, 'cpus': 80, 'nic_speed': 26,
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not use id as object or function name. It's might confuse with built-in python id function. Can you use plural ids?

'First Disk': 81, 'Second Disk': 82, 'Third Disk': 92,
'Fourth Disk': 93, 'Fifth Disk': 116}
f = 0
for item in package_items:
if len(filter(lambda x: x.get('id') == id[option], \
item['categories'])) \
and item.get('capacity') == str(value):
if option == 'cpus' or option =='nic_speed':
if f == 1:
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is this f? I'm unable to infer its purpose.

return item['prices'][0]['id']
else:
f = f + 1
else:
return item['prices'][0]['id']
23 changes: 0 additions & 23 deletions SoftLayer/managers/cci.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,26 +516,3 @@ def get_package_items_for_virtual_guest(self):
mask = "mask[capacity,prices.id,categories[name,id]]"
package = self.client['Product_Package']
return package.getItems(id=46, mask=mask)

def get_item_id_for_upgrade(self, package_items, option, value):
"""
Find the item ids for the parameters you want to upgrade to.
:param list package_items: Contains all the items related to an CCI
:param string option: Describes type of paramter to be upgraded
:param int value: The value of the parameter to be upgraded
"""
id = {'memory': 3, 'cpus': 80, 'nic_speed': 26,
'First Disk': 81, 'Second Disk': 82, 'Third Disk': 92,
'Fourth Disk': 93, 'Fifth Disk': 116}
f = 0
for item in package_items:
if len(filter(lambda x: x.get('id') == id[option], \
item['categories'])) \
and item.get('capacity') == str(value):
if option == 'cpus' or option =='nic_speed':
if f == 1:
return item['prices'][0]['id']
else:
f = f + 1
else:
return item['prices'][0]['id']
1 change: 1 addition & 0 deletions SoftLayer/tests/fixtures/Virtual_Guest.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,5 +214,6 @@
generateOrderTemplate = {}
setUserMetadata = ['meta']
reloadOperatingSystem = 'OK'
rebootSoft = True

createArchiveTransaction = {}
37 changes: 22 additions & 15 deletions SoftLayer/tests/managers/cci_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,35 +532,42 @@ def test_captures(self):
archive.called_once_with('a', [{"device": 0, "uuid": 1},
{"device": 2, "uuid": 2}], "", id=1)


def test_upgrade_(self):
def test_upgrade(self):
# Testing Upgrade
orderClient = self.client['Product_Order']

# test memory/RAM upgrade
self.cci.upgrade(1, memory = 2048)

# test single upgrade
item_ids = [{'id': 1024}]
self.cci.upgrade(1, item_ids)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are we testing here? Nothing seems to be getting asserted after this.


# test single upgrade with rebot
item_ids = [{'id': 1024}]
self.cci.upgrade(1, item_ids, reboot = True)

# Now test a blank upgrade
self.assertTrue(self.cci.upgrade, 1)

# Finally, test a full Upgrade
args = {
'cpus': 2,
'memory': 2048,
'disk': [25,50],
'nic_speed': 100 }
self.cci.upgrade(1, **args)
item_ids = [{'id': 1}, {'id': 2}, {'id': 3}]
self.cci.upgrade(1, item_ids)
order = self.test_ordercontainer_options()
orderClient.verifyOrder.called_once_with(order)
orderClient.placeOrder.called_once_with(order)

def test_package_ids_for_virtual_guest(self):
result = self.cci.get_package_items_for_virtual_guest()[0]
self.assertEqual(4444, result['prices'][0]['id'])

def test_ordercontainer_options(self):
orderContainer = {}
orderContainer['complexType'] = \
'SoftLayer_Container_Product_Order_Virtual_Guest_Upgrade'
orderContainer['virtualGuests'] = [{'id': 1}]
orderContainer['prices'] = [{'id': 1645}]
orderContainer['properties'] = [{'name': 'MAINTENANCE_WINDOW',
'value':'2014-03-21 03:12:47.942307'}]
orderClient.verifyOrder.assert_called_once_with(orderContainer)
orderClient.placeOrder.assert_called_once_with(orderContainer)

'value': '2014-03-21 03:12:47.942307'}]
return orderContainer


class CCIWaitReadyGoTests(unittest.TestCase):

Expand Down