diff options
author | Albin Vass <albin.vass@gmail.com> | 2020-04-28 19:47:46 +0200 |
---|---|---|
committer | Albin Vass <albin.vass@gmail.com> | 2020-05-08 09:03:10 +0200 |
commit | f9a1e1a9585dfd8b3f8136c8ccbfd154915b5b59 (patch) | |
tree | 555216097b6aed36b22c001cd22f99bde8cafa30 /zuul/lib | |
parent | 7381be2573d78e8e78885d7ca45cdb78cdb707ff (diff) | |
download | zuul-f9a1e1a9585dfd8b3f8136c8ccbfd154915b5b59.tar.gz |
Validate ansible extra packages
Currently when validating the ansible installation, zuul only checks
if ansible is installed and not any packages that would have been
installed with ANSIBLE_EXTRA_PACKAGES. Since the executor image has
ansible pre installed the ANSIBLE_EXTRA_PACKAGES environment variable
has no effect unless ansible is removed.
This adds a check to make sure packages specified with
ANSIBLE_EXTRA_PACKAGES are installed as well.
Change-Id: I7ee4125d6716db718bb355b837e90dbcfce9b857
Diffstat (limited to 'zuul/lib')
-rw-r--r-- | zuul/lib/ansible.py | 61 |
1 files changed, 43 insertions, 18 deletions
diff --git a/zuul/lib/ansible.py b/zuul/lib/ansible.py index f5eb7e0e8..df0ed0213 100644 --- a/zuul/lib/ansible.py +++ b/zuul/lib/ansible.py @@ -202,29 +202,54 @@ class AnsibleManager: for future in concurrent.futures.as_completed(futures): future.result() + def _validate_ansible(self, version): + result = True + try: + command = [ + self.getAnsibleCommand(version, 'ansible'), + '--version', + ] + + ret = subprocess.run(command, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + check=True) + self.log.info('Ansible version %s information: \n%s', + version, ret.stdout.decode()) + except subprocess.CalledProcessError: + result = False + self.log.exception("Ansible version %s not working" % version) + except Exception: + result = False + self.log.exception( + 'Ansible version %s not installed' % version) + return result + + def _validate_packages(self, version): + result = True + try: + extra_packages = self._getAnsible(version).extra_packages + python_package_check = \ + "import pkg_resources; pkg_resources.require({})".format( + repr(extra_packages)) + + command = [self.getAnsibleCommand(version, 'python'), + '-c', python_package_check] + subprocess.run(command, check=True) + except Exception: + result = False + self.log.exception( + 'Ansible version %s installation is missing packages' % + version) + return result + def validate(self): result = True for version in self._supported_versions: - try: - command = [ - self.getAnsibleCommand(version, 'ansible'), - '--version', - ] - - ret = subprocess.run(command, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - check=True) - self.log.info('Ansible version %s information: \n%s', - version, ret.stdout.decode()) - except subprocess.CalledProcessError: + if not self._validate_ansible(version): result = False - self.log.exception("Ansible version %s not working" % version) - except Exception: + elif not self._validate_packages(version): result = False - self.log.exception( - 'Ansible version %s not installed' % version) - return result def _getAnsible(self, version): |