Skip to content

Commit dab2c05

Browse files
Merge pull request #2126 from allmightyspiff/issues2124
Added network flag to update-firmware
2 parents 16d18f2 + d5f1ed5 commit dab2c05

File tree

6 files changed

+145
-47
lines changed

6 files changed

+145
-47
lines changed

SoftLayer/CLI/formatting.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,7 @@ def no_going_back(confirmation):
259259
if not confirmation:
260260
confirmation = 'yes'
261261

262-
prompt = ('This action cannot be undone! Type "%s" or press Enter '
263-
'to abort' % confirmation)
262+
prompt = f"This action cannot be undone! Type '{confirmation}' or press Enter to abort"
264263

265264
ans = click.prompt(prompt, default='', show_default=False)
266265
if ans.lower() == str(confirmation):

SoftLayer/CLI/hardware/update_firmware.py

+14-6
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,23 @@
1212

1313
@click.command(cls=SoftLayer.CLI.command.SLCommand, )
1414
@click.argument('identifier')
15+
@click.option('-i', '--ipmi', is_flag=True, help="Update IPMI firmware")
16+
@click.option('-r', '--raid', is_flag=True, help="Update RAID firmware")
17+
@click.option('-b', '--bios', is_flag=True, help="Update BIOS firmware")
18+
@click.option('-d', '--harddrive', is_flag=True, help="Update Hard Drives firmware")
19+
@click.option('-n', '--network', is_flag=True, help="Update Network Card firmware")
1520
@environment.pass_env
16-
def cli(env, identifier):
17-
"""Update server firmware."""
21+
def cli(env, identifier, ipmi, raid, bios, harddrive, network):
22+
"""Update server firmware. By default will update all available server components."""
1823

1924
mgr = SoftLayer.HardwareManager(env.client)
2025
hw_id = helpers.resolve_id(mgr.resolve_ids, identifier, 'hardware')
21-
if not (env.skip_confirmations or
22-
formatting.confirm('This will power off the server with id %s and '
23-
'update device firmware. Continue?' % hw_id)):
26+
confirm_message = f"This will power off the server with id {hw_id} and update device firmware. Continue?"
27+
if not (env.skip_confirmations or formatting.confirm(confirm_message)):
2428
raise exceptions.CLIAbort('Aborted.')
2529

26-
mgr.update_firmware(hw_id)
30+
# If no options were specified, set them all to enabled.
31+
if not any([ipmi, raid, bios, harddrive, network]):
32+
ipmi = raid = bios = harddrive = network = 1
33+
mgr.update_firmware(hw_id, ipmi, raid, bios, harddrive, network)
34+
env.fout(f"[green]Firmware update for {identifier} started")

SoftLayer/managers/hardware.py

+19-17
Original file line numberDiff line numberDiff line change
@@ -723,44 +723,46 @@ def edit(self, hardware_id, userdata=None, hostname=None, domain=None,
723723

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

726-
def update_firmware(self,
727-
hardware_id,
728-
ipmi=True,
729-
raid_controller=True,
730-
bios=True,
731-
hard_drive=True):
726+
def update_firmware(self, hardware_id: int,
727+
ipmi: bool = True,
728+
raid_controller: bool = True,
729+
bios: bool = True,
730+
hard_drive: bool = True,
731+
network: bool = True):
732732
"""Update hardware firmware.
733733
734734
This will cause the server to be unavailable for ~20 minutes.
735+
https://sldn.softlayer.com/reference/services/SoftLayer_Hardware_Server/createFirmwareUpdateTransaction/
735736
736-
:param int hardware_id: The ID of the hardware to have its firmware
737-
updated.
737+
:param int hardware_id: The ID of the hardware to have its firmware updated.
738738
:param bool ipmi: Update the ipmi firmware.
739739
:param bool raid_controller: Update the raid controller firmware.
740740
:param bool bios: Update the bios firmware.
741741
:param bool hard_drive: Update the hard drive firmware.
742+
:param bool network: Update the network card firmware
742743
743744
Example::
744745
745746
# Check the servers active transactions to see progress
746747
result = mgr.update_firmware(hardware_id=1234)
747748
"""
748749

749-
return self.hardware.createFirmwareUpdateTransaction(
750-
bool(ipmi), bool(raid_controller), bool(bios), bool(hard_drive), id=hardware_id)
750+
return self.client.call(
751+
'SoftLayer_Hardware_Server', 'createFirmwareUpdateTransaction',
752+
bool(ipmi), bool(raid_controller), bool(bios), bool(hard_drive), bool(network), id=hardware_id
753+
)
751754

752-
def reflash_firmware(self,
753-
hardware_id,
754-
ipmi=True,
755-
raid_controller=True,
756-
bios=True):
755+
def reflash_firmware(self, hardware_id: int,
756+
ipmi: bool = True,
757+
raid_controller: bool = True,
758+
bios: bool = True,):
757759
"""Reflash hardware firmware.
758760
759761
This will cause the server to be unavailable for ~60 minutes.
760762
The firmware will not be upgraded but rather reflashed to the version installed.
763+
https://sldn.softlayer.com/reference/services/SoftLayer_Hardware_Server/createFirmwareReflashTransaction/
761764
762-
:param int hardware_id: The ID of the hardware to have its firmware
763-
reflashed.
765+
:param int hardware_id: The ID of the hardware to have its firmware reflashed.
764766
:param bool ipmi: Reflash the ipmi firmware.
765767
:param bool raid_controller: Reflash the raid controller firmware.
766768
:param bool bios: Reflash the bios firmware.

tests/CLI/modules/hardware/hardware_basic_tests.py

-20
Original file line numberDiff line numberDiff line change
@@ -498,26 +498,6 @@ def test_edit_server_userfile(self):
498498
self.assert_called_with('SoftLayer_Hardware_Server', 'setUserMetadata',
499499
args=(['some data'],), identifier=1000)
500500

501-
@mock.patch('SoftLayer.CLI.formatting.confirm')
502-
def test_update_firmware(self, confirm_mock):
503-
confirm_mock.return_value = True
504-
result = self.run_command(['server', 'update-firmware', '1000'])
505-
506-
self.assert_no_fail(result)
507-
self.assertEqual(result.output, "")
508-
self.assert_called_with('SoftLayer_Hardware_Server', 'createFirmwareUpdateTransaction',
509-
args=((1, 1, 1, 1)), identifier=1000)
510-
511-
@mock.patch('SoftLayer.CLI.formatting.confirm')
512-
def test_reflash_firmware(self, confirm_mock):
513-
confirm_mock.return_value = True
514-
result = self.run_command(['server', 'reflash-firmware', '1000'])
515-
516-
self.assert_no_fail(result)
517-
self.assertEqual(result.output, 'Successfully device firmware reflashed\n')
518-
self.assert_called_with('SoftLayer_Hardware_Server', 'createFirmwareReflashTransaction',
519-
args=((1, 1, 1)), identifier=1000)
520-
521501
def test_edit(self):
522502
result = self.run_command(['server', 'edit',
523503
'--domain=example.com',
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
"""
2+
SoftLayer.tests.CLI.modules.hardware.hardware_firmware_tests
3+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4+
5+
This suite is for the firmware related tests.
6+
7+
:license: MIT, see LICENSE for more details.
8+
"""
9+
from SoftLayer.CLI import exceptions
10+
from SoftLayer import testing
11+
from unittest import mock as mock
12+
13+
14+
class HardwareFirmwareTests(testing.TestCase):
15+
16+
@mock.patch('SoftLayer.CLI.formatting.confirm')
17+
def test_update_firmware(self, confirm_mock):
18+
confirm_mock.return_value = True
19+
result = self.run_command(['server', 'update-firmware', '1000'])
20+
self.assert_no_fail(result)
21+
self.assertIn("Firmware update for 1000 started", result.output)
22+
self.assert_called_with('SoftLayer_Hardware_Server', 'createFirmwareUpdateTransaction',
23+
args=((1, 1, 1, 1, 1)), identifier=1000)
24+
25+
@mock.patch('SoftLayer.CLI.formatting.confirm')
26+
def test_update_firmware_just_ipmi(self, confirm_mock):
27+
confirm_mock.return_value = True
28+
result = self.run_command(['server', 'update-firmware', '1000', '-i'])
29+
30+
self.assert_no_fail(result)
31+
self.assertIn("Firmware update for 1000 started", result.output)
32+
self.assert_called_with('SoftLayer_Hardware_Server', 'createFirmwareUpdateTransaction',
33+
args=((1, 0, 0, 0, 0)), identifier=1000)
34+
35+
@mock.patch('SoftLayer.CLI.formatting.confirm')
36+
def test_update_firmware_just_raid(self, confirm_mock):
37+
confirm_mock.return_value = True
38+
result = self.run_command(['server', 'update-firmware', '1000', '-r'])
39+
40+
self.assert_no_fail(result)
41+
self.assertIn("Firmware update for 1000 started", result.output)
42+
self.assert_called_with('SoftLayer_Hardware_Server', 'createFirmwareUpdateTransaction',
43+
args=((0, 1, 0, 0, 0)), identifier=1000)
44+
45+
@mock.patch('SoftLayer.CLI.formatting.confirm')
46+
def test_update_firmware_just_bios(self, confirm_mock):
47+
confirm_mock.return_value = True
48+
result = self.run_command(['server', 'update-firmware', '1000', '-b'])
49+
50+
self.assert_no_fail(result)
51+
self.assertIn("Firmware update for 1000 started", result.output)
52+
self.assert_called_with('SoftLayer_Hardware_Server', 'createFirmwareUpdateTransaction',
53+
args=((0, 0, 1, 0, 0)), identifier=1000)
54+
55+
@mock.patch('SoftLayer.CLI.formatting.confirm')
56+
def test_update_firmware_just_disk(self, confirm_mock):
57+
confirm_mock.return_value = True
58+
result = self.run_command(['server', 'update-firmware', '1000', '-d'])
59+
60+
self.assert_no_fail(result)
61+
self.assertIn("Firmware update for 1000 started", result.output)
62+
self.assert_called_with('SoftLayer_Hardware_Server', 'createFirmwareUpdateTransaction',
63+
args=((0, 0, 0, 1, 0)), identifier=1000)
64+
65+
@mock.patch('SoftLayer.CLI.formatting.confirm')
66+
def test_update_firmware_just_nic(self, confirm_mock):
67+
confirm_mock.return_value = True
68+
result = self.run_command(['server', 'update-firmware', '1000', '-n'])
69+
70+
self.assert_no_fail(result)
71+
self.assertIn("Firmware update for 1000 started", result.output)
72+
self.assert_called_with('SoftLayer_Hardware_Server', 'createFirmwareUpdateTransaction',
73+
args=((0, 0, 0, 0, 1)), identifier=1000)
74+
75+
@mock.patch('SoftLayer.CLI.formatting.confirm')
76+
def test_update_firmware_just_all(self, confirm_mock):
77+
confirm_mock.return_value = True
78+
result = self.run_command(['server', 'update-firmware', '1000', '-i', '-r', '-b', '-d', '-n'])
79+
80+
self.assert_no_fail(result)
81+
self.assertIn("Firmware update for 1000 started", result.output)
82+
self.assert_called_with('SoftLayer_Hardware_Server', 'createFirmwareUpdateTransaction',
83+
args=((1, 1, 1, 1, 1)), identifier=1000)
84+
85+
@mock.patch('SoftLayer.CLI.formatting.confirm')
86+
def test_update_firmware_no_confirm(self, confirm_mock):
87+
confirm_mock.return_value = False
88+
89+
result = self.run_command(['server', 'update-firmware', '1000'])
90+
self.assertEqual(result.exit_code, 2)
91+
self.assertIsInstance(result.exception, exceptions.CLIAbort)
92+
93+
@mock.patch('SoftLayer.CLI.formatting.confirm')
94+
def test_reflash_firmware(self, confirm_mock):
95+
confirm_mock.return_value = True
96+
result = self.run_command(['server', 'reflash-firmware', '1000'])
97+
98+
self.assert_no_fail(result)
99+
self.assertEqual(result.output, 'Successfully device firmware reflashed\n')
100+
self.assert_called_with('SoftLayer_Hardware_Server', 'createFirmwareReflashTransaction',
101+
args=((1, 1, 1)), identifier=1000)
102+
103+
@mock.patch('SoftLayer.CLI.formatting.confirm')
104+
def test_reflash_firmware_no_confirm(self, confirm_mock):
105+
confirm_mock.return_value = False
106+
107+
result = self.run_command(['server', 'reflash-firmware', '1000'])
108+
self.assertEqual(result.exit_code, 2)
109+
self.assertIsInstance(result.exception, exceptions.CLIAbort)

tests/managers/hardware_tests.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -543,14 +543,14 @@ def test_update_firmware(self):
543543

544544
self.assertEqual(result, True)
545545
self.assert_called_with('SoftLayer_Hardware_Server', 'createFirmwareUpdateTransaction',
546-
identifier=100, args=(1, 1, 1, 1))
546+
identifier=100, args=(1, 1, 1, 1, 1))
547547

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

551551
self.assertEqual(result, True)
552552
self.assert_called_with('SoftLayer_Hardware_Server', 'createFirmwareUpdateTransaction',
553-
identifier=100, args=(0, 1, 1, 0))
553+
identifier=100, args=(0, 1, 1, 0, 1))
554554

555555
def test_reflash_firmware(self):
556556
result = self.hardware.reflash_firmware(100)

0 commit comments

Comments
 (0)