From c2950fdbdfa6beac39dc25f99190f17acafa6906 Mon Sep 17 00:00:00 2001 From: Matthew Jones Date: Thu, 13 Mar 2014 13:25:45 -0400 Subject: [PATCH] Unit test updates for task system... remove old monkeypatch procedure for getting job args in favor of using the job info from the database. Can't do this anymore anyway since the job is running in another process --- .../management/commands/run_task_system.py | 8 ++-- awx/main/tests/projects.py | 5 +-- awx/main/tests/tasks.py | 42 +++++++------------ 3 files changed, 23 insertions(+), 32 deletions(-) diff --git a/awx/main/management/commands/run_task_system.py b/awx/main/management/commands/run_task_system.py index 790b81af7d..b65f3a44ec 100644 --- a/awx/main/management/commands/run_task_system.py +++ b/awx/main/management/commands/run_task_system.py @@ -188,8 +188,9 @@ def rebuild_graph(message): dep.status = 'waiting' dep.save() waiting_tasks.insert(waiting_tasks.index(task), dep) - task.status = 'waiting' - task.save() + if not hasattr(settings, 'CELERY_UNIT_TEST'): + task.status = 'waiting' + task.save() # Rebuild graph graph = SimpleDAG() @@ -242,7 +243,8 @@ def process_graph(graph, task_capacity): continue remaining_volume -= impact running_impact += impact - print("Started Node: %s (capacity hit: %s) Remaining Capacity: %s" % (str(node_obj), str(impact), str(remaining_volume))) + if settings.DEBUG: + print("Started Node: %s (capacity hit: %s) Remaining Capacity: %s" % (str(node_obj), str(impact), str(remaining_volume))) def run_taskmanager(command_port): ''' Receive task start and finish signals to rebuild a dependency graph and manage the actual running of tasks ''' diff --git a/awx/main/tests/projects.py b/awx/main/tests/projects.py index 95d92ee236..7353a16ba6 100644 --- a/awx/main/tests/projects.py +++ b/awx/main/tests/projects.py @@ -1012,7 +1012,7 @@ class ProjectUpdatesTest(BaseTransactionTest): if project.scm_type: self.assertTrue(project.last_update) self.check_project_update(project, - project_udpate=project.last_update) + project_update=project.last_update) self.assertTrue(os.path.exists(project_path)) else: self.assertFalse(os.path.exists(project_path)) @@ -1567,8 +1567,7 @@ class ProjectUpdatesTest(BaseTransactionTest): job = self.create_test_job(job_template=job_template) self.assertEqual(job.status, 'new') self.assertFalse(job.passwords_needed_to_start) - self.assertTrue(job.start()) - self.assertEqual(job.status, 'waiting') + self.assertTrue(job.signal_start()) job = Job.objects.get(pk=job.pk) self.assertTrue(job.status in ('successful', 'failed')) self.assertEqual(self.project.project_updates.count(), 3) diff --git a/awx/main/tests/tasks.py b/awx/main/tests/tasks.py index 424d5cfa62..fbc4ee2395 100644 --- a/awx/main/tests/tasks.py +++ b/awx/main/tests/tasks.py @@ -177,16 +177,6 @@ class RunJobTest(BaseCeleryTest): self.project = None self.credential = None self.cloud_credential = None - # Monkeypatch RunJob to capture list of command line arguments. - self.original_build_args = RunJob.build_args - self.run_job_args = None - self.build_args_callback = lambda: None - def new_build_args(_self, job, **kw): - args = self.original_build_args(_self, job, **kw) - self.run_job_args = args - self.build_args_callback() - return args - RunJob.build_args = new_build_args settings.INTERNAL_API_URL = self.live_server_url self.start_taskmanager(settings.TASK_COMMAND_PORT) if settings.CALLBACK_CONSUMER_PORT: @@ -684,9 +674,9 @@ class RunJobTest(BaseCeleryTest): self.assertTrue(job.signal_start()) job = Job.objects.get(pk=job.pk) self.check_job_result(job, 'successful') - self.assertTrue('--forks=3' in self.run_job_args) - self.assertTrue('-vv' in self.run_job_args) - self.assertTrue('-e' in self.run_job_args) + self.assertTrue('--forks=3' in job.job_args) + self.assertTrue('-vv' in job.job_args) + self.assertTrue('-e' in job.job_args) # Test with extra_vars as key=value (old format). job_template2 = self.create_test_job_template(extra_vars='foo=1') job2 = self.create_test_job(job_template=job_template2) @@ -713,7 +703,7 @@ class RunJobTest(BaseCeleryTest): job = Job.objects.get(pk=job.pk) self.assertTrue(len(job.job_args) > 1024) self.check_job_result(job, 'successful') - self.assertTrue('-e' in self.run_job_args) + self.assertTrue('-e' in job.job_args) def test_limit_option(self): self.create_test_project(TEST_PLAYBOOK) @@ -724,7 +714,7 @@ class RunJobTest(BaseCeleryTest): self.assertTrue(job.signal_start()) job = Job.objects.get(pk=job.pk) self.check_job_result(job, 'failed') - self.assertTrue('-l' in self.run_job_args) + self.assertTrue('-l' in job.job_args) def test_limit_option_with_group_pattern_and_ssh_agent(self): self.create_test_credential(ssh_key_data=TEST_SSH_KEY_DATA) @@ -736,7 +726,7 @@ class RunJobTest(BaseCeleryTest): self.assertTrue(job.signal_start()) job = Job.objects.get(pk=job.pk) self.check_job_result(job, 'successful') - self.assertTrue('ssh-agent' in self.run_job_args) + self.assertTrue('ssh-agent' in job.job_args) def test_ssh_username_and_password(self): self.create_test_credential(username='sshuser', password='sshpass') @@ -748,8 +738,8 @@ class RunJobTest(BaseCeleryTest): self.assertTrue(job.signal_start()) job = Job.objects.get(pk=job.pk) self.check_job_result(job, 'successful') - self.assertTrue('-u' in self.run_job_args) - self.assertTrue('--ask-pass' in self.run_job_args) + self.assertTrue('-u' in job.job_args) + self.assertTrue('--ask-pass' in job.job_args) def test_ssh_ask_password(self): self.create_test_credential(password='ASK') @@ -764,7 +754,7 @@ class RunJobTest(BaseCeleryTest): self.assertTrue(job.signal_start(ssh_password='sshpass')) job = Job.objects.get(pk=job.pk) self.check_job_result(job, 'successful') - self.assertTrue('--ask-pass' in self.run_job_args) + self.assertTrue('--ask-pass' in job.job_args) def test_sudo_username_and_password(self): self.create_test_credential(sudo_username='sudouser', @@ -779,8 +769,8 @@ class RunJobTest(BaseCeleryTest): # Job may fail if current user doesn't have password-less sudo # privileges, but we're mainly checking the command line arguments. self.check_job_result(job, ('successful', 'failed')) - self.assertTrue('-U' in self.run_job_args) - self.assertTrue('--ask-sudo-pass' in self.run_job_args) + self.assertTrue('-U' in job.job_args) + self.assertTrue('--ask-sudo-pass' in job.job_args) def test_sudo_ask_password(self): self.create_test_credential(sudo_password='ASK') @@ -796,7 +786,7 @@ class RunJobTest(BaseCeleryTest): # Job may fail if current user doesn't have password-less sudo # privileges, but we're mainly checking the command line arguments. self.assertTrue(job.status in ('successful', 'failed')) - self.assertTrue('--ask-sudo-pass' in self.run_job_args) + self.assertTrue('--ask-sudo-pass' in job.job_args) def test_unlocked_ssh_key(self): self.create_test_credential(ssh_key_data=TEST_SSH_KEY_DATA) @@ -808,7 +798,7 @@ class RunJobTest(BaseCeleryTest): self.assertTrue(job.signal_start()) job = Job.objects.get(pk=job.pk) self.check_job_result(job, 'successful') - self.assertTrue('ssh-agent' in self.run_job_args) + self.assertTrue('ssh-agent' in job.job_args) def test_locked_ssh_key_with_password(self): self.create_test_credential(ssh_key_data=TEST_SSH_KEY_DATA_LOCKED, @@ -821,7 +811,7 @@ class RunJobTest(BaseCeleryTest): self.assertTrue(job.signal_start()) job = Job.objects.get(pk=job.pk) self.check_job_result(job, 'successful') - self.assertTrue('ssh-agent' in self.run_job_args) + self.assertTrue('ssh-agent' in job.job_args) self.assertTrue('Bad passphrase' not in job.result_stdout) def test_locked_ssh_key_with_bad_password(self): @@ -835,7 +825,7 @@ class RunJobTest(BaseCeleryTest): self.assertTrue(job.signal_start()) job = Job.objects.get(pk=job.pk) self.check_job_result(job, 'failed') - self.assertTrue('ssh-agent' in self.run_job_args) + self.assertTrue('ssh-agent' in job.job_args) self.assertTrue('Bad passphrase' in job.result_stdout) def test_locked_ssh_key_ask_password(self): @@ -852,7 +842,7 @@ class RunJobTest(BaseCeleryTest): self.assertTrue(job.signal_start(ssh_key_unlock=TEST_SSH_KEY_DATA_UNLOCK)) job = Job.objects.get(pk=job.pk) self.check_job_result(job, 'successful') - self.assertTrue('ssh-agent' in self.run_job_args) + self.assertTrue('ssh-agent' in job.job_args) self.assertTrue('Bad passphrase' not in job.result_stdout) def _test_cloud_credential_environment_variables(self, kind):