<s> """<STR_LIT>""" <EOL> import hashlib <EOL> import os <EOL> import shutil <EOL> import tempfile <EOL> from ironic_lib import utils as ironic_utils <EOL> import mock <EOL> from oslo_config import cfg <EOL> from oslo_utils import importutils <EOL> import six <EOL> import six . moves . builtins as __builtin__ <EOL> from ironic . common import boot_devices <EOL> from ironic . common import exception <EOL> from ironic . common import images <EOL> from ironic . common import swift <EOL> from ironic . conductor import task_manager <EOL> from ironic . conductor import utils as manager_utils <EOL> from ironic . drivers . modules import deploy_utils <EOL> from ironic . drivers . modules . ilo import common as ilo_common <EOL> from ironic . tests . unit . conductor import mgr_utils <EOL> from ironic . tests . unit . db import base as db_base <EOL> from ironic . tests . unit . db import utils as db_utils <EOL> from ironic . tests . unit . objects import utils as obj_utils <EOL> ilo_client = importutils . try_import ( '<STR_LIT>' ) <EOL> ilo_error = importutils . try_import ( '<STR_LIT>' ) <EOL> if six . PY3 : <EOL> import io <EOL> file = io . BytesIO <EOL> CONF = cfg . CONF <EOL> class IloValidateParametersTestCase ( db_base . DbTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( IloValidateParametersTestCase , self ) . setUp ( ) <EOL> self . node = obj_utils . create_test_node ( <EOL> self . context , driver = '<STR_LIT>' , <EOL> driver_info = db_utils . get_test_ilo_info ( ) ) <EOL> def test_parse_driver_info ( self ) : <EOL> info = ilo_common . parse_driver_info ( self . node ) <EOL> self . assertIsNotNone ( info . get ( '<STR_LIT>' ) ) <EOL> self . assertIsNotNone ( info . get ( '<STR_LIT>' ) ) <EOL> self . assertIsNotNone ( info . get ( '<STR_LIT>' ) ) <EOL> self . assertIsNotNone ( info . get ( '<STR_LIT>' ) ) <EOL> self . assertIsNotNone ( info . get ( '<STR_LIT>' ) ) <EOL> def test_parse_driver_info_missing_address ( self ) : <EOL> del self . node . driver_info [ '<STR_LIT>' ] <EOL> self . assertRaises ( exception . MissingParameterValue , <EOL> ilo_common . parse_driver_info , self . node ) <EOL> def test_parse_driver_info_missing_username ( self ) : <EOL> del self . node . driver_info [ '<STR_LIT>' ] <EOL> self . assertRaises ( exception . MissingParameterValue , <EOL> ilo_common . parse_driver_info , self . node ) <EOL> def test_parse_driver_info_missing_password ( self ) : <EOL> del self . node . driver_info [ '<STR_LIT>' ] <EOL> self . assertRaises ( exception . MissingParameterValue , <EOL> ilo_common . parse_driver_info , self . node ) <EOL> def test_parse_driver_info_invalid_timeout ( self ) : <EOL> self . node . driver_info [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> self . assertRaises ( exception . InvalidParameterValue , <EOL> ilo_common . parse_driver_info , self . node ) <EOL> def test_parse_driver_info_invalid_port ( self ) : <EOL> self . node . driver_info [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> self . assertRaises ( exception . InvalidParameterValue , <EOL> ilo_common . parse_driver_info , self . node ) <EOL> self . node . driver_info [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> self . assertRaises ( exception . InvalidParameterValue , <EOL> ilo_common . parse_driver_info , self . node ) <EOL> self . node . driver_info [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> self . assertRaises ( exception . InvalidParameterValue , <EOL> ilo_common . parse_driver_info , self . node ) <EOL> self . node . driver_info [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> self . assertRaises ( exception . InvalidParameterValue , <EOL> ilo_common . parse_driver_info , self . node ) <EOL> def test_parse_driver_info_missing_multiple_params ( self ) : <EOL> del self . node . driver_info [ '<STR_LIT>' ] <EOL> del self . node . driver_info [ '<STR_LIT>' ] <EOL> try : <EOL> ilo_common . parse_driver_info ( self . node ) <EOL> self . fail ( "<STR_LIT>" ) <EOL> except exception . MissingParameterValue as e : <EOL> self . assertIn ( '<STR_LIT>' , str ( e ) ) <EOL> self . assertIn ( '<STR_LIT>' , str ( e ) ) <EOL> def test_parse_driver_info_invalid_multiple_params ( self ) : <EOL> self . node . driver_info [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> try : <EOL> ilo_common . parse_driver_info ( self . node ) <EOL> self . fail ( "<STR_LIT>" ) <EOL> except exception . InvalidParameterValue as e : <EOL> self . assertIn ( '<STR_LIT>' , str ( e ) ) <EOL> class IloCommonMethodsTestCase ( db_base . DbTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( IloCommonMethodsTestCase , self ) . setUp ( ) <EOL> mgr_utils . mock_the_extension_manager ( driver = "<STR_LIT>" ) <EOL> self . info = db_utils . get_test_ilo_info ( ) <EOL> self . node = obj_utils . create_test_node ( <EOL> self . context , driver = '<STR_LIT>' , driver_info = self . info ) <EOL> @ mock . patch . object ( ilo_client , '<STR_LIT>' , spec_set = True , <EOL> autospec = True ) <EOL> def test_get_ilo_object ( self , ilo_client_mock ) : <EOL> self . info [ '<STR_LIT>' ] = <NUM_LIT> <EOL> self . info [ '<STR_LIT>' ] = <NUM_LIT> <EOL> ilo_client_mock . return_value = '<STR_LIT>' <EOL> returned_ilo_object = ilo_common . get_ilo_object ( self . node ) <EOL> ilo_client_mock . assert_called_with ( <EOL> self . info [ '<STR_LIT>' ] , <EOL> self . info [ '<STR_LIT>' ] , <EOL> self . info [ '<STR_LIT>' ] , <EOL> self . info [ '<STR_LIT>' ] , <EOL> self . info [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( '<STR_LIT>' , returned_ilo_object ) <EOL> @ mock . patch . object ( ilo_common , '<STR_LIT>' , spec_set = True , <EOL> autospec = True ) <EOL> def test_get_ilo_license ( self , get_ilo_object_mock ) : <EOL> ilo_advanced_license = { '<STR_LIT>' : '<STR_LIT>' } <EOL> ilo_standard_license = { '<STR_LIT>' : '<STR_LIT>' } <EOL> ilo_mock_object = get_ilo_object_mock . return_value <EOL> ilo_mock_object . get_all_licenses . return_value = ilo_advanced_license <EOL> license = ilo_common . get_ilo_license ( self . node ) <EOL> self . assertEqual ( ilo_common . ADVANCED_LICENSE , license ) <EOL> ilo_mock_object . get_all_licenses . return_value = ilo_standard_license <EOL> license = ilo_common . get_ilo_license ( self . node ) <EOL> self . assertEqual ( ilo_common . STANDARD_LICENSE , license ) <EOL> @ mock . patch . object ( ilo_common , '<STR_LIT>' , spec_set = True , <EOL> autospec = True ) <EOL> def test_get_ilo_license_fail ( self , get_ilo_object_mock ) : <EOL> ilo_mock_object = get_ilo_object_mock . return_value <EOL> exc = ilo_error . IloError ( '<STR_LIT:error>' ) <EOL> ilo_mock_object . get_all_licenses . side_effect = exc <EOL> self . assertRaises ( exception . IloOperationError , <EOL> ilo_common . get_ilo_license , <EOL> self . node ) <EOL> def test_update_ipmi_properties ( self ) : <EOL> with task_manager . acquire ( self . context , self . node . uuid , <EOL> shared = False ) as task : <EOL> ipmi_info = { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : <NUM_LIT> <EOL> } <EOL> self . info [ '<STR_LIT>' ] = <NUM_LIT> <EOL> task . node . driver_info = self . info <EOL> ilo_common . update_ipmi_properties ( task ) <EOL> actual_info = task . node . driver_info <EOL> expected_info = dict ( self . info , ** ipmi_info ) <EOL> self . assertEqual ( expected_info , actual_info ) <EOL> def test__get_floppy_image_name ( self ) : <EOL> image_name_expected = '<STR_LIT>' + self . node . uuid <EOL> image_name_actual = ilo_common . _get_floppy_image_name ( self . node ) <EOL> self . assertEqual ( image_name_expected , image_name_actual ) <EOL> @ mock . patch . object ( swift , '<STR_LIT>' , spec_set = True , autospec = True ) <EOL> @ mock . patch . object ( images , '<STR_LIT>' , spec_set = True , <EOL> autospec = True ) <EOL> @ mock . patch . object ( tempfile , '<STR_LIT>' , spec_set = True , <EOL> autospec = True ) <EOL> def test__prepare_floppy_image ( self , tempfile_mock , fatimage_mock , <EOL> swift_api_mock ) : <EOL> mock_image_file_handle = mock . MagicMock ( spec = file ) <EOL> mock_image_file_obj = mock . MagicMock ( spec = file ) <EOL> mock_image_file_obj . name = '<STR_LIT>' <EOL> mock_image_file_handle . __enter__ . return_value = mock_image_file_obj <EOL> tempfile_mock . return_value = mock_image_file_handle <EOL> swift_obj_mock = swift_api_mock . return_value <EOL> self . config ( swift_ilo_container = '<STR_LIT>' , group = '<STR_LIT>' ) <EOL> self . config ( swift_object_expiry_timeout = <NUM_LIT:1> , group = '<STR_LIT>' ) <EOL> deploy_args = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } <EOL> swift_obj_mock . get_temp_url . return_value = '<STR_LIT>' <EOL> timeout = CONF . ilo . swift_object_expiry_timeout <EOL> object_headers = { '<STR_LIT>' : timeout } <EOL> with task_manager . acquire ( self . context , self . node . uuid , <EOL> shared = False ) as task : <EOL> temp_url = ilo_common . _prepare_floppy_image ( task , deploy_args ) <EOL> node_uuid = task . node . uuid <EOL> object_name = '<STR_LIT>' + node_uuid <EOL> fatimage_mock . assert_called_once_with ( '<STR_LIT>' , <EOL> parameters = deploy_args ) <EOL> swift_obj_mock . create_object . assert_called_once_with ( <EOL> '<STR_LIT>' , object_name , '<STR_LIT>' , <EOL> object_headers = object_headers ) <EOL> swift_obj_mock . get_temp_url . assert_called_once_with ( <EOL> '<STR_LIT>' , object_name , timeout ) <EOL> self . assertEqual ( '<STR_LIT>' , temp_url ) <EOL> @ mock . patch . object ( ilo_common , '<STR_LIT>' , <EOL> spec_set = True , autospec = True ) <EOL> @ mock . patch . object ( images , '<STR_LIT>' , spec_set = True , <EOL> autospec = True ) <EOL> @ mock . patch . object ( tempfile , '<STR_LIT>' , spec_set = True , <EOL> autospec = True ) <EOL> def test__prepare_floppy_image_use_webserver ( self , tempfile_mock , <EOL> fatimage_mock , <EOL> copy_mock ) : <EOL> mock_image_file_handle = mock . MagicMock ( spec = file ) <EOL> mock_image_file_obj = mock . MagicMock ( spec = file ) <EOL> mock_image_file_obj . name = '<STR_LIT>' <EOL> mock_image_file_handle . __enter__ . return_value = mock_image_file_obj <EOL> tempfile_mock . return_value = mock_image_file_handle <EOL> self . config ( use_web_server_for_images = True , group = '<STR_LIT>' ) <EOL> deploy_args = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } <EOL> CONF . deploy . http_url = "<STR_LIT>" <EOL> CONF . deploy . http_root = "<STR_LIT>" <EOL> with task_manager . acquire ( self . context , self . node . uuid , <EOL> shared = False ) as task : <EOL> node_uuid = task . node . uuid <EOL> object_name = '<STR_LIT>' + node_uuid <EOL> http_url = CONF . deploy . http_url + '<STR_LIT:/>' + object_name <EOL> copy_mock . return_value = "<STR_LIT>" + object_name <EOL> temp_url = ilo_common . _prepare_floppy_image ( task , deploy_args ) <EOL> fatimage_mock . assert_called_once_with ( '<STR_LIT>' , <EOL> parameters = deploy_args ) <EOL> copy_mock . assert_called_once_with ( '<STR_LIT>' , object_name ) <EOL> self . assertEqual ( http_url , temp_url ) <EOL> @ mock . patch . object ( ilo_common , '<STR_LIT>' , spec_set = True , <EOL> autospec = True ) <EOL> def test_attach_vmedia ( self , get_ilo_object_mock ) : <EOL> ilo_mock_object = get_ilo_object_mock . return_value <EOL> insert_media_mock = ilo_mock_object . insert_virtual_media <EOL> set_status_mock = ilo_mock_object . set_vm_status <EOL> ilo_common . attach_vmedia ( self . node , '<STR_LIT>' , '<STR_LIT:url>' ) <EOL> insert_media_mock . assert_called_once_with ( '<STR_LIT:url>' , device = '<STR_LIT>' ) <EOL> set_status_mock . assert_called_once_with ( <EOL> device = '<STR_LIT>' , boot_option = '<STR_LIT>' , write_protect = '<STR_LIT>' ) <EOL> @ mock . patch . object ( ilo_common , '<STR_LIT>' , spec_set = True , <EOL> autospec = True ) <EOL> def test_attach_vmedia_fails ( self , get_ilo_object_mock ) : <EOL> ilo_mock_object = get_ilo_object_mock . return_value <EOL> set_status_mock = ilo_mock_object . set_vm_status <EOL> exc = ilo_error . IloError ( '<STR_LIT:error>' ) <EOL> set_status_mock . side_effect = exc <EOL> self . assertRaises ( exception . IloOperationError , <EOL> ilo_common . attach_vmedia , self . node , <EOL> '<STR_LIT>' , '<STR_LIT:url>' ) <EOL> @ mock . patch . object ( ilo_common , '<STR_LIT>' , spec_set = True , <EOL> autospec = True ) <EOL> def test_set_boot_mode ( self , get_ilo_object_mock ) : <EOL> ilo_object_mock = get_ilo_object_mock . return_value <EOL> get_pending_boot_mode_mock = ilo_object_mock . get_pending_boot_mode <EOL> set_pending_boot_mode_mock = ilo_object_mock . set_pending_boot_mode <EOL> get_pending_boot_mode_mock . return_value = '<STR_LIT>' <EOL> ilo_common . set_boot_mode ( self . node , '<STR_LIT>' ) <EOL> get_ilo_object_mock . assert_called_once_with ( self . node ) <EOL> get_pending_boot_mode_mock . assert_called_once_with ( ) <EOL> set_pending_boot_mode_mock . assert_called_once_with ( '<STR_LIT>' ) <EOL> @ mock . patch . object ( ilo_common , '<STR_LIT>' , spec_set = True , <EOL> autospec = True ) <EOL> def test_set_boot_mode_without_set_pending_boot_mode ( self , <EOL> get_ilo_object_mock ) : <EOL> ilo_object_mock = get_ilo_object_mock . return_value <EOL> get_pending_boot_mode_mock = ilo_object_mock . get_pending_boot_mode <EOL> get_pending_boot_mode_mock . return_value = '<STR_LIT>' <EOL> ilo_common . set_boot_mode ( self . node , '<STR_LIT>' ) <EOL> get_ilo_object_mock . assert_called_once_with ( self . node ) <EOL> get_pending_boot_mode_mock . assert_called_once_with ( ) <EOL> self . assertFalse ( ilo_object_mock . set_pending_boot_mode . called ) <EOL> @ mock . patch . object ( ilo_common , '<STR_LIT>' , spec_set = True , <EOL> autospec = True ) <EOL> def test_set_boot_mode_with_IloOperationError ( self , <EOL> get_ilo_object_mock ) : <EOL> ilo_object_mock = get_ilo_object_mock . return_value <EOL> get_pending_boot_mode_mock = ilo_object_mock . get_pending_boot_mode <EOL> get_pending_boot_mode_mock . return_value = '<STR_LIT>' <EOL> set_pending_boot_mode_mock = ilo_object_mock . set_pending_boot_mode <EOL> exc = ilo_error . IloError ( '<STR_LIT:error>' ) <EOL> set_pending_boot_mode_mock . side_effect = exc <EOL> self . assertRaises ( exception . IloOperationError , <EOL> ilo_common . set_boot_mode , self . node , '<STR_LIT>' ) <EOL> get_ilo_object_mock . assert_called_once_with ( self . node ) <EOL> get_pending_boot_mode_mock . assert_called_once_with ( ) <EOL> @ mock . patch . object ( ilo_common , '<STR_LIT>' , spec_set = True , <EOL> autospec = True ) <EOL> def test_update_boot_mode_instance_info_exists ( self , <EOL> set_boot_mode_mock ) : <EOL> with task_manager . acquire ( self . context , self . node . uuid , <EOL> shared = False ) as task : <EOL> task . node . instance_info [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> ilo_common . update_boot_mode ( task ) <EOL> set_boot_mode_mock . assert_called_once_with ( task . node , '<STR_LIT>' ) <EOL> @ mock . patch . object ( ilo_common , '<STR_LIT>' , spec_set = True , <EOL> autospec = True ) <EOL> def test_update_boot_mode_capabilities_exist ( self , <EOL> set_boot_mode_mock ) : <EOL> with task_manager . acquire ( self . context , self . node . uuid , <EOL> shared = False ) as task : <EOL> task . node . properties [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> ilo_common . update_boot_mode ( task ) <EOL> set_boot_mode_mock . assert_called_once_with ( task . node , '<STR_LIT>' ) <EOL> @ mock . patch . object ( ilo_common , '<STR_LIT>' , spec_set = True , <EOL> autospec = True ) <EOL> def test_update_boot_mode ( self , get_ilo_object_mock ) : <EOL> ilo_mock_obj = get_ilo_object_mock . return_value <EOL> ilo_mock_obj . get_pending_boot_mode . return_value = '<STR_LIT>' <EOL> with task_manager . acquire ( self . context , self . node . uuid , <EOL> shared = False ) as task : <EOL> ilo_common . update_boot_mode ( task ) <EOL> get_ilo_object_mock . assert_called_once_with ( task . node ) <EOL> ilo_mock_obj . get_pending_boot_mode . assert_called_once_with ( ) <EOL> self . assertEqual ( '<STR_LIT>' , <EOL> task . node . instance_info [ '<STR_LIT>' ] ) <EOL> @ mock . patch . object ( ilo_common , '<STR_LIT>' , spec_set = True , <EOL> autospec = True ) <EOL> def test_update_boot_mode_unknown ( self , <EOL> get_ilo_object_mock ) : <EOL> ilo_mock_obj = get_ilo_object_mock . return_value <EOL> ilo_mock_obj . get_pending_boot_mode . return_value = '<STR_LIT>' <EOL> set_pending_boot_mode_mock = ilo_mock_obj . set_pending_boot_mode <EOL> with task_manager . acquire ( self . context , self . node . uuid , <EOL> shared = False ) as task : <EOL> ilo_common . update_boot_mode ( task ) <EOL> get_ilo_object_mock . assert_called_once_with ( task . node ) <EOL> ilo_mock_obj . get_pending_boot_mode . assert_called_once_with ( ) <EOL> set_pending_boot_mode_mock . assert_called_once_with ( '<STR_LIT>' ) <EOL> self . assertEqual ( '<STR_LIT>' , <EOL> task . node . instance_info [ '<STR_LIT>' ] ) <EOL> @ mock . patch . object ( ilo_common , '<STR_LIT>' , spec_set = True , <EOL> autospec = True ) <EOL> def test_update_boot_mode_unknown_except ( self , <EOL> get_ilo_object_mock ) : <EOL> ilo_mock_obj = get_ilo_object_mock . return_value <EOL> ilo_mock_obj . get_pending_boot_mode . return_value = '<STR_LIT>' <EOL> set_pending_boot_mode_mock = ilo_mock_obj . set_pending_boot_mode <EOL> exc = ilo_error . IloError ( '<STR_LIT:error>' ) <EOL> set_pending_boot_mode_mock . side_effect = exc <EOL> with task_manager . acquire ( self . context , self . node . uuid , <EOL> shared = False ) as task : <EOL> self . assertRaises ( exception . IloOperationError , <EOL> ilo_common . update_boot_mode , task ) <EOL> get_ilo_object_mock . assert_called_once_with ( task . node ) <EOL> ilo_mock_obj . get_pending_boot_mode . assert_called_once_with ( ) <EOL> @ mock . patch . object ( ilo_common , '<STR_LIT>' , spec_set = True , <EOL> autospec = True ) <EOL> def test_update_boot_mode_legacy ( self , <EOL> get_ilo_object_mock ) : <EOL> ilo_mock_obj = get_ilo_object_mock . return_value <EOL> exc = ilo_error . IloCommandNotSupportedError ( '<STR_LIT:error>' ) <EOL> ilo_mock_obj . get_pending_boot_mode . side_effect = exc <EOL> with task_manager . acquire ( self . context , self . node . uuid , <EOL> shared = False ) as task : <EOL> ilo_common . update_boot_mode ( task ) <EOL> get_ilo_object_mock . assert_called_once_with ( task . node ) <EOL> ilo_mock_obj . get_pending_boot_mode . assert_called_once_with ( ) <EOL> self . assertEqual ( '<STR_LIT>' , <EOL> task . node . instance_info [ '<STR_LIT>' ] ) <EOL> @ mock . patch . object ( ilo_common , '<STR_LIT>' , spec_set = True , <EOL> autospec = True ) <EOL> def test_update_boot_mode_prop_boot_mode_exist ( self , <EOL> set_boot_mode_mock ) : <EOL> properties = { '<STR_LIT>' : '<STR_LIT>' } <EOL> with task_manager . acquire ( self . context , self . node . uuid , <EOL> shared = False ) as task : <EOL> task . node . properties = properties <EOL> ilo_common . update_boot_mode ( task ) <EOL> set_boot_mode_mock . assert_called_once_with ( task . node , '<STR_LIT>' ) <EOL> @ mock . patch . object ( images , '<STR_LIT>' , spec_set = True , <EOL> autospec = True ) <EOL> @ mock . patch . object ( ilo_common , '<STR_LIT>' , spec_set = True , <EOL> autospec = True ) <EOL> @ mock . patch . object ( ilo_common , '<STR_LIT>' , spec_set = True , <EOL> autospec = True ) <EOL> def test_setup_vmedia_for_boot_with_parameters ( <EOL> self , prepare_image_mock , attach_vmedia_mock , temp_url_mock ) : <EOL> parameters = { '<STR_LIT:a>' : '<STR_LIT:b>' } <EOL> boot_iso = '<STR_LIT>' <EOL> prepare_image_mock . return_value = '<STR_LIT>' <EOL> temp_url_mock . return_value = '<STR_LIT>' <EOL> with task_manager . acquire ( self . context , self . node . uuid , <EOL> shared = False ) as task : <EOL> ilo_common . setup_vmedia_for_boot ( task , boot_iso , parameters ) <EOL> prepare_image_mock . assert_called_once_with ( task , parameters ) <EOL> attach_vmedia_mock . assert_any_call ( task . node , '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> temp_url_mock . assert_called_once_with ( <EOL> task . context , '<STR_LIT>' ) <EOL> attach_vmedia_mock . assert_any_call ( task . node , '<STR_LIT>' , '<STR_LIT>' ) <EOL> @ mock . patch . object ( swift , '<STR_LIT>' , spec_set = True , autospec = True ) <EOL> @ mock . patch . object ( ilo_common , '<STR_LIT>' , spec_set = True , <EOL> autospec = True ) <EOL> def test_setup_vmedia_for_boot_with_swift ( self , attach_vmedia_mock , <EOL> swift_api_mock ) : <EOL> swift_obj_mock = swift_api_mock . return_value <EOL> boot_iso = '<STR_LIT>' <EOL> swift_obj_mock . get_temp_url . return_value = '<STR_LIT>' <EOL> CONF . keystone_authtoken . auth_uri = '<STR_LIT>' <EOL> CONF . ilo . swift_ilo_container = '<STR_LIT>' <EOL> CONF . ilo . swift_object_expiry_timeout = <NUM_LIT:1> <EOL> with task_manager . acquire ( self . context , self . node . uuid , <EOL> shared = False ) as task : <EOL> ilo_common . setup_vmedia_for_boot ( task , boot_iso ) <EOL> swift_obj_mock . get_temp_url . assert_called_once_with ( <EOL> '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:1> ) <EOL> attach_vmedia_mock . assert_called_once_with ( <EOL> task . node , '<STR_LIT>' , '<STR_LIT>' ) <EOL> @ mock . patch . object ( ilo_common , '<STR_LIT>' , spec_set = True , <EOL> autospec = True ) <EOL> def test_setup_vmedia_for_boot_with_url ( self , attach_vmedia_mock ) : <EOL> boot_iso = '<STR_LIT>' <EOL> with task_manager . acquire ( self . context , self . node . uuid , <EOL> shared = False ) as task : <EOL> ilo_common . setup_vmedia_for_boot ( task , boot_iso ) <EOL> attach_vmedia_mock . assert_called_once_with ( task . node , '<STR_LIT>' , <EOL> boot_iso ) <EOL> @ mock . patch . object ( ilo_common , '<STR_LIT>' , <EOL> spec_set = True , autospec = True ) <EOL> @ mock . patch . object ( swift , '<STR_LIT>' , spec_set = True , autospec = True ) <EOL> @ mock . patch . object ( ilo_common , '<STR_LIT>' , spec_set = True , <EOL> autospec = True ) <EOL> def test_cleanup_vmedia_boot ( self , get_name_mock , swift_api_mock , <EOL> eject_mock ) : <EOL> swift_obj_mock = swift_api_mock . return_value <EOL> CONF . ilo . swift_ilo_container = '<STR_LIT>' <EOL> get_name_mock . return_value = '<STR_LIT>' <EOL> with task_manager . acquire ( self . context , self . node . uuid , <EOL> shared = False ) as task : <EOL> ilo_common . cleanup_vmedia_boot ( task ) <EOL> swift_obj_mock . delete_object . assert_called_once_with ( <EOL> '<STR_LIT>' , '<STR_LIT>' ) <EOL> eject_mock . assert_called_once_with ( task ) <EOL> @ mock . patch . object ( ilo_common . LOG , '<STR_LIT>' , spec_set = True , <EOL> autospec = True ) <EOL> @ mock . patch . object ( ilo_common , '<STR_LIT>' , <EOL> spec_set = True , autospec = True ) <EOL> @ mock . patch . object ( swift , '<STR_LIT>' , spec_set = True , autospec = True ) <EOL> @ mock . patch . object ( ilo_common , '<STR_LIT>' , spec_set = True , <EOL> autospec = True ) <EOL> def test_cleanup_vmedia_boot_exc ( self , get_name_mock , swift_api_mock , <EOL> eject_mock , log_mock ) : <EOL> exc = exception . SwiftOperationError ( '<STR_LIT:error>' ) <EOL> swift_obj_mock = swift_api_mock . return_value <EOL> swift_obj_mock . delete_object . side_effect = exc <EOL> CONF . ilo . swift_ilo_container = '<STR_LIT>' <EOL> get_name_mock . return_value = '<STR_LIT>' <EOL> with task_manager . acquire ( self . context , self . node . uuid , <EOL> shared = False ) as task : <EOL> ilo_common . cleanup_vmedia_boot ( task ) <EOL> swift_obj_mock . delete_object . assert_called_once_with ( <EOL> '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertTrue ( log_mock . called ) <EOL> eject_mock . assert_called_once_with ( task ) <EOL> @ mock . patch . object ( ilo_common . LOG , '<STR_LIT>' , spec_set = True , <EOL> autospec = True ) <EOL> @ mock . patch . object ( ilo_common , '<STR_LIT>' , <EOL> spec_set = True , autospec = True ) <EOL> @ mock . patch . object ( swift , '<STR_LIT>' , spec_set = True , autospec = True ) <EOL> @ mock . patch . object ( ilo_common , '<STR_LIT>' , spec_set = True , <EOL> autospec = True ) <EOL> def test_cleanup_vmedia_boot_exc_resource_not_found ( self , get_name_mock , <EOL> swift_api_mock , <EOL> eject_mock , log_mock ) : <EOL> exc = exception . SwiftObjectNotFoundError ( '<STR_LIT:error>' ) <EOL> swift_obj_mock = swift_api_mock . return_value <EOL> swift_obj_mock . delete_object . side_effect = exc <EOL> CONF . ilo . swift_ilo_container = '<STR_LIT>' <EOL> get_name_mock . return_value = '<STR_LIT>' <EOL> with task_manager . acquire ( self . context , self . node . uuid , <EOL> shared = False ) as task : <EOL> ilo_common . cleanup_vmedia_boot ( task ) <EOL> swift_obj_mock . delete_object . assert_called_once_with ( <EOL> '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertTrue ( log_mock . called ) <EOL> eject_mock . assert_called_once_with ( task ) <EOL> @ mock . patch . object ( ilo_common , '<STR_LIT>' , <EOL> spec_set = True , autospec = True ) <EOL> @ mock . patch . object ( ilo_common , '<STR_LIT>' , <EOL> spec_set = True , autospec = True ) <EOL> def test_cleanup_vmedia_boot_for_webserver ( self , <EOL> destroy_image_mock , <EOL> eject_mock ) : <EOL> CONF . ilo . use_web_server_for_images = True <EOL> with task_manager . acquire ( self . context , self . node . uuid , <EOL> shared = False ) as task : <EOL> ilo_common . cleanup_vmedia_boot ( task ) <EOL> destroy_image_mock . assert_called_once_with ( task . node ) <EOL> eject_mock . assert_called_once_with ( task ) <EOL> @ mock . patch . object ( ilo_common , '<STR_LIT>' , spec_set = True , <EOL> autospec = True ) <EOL> def test_eject_vmedia_devices ( self , get_ilo_object_mock ) : <EOL> ilo_object_mock = mock . MagicMock ( spec = [ '<STR_LIT>' ] ) <EOL> get_ilo_object_mock . return_value = ilo_object_mock <EOL> with task_manager . acquire ( self . context , self . node . uuid , <EOL> shared = False ) as task : <EOL> ilo_common . eject_vmedia_devices ( task ) <EOL> ilo_object_mock . eject_virtual_media . assert_has_calls ( <EOL> [ mock . call ( '<STR_LIT>' ) , mock . call ( '<STR_LIT>' ) ] ) <EOL> @ mock . patch . object ( ilo_common , '<STR_LIT>' , spec_set = True , <EOL> autospec = True ) <EOL> def test_eject_vmedia_devices_raises ( <EOL> self , get_ilo_object_mock ) : <EOL> ilo_object_mock = mock . MagicMock ( spec = [ '<STR_LIT>' ] ) <EOL> get_ilo_object_mock . return_value = ilo_object_mock <EOL> exc = ilo_error . IloError ( '<STR_LIT:error>' ) <EOL> ilo_object_mock . eject_virtual_media . side_effect = exc <EOL> with task_manager . acquire ( self . context , self . node . uuid , <EOL> shared = False ) as task : <EOL> self . assertRaises ( exception . IloOperationError , <EOL> ilo_common . eject_vmedia_devices , <EOL> task ) <EOL> ilo_object_mock . eject_virtual_media . assert_called_once_with ( <EOL> '<STR_LIT>' ) <EOL> @ mock . patch . object ( ilo_common , '<STR_LIT>' , spec_set = True , <EOL> autospec = True ) <EOL> def test_get_secure_boot_mode ( self , <EOL> get_ilo_object_mock ) : <EOL> ilo_object_mock = get_ilo_object_mock . return_value <EOL> ilo_object_mock . get_current_boot_mode . return_value = '<STR_LIT>' <EOL> ilo_object_mock . get_secure_boot_mode . return_value = True <EOL> with task_manager . acquire ( self . context , self . node . uuid , <EOL> shared = False ) as task : <EOL> ret = ilo_common . get_secure_boot_mode ( task ) <EOL> ilo_object_mock . get_current_boot_mode . assert_called_once_with ( ) <EOL> ilo_object_mock . get_secure_boot_mode . assert_called_once_with ( ) <EOL> self . assertTrue ( ret ) <EOL> @ mock . patch . object ( ilo_common , '<STR_LIT>' , spec_set = True , <EOL> autospec = True ) <EOL> def test_get_secure_boot_mode_bios ( self , <EOL> get_ilo_object_mock ) : <EOL> ilo_object_mock = get_ilo_object_mock . return_value <EOL> ilo_object_mock . get_current_boot_mode . return_value = '<STR_LIT>' <EOL> with task_manager . acquire ( self . context , self . node . uuid , <EOL> shared = False ) as task : <EOL> ret = ilo_common . get_secure_boot_mode ( task ) <EOL> ilo_object_mock . get_current_boot_mode . assert_called_once_with ( ) <EOL> self . assertFalse ( ilo_object_mock . get_secure_boot_mode . called ) <EOL> self . assertFalse ( ret ) <EOL> @ mock . patch . object ( ilo_common , '<STR_LIT>' , spec_set = True , <EOL> autospec = True ) <EOL> def test_get_secure_boot_mode_fail ( self , <EOL> get_ilo_object_mock ) : <EOL> ilo_mock_object = get_ilo_object_mock . return_value <EOL> exc = ilo_error . IloError ( '<STR_LIT:error>' ) <EOL> ilo_mock_object . get_current_boot_mode . side_effect = exc <EOL> with task_manager . acquire ( self . context , self . node . uuid , <EOL> shared = False ) as task : <EOL> self . assertRaises ( exception . IloOperationError , <EOL> ilo_common . get_secure_boot_mode , <EOL> task ) <EOL> ilo_mock_object . get_current_boot_mode . assert_called_once_with ( ) <EOL> @ mock . patch . object ( ilo_common , '<STR_LIT>' , spec_set = True , <EOL> autospec = True ) <EOL> def test_get_secure_boot_mode_not_supported ( self , <EOL> ilo_object_mock ) : <EOL> ilo_mock_object = ilo_object_mock . return_value <EOL> exc = ilo_error . IloCommandNotSupportedError ( '<STR_LIT:error>' ) <EOL> ilo_mock_object . get_current_boot_mode . return_value = '<STR_LIT>' <EOL> ilo_mock_object . get_secure_boot_mode . side_effect = exc <EOL> with task_manager . acquire ( self . context , self . node . uuid , <EOL> shared = False ) as task : <EOL> self . assertRaises ( exception . IloOperationNotSupported , <EOL> ilo_common . get_secure_boot_mode , <EOL> task ) <EOL> ilo_mock_object . get_current_boot_mode . assert_called_once_with ( ) <EOL> ilo_mock_object . get_secure_boot_mode . assert_called_once_with ( ) <EOL> @ mock . patch . object ( ilo_common , '<STR_LIT>' , spec_set = True , <EOL> autospec = True ) <EOL> def test_set_secure_boot_mode ( self , <EOL> get_ilo_object_mock ) : <EOL> ilo_object_mock = get_ilo_object_mock . return_value <EOL> with task_manager . acquire ( self . context , self . node . uuid , <EOL> shared = False ) as task : <EOL> ilo_common . set_secure_boot_mode ( task , True ) <EOL> ilo_object_mock . set_secure_boot_mode . assert_called_once_with ( True ) <EOL> @ mock . patch . object ( ilo_common , '<STR_LIT>' , spec_set = True , <EOL> autospec = True ) <EOL> def test_set_secure_boot_mode_fail ( self , <EOL> get_ilo_object_mock ) : <EOL> ilo_mock_object = get_ilo_object_mock . return_value <EOL> exc = ilo_error . IloError ( '<STR_LIT:error>' ) <EOL> ilo_mock_object . set_secure_boot_mode . side_effect = exc <EOL> with task_manager . acquire ( self . context , self . node . uuid , <EOL> shared = False ) as task : <EOL> self . assertRaises ( exception . IloOperationError , <EOL> ilo_common . set_secure_boot_mode , <EOL> task , False ) <EOL> ilo_mock_object . set_secure_boot_mode . assert_called_once_with ( False ) <EOL> @ mock . patch . object ( ilo_common , '<STR_LIT>' , spec_set = True , <EOL> autospec = True ) <EOL> def test_set_secure_boot_mode_not_supported ( self , <EOL> ilo_object_mock ) : <EOL> ilo_mock_object = ilo_object_mock . return_value <EOL> exc = ilo_error . IloCommandNotSupportedError ( '<STR_LIT:error>' ) <EOL> ilo_mock_object . set_secure_boot_mode . side_effect = exc <EOL> with task_manager . acquire ( self . context , self . node . uuid , <EOL> shared = False ) as task : <EOL> self . assertRaises ( exception . IloOperationNotSupported , <EOL> ilo_common . set_secure_boot_mode , <EOL> task , False ) <EOL> ilo_mock_object . set_secure_boot_mode . assert_called_once_with ( False ) <EOL> @ mock . patch . object ( os , '<STR_LIT>' , spec_set = True , <EOL> autospec = True ) <EOL> @ mock . patch . object ( shutil , '<STR_LIT>' , spec_set = True , <EOL> autospec = True ) <EOL> def test_copy_image_to_web_server ( self , copy_mock , <EOL> chmod_mock ) : <EOL> CONF . deploy . http_url = "<STR_LIT>" <EOL> CONF . deploy . http_root = "<STR_LIT>" <EOL> expected_url = "<STR_LIT>" <EOL> source = '<STR_LIT>' <EOL> destination = "<STR_LIT>" <EOL> image_path = "<STR_LIT>" <EOL> actual_url = ilo_common . copy_image_to_web_server ( source , destination ) <EOL> self . assertEqual ( expected_url , actual_url ) <EOL> copy_mock . assert_called_once_with ( source , image_path ) <EOL> chmod_mock . assert_called_once_with ( image_path , <NUM_LIT> ) <EOL> @ mock . patch . object ( os , '<STR_LIT>' , spec_set = True , <EOL> autospec = True ) <EOL> @ mock . patch . object ( shutil , '<STR_LIT>' , spec_set = True , <EOL> autospec = True ) <EOL> def test_copy_image_to_web_server_fails ( self , copy_mock , <EOL> chmod_mock ) : <EOL> CONF . deploy . http_url = "<STR_LIT>" <EOL> CONF . deploy . http_root = "<STR_LIT>" <EOL> source = '<STR_LIT>' <EOL> destination = "<STR_LIT>" <EOL> image_path = "<STR_LIT>" <EOL> exc = exception . ImageUploadFailed ( '<STR_LIT>' ) <EOL> copy_mock . side_effect = exc <EOL> self . assertRaises ( exception . ImageUploadFailed , <EOL> ilo_common . copy_image_to_web_server , <EOL> source , destination ) <EOL> copy_mock . assert_called_once_with ( source , image_path ) <EOL> self . assertFalse ( chmod_mock . called ) <EOL> @ mock . patch . object ( ilo_common , '<STR_LIT>' , autospec = True ) <EOL> def test_remove_image_from_web_server ( self , utils_mock ) : <EOL> CONF . deploy . http_url = "<STR_LIT>" <EOL> CONF . deploy . http_root = "<STR_LIT>" <EOL> object_name = '<STR_LIT>' <EOL> ilo_common . remove_image_from_web_server ( object_name ) <EOL> ( utils_mock . unlink_without_raise . <EOL> assert_called_once_with ( "<STR_LIT>" ) ) <EOL> @ mock . patch . object ( swift , '<STR_LIT>' , spec_set = True , autospec = True ) <EOL> @ mock . patch . object ( ilo_common , '<STR_LIT>' ) <EOL> def test_copy_image_to_swift ( self , LOG_mock , swift_api_mock ) : <EOL> self . config ( swift_ilo_container = '<STR_LIT>' , group = '<STR_LIT>' ) <EOL> self . config ( swift_object_expiry_timeout = <NUM_LIT:1> , group = '<STR_LIT>' ) <EOL> container = CONF . ilo . swift_ilo_container <EOL> timeout = CONF . ilo . swift_object_expiry_timeout <EOL> swift_obj_mock = swift_api_mock . return_value <EOL> destination_object_name = '<STR_LIT>' <EOL> source_file_path = '<STR_LIT>' <EOL> object_headers = { '<STR_LIT>' : timeout } <EOL> ilo_common . copy_image_to_swift ( source_file_path , <EOL> destination_object_name ) <EOL> swift_obj_mock . create_object . assert_called_once_with ( <EOL> container , destination_object_name , source_file_path , <EOL> object_headers = object_headers ) <EOL> swift_obj_mock . get_temp_url . assert_called_once_with ( <EOL> container , destination_object_name , timeout ) <EOL> @ mock . patch . object ( swift , '<STR_LIT>' , spec_set = True , autospec = True ) <EOL> def test_copy_image_to_swift_throws_error_if_swift_operation_fails ( <EOL> self , swift_api_mock ) : <EOL> self . config ( swift_ilo_container = '<STR_LIT>' , group = '<STR_LIT>' ) <EOL> self . config ( swift_object_expiry_timeout = <NUM_LIT:1> , group = '<STR_LIT>' ) <EOL> swift_obj_mock = swift_api_mock . return_value <EOL> destination_object_name = '<STR_LIT>' <EOL> source_file_path = '<STR_LIT>' <EOL> swift_obj_mock . create_object . side_effect = ( <EOL> exception . SwiftOperationError ( operation = '<STR_LIT>' , <EOL> error = '<STR_LIT>' ) ) <EOL> self . assertRaises ( exception . SwiftOperationError , <EOL> ilo_common . copy_image_to_swift , <EOL> source_file_path , destination_object_name ) <EOL> @ mock . patch . object ( swift , '<STR_LIT>' , spec_set = True , autospec = True ) <EOL> def test_remove_image_from_swift ( self , swift_api_mock ) : <EOL> self . config ( swift_ilo_container = '<STR_LIT>' , group = '<STR_LIT>' ) <EOL> container = CONF . ilo . swift_ilo_container <EOL> swift_obj_mock = swift_api_mock . return_value <EOL> object_name = '<STR_LIT:object_name>' <EOL> ilo_common . remove_image_from_swift ( object_name ) <EOL> swift_obj_mock . delete_object . assert_called_once_with ( <EOL> container , object_name ) <EOL> @ mock . patch . object ( ilo_common , '<STR_LIT>' ) <EOL> @ mock . patch . object ( swift , '<STR_LIT>' , spec_set = True , autospec = True ) <EOL> def test_remove_image_from_swift_suppresses_notfound_exc ( <EOL> self , swift_api_mock , LOG_mock ) : <EOL> self . config ( swift_ilo_container = '<STR_LIT>' , group = '<STR_LIT>' ) <EOL> container = CONF . ilo . swift_ilo_container <EOL> swift_obj_mock = swift_api_mock . return_value <EOL> object_name = '<STR_LIT:object_name>' <EOL> raised_exc = exception . SwiftObjectNotFoundError ( <EOL> operation = '<STR_LIT>' , object = object_name , container = container ) <EOL> swift_obj_mock . delete_object . side_effect = raised_exc <EOL> ilo_common . remove_image_from_swift ( object_name ) <EOL> LOG_mock . warning . assert_called_once_with ( <EOL> mock . ANY , { '<STR_LIT>' : "<STR_LIT>" , '<STR_LIT>' : raised_exc } ) <EOL> @ mock . patch . object ( ilo_common , '<STR_LIT>' ) <EOL> @ mock . patch . object ( swift , '<STR_LIT>' , spec_set = True , autospec = True ) <EOL> def test_remove_image_from_swift_suppresses_operror_exc ( <EOL> self , swift_api_mock , LOG_mock ) : <EOL> self . config ( swift_ilo_container = '<STR_LIT>' , group = '<STR_LIT>' ) <EOL> container = CONF . ilo . swift_ilo_container <EOL> swift_obj_mock = swift_api_mock . return_value <EOL> object_name = '<STR_LIT:object_name>' <EOL> raised_exc = exception . SwiftOperationError ( operation = '<STR_LIT>' , <EOL> error = '<STR_LIT>' ) <EOL> swift_obj_mock . delete_object . side_effect = raised_exc <EOL> ilo_common . remove_image_from_swift ( object_name , '<STR_LIT>' ) <EOL> LOG_mock . exception . assert_called_once_with ( <EOL> mock . ANY , { '<STR_LIT:object_name>' : object_name , '<STR_LIT>' : container , <EOL> '<STR_LIT>' : ( "<STR_LIT>" <EOL> "<STR_LIT>" ) , <EOL> '<STR_LIT>' : raised_exc } ) <EOL> @ mock . patch . object ( ironic_utils , '<STR_LIT>' , spec_set = True , <EOL> autospec = True ) <EOL> @ mock . patch . object ( ilo_common , '<STR_LIT>' , spec_set = True , <EOL> autospec = True ) <EOL> def test_destroy_floppy_image_from_web_server ( self , get_floppy_name_mock , <EOL> utils_mock ) : <EOL> get_floppy_name_mock . return_value = '<STR_LIT>' <EOL> CONF . deploy . http_root = "<STR_LIT>" <EOL> with task_manager . acquire ( self . context , self . node . uuid , <EOL> shared = False ) as task : <EOL> ilo_common . destroy_floppy_image_from_web_server ( task . node ) <EOL> get_floppy_name_mock . assert_called_once_with ( task . node ) <EOL> utils_mock . assert_called_once_with ( '<STR_LIT>' ) <EOL> @ mock . patch . object ( manager_utils , '<STR_LIT>' , spec_set = True , <EOL> autospec = True ) <EOL> @ mock . patch . object ( ilo_common , '<STR_LIT>' , spec_set = True , <EOL> autospec = True ) <EOL> def test_setup_vmedia ( self , <EOL> func_setup_vmedia_for_boot , <EOL> func_set_boot_device ) : <EOL> with task_manager . acquire ( self . context , self . node . uuid , <EOL> shared = False ) as task : <EOL> parameters = { '<STR_LIT:a>' : '<STR_LIT:b>' } <EOL> iso = '<STR_LIT>' <EOL> ilo_common . setup_vmedia ( task , iso , parameters ) <EOL> func_setup_vmedia_for_boot . assert_called_once_with ( task , iso , <EOL> parameters ) <EOL> func_set_boot_device . assert_called_once_with ( task , <EOL> boot_devices . CDROM ) <EOL> @ mock . patch . object ( deploy_utils , '<STR_LIT>' , spec_set = True , <EOL> autospec = True ) <EOL> @ mock . patch . object ( ilo_common , '<STR_LIT>' , spec_set = True , <EOL> autospec = True ) <EOL> def test_update_secure_boot_mode_passed_true ( self , <EOL> func_set_secure_boot_mode , <EOL> func_is_secure_boot_req ) : <EOL> with task_manager . acquire ( self . context , self . node . uuid , <EOL> shared = False ) as task : <EOL> func_is_secure_boot_req . return_value = True <EOL> ilo_common . update_secure_boot_mode ( task , True ) <EOL> func_set_secure_boot_mode . assert_called_once_with ( task , True ) <EOL> @ mock . patch . object ( deploy_utils , '<STR_LIT>' , spec_set = True , <EOL> autospec = True ) <EOL> @ mock . patch . object ( ilo_common , '<STR_LIT>' , spec_set = True , <EOL> autospec = True ) <EOL> def test_update_secure_boot_mode_passed_false ( self , <EOL> func_set_secure_boot_mode , <EOL> func_is_secure_boot_req ) : <EOL> with task_manager . acquire ( self . context , self . node . uuid , <EOL> shared = False ) as task : <EOL> func_is_secure_boot_req . return_value = False <EOL> ilo_common . update_secure_boot_mode ( task , False ) <EOL> self . assertFalse ( func_set_secure_boot_mode . called ) <EOL> @ mock . patch . object ( ironic_utils , '<STR_LIT>' , spec_set = True , <EOL> autospec = True ) <EOL> def test_remove_single_or_list_of_files_with_file_list ( self , unlink_mock ) : <EOL> file_list = [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] <EOL> ilo_common . remove_single_or_list_of_files ( file_list ) <EOL> calls = [ mock . call ( '<STR_LIT>' ) , <EOL> mock . call ( '<STR_LIT>' ) , <EOL> mock . call ( '<STR_LIT>' ) ] <EOL> unlink_mock . assert_has_calls ( calls ) <EOL> @ mock . patch . object ( ironic_utils , '<STR_LIT>' , spec_set = True , <EOL> autospec = True ) <EOL> def test_remove_single_or_list_of_files_with_file_str ( self , unlink_mock ) : <EOL> file_path = '<STR_LIT>' <EOL> ilo_common . remove_single_or_list_of_files ( file_path ) <EOL> unlink_mock . assert_called_once_with ( '<STR_LIT>' ) <EOL> @ mock . patch . object ( __builtin__ , '<STR_LIT>' , autospec = True ) <EOL> def test_verify_image_checksum ( self , open_mock ) : <EOL> data = b'<STR_LIT>' <EOL> file_like_object = six . BytesIO ( data ) <EOL> open_mock ( ) . __enter__ . return_value = file_like_object <EOL> actual_hash = hashlib . md5 ( data ) . hexdigest ( ) <EOL> ilo_common . verify_image_checksum ( file_like_object , actual_hash ) <EOL> def test_verify_image_checksum_throws_for_nonexistent_file ( self ) : <EOL> invalid_file_path = '<STR_LIT>' <EOL> self . assertRaises ( exception . ImageRefValidationFailed , <EOL> ilo_common . verify_image_checksum , <EOL> invalid_file_path , '<STR_LIT>' ) <EOL> @ mock . patch . object ( __builtin__ , '<STR_LIT>' , autospec = True ) <EOL> def test_verify_image_checksum_throws_for_failed_validation ( self , <EOL> open_mock ) : <EOL> data = b'<STR_LIT>' <EOL> file_like_object = six . BytesIO ( data ) <EOL> open_mock ( ) . __enter__ . return_value = file_like_object <EOL> invalid_hash = '<STR_LIT>' <EOL> self . assertRaises ( exception . ImageRefValidationFailed , <EOL> ilo_common . verify_image_checksum , <EOL> file_like_object , <EOL> invalid_hash ) </s>
