diff --git a/ironic/drivers/modules/agent.py b/ironic/drivers/modules/agent.py index 6a1e8c0af6..e8c04f3013 100644 --- a/ironic/drivers/modules/agent.py +++ b/ironic/drivers/modules/agent.py @@ -307,6 +307,7 @@ class AgentDeploy(base.DeployInterface): manager_utils.node_power_action(task, states.POWER_OFF) return states.DELETED + @task_manager.require_exclusive_lock def prepare(self, task): """Prepare the deployment environment for this node. @@ -323,6 +324,7 @@ class AgentDeploy(base.DeployInterface): deploy_opts = deploy_utils.build_agent_options(node) task.driver.boot.prepare_ramdisk(task, deploy_opts) + @task_manager.require_exclusive_lock def clean_up(self, task): """Clean up the deployment environment for this node. diff --git a/ironic/drivers/modules/agent_base_vendor.py b/ironic/drivers/modules/agent_base_vendor.py index 4ca4183804..7b6758ec11 100644 --- a/ironic/drivers/modules/agent_base_vendor.py +++ b/ironic/drivers/modules/agent_base_vendor.py @@ -34,6 +34,7 @@ from ironic.common.i18n import _LW from ironic.common import states from ironic.common import utils from ironic.conductor import rpcapi +from ironic.conductor import task_manager from ironic.conductor import utils as manager_utils from ironic.drivers import base from ironic.drivers.modules import agent_client @@ -383,6 +384,7 @@ class BaseAgentVendor(base.VendorInterface): return manager_utils.cleaning_error_handler(task, msg) @base.passthru(['POST']) + @task_manager.require_exclusive_lock def heartbeat(self, task, **kwargs): """Method for agent to periodically check in. diff --git a/ironic/tests/unit/drivers/modules/test_agent_base_vendor.py b/ironic/tests/unit/drivers/modules/test_agent_base_vendor.py index 7f09f104d1..63227c84eb 100644 --- a/ironic/tests/unit/drivers/modules/test_agent_base_vendor.py +++ b/ironic/tests/unit/drivers/modules/test_agent_base_vendor.py @@ -287,13 +287,13 @@ class TestBaseAgentVendor(db_base.DbTestCase): 'agent_url': 'http://127.0.0.1:9999/bar' } with task_manager.acquire( - self.context, self.node['uuid'], shared=True) as task: + self.context, self.node['uuid'], shared=False) as task: self.passthru.heartbeat(task, **kwargs) def test_heartbeat_bad(self): kwargs = {} with task_manager.acquire( - self.context, self.node['uuid'], shared=True) as task: + self.context, self.node['uuid'], shared=False) as task: self.assertRaises(exception.MissingParameterValue, self.passthru.heartbeat, task, **kwargs) @@ -311,7 +311,7 @@ class TestBaseAgentVendor(db_base.DbTestCase): } done_mock.side_effect = iter([Exception('LlamaException')]) with task_manager.acquire( - self.context, self.node['uuid'], shared=True) as task: + self.context, self.node['uuid'], shared=False) as task: task.node.provision_state = states.DEPLOYWAIT task.node.target_provision_state = states.ACTIVE self.passthru.heartbeat(task, **kwargs) @@ -335,7 +335,7 @@ class TestBaseAgentVendor(db_base.DbTestCase): 'agent_url': 'http://127.0.0.1:9999/bar' } with task_manager.acquire( - self.context, self.node['uuid'], shared=True) as task: + self.context, self.node['uuid'], shared=False) as task: def driver_failure(*args, **kwargs): # simulate driver failure that both advances the FSM @@ -372,7 +372,7 @@ class TestBaseAgentVendor(db_base.DbTestCase): self.node.provision_state = state self.node.save() with task_manager.acquire( - self.context, self.node.uuid, shared=True) as task: + self.context, self.node.uuid, shared=False) as task: self.passthru.heartbeat(task, **kwargs) mock_touch.assert_called_once_with(mock.ANY) @@ -410,7 +410,7 @@ class TestBaseAgentVendor(db_base.DbTestCase): after_failed_mocks = mocks[i + 1:] failed_mock.side_effect = Exception() with task_manager.acquire( - self.context, self.node.uuid, shared=True) as task: + self.context, self.node.uuid, shared=False) as task: self.passthru.heartbeat(task, **kwargs) mock_touch.assert_called_once_with(mock.ANY) @@ -442,7 +442,7 @@ class TestBaseAgentVendor(db_base.DbTestCase): self.node.provision_state = state self.node.save() with task_manager.acquire( - self.context, self.node.uuid, shared=True) as task: + self.context, self.node.uuid, shared=False) as task: self.passthru.heartbeat(task, **kwargs) mock_touch.assert_called_once_with(mock.ANY) @@ -472,7 +472,7 @@ class TestBaseAgentVendor(db_base.DbTestCase): self.node.provision_state = state self.node.save() with task_manager.acquire( - self.context, self.node.uuid, shared=True) as task: + self.context, self.node.uuid, shared=False) as task: self.passthru.heartbeat(task, **kwargs) mock_continue.assert_called_once_with(mock.ANY, task, **kwargs) @@ -501,7 +501,7 @@ class TestBaseAgentVendor(db_base.DbTestCase): self.node.provision_state = state self.node.save() with task_manager.acquire( - self.context, self.node.uuid, shared=True) as task: + self.context, self.node.uuid, shared=False) as task: self.passthru.heartbeat(task, **kwargs) mock_continue.assert_called_once_with(mock.ANY, task, **kwargs) @@ -527,7 +527,7 @@ class TestBaseAgentVendor(db_base.DbTestCase): self.node.provision_state = state self.node.save() with task_manager.acquire( - self.context, self.node['uuid'], shared=True) as task: + self.context, self.node['uuid'], shared=False) as task: self.passthru.heartbeat(task, **kwargs) self.assertEqual(0, ncrc_mock.call_count) @@ -547,7 +547,7 @@ class TestBaseAgentVendor(db_base.DbTestCase): self.node.provision_state = states.DEPLOYWAIT self.node.save() with task_manager.acquire( - self.context, self.node.uuid, shared=True) as task: + self.context, self.node.uuid, shared=False) as task: self.passthru.heartbeat(task, **kwargs) mock_touch.assert_called_once_with(mock.ANY)