Validate ansible installations on startup

Instead of failing jobs when trying to use non-existing ansible
installations it should validate if all supported ansible
installations are available during startup.

Change-Id: Ida05001634938f5b3a6c191cf2c750e788f3ccbb
This commit is contained in:
Tobias Henkel 2019-02-17 08:48:18 +01:00
parent cd9827e664
commit 07ab212f01
No known key found for this signature in database
GPG Key ID: 03750DEC158E5FA2
2 changed files with 29 additions and 0 deletions

View File

@ -2279,6 +2279,12 @@ class ExecutorServer(object):
ansible_dir = os.path.join(state_dir, 'ansible')
self.ansible_manager = AnsibleManager(ansible_dir)
if not self.ansible_manager.validate():
# TODO(tobiash): Install ansible here if auto install on startup is
# requested
raise Exception('Error while validating ansible installations. '
'Please run zuul-manage-ansible to install all '
'supported ansible versions.')
self.ansible_manager.copyAnsibleFiles()
def _getMerger(self, root, cache_root, logger=None):

View File

@ -161,6 +161,29 @@ class AnsibleManager:
for future in concurrent.futures.as_completed(futures):
future.result()
def validate(self):
result = True
for version in self._supported_versions:
command = [
self.getAnsibleCommand(version, 'ansible'),
'--version',
]
try:
result = subprocess.run(command,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
check=True)
self.log.info('Ansible version %s information: \n%s',
version, result.stdout.decode())
except FileNotFoundError:
result = False
self.log.exception('Ansible version %s not found' % version)
except subprocess.CalledProcessError:
result = False
self.log.exception("Ansible version %s not working" % version)
return result
def _getAnsible(self, version):
if not version:
version = self.default_version