From 280527f99318e50c7f46b71901594269081a68d6 Mon Sep 17 00:00:00 2001 From: Matthew Jones Date: Thu, 30 Jan 2014 10:54:54 -0500 Subject: [PATCH] Enable canceling on certain levels.... fix up some unit tests --- awx/main/models/jobs.py | 1 - awx/main/tasks.py | 10 +++----- awx/main/tests/commands.py | 2 +- awx/main/tests/tasks.py | 50 +++++++++++++++++++------------------- 4 files changed, 30 insertions(+), 33 deletions(-) diff --git a/awx/main/models/jobs.py b/awx/main/models/jobs.py index a2ca766ecd..e0a94d82d3 100644 --- a/awx/main/models/jobs.py +++ b/awx/main/models/jobs.py @@ -343,7 +343,6 @@ class Job(CommonTask): opts = dict([(field, kwargs.get(field, '')) for field in needed]) if not all(opts.values()): return False - # TODO: This is temporary to allow a dependent task to continue self.status = 'waiting' self.save(update_fields=['status']) transaction.commit() diff --git a/awx/main/tasks.py b/awx/main/tasks.py index 482622d235..2b83597204 100644 --- a/awx/main/tasks.py +++ b/awx/main/tasks.py @@ -237,12 +237,10 @@ class BaseTask(Task): if logfile_pos != logfile.tell(): logfile_pos = logfile.tell() last_stdout_update = time.time() - #TODO: Find replacement for cancel flag - #TODO: Something about checking celery status - # if instance.cancel_flag: - # child.close(True) - # canceled = True - # FIXME: Find a way to determine if task is hung waiting at a prompt. + # NOTE: In case revoke doesn't have an affect + if instance.cancel_flag: + child.close(True) + canceled = True if idle_timeout and (time.time() - last_stdout_update) > idle_timeout: child.close(True) canceled = True diff --git a/awx/main/tests/commands.py b/awx/main/tests/commands.py index 05dd37c665..b25d6a04d1 100644 --- a/awx/main/tests/commands.py +++ b/awx/main/tests/commands.py @@ -377,7 +377,7 @@ class CleanupJobsTest(BaseCommandMixin, BaseLiveServerTest): self.assertEqual(job.status, 'new') self.assertFalse(job.passwords_needed_to_start) self.assertTrue(job.start()) - self.assertEqual(job.status, 'pending') + self.assertEqual(job.status, 'waiting') job = Job.objects.get(pk=job.pk) self.assertEqual(job.status, 'successful') # With days=1, no jobs will be deleted. diff --git a/awx/main/tests/tasks.py b/awx/main/tests/tasks.py index b781ab5fc3..63936c23d1 100644 --- a/awx/main/tests/tasks.py +++ b/awx/main/tests/tasks.py @@ -404,7 +404,7 @@ class RunJobTest(BaseCeleryTest): self.assertEqual(job.status, 'new') self.assertFalse(job.passwords_needed_to_start) self.assertTrue(job.start()) - self.assertEqual(job.status, 'pending') + self.assertEqual(job.status, 'waiting') job = Job.objects.get(pk=job.pk) self.check_job_result(job, 'successful') self.check_job_events(job, 'ok', 1, 2) @@ -433,7 +433,7 @@ class RunJobTest(BaseCeleryTest): self.assertEqual(job.status, 'new') self.assertFalse(job.passwords_needed_to_start) self.assertTrue(job.start()) - self.assertEqual(job.status, 'pending') + self.assertEqual(job.status, 'waiting') job = Job.objects.get(pk=job.pk) self.check_job_result(job, 'successful') self.check_job_events(job, 'skipped', 1, 2) @@ -461,7 +461,7 @@ class RunJobTest(BaseCeleryTest): self.assertEqual(job.status, 'new') self.assertFalse(job.passwords_needed_to_start) self.assertTrue(job.start()) - self.assertEqual(job.status, 'pending') + self.assertEqual(job.status, 'waiting') job = Job.objects.get(pk=job.pk) self.check_job_result(job, 'failed') self.check_job_events(job, 'failed', 1, 1) @@ -489,7 +489,7 @@ class RunJobTest(BaseCeleryTest): self.assertEqual(job.status, 'new') self.assertFalse(job.passwords_needed_to_start) self.assertTrue(job.start()) - self.assertEqual(job.status, 'pending') + self.assertEqual(job.status, 'waiting') job = Job.objects.get(pk=job.pk) self.check_job_result(job, 'successful') self.check_job_events(job, 'ok', 1, 1, check_ignore_errors=True) @@ -612,7 +612,7 @@ class RunJobTest(BaseCeleryTest): self.assertEqual(job.status, 'new') self.assertFalse(job.passwords_needed_to_start) self.assertTrue(job.start()) - self.assertEqual(job.status, 'pending') + self.assertEqual(job.status, 'waiting') job = Job.objects.get(pk=job.pk) # Since we don't actually run the task, the --check should indicate # everything is successful. @@ -653,7 +653,7 @@ class RunJobTest(BaseCeleryTest): self.assertFalse(job.passwords_needed_to_start) self.build_args_callback = self._cancel_job_callback self.assertTrue(job.start()) - self.assertEqual(job.status, 'pending') + self.assertEqual(job.status, 'waiting') job = Job.objects.get(pk=job.pk) self.check_job_result(job, 'canceled') self.assertEqual(job.cancel_flag, True) @@ -676,7 +676,7 @@ class RunJobTest(BaseCeleryTest): self.assertEqual(job.status, 'new') self.assertFalse(job.passwords_needed_to_start) self.assertTrue(job.start()) - self.assertEqual(job.status, 'pending') + self.assertEqual(job.status, 'waiting') job = Job.objects.get(pk=job.pk) self.check_job_result(job, 'successful') self.assertTrue('--forks=3' in self.run_job_args) @@ -687,7 +687,7 @@ class RunJobTest(BaseCeleryTest): job2 = self.create_test_job(job_template=job_template2) self.assertEqual(job2.status, 'new') self.assertTrue(job2.start()) - self.assertEqual(job2.status, 'pending') + self.assertEqual(job2.status, 'waiting') job2 = Job.objects.get(pk=job2.pk) self.check_job_result(job2, 'successful') # Test with extra_vars as YAML (should be converted to JSON in args). @@ -695,7 +695,7 @@ class RunJobTest(BaseCeleryTest): job3 = self.create_test_job(job_template=job_template3) self.assertEqual(job3.status, 'new') self.assertTrue(job3.start()) - self.assertEqual(job3.status, 'pending') + self.assertEqual(job3.status, 'waiting') job3 = Job.objects.get(pk=job3.pk) self.check_job_result(job3, 'successful') @@ -707,7 +707,7 @@ class RunJobTest(BaseCeleryTest): self.assertEqual(job.status, 'new') self.assertFalse(job.passwords_needed_to_start) self.assertTrue(job.start()) - self.assertEqual(job.status, 'pending') + self.assertEqual(job.status, 'waiting') job = Job.objects.get(pk=job.pk) self.assertTrue(len(job.job_args) > 1024) self.check_job_result(job, 'successful') @@ -720,7 +720,7 @@ class RunJobTest(BaseCeleryTest): self.assertEqual(job.status, 'new') self.assertFalse(job.passwords_needed_to_start) self.assertTrue(job.start()) - self.assertEqual(job.status, 'pending') + self.assertEqual(job.status, 'waiting') job = Job.objects.get(pk=job.pk) self.check_job_result(job, 'failed') self.assertTrue('-l' in self.run_job_args) @@ -733,7 +733,7 @@ class RunJobTest(BaseCeleryTest): self.assertEqual(job.status, 'new') self.assertFalse(job.passwords_needed_to_start) self.assertTrue(job.start()) - self.assertEqual(job.status, 'pending') + self.assertEqual(job.status, 'waiting') job = Job.objects.get(pk=job.pk) self.check_job_result(job, 'successful') self.assertTrue('ssh-agent' in self.run_job_args) @@ -746,7 +746,7 @@ class RunJobTest(BaseCeleryTest): self.assertEqual(job.status, 'new') self.assertFalse(job.passwords_needed_to_start) self.assertTrue(job.start()) - self.assertEqual(job.status, 'pending') + self.assertEqual(job.status, 'waiting') job = Job.objects.get(pk=job.pk) self.check_job_result(job, 'successful') self.assertTrue('-u' in self.run_job_args) @@ -763,7 +763,7 @@ class RunJobTest(BaseCeleryTest): self.assertFalse(job.start()) self.assertEqual(job.status, 'new') self.assertTrue(job.start(ssh_password='sshpass')) - self.assertEqual(job.status, 'pending') + self.assertEqual(job.status, 'waiting') job = Job.objects.get(pk=job.pk) self.check_job_result(job, 'successful') self.assertTrue('--ask-pass' in self.run_job_args) @@ -777,7 +777,7 @@ class RunJobTest(BaseCeleryTest): self.assertEqual(job.status, 'new') self.assertFalse(job.passwords_needed_to_start) self.assertTrue(job.start()) - self.assertEqual(job.status, 'pending') + self.assertEqual(job.status, 'waiting') job = Job.objects.get(pk=job.pk) # Job may fail if current user doesn't have password-less sudo # privileges, but we're mainly checking the command line arguments. @@ -796,7 +796,7 @@ class RunJobTest(BaseCeleryTest): self.assertFalse(job.start()) self.assertEqual(job.status, 'new') self.assertTrue(job.start(sudo_password='sudopass')) - self.assertEqual(job.status, 'pending') + self.assertEqual(job.status, 'waiting') job = Job.objects.get(pk=job.pk) # Job may fail if current user doesn't have password-less sudo # privileges, but we're mainly checking the command line arguments. @@ -811,7 +811,7 @@ class RunJobTest(BaseCeleryTest): self.assertEqual(job.status, 'new') self.assertFalse(job.passwords_needed_to_start) self.assertTrue(job.start()) - self.assertEqual(job.status, 'pending') + self.assertEqual(job.status, 'waiting') job = Job.objects.get(pk=job.pk) self.check_job_result(job, 'successful') self.assertTrue('ssh-agent' in self.run_job_args) @@ -825,7 +825,7 @@ class RunJobTest(BaseCeleryTest): self.assertEqual(job.status, 'new') self.assertFalse(job.passwords_needed_to_start) self.assertTrue(job.start()) - self.assertEqual(job.status, 'pending') + self.assertEqual(job.status, 'waiting') job = Job.objects.get(pk=job.pk) self.check_job_result(job, 'successful') self.assertTrue('ssh-agent' in self.run_job_args) @@ -840,7 +840,7 @@ class RunJobTest(BaseCeleryTest): self.assertEqual(job.status, 'new') self.assertFalse(job.passwords_needed_to_start) self.assertTrue(job.start()) - self.assertEqual(job.status, 'pending') + self.assertEqual(job.status, 'waiting') job = Job.objects.get(pk=job.pk) self.check_job_result(job, 'failed') self.assertTrue('ssh-agent' in self.run_job_args) @@ -858,7 +858,7 @@ class RunJobTest(BaseCeleryTest): self.assertFalse(job.start()) self.assertEqual(job.status, 'new') self.assertTrue(job.start(ssh_key_unlock=TEST_SSH_KEY_DATA_UNLOCK)) - self.assertEqual(job.status, 'pending') + self.assertEqual(job.status, 'waiting') job = Job.objects.get(pk=job.pk) self.check_job_result(job, 'successful') self.assertTrue('ssh-agent' in self.run_job_args) @@ -882,7 +882,7 @@ class RunJobTest(BaseCeleryTest): self.assertEqual(job.status, 'new') self.assertFalse(job.passwords_needed_to_start) self.assertTrue(job.start()) - self.assertEqual(job.status, 'pending') + self.assertEqual(job.status, 'waiting') job = Job.objects.get(pk=job.pk) self.check_job_result(job, 'successful') self.assertTrue(env_var1 in job.job_env) @@ -901,7 +901,7 @@ class RunJobTest(BaseCeleryTest): self.assertEqual(job.status, 'new') self.assertFalse(job.passwords_needed_to_start) self.assertTrue(job.start()) - self.assertEqual(job.status, 'pending') + self.assertEqual(job.status, 'waiting') job = Job.objects.get(pk=job.pk) self.check_job_result(job, 'successful') self.check_job_events(job, 'ok', 1, 1, async=True) @@ -929,7 +929,7 @@ class RunJobTest(BaseCeleryTest): self.assertEqual(job.status, 'new') self.assertFalse(job.passwords_needed_to_start) self.assertTrue(job.start()) - self.assertEqual(job.status, 'pending') + self.assertEqual(job.status, 'waiting') job = Job.objects.get(pk=job.pk) self.check_job_result(job, 'failed') self.check_job_events(job, 'failed', 1, 1, async=True) @@ -957,7 +957,7 @@ class RunJobTest(BaseCeleryTest): self.assertEqual(job.status, 'new') self.assertFalse(job.passwords_needed_to_start) self.assertTrue(job.start()) - self.assertEqual(job.status, 'pending') + self.assertEqual(job.status, 'waiting') job = Job.objects.get(pk=job.pk) self.check_job_result(job, 'failed') self.check_job_events(job, 'failed', 1, 1, async=True, @@ -986,7 +986,7 @@ class RunJobTest(BaseCeleryTest): self.assertEqual(job.status, 'new') self.assertFalse(job.passwords_needed_to_start) self.assertTrue(job.start()) - self.assertEqual(job.status, 'pending') + self.assertEqual(job.status, 'waiting') job = Job.objects.get(pk=job.pk) self.check_job_result(job, 'successful') self.check_job_events(job, 'ok', 1, 1, async=True, async_nowait=True)