<s> """<STR_LIT>""" <EOL> import mock <EOL> from oslo_config import cfg <EOL> import six <EOL> from ironic . common import exception <EOL> from ironic . common import states <EOL> from ironic . common import utils <EOL> from ironic . conductor import task_manager <EOL> from ironic . conductor import utils as conductor_utils <EOL> from ironic . db import api as dbapi <EOL> from ironic . drivers . modules . ilo import common as ilo_common <EOL> from ironic . drivers . modules . ilo import inspect as ilo_inspect <EOL> from ironic . drivers . modules . ilo import power as ilo_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_ilo_info ( ) <EOL> CONF = cfg . CONF <EOL> class IloInspectTestCase ( db_base . DbTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( IloInspectTestCase , self ) . setUp ( ) <EOL> mgr_utils . mock_the_extension_manager ( driver = "<STR_LIT>" ) <EOL> self . node = obj_utils . create_test_node ( <EOL> self . context , driver = '<STR_LIT>' , driver_info = INFO_DICT ) <EOL> def test_get_properties ( self ) : <EOL> with task_manager . acquire ( self . context , self . node . uuid , <EOL> shared = False ) as task : <EOL> properties = ilo_common . REQUIRED_PROPERTIES . copy ( ) <EOL> self . assertEqual ( properties , <EOL> task . driver . inspect . get_properties ( ) ) <EOL> @ mock . patch . object ( ilo_common , '<STR_LIT>' , spec_set = True , <EOL> autospec = True ) <EOL> def test_validate ( self , driver_info_mock ) : <EOL> with task_manager . acquire ( self . context , self . node . uuid , <EOL> shared = False ) as task : <EOL> task . driver . inspect . validate ( task ) <EOL> driver_info_mock . assert_called_once_with ( task . node ) <EOL> @ mock . patch . object ( ilo_inspect , '<STR_LIT>' , spec_set = True , <EOL> autospec = True ) <EOL> @ mock . patch . object ( ilo_inspect , '<STR_LIT>' , <EOL> spec_set = True , autospec = True ) <EOL> @ mock . patch . object ( ilo_inspect , '<STR_LIT>' , spec_set = True , <EOL> autospec = True ) <EOL> @ mock . patch . object ( ilo_power . IloPower , '<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_inspect_essential_ok ( self , get_ilo_object_mock , <EOL> power_mock , <EOL> get_essential_mock , <EOL> create_port_mock , <EOL> get_capabilities_mock ) : <EOL> ilo_object_mock = get_ilo_object_mock . return_value <EOL> properties = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:1>' , '<STR_LIT>' : '<STR_LIT>' } <EOL> macs = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } <EOL> capabilities = '<STR_LIT>' <EOL> result = { '<STR_LIT>' : properties , '<STR_LIT>' : macs } <EOL> get_essential_mock . return_value = result <EOL> get_capabilities_mock . return_value = capabilities <EOL> power_mock . return_value = states . POWER_ON <EOL> with task_manager . acquire ( self . context , self . node . uuid , <EOL> shared = False ) as task : <EOL> task . driver . inspect . inspect_hardware ( task ) <EOL> self . assertEqual ( properties , task . node . properties ) <EOL> power_mock . assert_called_once_with ( mock . ANY , task ) <EOL> get_essential_mock . assert_called_once_with ( task . node , <EOL> ilo_object_mock ) <EOL> get_capabilities_mock . assert_called_once_with ( task . node , <EOL> ilo_object_mock ) <EOL> create_port_mock . assert_called_once_with ( task . node , macs ) <EOL> @ mock . patch . object ( ilo_inspect , '<STR_LIT>' , spec_set = True , <EOL> autospec = True ) <EOL> @ mock . patch . object ( ilo_inspect , '<STR_LIT>' , <EOL> spec_set = True , autospec = True ) <EOL> @ mock . patch . object ( ilo_inspect , '<STR_LIT>' , spec_set = True , <EOL> autospec = True ) <EOL> @ mock . patch . object ( conductor_utils , '<STR_LIT>' , spec_set = True , <EOL> autospec = True ) <EOL> @ mock . patch . object ( ilo_power . IloPower , '<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_inspect_essential_ok_power_off ( self , get_ilo_object_mock , <EOL> power_mock , <EOL> set_power_mock , <EOL> get_essential_mock , <EOL> create_port_mock , <EOL> get_capabilities_mock ) : <EOL> ilo_object_mock = get_ilo_object_mock . return_value <EOL> properties = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:1>' , '<STR_LIT>' : '<STR_LIT>' } <EOL> macs = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } <EOL> capabilities = '<STR_LIT>' <EOL> result = { '<STR_LIT>' : properties , '<STR_LIT>' : macs } <EOL> get_essential_mock . return_value = result <EOL> get_capabilities_mock . return_value = capabilities <EOL> power_mock . return_value = states . POWER_OFF <EOL> with task_manager . acquire ( self . context , self . node . uuid , <EOL> shared = False ) as task : <EOL> task . driver . inspect . inspect_hardware ( task ) <EOL> self . assertEqual ( properties , task . node . properties ) <EOL> power_mock . assert_called_once_with ( mock . ANY , task ) <EOL> set_power_mock . assert_any_call ( task , states . POWER_ON ) <EOL> get_essential_mock . assert_called_once_with ( task . node , <EOL> ilo_object_mock ) <EOL> get_capabilities_mock . assert_called_once_with ( task . node , <EOL> ilo_object_mock ) <EOL> create_port_mock . assert_called_once_with ( task . node , macs ) <EOL> @ mock . patch . object ( ilo_inspect , '<STR_LIT>' , spec_set = True , <EOL> autospec = True ) <EOL> @ mock . patch . object ( ilo_inspect , '<STR_LIT>' , <EOL> spec_set = True , autospec = True ) <EOL> @ mock . patch . object ( ilo_inspect , '<STR_LIT>' , spec_set = True , <EOL> autospec = True ) <EOL> @ mock . patch . object ( ilo_power . IloPower , '<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_inspect_essential_capabilities_ok ( self , get_ilo_object_mock , <EOL> power_mock , <EOL> get_essential_mock , <EOL> create_port_mock , <EOL> get_capabilities_mock ) : <EOL> ilo_object_mock = get_ilo_object_mock . return_value <EOL> properties = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:1>' , '<STR_LIT>' : '<STR_LIT>' } <EOL> macs = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } <EOL> capability_str = '<STR_LIT>' <EOL> capabilities = { '<STR_LIT>' : '<STR_LIT>' } <EOL> result = { '<STR_LIT>' : properties , '<STR_LIT>' : macs } <EOL> get_essential_mock . return_value = result <EOL> get_capabilities_mock . return_value = capabilities <EOL> power_mock . return_value = states . POWER_ON <EOL> with task_manager . acquire ( self . context , self . node . uuid , <EOL> shared = False ) as task : <EOL> task . driver . inspect . inspect_hardware ( task ) <EOL> expected_properties = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:1>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : capability_str } <EOL> self . assertEqual ( expected_properties , task . node . properties ) <EOL> power_mock . assert_called_once_with ( mock . ANY , task ) <EOL> get_essential_mock . assert_called_once_with ( task . node , <EOL> ilo_object_mock ) <EOL> get_capabilities_mock . assert_called_once_with ( task . node , <EOL> ilo_object_mock ) <EOL> create_port_mock . assert_called_once_with ( task . node , macs ) <EOL> @ mock . patch . object ( ilo_inspect , '<STR_LIT>' , spec_set = True , <EOL> autospec = True ) <EOL> @ mock . patch . object ( ilo_inspect , '<STR_LIT>' , <EOL> spec_set = True , autospec = True ) <EOL> @ mock . patch . object ( ilo_inspect , '<STR_LIT>' , spec_set = True , <EOL> autospec = True ) <EOL> @ mock . patch . object ( ilo_power . IloPower , '<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_inspect_essential_capabilities_exist_ok ( self , get_ilo_object_mock , <EOL> power_mock , <EOL> get_essential_mock , <EOL> create_port_mock , <EOL> get_capabilities_mock ) : <EOL> ilo_object_mock = get_ilo_object_mock . return_value <EOL> properties = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:1>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> macs = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } <EOL> result = { '<STR_LIT>' : properties , '<STR_LIT>' : macs } <EOL> capabilities = { '<STR_LIT>' : '<STR_LIT>' } <EOL> get_essential_mock . return_value = result <EOL> get_capabilities_mock . return_value = capabilities <EOL> power_mock . return_value = states . POWER_ON <EOL> with task_manager . acquire ( self . context , self . node . uuid , <EOL> shared = False ) as task : <EOL> task . node . properties = { '<STR_LIT>' : '<STR_LIT>' } <EOL> expected_capabilities = ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> set1 = set ( expected_capabilities . split ( '<STR_LIT:U+002C>' ) ) <EOL> task . driver . inspect . inspect_hardware ( task ) <EOL> end_capabilities = task . node . properties [ '<STR_LIT>' ] <EOL> set2 = set ( end_capabilities . split ( '<STR_LIT:U+002C>' ) ) <EOL> self . assertEqual ( set1 , set2 ) <EOL> expected_properties = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:1>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : end_capabilities } <EOL> power_mock . assert_called_once_with ( mock . ANY , task ) <EOL> self . assertEqual ( task . node . properties , expected_properties ) <EOL> get_essential_mock . assert_called_once_with ( task . node , <EOL> ilo_object_mock ) <EOL> get_capabilities_mock . assert_called_once_with ( task . node , <EOL> ilo_object_mock ) <EOL> create_port_mock . assert_called_once_with ( task . node , macs ) <EOL> class TestInspectPrivateMethods ( db_base . DbTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( TestInspectPrivateMethods , self ) . setUp ( ) <EOL> mgr_utils . mock_the_extension_manager ( driver = "<STR_LIT>" ) <EOL> self . node = obj_utils . create_test_node ( <EOL> self . context , driver = '<STR_LIT>' , driver_info = INFO_DICT ) <EOL> @ mock . patch . object ( ilo_inspect . LOG , '<STR_LIT:info>' , spec_set = True , autospec = True ) <EOL> @ mock . patch . object ( dbapi , '<STR_LIT>' , spec_set = True , autospec = True ) <EOL> def test__create_ports_if_not_exist ( self , instance_mock , log_mock ) : <EOL> db_obj = instance_mock . return_value <EOL> macs = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } <EOL> node_id = self . node . id <EOL> port_dict1 = { '<STR_LIT:address>' : '<STR_LIT>' , '<STR_LIT>' : node_id } <EOL> port_dict2 = { '<STR_LIT:address>' : '<STR_LIT>' , '<STR_LIT>' : node_id } <EOL> ilo_inspect . _create_ports_if_not_exist ( self . node , macs ) <EOL> instance_mock . assert_called_once_with ( ) <EOL> self . assertTrue ( log_mock . called ) <EOL> db_obj . create_port . assert_any_call ( port_dict1 ) <EOL> db_obj . create_port . assert_any_call ( port_dict2 ) <EOL> @ mock . patch . object ( ilo_inspect . LOG , '<STR_LIT>' , <EOL> spec_set = True , autospec = True ) <EOL> @ mock . patch . object ( dbapi , '<STR_LIT>' , spec_set = True , autospec = True ) <EOL> def test__create_ports_if_not_exist_mac_exception ( self , <EOL> instance_mock , <EOL> log_mock ) : <EOL> dbapi_mock = instance_mock . return_value <EOL> dbapi_mock . create_port . side_effect = exception . MACAlreadyExists ( '<STR_LIT:f>' ) <EOL> macs = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } <EOL> ilo_inspect . _create_ports_if_not_exist ( self . node , macs ) <EOL> instance_mock . assert_called_once_with ( ) <EOL> self . assertTrue ( log_mock . called ) <EOL> def test__get_essential_properties_ok ( self ) : <EOL> ilo_mock = mock . MagicMock ( spec = [ '<STR_LIT>' ] ) <EOL> properties = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:1>' , '<STR_LIT>' : '<STR_LIT>' } <EOL> macs = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } <EOL> result = { '<STR_LIT>' : properties , '<STR_LIT>' : macs } <EOL> ilo_mock . get_essential_properties . return_value = result <EOL> actual_result = ilo_inspect . _get_essential_properties ( self . node , <EOL> ilo_mock ) <EOL> self . assertEqual ( result , actual_result ) <EOL> def test__get_essential_properties_fail ( self ) : <EOL> ilo_mock = mock . MagicMock ( <EOL> spec = [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> properties = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:1>' } <EOL> macs = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } <EOL> result = { '<STR_LIT>' : properties , '<STR_LIT>' : macs } <EOL> ilo_mock . get_essential_properties . return_value = result <EOL> result = self . assertRaises ( exception . HardwareInspectionFailure , <EOL> ilo_inspect . _get_essential_properties , <EOL> self . node , <EOL> ilo_mock ) <EOL> self . assertEqual ( <EOL> six . text_type ( result ) , <EOL> ( "<STR_LIT>" <EOL> "<STR_LIT>" ) ) <EOL> def test__get_essential_properties_fail_invalid_format ( self ) : <EOL> ilo_mock = mock . MagicMock ( <EOL> spec = [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> properties = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT:1>' ] <EOL> macs = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> capabilities = '<STR_LIT>' <EOL> result = { '<STR_LIT>' : properties , '<STR_LIT>' : macs } <EOL> ilo_mock . get_essential_properties . return_value = result <EOL> ilo_mock . get_additional_capabilities . return_value = capabilities <EOL> self . assertRaises ( exception . HardwareInspectionFailure , <EOL> ilo_inspect . _get_essential_properties , <EOL> self . node , ilo_mock ) <EOL> def test__get_essential_properties_fail_mac_invalid_format ( self ) : <EOL> ilo_mock = mock . MagicMock ( spec = [ '<STR_LIT>' ] ) <EOL> properties = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:1>' , '<STR_LIT>' : '<STR_LIT>' } <EOL> macs = '<STR_LIT>' <EOL> result = { '<STR_LIT>' : properties , '<STR_LIT>' : macs } <EOL> ilo_mock . get_essential_properties . return_value = result <EOL> self . assertRaises ( exception . HardwareInspectionFailure , <EOL> ilo_inspect . _get_essential_properties , <EOL> self . node , ilo_mock ) <EOL> def test__get_essential_properties_hardware_port_empty ( self ) : <EOL> ilo_mock = mock . MagicMock ( <EOL> spec = [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> properties = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:1>' , '<STR_LIT>' : '<STR_LIT>' } <EOL> macs = None <EOL> result = { '<STR_LIT>' : properties , '<STR_LIT>' : macs } <EOL> capabilities = '<STR_LIT>' <EOL> ilo_mock . get_essential_properties . return_value = result <EOL> ilo_mock . get_additional_capabilities . return_value = capabilities <EOL> self . assertRaises ( exception . HardwareInspectionFailure , <EOL> ilo_inspect . _get_essential_properties , <EOL> self . node , ilo_mock ) <EOL> def test__get_essential_properties_hardware_port_not_dict ( self ) : <EOL> ilo_mock = mock . MagicMock ( spec = [ '<STR_LIT>' ] ) <EOL> properties = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:1>' , '<STR_LIT>' : '<STR_LIT>' } <EOL> macs = '<STR_LIT>' <EOL> result = { '<STR_LIT>' : properties , '<STR_LIT>' : macs } <EOL> ilo_mock . get_essential_properties . return_value = result <EOL> result = self . assertRaises ( <EOL> exception . HardwareInspectionFailure , <EOL> ilo_inspect . _get_essential_properties , self . node , ilo_mock ) <EOL> @ mock . patch . object ( utils , '<STR_LIT>' , spec_set = True , <EOL> autospec = True ) <EOL> def test__get_capabilities_ok ( self , capability_mock ) : <EOL> ilo_mock = mock . MagicMock ( spec = [ '<STR_LIT>' ] ) <EOL> capabilities = { '<STR_LIT>' : '<STR_LIT>' } <EOL> ilo_mock . get_server_capabilities . return_value = capabilities <EOL> cap = ilo_inspect . _get_capabilities ( self . node , ilo_mock ) <EOL> self . assertEqual ( cap , capabilities ) <EOL> def test__validate_ok ( self ) : <EOL> properties = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:2>' , '<STR_LIT>' : '<STR_LIT>' } <EOL> macs = { '<STR_LIT>' : '<STR_LIT>' } <EOL> data = { '<STR_LIT>' : properties , '<STR_LIT>' : macs } <EOL> valid_keys = ilo_inspect . IloInspect . ESSENTIAL_PROPERTIES <EOL> ilo_inspect . _validate ( self . node , data ) <EOL> self . assertEqual ( sorted ( set ( properties ) ) , sorted ( valid_keys ) ) <EOL> def test__validate_essential_keys_fail_missing_key ( self ) : <EOL> properties = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:1>' } <EOL> macs = { '<STR_LIT>' : '<STR_LIT>' } <EOL> data = { '<STR_LIT>' : properties , '<STR_LIT>' : macs } <EOL> self . assertRaises ( exception . HardwareInspectionFailure , <EOL> ilo_inspect . _validate , self . node , data ) </s>
