Merge "Make some agent functions require exclusive lock"

This commit is contained in:
Jenkins 2016-03-04 03:45:40 +00:00 committed by Gerrit Code Review
commit c0dea3e122
3 changed files with 15 additions and 11 deletions

View File

@ -307,6 +307,7 @@ class AgentDeploy(base.DeployInterface):
manager_utils.node_power_action(task, states.POWER_OFF) manager_utils.node_power_action(task, states.POWER_OFF)
return states.DELETED return states.DELETED
@task_manager.require_exclusive_lock
def prepare(self, task): def prepare(self, task):
"""Prepare the deployment environment for this node. """Prepare the deployment environment for this node.
@ -323,6 +324,7 @@ class AgentDeploy(base.DeployInterface):
deploy_opts = deploy_utils.build_agent_options(node) deploy_opts = deploy_utils.build_agent_options(node)
task.driver.boot.prepare_ramdisk(task, deploy_opts) task.driver.boot.prepare_ramdisk(task, deploy_opts)
@task_manager.require_exclusive_lock
def clean_up(self, task): def clean_up(self, task):
"""Clean up the deployment environment for this node. """Clean up the deployment environment for this node.

View File

@ -34,6 +34,7 @@ from ironic.common.i18n import _LW
from ironic.common import states from ironic.common import states
from ironic.common import utils from ironic.common import utils
from ironic.conductor import rpcapi from ironic.conductor import rpcapi
from ironic.conductor import task_manager
from ironic.conductor import utils as manager_utils from ironic.conductor import utils as manager_utils
from ironic.drivers import base from ironic.drivers import base
from ironic.drivers.modules import agent_client from ironic.drivers.modules import agent_client
@ -383,6 +384,7 @@ class BaseAgentVendor(base.VendorInterface):
return manager_utils.cleaning_error_handler(task, msg) return manager_utils.cleaning_error_handler(task, msg)
@base.passthru(['POST']) @base.passthru(['POST'])
@task_manager.require_exclusive_lock
def heartbeat(self, task, **kwargs): def heartbeat(self, task, **kwargs):
"""Method for agent to periodically check in. """Method for agent to periodically check in.

View File

@ -287,13 +287,13 @@ class TestBaseAgentVendor(db_base.DbTestCase):
'agent_url': 'http://127.0.0.1:9999/bar' 'agent_url': 'http://127.0.0.1:9999/bar'
} }
with task_manager.acquire( 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.passthru.heartbeat(task, **kwargs)
def test_heartbeat_bad(self): def test_heartbeat_bad(self):
kwargs = {} kwargs = {}
with task_manager.acquire( 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.assertRaises(exception.MissingParameterValue,
self.passthru.heartbeat, task, **kwargs) self.passthru.heartbeat, task, **kwargs)
@ -311,7 +311,7 @@ class TestBaseAgentVendor(db_base.DbTestCase):
} }
done_mock.side_effect = iter([Exception('LlamaException')]) done_mock.side_effect = iter([Exception('LlamaException')])
with task_manager.acquire( 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.provision_state = states.DEPLOYWAIT
task.node.target_provision_state = states.ACTIVE task.node.target_provision_state = states.ACTIVE
self.passthru.heartbeat(task, **kwargs) self.passthru.heartbeat(task, **kwargs)
@ -335,7 +335,7 @@ class TestBaseAgentVendor(db_base.DbTestCase):
'agent_url': 'http://127.0.0.1:9999/bar' 'agent_url': 'http://127.0.0.1:9999/bar'
} }
with task_manager.acquire( 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): def driver_failure(*args, **kwargs):
# simulate driver failure that both advances the FSM # simulate driver failure that both advances the FSM
@ -372,7 +372,7 @@ class TestBaseAgentVendor(db_base.DbTestCase):
self.node.provision_state = state self.node.provision_state = state
self.node.save() self.node.save()
with task_manager.acquire( 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.passthru.heartbeat(task, **kwargs)
mock_touch.assert_called_once_with(mock.ANY) mock_touch.assert_called_once_with(mock.ANY)
@ -410,7 +410,7 @@ class TestBaseAgentVendor(db_base.DbTestCase):
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=True) as task: self.context, self.node.uuid, shared=False) as task:
self.passthru.heartbeat(task, **kwargs) self.passthru.heartbeat(task, **kwargs)
mock_touch.assert_called_once_with(mock.ANY) mock_touch.assert_called_once_with(mock.ANY)
@ -442,7 +442,7 @@ class TestBaseAgentVendor(db_base.DbTestCase):
self.node.provision_state = state self.node.provision_state = state
self.node.save() self.node.save()
with task_manager.acquire( 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.passthru.heartbeat(task, **kwargs)
mock_touch.assert_called_once_with(mock.ANY) mock_touch.assert_called_once_with(mock.ANY)
@ -472,7 +472,7 @@ class TestBaseAgentVendor(db_base.DbTestCase):
self.node.provision_state = state self.node.provision_state = state
self.node.save() self.node.save()
with task_manager.acquire( 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.passthru.heartbeat(task, **kwargs)
mock_continue.assert_called_once_with(mock.ANY, 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.provision_state = state
self.node.save() self.node.save()
with task_manager.acquire( 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.passthru.heartbeat(task, **kwargs)
mock_continue.assert_called_once_with(mock.ANY, 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.provision_state = state
self.node.save() self.node.save()
with task_manager.acquire( 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.passthru.heartbeat(task, **kwargs)
self.assertEqual(0, ncrc_mock.call_count) self.assertEqual(0, ncrc_mock.call_count)
@ -547,7 +547,7 @@ class TestBaseAgentVendor(db_base.DbTestCase):
self.node.provision_state = states.DEPLOYWAIT self.node.provision_state = states.DEPLOYWAIT
self.node.save() self.node.save()
with task_manager.acquire( 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.passthru.heartbeat(task, **kwargs)
mock_touch.assert_called_once_with(mock.ANY) mock_touch.assert_called_once_with(mock.ANY)