<s> """<STR_LIT>""" <EOL> import mock <EOL> from oslo_utils import uuidutils <EOL> from pyghmi import exceptions as pyghmi_exception <EOL> from ironic . common import boot_devices <EOL> from ironic . common import driver_factory <EOL> from ironic . common import exception <EOL> from ironic . common import states <EOL> from ironic . conductor import task_manager <EOL> from ironic . drivers . modules import console_utils <EOL> from ironic . drivers . modules import ipminative <EOL> from ironic . drivers import utils as driver_utils <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> INFO_DICT = db_utils . get_test_ipmi_info ( ) <EOL> class IPMINativePrivateMethodTestCase ( db_base . DbTestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> super ( IPMINativePrivateMethodTestCase , self ) . setUp ( ) <EOL> self . node = obj_utils . create_test_node ( self . context , <EOL> driver = '<STR_LIT>' , <EOL> driver_info = INFO_DICT ) <EOL> self . info = ipminative . _parse_driver_info ( self . node ) <EOL> def test__parse_driver_info ( self ) : <EOL> self . assertIsNotNone ( self . info . get ( '<STR_LIT:address>' ) ) <EOL> self . assertIsNotNone ( self . info . get ( '<STR_LIT:username>' ) ) <EOL> self . assertIsNotNone ( self . info . get ( '<STR_LIT:password>' ) ) <EOL> self . assertIsNotNone ( self . info . get ( '<STR_LIT>' ) ) <EOL> self . assertIsNotNone ( self . info . get ( '<STR_LIT>' ) ) <EOL> info = dict ( INFO_DICT ) <EOL> del info [ '<STR_LIT>' ] <EOL> node = obj_utils . get_test_node ( self . context , driver_info = info ) <EOL> self . assertRaises ( exception . MissingParameterValue , <EOL> ipminative . _parse_driver_info , <EOL> node ) <EOL> @ mock . patch ( '<STR_LIT>' , autospec = True ) <EOL> def test__power_status_on ( self , ipmi_mock ) : <EOL> ipmicmd = ipmi_mock . return_value <EOL> ipmicmd . get_power . return_value = { '<STR_LIT>' : '<STR_LIT>' } <EOL> state = ipminative . _power_status ( self . info ) <EOL> ipmicmd . get_power . assert_called_once_with ( ) <EOL> self . assertEqual ( states . POWER_ON , state ) <EOL> @ mock . patch ( '<STR_LIT>' , autospec = True ) <EOL> def test__power_status_off ( self , ipmi_mock ) : <EOL> ipmicmd = ipmi_mock . return_value <EOL> ipmicmd . get_power . return_value = { '<STR_LIT>' : '<STR_LIT>' } <EOL> state = ipminative . _power_status ( self . info ) <EOL> ipmicmd . get_power . assert_called_once_with ( ) <EOL> self . assertEqual ( states . POWER_OFF , state ) <EOL> @ mock . patch ( '<STR_LIT>' , autospec = True ) <EOL> def test__power_status_error ( self , ipmi_mock ) : <EOL> ipmicmd = ipmi_mock . return_value <EOL> ipmicmd . get_power . return_value = { '<STR_LIT>' : '<STR_LIT>' } <EOL> state = ipminative . _power_status ( self . info ) <EOL> ipmicmd . get_power . assert_called_once_with ( ) <EOL> self . assertEqual ( states . ERROR , state ) <EOL> @ mock . patch ( '<STR_LIT>' , autospec = True ) <EOL> def test__power_on ( self , ipmi_mock ) : <EOL> ipmicmd = ipmi_mock . return_value <EOL> ipmicmd . set_power . return_value = { '<STR_LIT>' : '<STR_LIT>' } <EOL> self . config ( retry_timeout = <NUM_LIT> , group = '<STR_LIT>' ) <EOL> state = ipminative . _power_on ( self . info ) <EOL> ipmicmd . set_power . assert_called_once_with ( '<STR_LIT>' , <NUM_LIT> ) <EOL> self . assertEqual ( states . POWER_ON , state ) <EOL> @ mock . patch ( '<STR_LIT>' , autospec = True ) <EOL> def test__power_off ( self , ipmi_mock ) : <EOL> ipmicmd = ipmi_mock . return_value <EOL> ipmicmd . set_power . return_value = { '<STR_LIT>' : '<STR_LIT>' } <EOL> self . config ( retry_timeout = <NUM_LIT> , group = '<STR_LIT>' ) <EOL> state = ipminative . _power_off ( self . info ) <EOL> ipmicmd . set_power . assert_called_once_with ( '<STR_LIT>' , <NUM_LIT> ) <EOL> self . assertEqual ( states . POWER_OFF , state ) <EOL> @ mock . patch ( '<STR_LIT>' , autospec = True ) <EOL> def test__reboot ( self , ipmi_mock ) : <EOL> ipmicmd = ipmi_mock . return_value <EOL> ipmicmd . set_power . return_value = { '<STR_LIT>' : '<STR_LIT>' } <EOL> self . config ( retry_timeout = <NUM_LIT> , group = '<STR_LIT>' ) <EOL> state = ipminative . _reboot ( self . info ) <EOL> ipmicmd . set_power . assert_called_once_with ( '<STR_LIT>' , <NUM_LIT> ) <EOL> self . assertEqual ( states . POWER_ON , state ) <EOL> def _create_sensor_object ( self , value , type_ , name , states = None , <EOL> units = '<STR_LIT>' , health = <NUM_LIT:0> ) : <EOL> if states is None : <EOL> states = [ ] <EOL> return type ( '<STR_LIT>' , ( object , ) , { <EOL> '<STR_LIT:value>' : value , '<STR_LIT:type>' : type_ , '<STR_LIT:name>' : name , <EOL> '<STR_LIT>' : states , '<STR_LIT>' : units , '<STR_LIT>' : health } ) ( ) <EOL> @ mock . patch ( '<STR_LIT>' , autospec = True ) <EOL> def test__get_sensors_data ( self , ipmi_mock ) : <EOL> reading_1 = self . _create_sensor_object ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> reading_2 = self . _create_sensor_object ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> reading_3 = self . _create_sensor_object ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> readings = [ reading_1 , reading_2 , reading_3 ] <EOL> ipmicmd = ipmi_mock . return_value <EOL> ipmicmd . get_sensor_data . return_value = readings <EOL> expected = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT:0>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT:0>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT:0>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> } <EOL> } <EOL> ret = ipminative . _get_sensors_data ( self . info ) <EOL> self . assertEqual ( expected , ret ) <EOL> @ mock . patch ( '<STR_LIT>' , autospec = True ) <EOL> def test__get_sensors_data_missing_values ( self , ipmi_mock ) : <EOL> reading_1 = self . _create_sensor_object ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> reading_2 = self . _create_sensor_object ( None , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> reading_3 = self . _create_sensor_object ( None , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> readings = [ reading_1 , reading_2 , reading_3 ] <EOL> ipmicmd = ipmi_mock . return_value <EOL> ipmicmd . get_sensor_data . return_value = readings <EOL> expected = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT:0>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> } <EOL> } <EOL> ret = ipminative . _get_sensors_data ( self . info ) <EOL> self . assertEqual ( expected , ret ) <EOL> def test__parse_raw_bytes_ok ( self ) : <EOL> bytes_string = '<STR_LIT>' <EOL> netfn , cmd , data = ipminative . _parse_raw_bytes ( bytes_string ) <EOL> self . assertEqual ( <NUM_LIT> , netfn ) <EOL> self . assertEqual ( <NUM_LIT> , cmd ) <EOL> self . assertEqual ( [ <NUM_LIT> , <NUM_LIT> ] , data ) <EOL> def test__parse_raw_bytes_invalid_value ( self ) : <EOL> bytes_string = '<STR_LIT>' <EOL> self . assertRaises ( exception . InvalidParameterValue , <EOL> ipminative . _parse_raw_bytes , <EOL> bytes_string ) <EOL> def test__parse_raw_bytes_missing_byte ( self ) : <EOL> bytes_string = '<STR_LIT>' <EOL> self . assertRaises ( exception . InvalidParameterValue , <EOL> ipminative . _parse_raw_bytes , <EOL> bytes_string ) <EOL> @ mock . patch ( '<STR_LIT>' , autospec = True ) <EOL> def test__send_raw ( self , ipmi_mock ) : <EOL> ipmicmd = ipmi_mock . return_value <EOL> ipminative . _send_raw ( self . info , '<STR_LIT>' ) <EOL> ipmicmd . xraw_command . assert_called_once_with ( <NUM_LIT:1> , <NUM_LIT:2> , data = [ <NUM_LIT:3> , <NUM_LIT:4> ] ) <EOL> @ mock . patch ( '<STR_LIT>' , autospec = True ) <EOL> def test__send_raw_fail ( self , ipmi_mock ) : <EOL> ipmicmd = ipmi_mock . return_value <EOL> ipmicmd . xraw_command . side_effect = pyghmi_exception . IpmiException ( ) <EOL> self . assertRaises ( exception . IPMIFailure , ipminative . _send_raw , <EOL> self . info , '<STR_LIT>' ) <EOL> class IPMINativeDriverTestCase ( db_base . DbTestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> super ( IPMINativeDriverTestCase , self ) . setUp ( ) <EOL> mgr_utils . mock_the_extension_manager ( driver = "<STR_LIT>" ) <EOL> self . driver = driver_factory . get_driver ( "<STR_LIT>" ) <EOL> self . node = obj_utils . create_test_node ( self . context , <EOL> driver = '<STR_LIT>' , <EOL> driver_info = INFO_DICT ) <EOL> self . info = ipminative . _parse_driver_info ( self . node ) <EOL> def test_get_properties ( self ) : <EOL> expected = ipminative . COMMON_PROPERTIES <EOL> self . assertEqual ( expected , self . driver . power . get_properties ( ) ) <EOL> self . assertEqual ( expected , self . driver . management . get_properties ( ) ) <EOL> self . assertEqual ( expected , self . driver . vendor . get_properties ( ) ) <EOL> expected = list ( ipminative . COMMON_PROPERTIES ) <EOL> expected += list ( ipminative . CONSOLE_PROPERTIES ) <EOL> self . assertEqual ( sorted ( expected ) , <EOL> sorted ( self . driver . console . get_properties ( ) . keys ( ) ) ) <EOL> self . assertEqual ( sorted ( expected ) , <EOL> sorted ( self . driver . get_properties ( ) . keys ( ) ) ) <EOL> @ mock . patch ( '<STR_LIT>' , autospec = True ) <EOL> def test_get_power_state ( self , ipmi_mock ) : <EOL> cmd_mock = ipmi_mock . return_value <EOL> get_power_mock = cmd_mock . get_power <EOL> return_values = [ { '<STR_LIT>' : '<STR_LIT:error>' } , <EOL> { '<STR_LIT>' : '<STR_LIT>' } , <EOL> { '<STR_LIT>' : '<STR_LIT>' } ] <EOL> get_power_mock . side_effect = lambda : return_values . pop ( ) <EOL> with task_manager . acquire ( self . context , self . node . uuid ) as task : <EOL> pstate = self . driver . power . get_power_state ( task ) <EOL> self . assertEqual ( states . POWER_OFF , pstate ) <EOL> pstate = self . driver . power . get_power_state ( task ) <EOL> self . assertEqual ( states . POWER_ON , pstate ) <EOL> pstate = self . driver . power . get_power_state ( task ) <EOL> self . assertEqual ( states . ERROR , pstate ) <EOL> self . assertEqual ( <NUM_LIT:3> , get_power_mock . call_count , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> @ mock . patch . object ( ipminative , '<STR_LIT>' , autospec = True ) <EOL> def test_set_power_on_ok ( self , power_on_mock ) : <EOL> power_on_mock . return_value = states . POWER_ON <EOL> with task_manager . acquire ( self . context , <EOL> self . node . uuid ) as task : <EOL> self . driver . power . set_power_state ( <EOL> task , states . POWER_ON ) <EOL> power_on_mock . assert_called_once_with ( self . info ) <EOL> @ mock . patch . object ( driver_utils , '<STR_LIT>' , autospec = True ) <EOL> @ mock . patch . object ( ipminative , '<STR_LIT>' , autospec = True ) <EOL> def test_set_power_on_with_next_boot ( self , power_on_mock , mock_next_boot ) : <EOL> power_on_mock . return_value = states . POWER_ON <EOL> with task_manager . acquire ( self . context , <EOL> self . node . uuid ) as task : <EOL> self . driver . power . set_power_state ( <EOL> task , states . POWER_ON ) <EOL> mock_next_boot . assert_called_once_with ( task , self . info ) <EOL> power_on_mock . assert_called_once_with ( self . info ) <EOL> @ mock . patch . object ( ipminative , '<STR_LIT>' , autospec = True ) <EOL> def test_set_power_off_ok ( self , power_off_mock ) : <EOL> power_off_mock . return_value = states . POWER_OFF <EOL> with task_manager . acquire ( self . context , <EOL> self . node . uuid ) as task : <EOL> self . driver . power . set_power_state ( <EOL> task , states . POWER_OFF ) <EOL> power_off_mock . assert_called_once_with ( self . info ) <EOL> @ mock . patch ( '<STR_LIT>' , autospec = True ) <EOL> def test_set_power_on_fail ( self , ipmi_mock ) : <EOL> ipmicmd = ipmi_mock . return_value <EOL> ipmicmd . set_power . return_value = { '<STR_LIT>' : '<STR_LIT:error>' } <EOL> self . config ( retry_timeout = <NUM_LIT> , group = '<STR_LIT>' ) <EOL> with task_manager . acquire ( self . context , <EOL> self . node . uuid ) as task : <EOL> self . assertRaises ( exception . PowerStateFailure , <EOL> self . driver . power . set_power_state , <EOL> task , <EOL> states . POWER_ON ) <EOL> ipmicmd . set_power . assert_called_once_with ( '<STR_LIT>' , <NUM_LIT> ) <EOL> @ mock . patch ( '<STR_LIT>' , autospec = True ) <EOL> def test_set_boot_device_ok ( self , ipmi_mock ) : <EOL> ipmicmd = ipmi_mock . return_value <EOL> ipmicmd . set_bootdev . return_value = None <EOL> with task_manager . acquire ( self . context , <EOL> self . node . uuid ) as task : <EOL> self . driver . management . set_boot_device ( task , boot_devices . PXE ) <EOL> ipmicmd . set_bootdev . assert_called_once_with ( '<STR_LIT>' , persist = False ) <EOL> @ mock . patch ( '<STR_LIT>' , autospec = True ) <EOL> def test_force_set_boot_device_ok ( self , ipmi_mock ) : <EOL> ipmicmd = ipmi_mock . return_value <EOL> ipmicmd . set_bootdev . return_value = None <EOL> with task_manager . acquire ( self . context , <EOL> self . node . uuid ) as task : <EOL> task . node . driver_info [ '<STR_LIT>' ] = True <EOL> self . driver . management . set_boot_device ( task , boot_devices . PXE ) <EOL> task . node . refresh ( ) <EOL> self . assertEqual ( <EOL> False , <EOL> task . node . driver_internal_info [ '<STR_LIT>' ] <EOL> ) <EOL> ipmicmd . set_bootdev . assert_called_once_with ( '<STR_LIT>' , persist = False ) <EOL> @ mock . patch ( '<STR_LIT>' , autospec = True ) <EOL> def test_set_boot_device_with_persistent ( self , ipmi_mock ) : <EOL> ipmicmd = ipmi_mock . return_value <EOL> ipmicmd . set_bootdev . return_value = None <EOL> with task_manager . acquire ( self . context , <EOL> self . node . uuid ) as task : <EOL> task . node . driver_info [ '<STR_LIT>' ] = True <EOL> self . driver . management . set_boot_device ( task , <EOL> boot_devices . PXE , <EOL> True ) <EOL> self . assertEqual ( <EOL> boot_devices . PXE , <EOL> task . node . driver_internal_info [ '<STR_LIT>' ] ) <EOL> ipmicmd . set_bootdev . assert_called_once_with ( '<STR_LIT>' , persist = False ) <EOL> def test_set_boot_device_bad_device ( self ) : <EOL> with task_manager . acquire ( self . context , self . node . uuid ) as task : <EOL> self . assertRaises ( exception . InvalidParameterValue , <EOL> self . driver . management . set_boot_device , <EOL> task , <EOL> '<STR_LIT>' ) <EOL> @ mock . patch . object ( driver_utils , '<STR_LIT>' , autospec = True ) <EOL> @ mock . patch . object ( ipminative , '<STR_LIT>' , autospec = True ) <EOL> def test_reboot_ok ( self , reboot_mock , mock_next_boot ) : <EOL> reboot_mock . return_value = None <EOL> with task_manager . acquire ( self . context , <EOL> self . node . uuid ) as task : <EOL> self . driver . power . reboot ( task ) <EOL> mock_next_boot . assert_called_once_with ( task , self . info ) <EOL> reboot_mock . assert_called_once_with ( self . info ) <EOL> @ mock . patch ( '<STR_LIT>' , autospec = True ) <EOL> def test_reboot_fail ( self , ipmi_mock ) : <EOL> ipmicmd = ipmi_mock . return_value <EOL> ipmicmd . set_power . return_value = { '<STR_LIT:error>' : '<STR_LIT>' } <EOL> self . config ( retry_timeout = <NUM_LIT> , group = '<STR_LIT>' ) <EOL> with task_manager . acquire ( self . context , <EOL> self . node . uuid ) as task : <EOL> self . assertRaises ( exception . PowerStateFailure , <EOL> self . driver . power . reboot , <EOL> task ) <EOL> ipmicmd . set_power . assert_called_once_with ( '<STR_LIT>' , <NUM_LIT> ) <EOL> def test_management_interface_get_supported_boot_devices ( self ) : <EOL> with task_manager . acquire ( self . context , self . node . uuid ) as task : <EOL> expected = [ boot_devices . PXE , boot_devices . DISK , <EOL> boot_devices . CDROM , boot_devices . BIOS ] <EOL> self . assertEqual ( sorted ( expected ) , sorted ( task . driver . management . <EOL> get_supported_boot_devices ( task ) ) ) <EOL> @ mock . patch ( '<STR_LIT>' , autospec = True ) <EOL> def test_management_interface_get_boot_device_good ( self , ipmi_mock ) : <EOL> ipmicmd = ipmi_mock . return_value <EOL> ipmicmd . get_bootdev . return_value = { '<STR_LIT>' : '<STR_LIT>' } <EOL> with task_manager . acquire ( self . context , self . node . uuid ) as task : <EOL> bootdev = self . driver . management . get_boot_device ( task ) <EOL> self . assertEqual ( boot_devices . DISK , bootdev [ '<STR_LIT>' ] ) <EOL> self . assertIsNone ( bootdev [ '<STR_LIT>' ] ) <EOL> @ mock . patch ( '<STR_LIT>' , autospec = True ) <EOL> def test_management_interface_get_boot_device_persistent ( self , ipmi_mock ) : <EOL> ipmicmd = ipmi_mock . return_value <EOL> ipmicmd . get_bootdev . return_value = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True } <EOL> with task_manager . acquire ( self . context , self . node . uuid ) as task : <EOL> bootdev = self . driver . management . get_boot_device ( task ) <EOL> self . assertEqual ( boot_devices . DISK , bootdev [ '<STR_LIT>' ] ) <EOL> self . assertTrue ( bootdev [ '<STR_LIT>' ] ) <EOL> @ mock . patch ( '<STR_LIT>' , autospec = True ) <EOL> def test_management_interface_get_boot_device_fail ( self , ipmi_mock ) : <EOL> ipmicmd = ipmi_mock . return_value <EOL> ipmicmd . get_bootdev . side_effect = pyghmi_exception . IpmiException <EOL> with task_manager . acquire ( self . context , self . node . uuid ) as task : <EOL> self . assertRaises ( exception . IPMIFailure , <EOL> self . driver . management . get_boot_device , task ) <EOL> @ mock . patch ( '<STR_LIT>' , autospec = True ) <EOL> def test_management_interface_get_boot_device_fail_dict ( self , ipmi_mock ) : <EOL> ipmicmd = ipmi_mock . return_value <EOL> ipmicmd . get_bootdev . return_value = { '<STR_LIT:error>' : '<STR_LIT>' } <EOL> with task_manager . acquire ( self . context , self . node . uuid ) as task : <EOL> self . assertRaises ( exception . IPMIFailure , <EOL> self . driver . management . get_boot_device , task ) <EOL> @ mock . patch ( '<STR_LIT>' , autospec = True ) <EOL> def test_management_interface_get_boot_device_unknown ( self , ipmi_mock ) : <EOL> ipmicmd = ipmi_mock . return_value <EOL> ipmicmd . get_bootdev . return_value = { '<STR_LIT>' : '<STR_LIT>' } <EOL> with task_manager . acquire ( self . context , self . node . uuid ) as task : <EOL> expected = { '<STR_LIT>' : None , '<STR_LIT>' : None } <EOL> self . assertEqual ( expected , <EOL> self . driver . management . get_boot_device ( task ) ) <EOL> def test_get_force_boot_device_persistent ( self ) : <EOL> with task_manager . acquire ( self . context , self . node . uuid ) as task : <EOL> task . node . driver_info [ '<STR_LIT>' ] = True <EOL> task . node . driver_internal_info [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> bootdev = self . driver . management . get_boot_device ( task ) <EOL> self . assertEqual ( '<STR_LIT>' , bootdev [ '<STR_LIT>' ] ) <EOL> self . assertTrue ( bootdev [ '<STR_LIT>' ] ) <EOL> def test_management_interface_validate_good ( self ) : <EOL> with task_manager . acquire ( self . context , self . node . uuid ) as task : <EOL> task . driver . management . validate ( task ) <EOL> def test_management_interface_validate_fail ( self ) : <EOL> node = obj_utils . create_test_node ( self . context , <EOL> uuid = uuidutils . generate_uuid ( ) , <EOL> driver = '<STR_LIT>' ) <EOL> with task_manager . acquire ( self . context , node . uuid ) as task : <EOL> self . assertRaises ( exception . MissingParameterValue , <EOL> task . driver . management . validate , task ) <EOL> @ mock . patch ( '<STR_LIT>' , autospec = True ) <EOL> def test_get_sensors_data ( self , ipmi_mock ) : <EOL> ipmicmd = ipmi_mock . return_value <EOL> ipmicmd . get_sensor_data . return_value = None <EOL> with task_manager . acquire ( self . context , <EOL> self . node . uuid ) as task : <EOL> self . driver . management . get_sensors_data ( task ) <EOL> ipmicmd . get_sensor_data . assert_called_once_with ( ) <EOL> @ mock . patch . object ( console_utils , '<STR_LIT>' , <EOL> autospec = True ) <EOL> def test_start_console ( self , mock_exec ) : <EOL> mock_exec . return_value = None <EOL> with task_manager . acquire ( self . context , <EOL> self . node . uuid ) as task : <EOL> self . driver . console . start_console ( task ) <EOL> mock_exec . assert_called_once_with ( self . info [ '<STR_LIT>' ] , <EOL> self . info [ '<STR_LIT:port>' ] , <EOL> mock . ANY ) <EOL> self . assertTrue ( mock_exec . called ) <EOL> @ mock . patch . object ( console_utils , '<STR_LIT>' , <EOL> autospec = True ) <EOL> def test_start_console_fail ( self , mock_exec ) : <EOL> mock_exec . side_effect = iter ( <EOL> [ exception . ConsoleSubprocessFailed ( error = '<STR_LIT:error>' ) ] ) <EOL> with task_manager . acquire ( self . context , <EOL> self . node . uuid ) as task : <EOL> self . assertRaises ( exception . ConsoleSubprocessFailed , <EOL> self . driver . console . start_console , <EOL> task ) <EOL> @ mock . patch . object ( console_utils , '<STR_LIT>' , <EOL> autospec = True ) <EOL> def test_stop_console ( self , mock_exec ) : <EOL> mock_exec . return_value = None <EOL> with task_manager . acquire ( self . context , <EOL> self . node [ '<STR_LIT>' ] ) as task : <EOL> self . driver . console . stop_console ( task ) <EOL> mock_exec . assert_called_once_with ( self . info [ '<STR_LIT>' ] ) <EOL> self . assertTrue ( mock_exec . called ) <EOL> @ mock . patch . object ( console_utils , '<STR_LIT>' , <EOL> autospec = True ) <EOL> def test_stop_console_fail ( self , mock_stop ) : <EOL> mock_stop . side_effect = iter ( [ exception . ConsoleError ( ) ] ) <EOL> with task_manager . acquire ( self . context , <EOL> self . node . uuid ) as task : <EOL> self . assertRaises ( exception . ConsoleError , <EOL> self . driver . console . stop_console , <EOL> task ) <EOL> mock_stop . assert_called_once_with ( self . node . uuid ) <EOL> @ mock . patch . object ( console_utils , '<STR_LIT>' , <EOL> autospec = True ) <EOL> def test_get_console ( self , mock_exec ) : <EOL> url = '<STR_LIT>' <EOL> mock_exec . return_value = url <EOL> expected = { '<STR_LIT:type>' : '<STR_LIT>' , '<STR_LIT:url>' : url } <EOL> with task_manager . acquire ( self . context , <EOL> self . node . uuid ) as task : <EOL> console_info = self . driver . console . get_console ( task ) <EOL> self . assertEqual ( expected , console_info ) <EOL> mock_exec . assert_called_once_with ( self . info [ '<STR_LIT:port>' ] ) <EOL> self . assertTrue ( mock_exec . called ) <EOL> @ mock . patch . object ( ipminative , '<STR_LIT>' , autospec = True ) <EOL> @ mock . patch . object ( ipminative , '<STR_LIT>' , autospec = True ) <EOL> def test_vendor_passthru_validate__send_raw_bytes_good ( self , mock_raw , <EOL> mock_driver ) : <EOL> with task_manager . acquire ( self . context , self . node . uuid ) as task : <EOL> self . driver . vendor . validate ( task , <EOL> method = '<STR_LIT>' , <EOL> http_method = '<STR_LIT:POST>' , <EOL> raw_bytes = '<STR_LIT>' ) <EOL> mock_raw . assert_called_once_with ( '<STR_LIT>' ) <EOL> mock_driver . assert_called_once_with ( task . node ) <EOL> def test_vendor_passthru_validate__send_raw_bytes_fail ( self ) : <EOL> with task_manager . acquire ( self . context , self . node . uuid ) as task : <EOL> self . assertRaises ( exception . MissingParameterValue , <EOL> self . driver . vendor . validate , <EOL> task , method = '<STR_LIT>' ) <EOL> def test_vendor_passthru_vendor_routes ( self ) : <EOL> expected = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> with task_manager . acquire ( self . context , self . node . uuid , <EOL> shared = True ) as task : <EOL> vendor_routes = task . driver . vendor . vendor_routes <EOL> self . assertIsInstance ( vendor_routes , dict ) <EOL> self . assertEqual ( sorted ( expected ) , sorted ( vendor_routes ) ) <EOL> @ mock . patch . object ( ipminative , '<STR_LIT>' , autospec = True ) <EOL> def test_send_raw ( self , send_raw_mock ) : <EOL> bytes = '<STR_LIT>' <EOL> with task_manager . acquire ( self . context , <EOL> self . node . uuid ) as task : <EOL> self . driver . vendor . send_raw ( task , http_method = '<STR_LIT:POST>' , <EOL> raw_bytes = bytes ) <EOL> send_raw_mock . assert_called_once_with ( self . info , bytes ) <EOL> @ mock . patch . object ( ipminative , '<STR_LIT>' , autospec = True ) <EOL> def _test_bmc_reset ( self , warm , expected_bytes , send_raw_mock ) : <EOL> with task_manager . acquire ( self . context , <EOL> self . node . uuid ) as task : <EOL> self . driver . vendor . bmc_reset ( task , http_method = '<STR_LIT:POST>' , warm = warm ) <EOL> send_raw_mock . assert_called_once_with ( self . info , expected_bytes ) <EOL> def test_bmc_reset_cold ( self ) : <EOL> for param in ( False , '<STR_LIT:false>' , '<STR_LIT>' , '<STR_LIT:n>' , '<STR_LIT>' ) : <EOL> self . _test_bmc_reset ( param , '<STR_LIT>' ) <EOL> def test_bmc_reset_warm ( self ) : <EOL> for param in ( True , '<STR_LIT:true>' , '<STR_LIT>' , '<STR_LIT:y>' , '<STR_LIT:yes>' ) : <EOL> self . _test_bmc_reset ( param , '<STR_LIT>' ) </s>
