Skip to content

Commit

Permalink
Merge pull request #481 from sudorandom/firmware
Browse files Browse the repository at this point in the history
Update Firmware CLI/Manager method
  • Loading branch information
sudorandom committed Feb 16, 2015
2 parents 079d529 + 20ebcc5 commit 2fef3fd
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 5 deletions.
1 change: 1 addition & 0 deletions SoftLayer/CLI/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@
('server:reboot', 'SoftLayer.CLI.server.power:reboot'),
('server:reload', 'SoftLayer.CLI.server.reload:cli'),
('server:credentials', 'SoftLayer.CLI.server.credentials:cli'),
('server:update-firmware', 'SoftLayer.CLI.server.update_firmware:cli'),

('snapshot', 'SoftLayer.CLI.snapshot'),
('snapshot:cancel', 'SoftLayer.CLI.snapshot.cancel:cli'),
Expand Down
27 changes: 27 additions & 0 deletions SoftLayer/CLI/server/update_firmware.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""Update firmware."""
# :license: MIT, see LICENSE for more details.

import SoftLayer
from SoftLayer.CLI import environment
from SoftLayer.CLI import exceptions
from SoftLayer.CLI import formatting
from SoftLayer.CLI import helpers

import click


@click.command()
@click.argument('identifier')
@environment.pass_env
def cli(env, identifier):
"""Update server firmware."""

mgr = SoftLayer.HardwareManager(env.client)
hw_id = helpers.resolve_id(mgr.resolve_ids, identifier, 'hardware')
if env.skip_confirmations or formatting.confirm('This will power off the '
'server with id %s and '
'update device firmware. '
'Continue?' % hw_id):
mgr.update_firmware(hw_id)
else:
raise exceptions.CLIAbort('Aborted.')
22 changes: 22 additions & 0 deletions SoftLayer/managers/hardware.py
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,28 @@ def edit(self, hardware_id, userdata=None, hostname=None, domain=None,

return self.hardware.editObject(obj, id=hardware_id)

def update_firmware(self,
hardware_id,
ipmi=True,
raid_controller=True,
bios=True,
hard_drive=True):
"""Update hardware firmware.
This will cause the server to be unavailable for ~20 minutes.
:param int hardware_id: The ID of the hardware to have its firmware
updated.
:param bool ipmi: Update the ipmi firmware.
:param bool raid_controller: Update the raid controller firmware.
:param bool bios: Update the bios firmware.
:param bool hard_drive: Update the hard drive firmware.
"""

return self.hardware.createFirmwareUpdateTransaction(
bool(ipmi), bool(raid_controller), bool(bios), bool(hard_drive),
id=hardware_id)


def get_default_value(package_options, category, hourly=False):
"""Returns the default price ID for the specified category.
Expand Down
1 change: 1 addition & 0 deletions SoftLayer/testing/fixtures/SoftLayer_Hardware_Server.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
rebootSoft = True
rebootDefault = True
rebootHard = True
createFirmwareUpdateTransaction = True
setUserMetadata = ['meta']
reloadOperatingSystem = 'OK'
getReverseDomainRecords = [
Expand Down
11 changes: 11 additions & 0 deletions SoftLayer/tests/CLI/modules/server_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -636,3 +636,14 @@ def test_get_default_value_returns_none_for_unknown_category(self):
option_mock = {'categories': {'cat1': []}}
output = create._get_default_value(option_mock, 'nope')
self.assertEqual(None, output)

@mock.patch('SoftLayer.CLI.formatting.confirm')
def test_update_firmware(self, confirm_mock):
confirm_mock.return_value = True
result = self.run_command(['server', 'update-firmware', '1000'])

self.assertEqual(result.exit_code, 0)
self.assertEqual(result.output, "")
self.assert_called_with('SoftLayer_Hardware_Server',
'createFirmwareUpdateTransaction',
args=((1, 1, 1, 1)), identifier=1000)
23 changes: 20 additions & 3 deletions SoftLayer/tests/managers/hardware_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,10 +473,27 @@ def test_edit(self):
identifier=100)

def test_rescue(self):
# Test rescue environment
restult = self.hardware.rescue(1234)
result = self.hardware.rescue(1234)

self.assertEqual(restult, True)
self.assertEqual(result, True)
self.assert_called_with('SoftLayer_Hardware_Server',
'bootToRescueLayer',
identifier=1234)

def test_update_firmware(self):
result = self.hardware.update_firmware(100)

self.assertEqual(result, True)
self.assert_called_with('SoftLayer_Hardware_Server',
'createFirmwareUpdateTransaction',
identifier=100, args=(1, 1, 1, 1))

def test_update_firmware_selective(self):
result = self.hardware.update_firmware(100,
ipmi=False,
hard_drive=False)

self.assertEqual(result, True)
self.assert_called_with('SoftLayer_Hardware_Server',
'createFirmwareUpdateTransaction',
identifier=100, args=(0, 1, 1, 0))
4 changes: 2 additions & 2 deletions SoftLayer/transports.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,8 @@ def __call__(self, call):
module_path = 'SoftLayer.testing.fixtures.%s' % call.service
module = importlib.import_module(module_path)
except ImportError:
raise NotImplementedError('%s::%s fixture is not implemented'
% (call.service, call.method))
raise NotImplementedError('%s fixture is not implemented'
% call.service)
try:
return getattr(module, call.method)
except AttributeError:
Expand Down

0 comments on commit 2fef3fd

Please sign in to comment.