self.log.info(
"Scheduling deploy of %s %s",
self.os_type, self.os_version)
- # First, we need to find the right tasktype ID
+ # First, let's find and cancel any existing deploy tasks for the host.
+ for task in self.get_deploy_tasks():
+ self.cancel_deploy_task(task['id'])
+ # Next, we need to find the right tasktype ID
resp = self.do_request(
'/tasktype',
data=json.dumps(dict(name='deploy')),
:returns: A list of deploy tasks which are active on our host
"""
resp = self.do_request('/task/active')
- tasks = resp.json()['tasks']
+ try:
+ tasks = resp.json()['tasks']
+ except Exception:
+ self.log.exception("Failed to get deploy tasks!")
+ return list()
host_tasks = [obj for obj in tasks
if obj['host']['name'] == self.shortname]
return host_tasks
obj = self.klass('name.fqdn', 'type', '1.0')
result = obj.schedule_deploy_task(host_id)
assert local_mocks['get_deploy_tasks'].called_once_with()
- assert len(self.mocks['m_requests_Session_send'].call_args_list) == 2
+ assert len(self.mocks['m_requests_Session_send'].call_args_list) == 3
assert result == task_id
def test_get_deploy_tasks(self):