Handle multiple playbook extensions

Detecting whether to look for a .yaml or .yml file for a playbook,
and detecting whether that playbook exists would ideally be done
in the scheduler.  However, doing so involves passing and storing
quite a bit of extra data (file lists for each project-branch
combination), and might put a crimp in making playbook specification
more sophisticated later.  So for now, let's do it in the launcher
where it's easy for us to test for the presence of files right
before we run a job.  Even though that means we won't detect errors
until later, for many changes this will still be self testing and
should prevent many config errors from landing.

If need be, we can do the extra work to move it into the scheduler
later.

Change-Id: I1ad2eb4a5d0ff08fbd2070f55e352633dd6de81b
This commit is contained in:
James E. Blair 2017-01-25 14:56:10 -08:00
parent 1c236dfe93
commit d130f718b0
2 changed files with 12 additions and 5 deletions

View File

@ -151,9 +151,7 @@ class JobParser(object):
job.source_project = conf.get('_source_project')
job.source_branch = conf.get('_source_branch')
job.source_configrepo = conf.get('_source_configrepo')
# TODOv3(jeblair): verify the playbook exists
# TODOv3(jeblair): remove hardcoded extension
job.playbook = os.path.join('playbooks', job.name + '.yaml')
job.playbook = os.path.join('playbooks', job.name)
job.failure_message = conf.get('failure-message', job.failure_message)
job.success_message = conf.get('success-message', job.success_message)
job.failure_url = conf.get('failure-url', job.failure_url)

View File

@ -408,6 +408,13 @@ class LaunchServer(object):
hosts.append((node['name'], dict(ansible_connection='local')))
return hosts
def findPlaybook(self, path):
for ext in ['.yaml', '.yml']:
fn = path + ext
if os.path.exists(fn):
return fn
raise Exception("Unable to find playbook %s" % path)
def preparePlaybookRepo(self, jobdir, args):
# Check out the playbook repo if needed and return the path to
# the playbook that should be run.
@ -424,9 +431,10 @@ class LaunchServer(object):
if (i['connection_name'] == playbook['connection'] and
i['project'] == playbook['project']):
# We already have this repo prepared
return os.path.join(jobdir.git_root,
path = os.path.join(jobdir.git_root,
project.name,
playbook['path'])
return self.findPlaybook(path)
# The playbook repo is either a config repo, or it isn't in
# the stack of changes we are testing, so check out the branch
# tip into a dedicated space.
@ -434,9 +442,10 @@ class LaunchServer(object):
merger = self._getMerger(jobdir.playbook_root)
merger.checkoutBranch(project.name, url, playbook['branch'])
return os.path.join(jobdir.playbook_root,
path = os.path.join(jobdir.playbook_root,
project.name,
playbook['path'])
return self.findPlaybook(path)
def prepareAnsibleFiles(self, jobdir, args):
with open(jobdir.inventory, 'w') as inventory: