<s> """<STR_LIT>""" <EOL> import mock <EOL> from oslo_config import cfg <EOL> from oslo_utils import uuidutils <EOL> from ironic . common import exception <EOL> from ironic . common import states <EOL> from ironic . conductor import task_manager <EOL> from ironic . drivers . modules . irmc import boot as irmc_boot <EOL> from ironic . drivers . modules . irmc import common as irmc_common <EOL> from ironic . drivers . modules . irmc import power as irmc_power <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_irmc_info ( ) <EOL> CONF = cfg . CONF <EOL> @ mock . patch . object ( irmc_common , '<STR_LIT>' , spec_set = True , <EOL> autospec = True ) <EOL> class IRMCPowerInternalMethodsTestCase ( db_base . DbTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( IRMCPowerInternalMethodsTestCase , self ) . setUp ( ) <EOL> mgr_utils . mock_the_extension_manager ( driver = '<STR_LIT>' ) <EOL> driver_info = INFO_DICT <EOL> self . node = db_utils . create_test_node ( <EOL> driver = '<STR_LIT>' , <EOL> driver_info = driver_info , <EOL> instance_uuid = uuidutils . generate_uuid ( ) ) <EOL> @ mock . patch . object ( irmc_boot , '<STR_LIT>' ) <EOL> def test__set_power_state_power_on_ok ( <EOL> self , <EOL> attach_boot_iso_if_needed_mock , <EOL> get_irmc_client_mock ) : <EOL> irmc_client = get_irmc_client_mock . return_value <EOL> target_state = states . POWER_ON <EOL> with task_manager . acquire ( self . context , self . node . uuid , <EOL> shared = True ) as task : <EOL> irmc_power . _set_power_state ( task , target_state ) <EOL> attach_boot_iso_if_needed_mock . assert_called_once_with ( task ) <EOL> irmc_client . assert_called_once_with ( irmc_power . scci . POWER_ON ) <EOL> def test__set_power_state_power_off_ok ( self , <EOL> get_irmc_client_mock ) : <EOL> irmc_client = get_irmc_client_mock . return_value <EOL> target_state = states . POWER_OFF <EOL> with task_manager . acquire ( self . context , self . node . uuid , <EOL> shared = True ) as task : <EOL> irmc_power . _set_power_state ( task , target_state ) <EOL> irmc_client . assert_called_once_with ( irmc_power . scci . POWER_OFF ) <EOL> @ mock . patch . object ( irmc_boot , '<STR_LIT>' ) <EOL> def test__set_power_state_power_reboot_ok ( <EOL> self , <EOL> attach_boot_iso_if_needed_mock , <EOL> get_irmc_client_mock ) : <EOL> irmc_client = get_irmc_client_mock . return_value <EOL> target_state = states . REBOOT <EOL> with task_manager . acquire ( self . context , self . node . uuid , <EOL> shared = True ) as task : <EOL> irmc_power . _set_power_state ( task , target_state ) <EOL> attach_boot_iso_if_needed_mock . assert_called_once_with ( task ) <EOL> irmc_client . assert_called_once_with ( irmc_power . scci . POWER_RESET ) <EOL> def test__set_power_state_invalid_target_state ( self , <EOL> get_irmc_client_mock ) : <EOL> with task_manager . acquire ( self . context , self . node . uuid , <EOL> shared = True ) as task : <EOL> self . assertRaises ( exception . InvalidParameterValue , <EOL> irmc_power . _set_power_state , <EOL> task , <EOL> states . ERROR ) <EOL> def test__set_power_state_scci_exception ( self , <EOL> get_irmc_client_mock ) : <EOL> irmc_client = get_irmc_client_mock . return_value <EOL> irmc_client . side_effect = Exception ( ) <EOL> irmc_power . scci . SCCIClientError = Exception <EOL> with task_manager . acquire ( self . context , self . node . uuid , <EOL> shared = True ) as task : <EOL> self . assertRaises ( exception . IRMCOperationError , <EOL> irmc_power . _set_power_state , <EOL> task , <EOL> states . POWER_ON ) <EOL> class IRMCPowerTestCase ( db_base . DbTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( IRMCPowerTestCase , self ) . setUp ( ) <EOL> driver_info = INFO_DICT <EOL> mgr_utils . mock_the_extension_manager ( driver = "<STR_LIT>" ) <EOL> self . node = obj_utils . create_test_node ( self . context , <EOL> driver = '<STR_LIT>' , <EOL> driver_info = driver_info ) <EOL> def test_get_properties ( self ) : <EOL> with task_manager . acquire ( self . context , self . node . uuid , <EOL> shared = True ) as task : <EOL> properties = task . driver . get_properties ( ) <EOL> for prop in irmc_common . COMMON_PROPERTIES : <EOL> self . assertIn ( prop , properties ) <EOL> @ mock . patch . object ( irmc_common , '<STR_LIT>' , spec_set = True , <EOL> autospec = True ) <EOL> def test_validate ( self , mock_drvinfo ) : <EOL> with task_manager . acquire ( self . context , self . node . uuid , <EOL> shared = True ) as task : <EOL> task . driver . power . validate ( task ) <EOL> mock_drvinfo . assert_called_once_with ( task . node ) <EOL> @ mock . patch . object ( irmc_common , '<STR_LIT>' , spec_set = True , <EOL> autospec = True ) <EOL> def test_validate_fail ( self , mock_drvinfo ) : <EOL> side_effect = iter ( [ exception . InvalidParameterValue ( "<STR_LIT>" ) ] ) <EOL> mock_drvinfo . side_effect = side_effect <EOL> with task_manager . acquire ( self . context , self . node . uuid , <EOL> shared = True ) as task : <EOL> self . assertRaises ( exception . InvalidParameterValue , <EOL> task . driver . power . validate , <EOL> task ) <EOL> @ mock . patch ( '<STR_LIT>' , <EOL> spec_set = True , autospec = True ) <EOL> def test_get_power_state ( self , mock_IPMIPower ) : <EOL> ipmi_power = mock_IPMIPower . return_value <EOL> ipmi_power . get_power_state . return_value = states . POWER_ON <EOL> with task_manager . acquire ( self . context , self . node . uuid , <EOL> shared = True ) as task : <EOL> self . assertEqual ( states . POWER_ON , <EOL> task . driver . power . get_power_state ( task ) ) <EOL> ipmi_power . get_power_state . assert_called_once_with ( task ) <EOL> @ mock . patch . object ( irmc_power , '<STR_LIT>' , spec_set = True , <EOL> autospec = True ) <EOL> def test_set_power_state ( self , mock_set_power ) : <EOL> mock_set_power . return_value = states . POWER_ON <EOL> with task_manager . acquire ( self . context , self . node . uuid , <EOL> shared = False ) as task : <EOL> task . driver . power . set_power_state ( task , states . POWER_ON ) <EOL> mock_set_power . assert_called_once_with ( task , states . POWER_ON ) <EOL> @ mock . patch . object ( irmc_power , '<STR_LIT>' , spec_set = True , <EOL> autospec = True ) <EOL> @ mock . patch . object ( irmc_power . IRMCPower , '<STR_LIT>' , spec_set = True , <EOL> autospec = True ) <EOL> def test_reboot_reboot ( self , mock_get_power , mock_set_power ) : <EOL> with task_manager . acquire ( self . context , self . node . uuid , <EOL> shared = False ) as task : <EOL> mock_get_power . return_value = states . POWER_ON <EOL> task . driver . power . reboot ( task ) <EOL> mock_get_power . assert_called_once_with ( <EOL> task . driver . power , task ) <EOL> mock_set_power . assert_called_once_with ( task , states . REBOOT ) <EOL> @ mock . patch . object ( irmc_power , '<STR_LIT>' , spec_set = True , <EOL> autospec = True ) <EOL> @ mock . patch . object ( irmc_power . IRMCPower , '<STR_LIT>' , spec_set = True , <EOL> autospec = True ) <EOL> def test_reboot_power_on ( self , mock_get_power , mock_set_power ) : <EOL> with task_manager . acquire ( self . context , self . node . uuid , <EOL> shared = False ) as task : <EOL> mock_get_power . return_value = states . POWER_OFF <EOL> task . driver . power . reboot ( task ) <EOL> mock_get_power . assert_called_once_with ( <EOL> task . driver . power , task ) <EOL> mock_set_power . assert_called_once_with ( task , states . POWER_ON ) </s>
