def test_disable_embedded_lldp_agent_in_cna_card(self, mock_exists, mock_listdir, mock_log): mock_exists.return_value = True mock_listdir.return_value = ['foo', 'bar'] write_mock = mock.mock_open() with mock.patch('six.moves.builtins.open', write_mock, create=True): cna._disable_embedded_lldp_agent_in_cna_card() write_mock().write.assert_called_with('lldp stop') self.assertFalse(mock_log.warning.called)
def test_disable_embedded_lldp_agent_in_cna_card(self, mock_exists, mock_listdir, mock_log): mock_exists.return_value = True mock_listdir.return_value = ['foo', 'bar'] write_mock = mock.mock_open() with mock.patch('six.moves.builtins.open', write_mock, create=True): cna._disable_embedded_lldp_agent_in_cna_card() write_mock().write.assert_called_with('lldp stop') self.assertFalse(mock_log.warning.called)
def test_disable_embedded_lldp_agent_write_error(self, mock_exists, mock_listdir, mock_log): mock_exists.return_value = True listdir_dict = ['foo', 'bar'] mock_listdir.return_value = listdir_dict write_mock = mock.mock_open() with mock.patch('six.moves.builtins.open', write_mock, create=True): write_mock.side_effect = IOError('fake error') cna._disable_embedded_lldp_agent_in_cna_card() expected_log_message = ('Failed to disable the embedded LLDP on ' 'Intel CNA network card. Addresses of ' 'failed pci devices: {}'.format( str(listdir_dict).strip('[]'))) mock_log.warning.assert_called_once_with(expected_log_message)
def test_disable_embedded_lldp_agent_write_error(self, mock_exists, mock_listdir, mock_log): mock_exists.return_value = True listdir_dict = ['foo', 'bar'] mock_listdir.return_value = listdir_dict write_mock = mock.mock_open() with mock.patch('six.moves.builtins.open', write_mock, create=True): write_mock.side_effect = IOError('fake error') cna._disable_embedded_lldp_agent_in_cna_card() expected_log_message = ('Failed to disable the embedded LLDP on ' 'Intel CNA network card. Addresses of ' 'failed pci devices: {}' .format(str(listdir_dict).strip('[]'))) mock_log.warning.assert_called_once_with(expected_log_message)
def test_disable_embedded_lldp_agent_wrong_dir_path( self, mock_exists, mock_log): mock_exists.return_value = False cna._disable_embedded_lldp_agent_in_cna_card() expected_log_message = 'Driver i40e was not loaded properly' mock_log.warning.assert_called_once_with(expected_log_message)
def test_disable_embedded_lldp_agent_wrong_dir_path(self, mock_exists, mock_log): mock_exists.return_value = False cna._disable_embedded_lldp_agent_in_cna_card() expected_log_message = 'Driver i40e was not loaded properly' mock_log.warning.assert_called_once_with(expected_log_message)