Remove deploy_is_done() from AgentClient

The deploy_is_done() method from the AgentClient is very implementation
specific, so this patch is moving it into the AgentVendorInterface class
for the agent driver.

Change-Id: I92cdac24d5225ecfcb858bacdd672c3f8c0efed2
This commit is contained in:
Lucas Alvares Gomes 2015-02-12 14:18:29 +00:00
parent aa350eec76
commit 0d80093070
4 changed files with 41 additions and 54 deletions

View File

@ -277,7 +277,21 @@ class AgentDeploy(base.DeployInterface):
class AgentVendorInterface(agent_base_vendor.BaseAgentVendor):
def deploy_is_done(self, task):
return self._client.deploy_is_done(task.node)
commands = self._client.get_commands_status(task.node)
if not commands:
return False
last_command = commands[-1]
if last_command['command_name'] != 'prepare_image':
# catches race condition where prepare_image is still processing
# so deploy hasn't started yet
return False
if last_command['command_status'] != 'RUNNING':
return True
return False
@task_manager.require_exclusive_lock
def continue_deploy(self, task, **kwargs):

View File

@ -81,23 +81,6 @@ class AgentClient(object):
res = self.session.get(url, headers=headers)
return res.json()['commands']
def deploy_is_done(self, node):
commands = self.get_commands_status(node)
if not commands:
return False
last_command = commands[-1]
if last_command['command_name'] != 'prepare_image':
# catches race condition where prepare_image is still processing
# so deploy hasn't started yet
return False
if last_command['command_status'] != 'RUNNING':
return True
return False
def prepare_image(self, node, image_info, wait=False):
"""Call the `prepare_image` method on the node."""
LOG.debug('Preparing image %(image)s on node %(node)s.',

View File

@ -22,6 +22,7 @@ from ironic.common import pxe_utils
from ironic.common import states
from ironic.conductor import task_manager
from ironic.drivers.modules import agent
from ironic.drivers.modules import agent_client
from ironic.tests.conductor import utils as mgr_utils
from ironic.tests.db import base as db_base
from ironic.tests.db import utils as db_utils
@ -220,11 +221,29 @@ class TestAgentVendor(db_base.DbTestCase):
self.assertEqual(states.ACTIVE, task.node.provision_state)
self.assertEqual(states.NOSTATE, task.node.target_provision_state)
def test_deploy_is_done(self):
client_mock = mock.Mock()
self.passthru._client = client_mock
@mock.patch.object(agent_client.AgentClient, 'get_commands_status')
def test_deploy_is_done(self, mock_get_cmd):
with task_manager.acquire(self.context, self.node.uuid) as task:
self.passthru.deploy_is_done(task)
self.passthru._client.deploy_is_done.assert_called_once_with(
task.node)
mock_get_cmd.return_value = [{'command_name': 'prepare_image',
'command_status': 'SUCCESS'}]
self.assertTrue(self.passthru.deploy_is_done(task))
@mock.patch.object(agent_client.AgentClient, 'get_commands_status')
def test_deploy_is_done_empty_response(self, mock_get_cmd):
with task_manager.acquire(self.context, self.node.uuid) as task:
mock_get_cmd.return_value = []
self.assertFalse(self.passthru.deploy_is_done(task))
@mock.patch.object(agent_client.AgentClient, 'get_commands_status')
def test_deploy_is_done_race(self, mock_get_cmd):
with task_manager.acquire(self.context, self.node.uuid) as task:
mock_get_cmd.return_value = [{'command_name': 'some_other_command',
'command_status': 'SUCCESS'}]
self.assertFalse(self.passthru.deploy_is_done(task))
@mock.patch.object(agent_client.AgentClient, 'get_commands_status')
def test_deploy_is_done_still_running(self, mock_get_cmd):
with task_manager.acquire(self.context, self.node.uuid) as task:
mock_get_cmd.return_value = [{'command_name': 'prepare_image',
'command_status': 'RUNNING'}]
self.assertFalse(self.passthru.deploy_is_done(task))

View File

@ -90,35 +90,6 @@ class TestAgentClient(base.TestCase):
mock_get.return_value = res
self.assertEqual([], self.client.get_commands_status(self.node))
def test_deploy_is_done(self):
with mock.patch.object(self.client, 'get_commands_status') as mock_s:
mock_s.return_value = [{
'command_name': 'prepare_image',
'command_status': 'SUCCESS'
}]
self.assertTrue(self.client.deploy_is_done(self.node))
def test_deploy_is_done_empty_response(self):
with mock.patch.object(self.client, 'get_commands_status') as mock_s:
mock_s.return_value = []
self.assertFalse(self.client.deploy_is_done(self.node))
def test_deploy_is_done_race(self):
with mock.patch.object(self.client, 'get_commands_status') as mock_s:
mock_s.return_value = [{
'command_name': 'some_other_command',
'command_status': 'SUCCESS'
}]
self.assertFalse(self.client.deploy_is_done(self.node))
def test_deploy_is_done_still_running(self):
with mock.patch.object(self.client, 'get_commands_status') as mock_s:
mock_s.return_value = [{
'command_name': 'prepare_image',
'command_status': 'RUNNING'
}]
self.assertFalse(self.client.deploy_is_done(self.node))
@mock.patch('uuid.uuid4', mock.MagicMock(return_value='uuid'))
def test_prepare_image(self):
self.client._command = mock.Mock()