"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "ironic/tests/unit/drivers/modules/test_agent_base.py" between
ironic-16.0.2.tar.gz and ironic-16.0.3.tar.gz

About: OpenStack Ironic (Optional Service: Bare-Metal Provisioning) aims to provision bare metal machines instead of virtual machines, forked from the Nova baremetal driver.
The "Victoria" series (latest release).

test_agent_base.py  (ironic-16.0.2):test_agent_base.py  (ironic-16.0.3)
skipping to change at line 598 skipping to change at line 598
for i in range(len(mocks)): for i in range(len(mocks)):
before_failed_mocks = mocks[:i] before_failed_mocks = mocks[:i]
failed_mock = mocks[i] failed_mock = mocks[i]
after_failed_mocks = mocks[i + 1:] after_failed_mocks = mocks[i + 1:]
failed_mock.side_effect = Exception() failed_mock.side_effect = Exception()
with task_manager.acquire( with task_manager.acquire(
self.context, self.node.uuid, shared=False) as task: self.context, self.node.uuid, shared=False) as task:
self.deploy.heartbeat(task, 'http://127.0.0.1:8080', '1.0.0') self.deploy.heartbeat(task, 'http://127.0.0.1:8080', '1.0.0')
mock_touch.assert_called_once_with(mock.ANY) mock_touch.assert_called_once_with(mock.ANY)
mock_handler.assert_called_once_with(task, mock.ANY) mock_handler.assert_called_once_with(task, mock.ANY, mock.ANY)
for called in before_failed_mocks + [failed_mock]: for called in before_failed_mocks + [failed_mock]:
self.assertTrue(called.called) self.assertTrue(called.called)
for not_called in after_failed_mocks: for not_called in after_failed_mocks:
self.assertFalse(not_called.called) self.assertFalse(not_called.called)
# Reset mocks for the next interaction # Reset mocks for the next interaction
for m in mocks + [mock_touch, mock_handler]: for m in mocks + [mock_touch, mock_handler]:
m.reset_mock() m.reset_mock()
failed_mock.side_effect = None failed_mock.side_effect = None
skipping to change at line 672 skipping to change at line 672
mock_continue.side_effect = Exception() mock_continue.side_effect = Exception()
self.node.provision_state = states.CLEANWAIT self.node.provision_state = states.CLEANWAIT
self.node.save() self.node.save()
with task_manager.acquire( with task_manager.acquire(
self.context, self.node.uuid, shared=False) as task: self.context, self.node.uuid, shared=False) as task:
self.deploy.heartbeat(task, 'http://127.0.0.1:8080', '1.0.0') self.deploy.heartbeat(task, 'http://127.0.0.1:8080', '1.0.0')
mock_continue.assert_called_once_with(mock.ANY, task) mock_continue.assert_called_once_with(mock.ANY, task)
mock_handler.assert_called_once_with(task, mock.ANY) mock_handler.assert_called_once_with(task, mock.ANY, mock.ANY)
@mock.patch.object(manager_utils, 'rescuing_error_handler', autospec=True) @mock.patch.object(manager_utils, 'rescuing_error_handler', autospec=True)
@mock.patch.object(agent_base.HeartbeatMixin, '_finalize_rescue', @mock.patch.object(agent_base.HeartbeatMixin, '_finalize_rescue',
autospec=True) autospec=True)
def test_heartbeat_rescue(self, mock_finalize_rescue, def test_heartbeat_rescue(self, mock_finalize_rescue,
mock_rescue_err_handler): mock_rescue_err_handler):
self.node.provision_state = states.RESCUEWAIT self.node.provision_state = states.RESCUEWAIT
self.node.save() self.node.save()
with task_manager.acquire( with task_manager.acquire(
self.context, self.node.uuid, shared=False) as task: self.context, self.node.uuid, shared=False) as task:
skipping to change at line 1732 skipping to change at line 1732
@mock.patch.object(manager_utils, 'cleaning_error_handler', autospec=True) @mock.patch.object(manager_utils, 'cleaning_error_handler', autospec=True)
@mock.patch.object(manager_utils, 'node_power_action', autospec=True) @mock.patch.object(manager_utils, 'node_power_action', autospec=True)
def test__post_step_reboot_fail(self, mock_reboot, mock_handler, def test__post_step_reboot_fail(self, mock_reboot, mock_handler,
mock_prepare, mock_build_opt): mock_prepare, mock_build_opt):
mock_reboot.side_effect = RuntimeError("broken") mock_reboot.side_effect = RuntimeError("broken")
with task_manager.acquire(self.context, self.node['uuid'], with task_manager.acquire(self.context, self.node['uuid'],
shared=False) as task: shared=False) as task:
agent_base._post_step_reboot(task, 'clean') agent_base._post_step_reboot(task, 'clean')
mock_reboot.assert_called_once_with(task, states.REBOOT) mock_reboot.assert_called_once_with(task, states.REBOOT)
mock_handler.assert_called_once_with(task, mock.ANY) mock_handler.assert_called_once_with(task, mock.ANY,
traceback=True)
self.assertNotIn('cleaning_reboot', self.assertNotIn('cleaning_reboot',
task.node.driver_internal_info) task.node.driver_internal_info)
@mock.patch.object(deploy_utils, 'build_agent_options', autospec=True) @mock.patch.object(deploy_utils, 'build_agent_options', autospec=True)
@mock.patch.object(pxe.PXEBoot, 'prepare_ramdisk', spec_set=True, @mock.patch.object(pxe.PXEBoot, 'prepare_ramdisk', spec_set=True,
autospec=True) autospec=True)
@mock.patch.object(manager_utils, 'deploying_error_handler', autospec=True) @mock.patch.object(manager_utils, 'deploying_error_handler', autospec=True)
@mock.patch.object(manager_utils, 'node_power_action', autospec=True) @mock.patch.object(manager_utils, 'node_power_action', autospec=True)
def test__post_step_reboot_fail_deploy(self, mock_reboot, mock_handler, def test__post_step_reboot_fail_deploy(self, mock_reboot, mock_handler,
mock_prepare, mock_build_opt): mock_prepare, mock_build_opt):
mock_reboot.side_effect = RuntimeError("broken") mock_reboot.side_effect = RuntimeError("broken")
with task_manager.acquire(self.context, self.node['uuid'], with task_manager.acquire(self.context, self.node['uuid'],
shared=False) as task: shared=False) as task:
agent_base._post_step_reboot(task, 'deploy') agent_base._post_step_reboot(task, 'deploy')
mock_reboot.assert_called_once_with(task, states.REBOOT) mock_reboot.assert_called_once_with(task, states.REBOOT)
mock_handler.assert_called_once_with(task, mock.ANY) mock_handler.assert_called_once_with(task, mock.ANY,
traceback=True)
self.assertNotIn('deployment_reboot', self.assertNotIn('deployment_reboot',
task.node.driver_internal_info) task.node.driver_internal_info)
@mock.patch.object(deploy_utils, 'build_agent_options', autospec=True) @mock.patch.object(deploy_utils, 'build_agent_options', autospec=True)
@mock.patch.object(pxe.PXEBoot, 'prepare_ramdisk', spec_set=True, @mock.patch.object(pxe.PXEBoot, 'prepare_ramdisk', spec_set=True,
autospec=True) autospec=True)
@mock.patch.object(manager_utils, 'node_power_action', autospec=True) @mock.patch.object(manager_utils, 'node_power_action', autospec=True)
@mock.patch.object(agent_client.AgentClient, 'get_commands_status', @mock.patch.object(agent_client.AgentClient, 'get_commands_status',
autospec=True) autospec=True)
def test_continue_cleaning_reboot( def test_continue_cleaning_reboot(
skipping to change at line 1867 skipping to change at line 1869
status_mock.return_value = [command_status] status_mock.return_value = [command_status]
hook_mock = mock.MagicMock(spec=types.FunctionType, __name__='foo') hook_mock = mock.MagicMock(spec=types.FunctionType, __name__='foo')
hook_mock.side_effect = RuntimeError('error') hook_mock.side_effect = RuntimeError('error')
get_hook_mock.return_value = hook_mock get_hook_mock.return_value = hook_mock
with task_manager.acquire(self.context, self.node.uuid, with task_manager.acquire(self.context, self.node.uuid,
shared=False) as task: shared=False) as task:
self.deploy.continue_cleaning(task) self.deploy.continue_cleaning(task)
get_hook_mock.assert_called_once_with(task.node, 'clean') get_hook_mock.assert_called_once_with(task.node, 'clean')
hook_mock.assert_called_once_with(task, command_status) hook_mock.assert_called_once_with(task, command_status)
error_handler_mock.assert_called_once_with(task, mock.ANY) error_handler_mock.assert_called_once_with(task, mock.ANY,
traceback=True)
self.assertFalse(notify_mock.called) self.assertFalse(notify_mock.called)
collect_logs_mock.assert_called_once_with(task.node, collect_logs_mock.assert_called_once_with(task.node,
label='cleaning') label='cleaning')
@mock.patch.object(manager_utils, 'notify_conductor_resume_operation', @mock.patch.object(manager_utils, 'notify_conductor_resume_operation',
autospec=True) autospec=True)
@mock.patch.object(agent_client.AgentClient, 'get_commands_status', @mock.patch.object(agent_client.AgentClient, 'get_commands_status',
autospec=True) autospec=True)
def test_continue_cleaning_old_command(self, status_mock, notify_mock): def test_continue_cleaning_old_command(self, status_mock, notify_mock):
# Test when a second execute_clean_step happens to the agent, but # Test when a second execute_clean_step happens to the agent, but
skipping to change at line 1947 skipping to change at line 1950
collect_logs_mock): collect_logs_mock):
# Test that a failure puts the node in CLEANFAIL # Test that a failure puts the node in CLEANFAIL
status_mock.return_value = [{ status_mock.return_value = [{
'command_status': 'FAILED', 'command_status': 'FAILED',
'command_name': 'execute_clean_step', 'command_name': 'execute_clean_step',
'command_result': {} 'command_result': {}
}] }]
with task_manager.acquire(self.context, self.node['uuid'], with task_manager.acquire(self.context, self.node['uuid'],
shared=False) as task: shared=False) as task:
self.deploy.continue_cleaning(task) self.deploy.continue_cleaning(task)
error_mock.assert_called_once_with(task, mock.ANY) error_mock.assert_called_once_with(task, mock.ANY, traceback=False)
collect_logs_mock.assert_called_once_with(task.node, collect_logs_mock.assert_called_once_with(task.node,
label='cleaning') label='cleaning')
@mock.patch.object(conductor_steps, 'set_node_cleaning_steps', @mock.patch.object(conductor_steps, 'set_node_cleaning_steps',
autospec=True) autospec=True)
@mock.patch.object(manager_utils, 'notify_conductor_resume_operation', @mock.patch.object(manager_utils, 'notify_conductor_resume_operation',
autospec=True) autospec=True)
@mock.patch.object(agent_base.AgentDeployMixin, @mock.patch.object(agent_base.AgentDeployMixin,
'refresh_steps', autospec=True) 'refresh_steps', autospec=True)
@mock.patch.object(agent_client.AgentClient, 'get_commands_status', @mock.patch.object(agent_client.AgentClient, 'get_commands_status',
skipping to change at line 2018 skipping to change at line 2021
tgt_prov_state = states.MANAGEABLE if manual else states.AVAILABLE tgt_prov_state = states.MANAGEABLE if manual else states.AVAILABLE
self.node.provision_state = states.CLEANWAIT self.node.provision_state = states.CLEANWAIT
self.node.target_provision_state = tgt_prov_state self.node.target_provision_state = tgt_prov_state
self.node.save() self.node.save()
with task_manager.acquire(self.context, self.node.uuid, with task_manager.acquire(self.context, self.node.uuid,
shared=False) as task: shared=False) as task:
self.deploy.continue_cleaning(task) self.deploy.continue_cleaning(task)
status_mock.assert_called_once_with(mock.ANY, task.node) status_mock.assert_called_once_with(mock.ANY, task.node)
refresh_steps_mock.assert_called_once_with(mock.ANY, task, 'clean') refresh_steps_mock.assert_called_once_with(mock.ANY, task, 'clean')
error_mock.assert_called_once_with(task, mock.ANY) error_mock.assert_called_once_with(task, mock.ANY, traceback=True)
self.assertFalse(notify_mock.called) self.assertFalse(notify_mock.called)
self.assertFalse(steps_mock.called) self.assertFalse(steps_mock.called)
@mock.patch.object(manager_utils, 'cleaning_error_handler', autospec=True) @mock.patch.object(manager_utils, 'cleaning_error_handler', autospec=True)
@mock.patch.object(agent_client.AgentClient, 'get_commands_status', @mock.patch.object(agent_client.AgentClient, 'get_commands_status',
autospec=True) autospec=True)
def test_continue_cleaning_unknown(self, status_mock, error_mock): def test_continue_cleaning_unknown(self, status_mock, error_mock):
# Test that unknown commands are treated as failures # Test that unknown commands are treated as failures
status_mock.return_value = [{ status_mock.return_value = [{
'command_status': 'UNKNOWN', 'command_status': 'UNKNOWN',
'command_name': 'execute_clean_step', 'command_name': 'execute_clean_step',
'command_result': {} 'command_result': {}
}] }]
with task_manager.acquire(self.context, self.node['uuid'], with task_manager.acquire(self.context, self.node['uuid'],
shared=False) as task: shared=False) as task:
self.deploy.continue_cleaning(task) self.deploy.continue_cleaning(task)
error_mock.assert_called_once_with(task, mock.ANY) error_mock.assert_called_once_with(task, mock.ANY, traceback=False)
def _test_clean_step_hook(self): def _test_clean_step_hook(self):
"""Helper method for unit tests related to clean step hooks.""" """Helper method for unit tests related to clean step hooks."""
some_function_mock = mock.MagicMock() some_function_mock = mock.MagicMock()
@agent_base.post_clean_step_hook( @agent_base.post_clean_step_hook(
interface='raid', step='delete_configuration') interface='raid', step='delete_configuration')
@agent_base.post_clean_step_hook( @agent_base.post_clean_step_hook(
interface='raid', step='create_configuration') interface='raid', step='create_configuration')
def hook_method(): def hook_method():
 End of changes. 8 change blocks. 
8 lines changed or deleted 11 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)