From: Zack Cerza Date: Mon, 4 Dec 2017 19:11:19 +0000 (-0700) Subject: fog: Cancel stale deploy tasks X-Git-Tag: 1.1.0~374^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=12808511a8ac4b96cfe26b8bc690a038d9a173e9;p=teuthology.git fog: Cancel stale deploy tasks In case, for whatever reason, any active deploy tasks already exist for a given host, cancel them before we schedule a new one. Signed-off-by: Zack Cerza --- diff --git a/teuthology/provision/fog.py b/teuthology/provision/fog.py index aa267ea7f2..a9a3cca05e 100644 --- a/teuthology/provision/fog.py +++ b/teuthology/provision/fog.py @@ -182,7 +182,10 @@ class FOG(object): 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')), @@ -213,7 +216,11 @@ class FOG(object): :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 diff --git a/teuthology/provision/test/test_fog.py b/teuthology/provision/test/test_fog.py index f370cd6e48..d849bee21f 100644 --- a/teuthology/provision/test/test_fog.py +++ b/teuthology/provision/test/test_fog.py @@ -213,7 +213,7 @@ class TestFOG(object): 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):