From 4ab3caedc5fb1d81c3c97392a2cacb5c438a19e7 Mon Sep 17 00:00:00 2001 From: Aparna Date: Thu, 3 Aug 2017 11:26:46 +0000 Subject: [PATCH] Renaming clean step 'update_firmware' to 'update_firmware_sum' This commit renames the 'update_firmware' clean step to 'update_firmware_sum' and also changes needed to support Smart Update Manager. Change-Id: I2dcb4ab25c0465e04db77f5d759abd44bb06c652 --- proliantutils/exception.py | 10 +- .../ipa_hw_manager/hardware_manager.py | 14 +- proliantutils/{hpsum => sum}/__init__.py | 0 .../sum_controller.py} | 82 +++++----- .../ipa_hw_manager/test_hardware_manager.py | 11 +- .../tests/{hpsum => sum}/__init__.py | 0 .../sum_sample_output.py} | 6 +- .../test_sum_controller.py} | 153 +++++++++++------- 8 files changed, 156 insertions(+), 120 deletions(-) rename proliantutils/{hpsum => sum}/__init__.py (100%) rename proliantutils/{hpsum/hpsum_controller.py => sum/sum_controller.py} (70%) rename proliantutils/tests/{hpsum => sum}/__init__.py (100%) rename proliantutils/tests/{hpsum/hpsum_sample_output.py => sum/sum_sample_output.py} (97%) rename proliantutils/tests/{hpsum/test_hpsum_controller.py => sum/test_sum_controller.py} (68%) diff --git a/proliantutils/exception.py b/proliantutils/exception.py index b272749e..0c455a84 100644 --- a/proliantutils/exception.py +++ b/proliantutils/exception.py @@ -185,21 +185,21 @@ class ImageRefValidationFailed(ProliantUtilsException): super(ImageRefValidationFailed, self).__init__(message) -class HpsumOperationError(ProliantUtilsException): - """Hpsum based firmware update operation error. +class SUMOperationError(ProliantUtilsException): + """SUM based firmware update operation error. This exception is used when a problem is encountered in - executing a hpsum operation. + executing a SUM operation. """ - message = ("An error occurred while performing hpsum based firmware " + message = ("An error occurred while performing SUM based firmware " "update, reason: %(reason)s") def __init__(self, message=None, **kwargs): if not message: message = self.message % kwargs - super(HpsumOperationError, self).__init__(message) + super(SUMOperationError, self).__init__(message) class RedfishError(ProliantUtilsException): diff --git a/proliantutils/ipa_hw_manager/hardware_manager.py b/proliantutils/ipa_hw_manager/hardware_manager.py index 41b00115..758c06fe 100644 --- a/proliantutils/ipa_hw_manager/hardware_manager.py +++ b/proliantutils/ipa_hw_manager/hardware_manager.py @@ -15,7 +15,7 @@ from ironic_python_agent import hardware from proliantutils.hpssa import manager as hpssa_manager -from proliantutils.hpsum import hpsum_controller +from proliantutils.sum import sum_controller class ProliantHardwareManager(hardware.GenericHardwareManager): @@ -45,7 +45,7 @@ class ProliantHardwareManager(hardware.GenericHardwareManager): {'step': 'erase_devices', 'interface': 'deploy', 'priority': 0}, - {'step': 'update_firmware', + {'step': 'update_firmware_sum', 'interface': 'management', 'priority': 0}] @@ -109,15 +109,15 @@ class ProliantHardwareManager(hardware.GenericHardwareManager): self).erase_devices(node, port)) return result - def update_firmware(self, node, port): - """Performs HPSUM based firmware update on the bare metal node. + def update_firmware_sum(self, node, port): + """Performs SUM based firmware update on the bare metal node. This method performs firmware update on all or some of the firmware components on the bare metal node. :returns: A string with return code and the statistics of updated/failed components. - :raises: HpsumOperationError, when the hpsum firmware update operation - on the node fails. + :raises: SUMOperationError, when the SUM based firmware update + operation on the node fails. """ - return hpsum_controller.update_firmware(node) + return sum_controller.update_firmware(node) diff --git a/proliantutils/hpsum/__init__.py b/proliantutils/sum/__init__.py similarity index 100% rename from proliantutils/hpsum/__init__.py rename to proliantutils/sum/__init__.py diff --git a/proliantutils/hpsum/hpsum_controller.py b/proliantutils/sum/sum_controller.py similarity index 70% rename from proliantutils/hpsum/hpsum_controller.py rename to proliantutils/sum/sum_controller.py index a101cf14..11581180 100644 --- a/proliantutils/hpsum/hpsum_controller.py +++ b/proliantutils/sum/sum_controller.py @@ -32,7 +32,9 @@ from proliantutils import utils HPSUM_LOCATION = 'hp/swpackages/hpsum' -# List of log files created by hpsum based firmware update. +WAIT_TIME_DISK_LABEL_TO_BE_VISIBLE = 5 + +# List of log files created by SUM based firmware update. OUTPUT_FILES = ['/var/hp/log/localhost/hpsum_log.txt', '/var/hp/log/localhost/hpsum_detail_log.txt'] @@ -46,62 +48,61 @@ EXIT_CODE_TO_STRING = { } -def _execute_hpsum(hpsum_file_path, components=None): - """Executes the hpsum firmware update command. +def _execute_sum(sum_file_path, components=None): + """Executes the SUM based firmware update command. - This method executes the hpsum firmware update command to update the + This method executes the SUM based firmware update command to update the components specified, if not, it performs update on all the firmware components on th server. - :param hpsum_file_path: A string with the path to the hpsum binary to be + :param sum_file_path: A string with the path to the SUM binary to be executed :param components: A list of components to be updated. If it is None, all the firmware components are updated. :returns: A string with the statistics of the updated/failed components. - :raises: HpsumOperationError, when the hpsum firmware update operation on - the node fails. + :raises: SUMOperationError, when the SUM based firmware update operation + on the node fails. """ cmd = ' --c ' + ' --c '.join(components) if components else '' try: - processutils.execute(hpsum_file_path, "--s", "--romonly", cmd) + processutils.execute(sum_file_path, '--s', '--romonly', cmd) except processutils.ProcessExecutionError as e: - result = _parse_hpsum_ouput(e.exit_code) + result = _parse_sum_ouput(e.exit_code) if result: return result else: - msg = ("Unable to perform hpsum firmware update on the node. " - "Error: " + str(e)) - raise exception.HpsumOperationError(reason=msg) + raise exception.SUMOperationError(reason=str(e)) def _get_log_file_data_as_encoded_content(): """Gzip and base64 encode files and BytesIO buffers. - This method gets the log files created by hpsum based + This method gets the log files created by SUM based firmware update and tar zip the files. :returns: A gzipped and base64 encoded string as text. """ with io.BytesIO() as fp: with tarfile.open(fileobj=fp, mode='w:gz') as tar: for f in OUTPUT_FILES: - tar.add(f) + if os.path.isfile(f): + tar.add(f) fp.seek(0) return base64.encode_as_bytes(fp.getvalue()) -def _parse_hpsum_ouput(exit_code): - """Parse the hpsum output log file. +def _parse_sum_ouput(exit_code): + """Parse the SUM output log file. - This method parses through the hpsum log file in the - default location to return the hpsum update status. Sample return + This method parses through the SUM log file in the + default location to return the SUM update status. Sample return string: "Summary: The installation of the component failed. Status of updated components: Total: 5 Success: 4 Failed: 1" - :param exit_code: A integer returned by the hpsum after command execution. + :param exit_code: A integer returned by the SUM after command execution. :returns: A string with the statistics of the updated/failed components and 'None' when the exit_code is not 0, 1, 3 or 253. """ @@ -140,29 +141,28 @@ def _parse_hpsum_ouput(exit_code): def update_firmware(node): - """Performs hpsum firmware update on the node. + """Performs SUM based firmware update on the node. - This method performs hpsum firmware update by mounting the + This method performs SUM firmware update by mounting the SPP ISO on the node. It performs firmware update on all or some of the firmware components. :param node: A node object of type dict. :returns: Operation Status string. - :raises: HpsumOperationError, when the vmedia device is not found or + :raises: SUMOperationError, when the vmedia device is not found or when the mount operation fails or when the image validation fails. :raises: IloConnectionError, when the iLO connection fails. :raises: IloError, when vmedia eject or insert operation fails. """ - hpsum_update_iso = node['clean_step']['args']['firmware_images'][0].get( - 'url') + sum_update_iso = node['clean_step']['args'].get('url') - # Validates the http image reference for hpsum update ISO. + # Validates the http image reference for SUM update ISO. try: - utils.validate_href(hpsum_update_iso) + utils.validate_href(sum_update_iso) except exception.ImageRefValidationFailed as e: - raise exception.HpsumOperationError(reason=e) + raise exception.SUMOperationError(reason=e) - # Ejects the CDROM device in the iLO and inserts the hpsum update ISO + # Ejects the CDROM device in the iLO and inserts the SUM update ISO # to the CDROM device. info = node.get('driver_info') ilo_object = client.IloClient(info.get('ilo_address'), @@ -170,28 +170,27 @@ def update_firmware(node): info.get('ilo_password')) ilo_object.eject_virtual_media('CDROM') - ilo_object.insert_virtual_media(hpsum_update_iso, 'CDROM') + ilo_object.insert_virtual_media(sum_update_iso, 'CDROM') # Waits for the OS to detect the disk and update the label file. SPP ISO # is identified by matching its label. - time.sleep(5) + time.sleep(WAIT_TIME_DISK_LABEL_TO_BE_VISIBLE) vmedia_device_dir = "/dev/disk/by-label/" for file in os.listdir(vmedia_device_dir): if fnmatch.fnmatch(file, 'SPP*'): vmedia_device_file = os.path.join(vmedia_device_dir, file) if not os.path.exists(vmedia_device_file): - msg = "Unable to find the virtual media device for HPSUM" - raise exception.HpsumOperationError(reason=msg) + msg = "Unable to find the virtual media device for SUM" + raise exception.SUMOperationError(reason=msg) # Validates the SPP ISO image for any file corruption using the checksum # of the ISO file. - expected_checksum = node['clean_step']['args']['firmware_images'][0].get( - 'checksum') + expected_checksum = node['clean_step']['args'].get('checksum') try: utils.verify_image_checksum(vmedia_device_file, expected_checksum) except exception.ImageRefValidationFailed as e: - raise exception.HpsumOperationError(reason=e) + raise exception.SUMOperationError(reason=e) # Mounts SPP ISO on a temporary directory. vmedia_mount_point = tempfile.mkdtemp() @@ -202,17 +201,14 @@ def update_firmware(node): except processutils.ProcessExecutionError as e: msg = ("Unable to mount virtual media device %(device)s: " "%(error)s" % {'device': vmedia_device_file, 'error': e}) - raise exception.HpsumOperationError(reason=msg) + raise exception.SUMOperationError(reason=msg) - # Executes the hpsum based firmware update by passing the default hpsum + # Executes the SUM based firmware update by passing the default hpsum # executable path and the components specified, if any. - hpsum_file_path = os.path.join(vmedia_mount_point, HPSUM_LOCATION) - components = node['clean_step']['args']['firmware_images'][0].get( - 'component') - if components: - components = components.strip().split(',') + sum_file_path = os.path.join(vmedia_mount_point, HPSUM_LOCATION) + components = node['clean_step']['args'].get('components') - result = _execute_hpsum(hpsum_file_path, components=components) + result = _execute_sum(sum_file_path, components=components) processutils.trycmd("umount", vmedia_mount_point) finally: diff --git a/proliantutils/tests/ipa_hw_manager/test_hardware_manager.py b/proliantutils/tests/ipa_hw_manager/test_hardware_manager.py index 4f9d47b4..97206560 100644 --- a/proliantutils/tests/ipa_hw_manager/test_hardware_manager.py +++ b/proliantutils/tests/ipa_hw_manager/test_hardware_manager.py @@ -19,6 +19,7 @@ import testtools from proliantutils import exception from proliantutils.hpssa import manager as hpssa_manager from proliantutils.ipa_hw_manager import hardware_manager +from proliantutils.sum import sum_controller ironic_python_agent = importutils.try_import('ironic_python_agent') @@ -40,7 +41,7 @@ class ProliantHardwareManagerTestCase(testtools.TestCase): {'step': 'erase_devices', 'interface': 'deploy', 'priority': 0}, - {'step': 'update_firmware', + {'step': 'update_firmware_sum', 'interface': 'management', 'priority': 0}], self.hardware_manager.get_clean_steps("", "")) @@ -91,3 +92,11 @@ class ProliantHardwareManagerTestCase(testtools.TestCase): node, port) self.assertIn(value, str(exc)) + + @mock.patch.object(sum_controller, 'update_firmware') + def test_update_firmware_sum(self, update_mock): + update_mock.return_value = "log files" + node = {'foo': 'bar'} + ret = self.hardware_manager.update_firmware_sum(node, "") + update_mock.assert_called_once_with(node) + self.assertEqual('log files', ret) diff --git a/proliantutils/tests/hpsum/__init__.py b/proliantutils/tests/sum/__init__.py similarity index 100% rename from proliantutils/tests/hpsum/__init__.py rename to proliantutils/tests/sum/__init__.py diff --git a/proliantutils/tests/hpsum/hpsum_sample_output.py b/proliantutils/tests/sum/sum_sample_output.py similarity index 97% rename from proliantutils/tests/hpsum/hpsum_sample_output.py rename to proliantutils/tests/sum/sum_sample_output.py index 53e3b00a..ce67ad2d 100644 --- a/proliantutils/tests/hpsum/hpsum_sample_output.py +++ b/proliantutils/tests/sum/sum_sample_output.py @@ -12,9 +12,9 @@ # License for the specific language governing permissions and limitations # under the License. -MODULE = "HPSUM" +MODULE = "SUM" -HPSUM_OUTPUT_DATA = """ +SUM_OUTPUT_DATA = """ Scouting completed, node type:LINUX Inventory started Inventory completed @@ -58,7 +58,7 @@ Deployed Components: Exit status: 0 """ -HPSUM_OUTPUT_DATA_FAILURE = """ +SUM_OUTPUT_DATA_FAILURE = """ Scouting completed, node type:LINUX Inventory started Inventory completed diff --git a/proliantutils/tests/hpsum/test_hpsum_controller.py b/proliantutils/tests/sum/test_sum_controller.py similarity index 68% rename from proliantutils/tests/hpsum/test_hpsum_controller.py rename to proliantutils/tests/sum/test_sum_controller.py index abcbb4f2..fe332cd4 100644 --- a/proliantutils/tests/hpsum/test_hpsum_controller.py +++ b/proliantutils/tests/sum/test_sum_controller.py @@ -23,35 +23,34 @@ from oslo_serialization import base64 import testtools from proliantutils import exception -from proliantutils.hpsum import hpsum_controller from proliantutils.ilo import client as ilo_client -from proliantutils.tests.hpsum import hpsum_sample_output as constants +from proliantutils.sum import sum_controller +from proliantutils.tests.sum import sum_sample_output as constants from proliantutils import utils -class HpsumFirmwareUpdateTest(testtools.TestCase): +class SUMFirmwareUpdateTest(testtools.TestCase): def setUp(self): - super(HpsumFirmwareUpdateTest, self).setUp() + super(SUMFirmwareUpdateTest, self).setUp() self.info = {'ilo_address': '1.2.3.4', 'ilo_password': '12345678', 'ilo_username': 'admin'} clean_step = { 'interface': 'management', - 'step': 'update_firmware', - 'args': {'firmware_update_mode': u'hpsum', - 'firmware_images': [{'url': 'http://1.2.3.4/SPP.iso', - 'checksum': '1234567890'}]}} + 'step': 'update_firmware_sum', + 'args': {'url': 'http://1.2.3.4/SPP.iso', + 'checksum': '1234567890'}} self.node = {'driver_info': self.info, 'clean_step': clean_step} - @mock.patch.object(hpsum_controller, + @mock.patch.object(sum_controller, '_get_log_file_data_as_encoded_content') - @mock.patch.object(hpsum_controller, 'open', - mock.mock_open(read_data=constants.HPSUM_OUTPUT_DATA)) + @mock.patch.object(sum_controller, 'open', + mock.mock_open(read_data=constants.SUM_OUTPUT_DATA)) @mock.patch.object(os.path, 'exists') @mock.patch.object(processutils, 'execute') - def test_execute_hpsum(self, execute_mock, exists_mock, log_mock): + def test_execute_sum(self, execute_mock, exists_mock, log_mock): exists_mock.return_value = True log_mock.return_value = "aaabbbcccdddd" value = ("hpsum_service_x64 started successfully. Sending Shutdown " @@ -65,13 +64,13 @@ class HpsumFirmwareUpdateTest(testtools.TestCase): "Failed: 0.") } - stdout = hpsum_controller._execute_hpsum("hpsum", components=None) + stdout = sum_controller._execute_sum("hpsum", components=None) self.assertEqual(ret_value, stdout) - execute_mock.assert_called_once_with("hpsum", "--s", "--romonly", "") + execute_mock.assert_called_once_with('hpsum', '--s', '--romonly', '') @mock.patch.object(processutils, 'execute') - def test_execute_hpsum_with_args(self, execute_mock): + def test_execute_sum_with_args(self, execute_mock): value = ("hpsum_service_x64 started successfully. Sending Shutdown " "request to engine. Successfully shutdown the service.") execute_mock.side_effect = processutils.ProcessExecutionError( @@ -79,22 +78,22 @@ class HpsumFirmwareUpdateTest(testtools.TestCase): ret_value = ("Summary: The smart component was not installed. Node is " "already up-to-date.") - stdout = hpsum_controller._execute_hpsum("hpsum", - components=["foo", "bar"]) + stdout = sum_controller._execute_sum("hpsum", + components=["foo", "bar"]) execute_mock.assert_called_once_with( "hpsum", "--s", "--romonly", " --c foo --c bar") self.assertEqual(ret_value, stdout) - @mock.patch.object(hpsum_controller, + @mock.patch.object(sum_controller, '_get_log_file_data_as_encoded_content') @mock.patch.object( - hpsum_controller, 'open', - mock.mock_open(read_data=constants.HPSUM_OUTPUT_DATA_FAILURE)) + sum_controller, 'open', + mock.mock_open(read_data=constants.SUM_OUTPUT_DATA_FAILURE)) @mock.patch.object(os.path, 'exists') @mock.patch.object(processutils, 'execute') - def test_execute_hpsum_update_fails(self, execute_mock, exists_mock, - log_mock): + def test_execute_sum_update_fails(self, execute_mock, exists_mock, + log_mock): exists_mock.return_value = True log_mock.return_value = "aaabbbcccdddd" ret = { @@ -108,33 +107,34 @@ class HpsumFirmwareUpdateTest(testtools.TestCase): execute_mock.side_effect = processutils.ProcessExecutionError( stdout=value, stderr=None, exit_code=253) - stdout = hpsum_controller._execute_hpsum("hpsum", components=None) + stdout = sum_controller._execute_sum("hpsum", components=None) self.assertEqual(ret, stdout) - execute_mock.assert_called_once_with("hpsum", "--s", "--romonly", "") + execute_mock.assert_called_once_with( + "hpsum", "--s", "--romonly", "") @mock.patch.object(os.path, 'exists') @mock.patch.object(processutils, 'execute') - def test_execute_hpsum_fails(self, execute_mock, exists_mock): + def test_execute_sum_fails(self, execute_mock, exists_mock): exists_mock.return_value = False value = ("Error: Cannot launch hpsum_service_x64 locally. Reason: " "General failure.") execute_mock.side_effect = processutils.ProcessExecutionError( stdout=value, stderr=None, exit_code=255) - ex = self.assertRaises(exception.HpsumOperationError, - hpsum_controller._execute_hpsum, "hpsum", + ex = self.assertRaises(exception.SUMOperationError, + sum_controller._execute_sum, "hpsum", None) self.assertIn(value, str(ex)) def test_get_log_file_data_as_encoded_content(self): - log_file_content = b'Sample Data for testing hpsum log output' + log_file_content = b'Sample Data for testing SUM log output' file_object = tempfile.NamedTemporaryFile(delete=False) file_object.write(log_file_content) file_object.close() - hpsum_controller.OUTPUT_FILES = [file_object.name] + sum_controller.OUTPUT_FILES = [file_object.name] - base64_encoded_text = (hpsum_controller. + base64_encoded_text = (sum_controller. _get_log_file_data_as_encoded_content()) tar_gzipped_content = base64.decode_as_bytes(base64_encoded_text) @@ -150,7 +150,7 @@ class HpsumFirmwareUpdateTest(testtools.TestCase): @mock.patch.object(utils, 'validate_href') @mock.patch.object(utils, 'verify_image_checksum') - @mock.patch.object(hpsum_controller, '_execute_hpsum') + @mock.patch.object(sum_controller, '_execute_sum') @mock.patch.object(os, 'listdir') @mock.patch.object(shutil, 'rmtree', autospec=True) @mock.patch.object(tempfile, 'mkdtemp', autospec=True) @@ -160,27 +160,27 @@ class HpsumFirmwareUpdateTest(testtools.TestCase): @mock.patch.object(ilo_client, 'IloClient', spec_set=True, autospec=True) def test_update_firmware(self, client_mock, execute_mock, mkdir_mock, exists_mock, mkdtemp_mock, rmtree_mock, - listdir_mock, execute_hpsum_mock, + listdir_mock, execute_sum_mock, verify_image_mock, validate_mock): ilo_mock_object = client_mock.return_value eject_media_mock = ilo_mock_object.eject_virtual_media insert_media_mock = ilo_mock_object.insert_virtual_media - execute_hpsum_mock.return_value = 'SUCCESS' + execute_sum_mock.return_value = 'SUCCESS' listdir_mock.return_value = ['SPP_LABEL'] mkdtemp_mock.return_value = "/tempdir" null_output = ["", ""] exists_mock.side_effect = [True, False] execute_mock.side_effect = [null_output, null_output] - ret_val = hpsum_controller.update_firmware(self.node) + ret_val = sum_controller.update_firmware(self.node) eject_media_mock.assert_called_once_with('CDROM') insert_media_mock.assert_called_once_with('http://1.2.3.4/SPP.iso', 'CDROM') execute_mock.assert_any_call('mount', "/dev/disk/by-label/SPP_LABEL", "/tempdir") - execute_hpsum_mock.assert_any_call('/tempdir/hp/swpackages/hpsum', - components=None) + execute_sum_mock.assert_any_call('/tempdir/hp/swpackages/hpsum', + components=None) exists_mock.assert_called_once_with("/dev/disk/by-label/SPP_LABEL") execute_mock.assert_any_call('umount', "/tempdir") mkdtemp_mock.assert_called_once_with() @@ -196,8 +196,8 @@ class HpsumFirmwareUpdateTest(testtools.TestCase): validate_href_mock.side_effect = exception.ImageRefValidationFailed( reason=value, image_href=invalid_file_path) - exc = self.assertRaises(exception.HpsumOperationError, - hpsum_controller.update_firmware, self.node) + exc = self.assertRaises(exception.SUMOperationError, + sum_controller.update_firmware, self.node) self.assertIn(value, str(exc)) @mock.patch.object(utils, 'validate_href') @@ -206,12 +206,12 @@ class HpsumFirmwareUpdateTest(testtools.TestCase): validate_mock): ilo_mock_object = client_mock.return_value eject_media_mock = ilo_mock_object.eject_virtual_media - value = ("Unable to attach hpsum SPP iso http://1.2.3.4/SPP.iso " + value = ("Unable to attach SUM SPP iso http://1.2.3.4/SPP.iso " "to the iLO") eject_media_mock.side_effect = exception.IloError(value) exc = self.assertRaises(exception.IloError, - hpsum_controller.update_firmware, self.node) + sum_controller.update_firmware, self.node) self.assertEqual(value, str(exc)) @mock.patch.object(utils, 'validate_href') @@ -228,17 +228,48 @@ class HpsumFirmwareUpdateTest(testtools.TestCase): listdir_mock.return_value = ['SPP_LABEL'] exists_mock.return_value = False - msg = ("An error occurred while performing hpsum based firmware " + msg = ("An error occurred while performing SUM based firmware " "update, reason: Unable to find the virtual media device " - "for HPSUM") - exc = self.assertRaises(exception.HpsumOperationError, - hpsum_controller.update_firmware, self.node) + "for SUM") + exc = self.assertRaises(exception.SUMOperationError, + sum_controller.update_firmware, self.node) self.assertEqual(msg, str(exc)) eject_media_mock.assert_called_once_with('CDROM') insert_media_mock.assert_called_once_with('http://1.2.3.4/SPP.iso', 'CDROM') exists_mock.assert_called_once_with("/dev/disk/by-label/SPP_LABEL") + @mock.patch.object(utils, 'validate_href') + @mock.patch.object(utils, 'verify_image_checksum') + @mock.patch.object(os, 'listdir') + @mock.patch.object(os.path, 'exists') + @mock.patch.object(ilo_client, 'IloClient', spec_set=True, autospec=True) + def test_update_firmware_invalid_checksum(self, client_mock, exists_mock, + listdir_mock, verify_image_mock, + validate_mock): + ilo_mock_object = client_mock.return_value + eject_media_mock = ilo_mock_object.eject_virtual_media + insert_media_mock = ilo_mock_object.insert_virtual_media + listdir_mock.return_value = ['SPP_LABEL'] + exists_mock.side_effect = [True, False] + + value = ("Error verifying image checksum. Image " + "http://1.2.3.4/SPP.iso failed to verify against checksum " + "123456789. Actual checksum is: xxxxxxxx") + + verify_image_mock.side_effect = exception.ImageRefValidationFailed( + reason=value, image_href='http://1.2.3.4/SPP.iso') + + self.assertRaisesRegex(exception.SUMOperationError, value, + sum_controller.update_firmware, self.node) + + verify_image_mock.assert_called_once_with( + '/dev/disk/by-label/SPP_LABEL', '1234567890') + eject_media_mock.assert_called_once_with('CDROM') + insert_media_mock.assert_called_once_with('http://1.2.3.4/SPP.iso', + 'CDROM') + exists_mock.assert_called_once_with("/dev/disk/by-label/SPP_LABEL") + @mock.patch.object(utils, 'validate_href') @mock.patch.object(utils, 'verify_image_checksum') @mock.patch.object(processutils, 'execute') @@ -261,20 +292,20 @@ class HpsumFirmwareUpdateTest(testtools.TestCase): msg = ("Unable to mount virtual media device " "/dev/disk/by-label/SPP_LABEL") - exc = self.assertRaises(exception.HpsumOperationError, - hpsum_controller.update_firmware, self.node) + exc = self.assertRaises(exception.SUMOperationError, + sum_controller.update_firmware, self.node) self.assertIn(msg, str(exc)) eject_media_mock.assert_called_once_with('CDROM') insert_media_mock.assert_called_once_with('http://1.2.3.4/SPP.iso', 'CDROM') exists_mock.assert_called_once_with("/dev/disk/by-label/SPP_LABEL") - @mock.patch.object(hpsum_controller, + @mock.patch.object(sum_controller, '_get_log_file_data_as_encoded_content') - @mock.patch.object(hpsum_controller, 'open', - mock.mock_open(read_data=constants.HPSUM_OUTPUT_DATA)) + @mock.patch.object(sum_controller, 'open', + mock.mock_open(read_data=constants.SUM_OUTPUT_DATA)) @mock.patch.object(os.path, 'exists') - def test__parse_hpsum_ouput(self, exists_mock, log_mock): + def test__parse_sum_ouput(self, exists_mock, log_mock): exists_mock.return_value = True log_mock.return_value = "aaabbbcccdddd" expt_ret = {'Log Data': 'aaabbbcccdddd', @@ -282,18 +313,18 @@ class HpsumFirmwareUpdateTest(testtools.TestCase): "successfully. Status of updated components: " "Total: 2 Success: 2 Failed: 0.")} - ret = hpsum_controller._parse_hpsum_ouput(0) + ret = sum_controller._parse_sum_ouput(0) - exists_mock.assert_called_once_with(hpsum_controller.OUTPUT_FILES[0]) + exists_mock.assert_called_once_with(sum_controller.OUTPUT_FILES[0]) self.assertEqual(expt_ret, ret) - @mock.patch.object(hpsum_controller, + @mock.patch.object(sum_controller, '_get_log_file_data_as_encoded_content') @mock.patch.object( - hpsum_controller, 'open', - mock.mock_open(read_data=constants.HPSUM_OUTPUT_DATA_FAILURE)) + sum_controller, 'open', + mock.mock_open(read_data=constants.SUM_OUTPUT_DATA_FAILURE)) @mock.patch.object(os.path, 'exists') - def test__parse_hpsum_ouput_some_failed(self, exists_mock, log_mock): + def test__parse_sum_ouput_some_failed(self, exists_mock, log_mock): exists_mock.return_value = True log_mock.return_value = "aaabbbcccdddd" expt_ret = {'Log Data': 'aaabbbcccdddd', @@ -301,17 +332,17 @@ class HpsumFirmwareUpdateTest(testtools.TestCase): "Status of updated components: Total: 2 " "Success: 1 Failed: 1.")} - ret = hpsum_controller._parse_hpsum_ouput(253) + ret = sum_controller._parse_sum_ouput(253) - exists_mock.assert_called_once_with(hpsum_controller.OUTPUT_FILES[0]) + exists_mock.assert_called_once_with(sum_controller.OUTPUT_FILES[0]) self.assertEqual(expt_ret, ret) @mock.patch.object(os.path, 'exists') - def test__parse_hpsum_ouput_fails(self, exists_mock): + def test__parse_sum_ouput_fails(self, exists_mock): exists_mock.return_value = False expt_ret = ("UPDATE STATUS: UNKNOWN") - ret = hpsum_controller._parse_hpsum_ouput(1) + ret = sum_controller._parse_sum_ouput(1) - exists_mock.assert_called_once_with(hpsum_controller.OUTPUT_FILES[0]) + exists_mock.assert_called_once_with(sum_controller.OUTPUT_FILES[0]) self.assertEqual(expt_ret, ret)