diff options
| author | Jim Rollenhagen <jim@jimrollenhagen.com> | 2014-10-01 10:59:09 -0700 |
|---|---|---|
| committer | Jim Rollenhagen <jim@jimrollenhagen.com> | 2014-10-13 11:09:09 -0700 |
| commit | 082cf29cec31efda2d63eeb9dda8c74e396be6eb (patch) | |
| tree | 22ff544ad2bc37b6c70c2678ba8ae9480cebd183 /ironic_python_agent/tests/extensions | |
| parent | 4f57590b2e41863770b764a8b84b8b81830ad577 (diff) | |
| download | ironic-python-agent-082cf29cec31efda2d63eeb9dda8c74e396be6eb.tar.gz | |
Force heartbeat immediately after async command completes
This change passes the agent object into extensions, such that
they may call agent methods as needed. It also causes async
commands to force a heartbeat immediately after completing the
command. This allows Ironic to get a heartbeat and continue
work as quickly as possible, while also allowing deployers to
configure Ironic (agent) to heartbeat less often.
Change-Id: Ib3c3a43dfd0ed4ed51b7d52ac099f01181ca822f
Diffstat (limited to 'ironic_python_agent/tests/extensions')
| -rw-r--r-- | ironic_python_agent/tests/extensions/base.py | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/ironic_python_agent/tests/extensions/base.py b/ironic_python_agent/tests/extensions/base.py index 4be19d94..30ce34a0 100644 --- a/ironic_python_agent/tests/extensions/base.py +++ b/ironic_python_agent/tests/extensions/base.py @@ -120,7 +120,9 @@ class TestExecuteCommandMixin(test_base.BaseTestCase): class TestExtensionDecorators(test_base.BaseTestCase): def setUp(self): super(TestExtensionDecorators, self).setUp() - self.extension = FakeExtension() + self.agent = FakeAgent() + self.agent.force_heartbeat = mock.Mock() + self.extension = FakeExtension(agent=self.agent) def test_async_command_success(self): result = self.extension.execute('fake_async_command', param='v1') @@ -132,12 +134,27 @@ class TestExtensionDecorators(test_base.BaseTestCase): result.command_status) self.assertEqual(None, result.command_error) self.assertEqual('v1', result.command_result) + self.agent.force_heartbeat.assert_called_once_with() + + def test_async_command_success_without_agent(self): + extension = FakeExtension(agent=None) + result = extension.execute('fake_async_command', param='v1') + self.assertIsInstance(result, base.AsyncCommandResult) + result.join() + self.assertEqual('fake_async_command', result.command_name) + self.assertEqual({'param': 'v1'}, result.command_params) + self.assertEqual(base.AgentCommandStatus.SUCCEEDED, + result.command_status) + self.assertEqual(None, result.command_error) + self.assertEqual('v1', result.command_result) def test_async_command_validation_failure(self): self.assertRaises(errors.InvalidCommandParamsError, self.extension.execute, 'fake_async_command', is_valid=False) + # validation is synchronous, no need to force a heartbeat + self.assertEqual(0, self.agent.force_heartbeat.call_count) def test_async_command_execution_failure(self): result = self.extension.execute('fake_async_command', param='v2') @@ -149,6 +166,7 @@ class TestExtensionDecorators(test_base.BaseTestCase): result.command_status) self.assertIsInstance(result.command_error, ExecutionError) self.assertEqual(None, result.command_result) + self.agent.force_heartbeat.assert_called_once_with() def test_async_command_name(self): self.assertEqual( @@ -164,18 +182,24 @@ class TestExtensionDecorators(test_base.BaseTestCase): result.command_status) self.assertEqual(None, result.command_error) self.assertEqual('v1', result.command_result) + # no need to force heartbeat on a sync command + self.assertEqual(0, self.agent.force_heartbeat.call_count) def test_sync_command_validation_failure(self): self.assertRaises(errors.InvalidCommandParamsError, self.extension.execute, 'fake_sync_command', is_valid=False) + # validation is synchronous, no need to force a heartbeat + self.assertEqual(0, self.agent.force_heartbeat.call_count) def test_sync_command_execution_failure(self): self.assertRaises(ExecutionError, self.extension.execute, 'fake_sync_command', param='v2') + # no need to force heartbeat on a sync command + self.assertEqual(0, self.agent.force_heartbeat.call_count) def test_sync_command_name(self): self.assertEqual( |
