Skip to content

Commit

Permalink
from PR review, clarify pre-check logging, minor docs additions
Browse files Browse the repository at this point in the history
  • Loading branch information
AlanCoding committed Jul 10, 2019
1 parent 5b38249 commit ce2e4ac
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 29 deletions.
39 changes: 13 additions & 26 deletions awx/main/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1569,17 +1569,6 @@ def should_use_proot(self, job):
'''
return getattr(settings, 'AWX_PROOT_ENABLED', False)

def copy_folders(self, project_path, galaxy_install_path, private_data_dir):
if project_path is None:
raise RuntimeError('project does not supply a valid path')
elif not os.path.exists(project_path):
raise RuntimeError('project path %s cannot be found' % project_path)
runner_project_folder = os.path.join(private_data_dir, 'project')
copy_tree(project_path, runner_project_folder)
if galaxy_install_path:
galaxy_run_path = os.path.join(private_data_dir, 'project', 'roles')
copy_tree(galaxy_install_path, galaxy_run_path)

def pre_run_hook(self, job, private_data_dir):
if job.inventory is None:
error = _('Job could not start because it does not have a valid inventory.')
Expand All @@ -1596,8 +1585,6 @@ def pre_run_hook(self, job, private_data_dir):
job = self.update_model(job.pk, status='failed', job_explanation=msg)
raise RuntimeError(msg)

galaxy_install_path = None
git_repo = None
project_path = job.project.get_project_path(check_if_exists=False)
job_revision = job.project.scm_revision
needs_sync = True
Expand All @@ -1606,21 +1593,20 @@ def pre_run_hook(self, job, private_data_dir):
needs_sync = False
elif not os.path.exists(project_path):
logger.debug('Performing fresh clone of {} on this instance.'.format(job.project))
needs_sync = True
elif job.project.scm_revision:
logger.debug('Revision not known for {}, will sync with remote'.format(job.project))
elif job.project.scm_type == 'git':
git_repo = git.Repo(project_path)
if job.scm_branch and job.scm_branch != job.project.scm_branch and git_repo:
try:
commit = git_repo.commit(job.scm_branch)
job_revision = commit.hexsha
logger.info('Skipping project sync for {} because commit is locally available'.format(job.log_format))
needs_sync = False # requested commit is already locally available
except (ValueError, BadGitName):
pass
else:
if git_repo.head.commit.hexsha == job.project.scm_revision:
logger.info('Source tree for for {} is already up to date'.format(job.log_format))
needs_sync = False
try:
desired_revision = job.project.scm_revision
if job.scm_branch and job.scm_branch != job.project.scm_branch:
desired_revision = job.scm_branch # could be commit or not, but will try as commit
commit = git_repo.commit(desired_revision)
job_revision = commit.hexsha
logger.info('Skipping project sync for {} because commit is locally available'.format(job.log_format))
needs_sync = False
except (ValueError, BadGitName):
logger.debug('Needed commit for {} not in local source tree, will sync with remote'.format(job.log_format))
# Galaxy requirements are not supported for manual projects
if not needs_sync and job.project.scm_type:
# see if we need a sync because of presence of roles
Expand All @@ -1629,6 +1615,7 @@ def pre_run_hook(self, job, private_data_dir):
logger.debug('Running project sync for {} because of galaxy role requirements.'.format(job.log_format))
needs_sync = True

galaxy_install_path = None
if needs_sync:
pu_ig = job.instance_group
pu_en = job.execution_node
Expand Down
7 changes: 4 additions & 3 deletions docs/clustering.md
Original file line number Diff line number Diff line change
Expand Up @@ -268,12 +268,13 @@ As Tower instances are brought online, it effectively expands the work capacity

It's important to note that not all instances are required to be provisioned with an equal capacity.

Project updates behave differently than they did before. Previously they were ordinary jobs that ran on a single instance. It's now important that they run successfully on any instance that could potentially run a job. Projects will now sync themselves to the correct version on the instance immediately prior to running the job.
If an Instance Group is configured but all instances in that group are offline or unavailable, any jobs that are launched targeting only that group will be stuck in a waiting state until instances become available. Fallback or backup resources should be provisioned to handle any work that might encounter this scenario.

When the sync happens, it is recorded in the database as a project update with a `launch_type` of "sync" and a `job_type` of "run". Project syncs will not change the status or version of the project; instead, they will update the source tree _only_ on the instance where they run. The only exception to this behavior is when the project is in the "never updated" state (meaning that no project updates of any type have been run), in which case a sync should fill in the project's initial revision and status, and subsequent syncs should not make such changes.
#### Project synchronization behavior

If an Instance Group is configured but all instances in that group are offline or unavailable, any jobs that are launched targeting only that group will be stuck in a waiting state until instances become available. Fallback or backup resources should be provisioned to handle any work that might encounter this scenario.
Project updates behave differently than they did before. Previously they were ordinary jobs that ran on a single instance. It's now important that they run successfully on any instance that could potentially run a job. Projects will sync themselves to the correct version on the instance immediately prior to running the job. If the needed revision is already locally available and galaxy or collections updates are not needed, then a sync may not be performed.

When the sync happens, it is recorded in the database as a project update with a `launch_type` of "sync" and a `job_type` of "run". Project syncs will not change the status or version of the project; instead, they will update the source tree _only_ on the instance where they run. The only exception to this behavior is when the project is in the "never updated" state (meaning that no project updates of any type have been run), in which case a sync should fill in the project's initial revision and status, and subsequent syncs should not make such changes.

#### Controlling where a particular job runs

Expand Down
1 change: 1 addition & 0 deletions docs/prompting.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ The standard pattern applies to fields
- `limit`
- `diff_mode`
- `verbosity`
- `scm_branch`

##### Non-Standard Cases (Credentials Changing in Tower 3.3)

Expand Down

0 comments on commit ce2e4ac

Please sign in to comment.