<s> """<STR_LIT>""" <EOL> import mock <EOL> from oslo_concurrency import processutils <EOL> from oslo_config import cfg <EOL> import time <EOL> from ironic . common import exception <EOL> from ironic . common import utils <EOL> from ironic . drivers . modules . amt import common as amt_common <EOL> from ironic . drivers . modules . amt import resource_uris <EOL> from ironic . tests import base <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 . drivers . modules . amt import utils as test_utils <EOL> from ironic . tests . unit . drivers import third_party_driver_mock_specs as mock_specs <EOL> from ironic . tests . unit . objects import utils as obj_utils <EOL> INFO_DICT = db_utils . get_test_amt_info ( ) <EOL> CONF = cfg . CONF <EOL> class AMTCommonMethodsTestCase ( db_base . DbTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( AMTCommonMethodsTestCase , self ) . setUp ( ) <EOL> self . node = obj_utils . create_test_node ( self . context , <EOL> driver = '<STR_LIT>' , <EOL> driver_info = INFO_DICT ) <EOL> def test_parse_driver_info ( self ) : <EOL> info = amt_common . parse_driver_info ( self . node ) <EOL> self . assertIsNotNone ( info . get ( '<STR_LIT:address>' ) ) <EOL> self . assertIsNotNone ( info . get ( '<STR_LIT:username>' ) ) <EOL> self . assertIsNotNone ( info . get ( '<STR_LIT:password>' ) ) <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> amt_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> amt_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> amt_common . parse_driver_info , self . node ) <EOL> def test_parse_driver_info_missing_protocol ( self ) : <EOL> del self . node . driver_info [ '<STR_LIT>' ] <EOL> info = amt_common . parse_driver_info ( self . node ) <EOL> self . assertEqual ( '<STR_LIT:http>' , info . get ( '<STR_LIT>' ) ) <EOL> def test_parse_driver_info_wrong_protocol ( self ) : <EOL> self . node . driver_info [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> self . assertRaises ( exception . InvalidParameterValue , <EOL> amt_common . parse_driver_info , self . node ) <EOL> @ mock . patch . object ( amt_common , '<STR_LIT>' , spec_set = True , autospec = True ) <EOL> def test_get_wsman_client ( self , mock_client ) : <EOL> info = amt_common . parse_driver_info ( self . node ) <EOL> amt_common . get_wsman_client ( self . node ) <EOL> options = { '<STR_LIT:address>' : info [ '<STR_LIT:address>' ] , <EOL> '<STR_LIT>' : info [ '<STR_LIT>' ] , <EOL> '<STR_LIT:username>' : info [ '<STR_LIT:username>' ] , <EOL> '<STR_LIT:password>' : info [ '<STR_LIT:password>' ] } <EOL> mock_client . assert_called_once_with ( ** options ) <EOL> def test_xml_find ( self ) : <EOL> namespace = '<STR_LIT>' <EOL> value = '<STR_LIT>' <EOL> test_xml = test_utils . build_soap_xml ( [ { '<STR_LIT>' : value } ] , <EOL> namespace ) <EOL> mock_doc = test_utils . mock_wsman_root ( test_xml ) <EOL> result = amt_common . xml_find ( mock_doc , namespace , '<STR_LIT>' ) <EOL> self . assertEqual ( value , result . text ) <EOL> def test_xml_find_fail ( self ) : <EOL> mock_doc = None <EOL> self . assertRaises ( exception . AMTConnectFailure , <EOL> amt_common . xml_find , <EOL> mock_doc , '<STR_LIT>' , '<STR_LIT>' ) <EOL> @ mock . patch . object ( amt_common , '<STR_LIT>' , spec_set = mock_specs . PYWSMAN_SPEC ) <EOL> class AMTCommonClientTestCase ( base . TestCase ) : <EOL> def setUp ( self ) : <EOL> super ( AMTCommonClientTestCase , self ) . setUp ( ) <EOL> self . info = { key [ <NUM_LIT:4> : ] : INFO_DICT [ key ] for key in INFO_DICT . keys ( ) } <EOL> def test_wsman_get ( self , mock_client_pywsman ) : <EOL> namespace = resource_uris . CIM_AssociatedPowerManagementService <EOL> result_xml = test_utils . build_soap_xml ( [ { '<STR_LIT>' : <EOL> '<STR_LIT:2>' } ] , <EOL> namespace ) <EOL> mock_doc = test_utils . mock_wsman_root ( result_xml ) <EOL> mock_pywsman = mock_client_pywsman . Client . return_value <EOL> mock_pywsman . get . return_value = mock_doc <EOL> client = amt_common . Client ( ** self . info ) <EOL> client . wsman_get ( namespace ) <EOL> mock_pywsman . get . assert_called_once_with ( mock . ANY , namespace ) <EOL> def test_wsman_get_fail ( self , mock_client_pywsman ) : <EOL> namespace = amt_common . _SOAP_ENVELOPE <EOL> result_xml = test_utils . build_soap_xml ( [ { '<STR_LIT>' : '<STR_LIT>' } ] , <EOL> namespace ) <EOL> mock_doc = test_utils . mock_wsman_root ( result_xml ) <EOL> mock_pywsman = mock_client_pywsman . Client . return_value <EOL> mock_pywsman . get . return_value = mock_doc <EOL> client = amt_common . Client ( ** self . info ) <EOL> self . assertRaises ( exception . AMTFailure , client . wsman_get , namespace ) <EOL> mock_pywsman . get . assert_called_once_with ( mock . ANY , namespace ) <EOL> def test_wsman_invoke ( self , mock_client_pywsman ) : <EOL> namespace = resource_uris . CIM_BootSourceSetting <EOL> result_xml = test_utils . build_soap_xml ( [ { '<STR_LIT>' : <EOL> '<STR_LIT:0>' } ] , <EOL> namespace ) <EOL> mock_doc = test_utils . mock_wsman_root ( result_xml ) <EOL> mock_pywsman = mock_client_pywsman . Client . return_value <EOL> mock_pywsman . invoke . return_value = mock_doc <EOL> method = '<STR_LIT>' <EOL> options = mock . Mock ( spec_set = [ ] ) <EOL> client = amt_common . Client ( ** self . info ) <EOL> doc = None <EOL> client . wsman_invoke ( options , namespace , method , doc ) <EOL> mock_pywsman . invoke . assert_called_once_with ( options , namespace , method ) <EOL> doc = '<STR_LIT>' <EOL> client . wsman_invoke ( options , namespace , method , doc ) <EOL> mock_pywsman . invoke . assert_called_with ( options , namespace , method , doc ) <EOL> def test_wsman_invoke_fail ( self , mock_client_pywsman ) : <EOL> namespace = resource_uris . CIM_BootSourceSetting <EOL> result_xml = test_utils . build_soap_xml ( [ { '<STR_LIT>' : <EOL> '<STR_LIT:2>' } ] , <EOL> namespace ) <EOL> mock_doc = test_utils . mock_wsman_root ( result_xml ) <EOL> mock_pywsman = mock_client_pywsman . Client . return_value <EOL> mock_pywsman . invoke . return_value = mock_doc <EOL> method = '<STR_LIT>' <EOL> options = mock . Mock ( spec_set = [ ] ) <EOL> client = amt_common . Client ( ** self . info ) <EOL> self . assertRaises ( exception . AMTFailure , <EOL> client . wsman_invoke , <EOL> options , namespace , method ) <EOL> mock_pywsman . invoke . assert_called_once_with ( options , namespace , method ) <EOL> class AwakeAMTInterfaceTestCase ( db_base . DbTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( AwakeAMTInterfaceTestCase , self ) . setUp ( ) <EOL> amt_common . AMT_AWAKE_CACHE = { } <EOL> self . info = INFO_DICT <EOL> self . node = obj_utils . create_test_node ( self . context , <EOL> driver = '<STR_LIT>' , <EOL> driver_info = self . info ) <EOL> @ mock . patch . object ( utils , '<STR_LIT>' , spec_set = True , autospec = True ) <EOL> def test_awake_amt_interface ( self , mock_ex ) : <EOL> amt_common . awake_amt_interface ( self . node ) <EOL> expected_args = [ '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT> , '<STR_LIT:-c>' , <NUM_LIT:5> , '<STR_LIT>' ] <EOL> mock_ex . assert_called_once_with ( * expected_args ) <EOL> @ mock . patch . object ( utils , '<STR_LIT>' , spec_set = True , autospec = True ) <EOL> def test_awake_amt_interface_fail ( self , mock_ex ) : <EOL> mock_ex . side_effect = processutils . ProcessExecutionError ( '<STR_LIT:x>' ) <EOL> self . assertRaises ( exception . AMTConnectFailure , <EOL> amt_common . awake_amt_interface , <EOL> self . node ) <EOL> @ mock . patch . object ( utils , '<STR_LIT>' , spec_set = True , autospec = True ) <EOL> def test_awake_amt_interface_in_cache_time ( self , mock_ex ) : <EOL> amt_common . AMT_AWAKE_CACHE [ self . node . uuid ] = time . time ( ) <EOL> amt_common . awake_amt_interface ( self . node ) <EOL> self . assertFalse ( mock_ex . called ) <EOL> @ mock . patch . object ( utils , '<STR_LIT>' , spec_set = True , autospec = True ) <EOL> def test_awake_amt_interface_disable ( self , mock_ex ) : <EOL> CONF . set_override ( '<STR_LIT>' , <NUM_LIT:0> , '<STR_LIT>' ) <EOL> amt_common . awake_amt_interface ( self . node ) <EOL> self . assertFalse ( mock_ex . called ) <EOL> def test_out_range_protocol ( self ) : <EOL> self . assertRaises ( ValueError , cfg . CONF . set_override , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> enforce_type = True ) </s>
