diff --git a/.ansible-lint b/.ansible-lint new file mode 100644 index 0000000..46a92f2 --- /dev/null +++ b/.ansible-lint @@ -0,0 +1,23 @@ +exclude_paths: + - releasenotes/ +parseable: true +quiet: false +skip_list: + # Lines should be no longer than 120 chars. + - '204' + # Using command rather module we have where + # we need to use curl or rsync. + - '303' + # shell tasks uses pipeline without pipefail, + # this requires refactoring, skip for now. + - '306' + # Tasks that run when changed should likely be handlers + # this requires refactoring, skip for now. + - '503' + # meta/main.yml should contain relevant info + - '701' + # Tags must contain lowercase letters and digits only + - '702' + # meta/main.yml default values should be changed + - '703' +verbosity: 1 diff --git a/.yamllint b/.yamllint new file mode 100644 index 0000000..7abc606 --- /dev/null +++ b/.yamllint @@ -0,0 +1,11 @@ +--- +extends: default + +rules: + line-length: + # matches hardcoded 160 value from ansible-lint + max: 160 + +ignore: | + zuul.d/*.yaml + releasenotes/notes/*.yaml diff --git a/requirements.txt b/requirements.txt index 8552d38..cdeaf68 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,14 +3,4 @@ # process, which may cause wedges in the gate later. pbr>=3.1.1 # Apache-2.0 -oslo.config>=5.2.0 # Apache-2.0 -keystoneauth1>=3.12.0 # Apache-2.0 -python-novaclient>=15.1.0 # Apache-2.0 -python-heatclient>=1.10.0 # Apache-2.0 -python-glanceclient>=2.9.1 # Apache-2.0 -python-ironicclient>=2.7.0 # Apache-2.0 -python-ironic-inspector-client>=3.1.1 # Apache-2.0 -os-net-config>=7.1.0 # Apache-2.0 -oslo.utils>=3.40.2 # Apache-2.0 -six>=1.11.0 # MIT -tripleo-common>=7.1.0 # Apache-2.0 +PyYAML diff --git a/setup.cfg b/setup.cfg index 0b1c3ab..51a85e0 100644 --- a/setup.cfg +++ b/setup.cfg @@ -26,10 +26,10 @@ packages = validations_common data_files = - share/validations-common/roles = roles/* - share/validations-common/callback_plugins = callback_plugins/* - share/validations-common/lookup_plugins = lookup_plugins/* - share/validations-common/library = library/* + share/validations-common/roles = validations_common/roles/* + share/validations-common/callback_plugins = validations_common/callback_plugins/* + share/validations-common/lookup_plugins = validations_common/lookup_plugins/* + share/validations-common/library = validations_common/library/* [build_sphinx] source-dir = doc/source diff --git a/test-requirements.txt b/test-requirements.txt index 1d86fba..6df0532 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -7,8 +7,6 @@ hacking<0.12,>=0.11.0 # Apache-2.0 coverage!=4.4,>=4.0 # Apache-2.0 python-subunit>=1.0.0 # Apache-2.0/BSD -sphinx>=1.8.0,<2.0.0;python_version=='2.7' # BSD -sphinx>=1.8.0,!=2.1.0;python_version>='3.4' # BSD oslotest>=3.2.0 # Apache-2.0 testrepository>=0.0.18 # Apache-2.0/BSD testscenarios>=0.4 # Apache-2.0/BSD diff --git a/tools/validate-files.py b/tools/validate-files.py index 7b35e06..92b7fb6 100755 --- a/tools/validate-files.py +++ b/tools/validate-files.py @@ -66,9 +66,7 @@ for base_path in path_args: if f.endswith('.py') \ and not f == '__init__.py' \ and subdir in [os.path.join(base_path, - 'validations', - 'library'), - os.path.join(base_path, + 'validations_common', 'library')]: file_path = os.path.join(subdir, f) if quiet < 1: diff --git a/tox.ini b/tox.ini index 473e92b..cf7ae53 100644 --- a/tox.ini +++ b/tox.ini @@ -7,10 +7,10 @@ skipdist = True usedevelop = True passenv = * setenv = - ANSIBLE_CALLBACK_PLUGINS={toxinidir}/callback_plugins - ANSIBLE_LOOKUP_PLUGINS={toxinidir}/lookup_plugins - ANSIBLE_LIBRARY={toxinidir}/library - ANSIBLE_ROLES_PATH={toxinidir}/roles + ANSIBLE_CALLBACK_PLUGINS={toxinidir}/validations_common/callback_plugins + ANSIBLE_LOOKUP_PLUGINS={toxinidir}/validations_common/lookup_plugins + ANSIBLE_LIBRARY={toxinidir}/validations_common/library + ANSIBLE_ROLES_PATH={toxinidir}/validations_common/roles ANSIBLE_NOCOWS=1 ANSIBLE_RETRY_FILES_ENABLED=0 ANSIBLE_STDOUT_CALLBACK=debug @@ -49,8 +49,8 @@ envdir = {toxworkdir}/linters deps = {[testenv:linters]deps} commands = - bash -c "ANSIBLE_ROLES_PATH='{toxinidir}/roles'" - bash -c "ANSIBLE_LIBRARY='{toxinidir}/library'" + bash -c "ANSIBLE_ROLES_PATH='{toxinidir}/validations_common/roles'" + bash -c "ANSIBLE_LIBRARY='{toxinidir}/validations_common/library'" python -m pre_commit run ansible-lint -a [testenv:yamllint] diff --git a/callback_plugins/fail_if_no_hosts.py b/validations_common/callback_plugins/fail_if_no_hosts.py similarity index 100% rename from callback_plugins/fail_if_no_hosts.py rename to validations_common/callback_plugins/fail_if_no_hosts.py diff --git a/callback_plugins/validation_json.py b/validations_common/callback_plugins/validation_json.py similarity index 100% rename from callback_plugins/validation_json.py rename to validations_common/callback_plugins/validation_json.py diff --git a/callback_plugins/validation_output.py b/validations_common/callback_plugins/validation_output.py similarity index 100% rename from callback_plugins/validation_output.py rename to validations_common/callback_plugins/validation_output.py diff --git a/validations_common/library/advanced_format.py b/validations_common/library/advanced_format.py new file mode 100644 index 0000000..84b1c99 --- /dev/null +++ b/validations_common/library/advanced_format.py @@ -0,0 +1,97 @@ +#!/usr/bin/env python +# Copyright 2016 Red Hat, Inc. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from os import path +from yaml import safe_load as yaml_safe_load + +from ansible.module_utils.basic import AnsibleModule + +DOCUMENTATION = ''' +--- +module: advanced_format +short_description: Check for advanced disk format +description: + - Check whether a drive uses advanced format +options: + drive: + required: true + description: + - drive name + type: str +author: "Martin Andre (@mandre)" +''' + +EXAMPLES = ''' +- hosts: webservers + tasks: + - name: Detect whether the drive uses Advanced Format + advanced_format: drive=vda +''' + + +def read_int(module, file_path): + '''Read a file and convert its value to int. + + Raise ansible failure otherwise. + ''' + try: + with open(file_path) as f: + file_contents = f.read() + return int(file_contents) + except IOError: + module.fail_json(msg="Cannot open '%s'" % file_path) + except ValueError: + module.fail_json(msg="The '%s' file doesn't contain an integer value" % + file_path) + + +def main(): + module = AnsibleModule( + argument_spec=yaml_safe_load(DOCUMENTATION)['options'] + ) + + drive = module.params.get('drive') + queue_path = path.join('/sys/class/block', drive, 'queue') + + physical_block_size_path = path.join(queue_path, 'physical_block_size') + logical_block_size_path = path.join(queue_path, 'logical_block_size') + + physical_block_size = read_int(module, physical_block_size_path) + logical_block_size = read_int(module, logical_block_size_path) + + if physical_block_size == logical_block_size: + module.exit_json( + changed=False, + msg="The disk %s probably doesn't use Advance Format." % drive, + ) + else: + module.exit_json( + # NOTE(shadower): we're marking this as `changed`, to make it + # visually stand out when running via Ansible directly instead of + # using the API. + # + # The API & UI is planned to look for the `warnings` field and + # display it differently. + changed=True, + warnings=["Physical and logical block sizes of drive %s differ " + "(%s vs. %s). This can mean the disk uses Advance " + "Format." % + (drive, physical_block_size, logical_block_size)], + ) + + +if __name__ == '__main__': + main() diff --git a/validations_common/library/check_package_update.py b/validations_common/library/check_package_update.py new file mode 100755 index 0000000..fcf42fb --- /dev/null +++ b/validations_common/library/check_package_update.py @@ -0,0 +1,145 @@ +#!/usr/bin/env python +# Copyright 2017 Red Hat, Inc. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +""" Check for available updates for a given package.""" + +import collections +import subprocess + +from ansible.module_utils.basic import AnsibleModule +from yaml import safe_load as yaml_safe_load + +DOCUMENTATION = ''' +--- +module: check_package_update +short_description: Check for available updates for a given package +description: + - Check for available updates for a given package +options: + package: + required: true + description: + - The name of the package you want to check + type: str + pkg_mgr: + required: true + description: + - Supported Package Manager, DNF or YUM + type: str +author: "Florian Fuchs" +''' + +EXAMPLES = ''' +- hosts: webservers + tasks: + - name: Get available updates for packages + check_package_update: + package: python-tripleoclient + pkg_mgr: "{{ ansible_pkg_mgr}}" +''' + +SUPPORTED_PKG_MGRS = ( + 'yum', + 'dnf', +) + + +PackageDetails = collections.namedtuple('PackageDetails', + ['name', 'version', 'release', 'arch']) + + +def get_package_details(output): + if output: + return PackageDetails( + output.split('|')[0], + output.split('|')[1], + output.split('|')[2], + output.split('|')[3], + ) + + +def _command(command): + # Return the result of a subprocess call + # as [stdout, stderr] + process = subprocess.Popen(command, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + universal_newlines=True) + return process.communicate() + + +def check_update(module, package, pkg_mgr): + if pkg_mgr not in SUPPORTED_PKG_MGRS: + module.fail_json( + msg='Package manager "{}" is not supported.'.format(pkg_mgr)) + return + + installed_stdout, installed_stderr = _command( + ['rpm', '-qa', '--qf', + '%{NAME}|%{VERSION}|%{RELEASE}|%{ARCH}', + package]) + + # Fail the module if for some reason we can't lookup the current package. + if installed_stderr != '': + module.fail_json(msg=installed_stderr) + return + elif not installed_stdout: + module.fail_json( + msg='"{}" is not an installed package.'.format(package)) + return + + installed = get_package_details(installed_stdout) + + pkg_mgr_option = 'available' + if pkg_mgr == 'dnf': + pkg_mgr_option = '--available' + + available_stdout, available_stderr = _command( + [pkg_mgr, '-q', 'list', pkg_mgr_option, installed.name]) + + if available_stdout: + new_pkg_info = available_stdout.split('\n')[1].rstrip().split()[:2] + new_ver, new_rel = new_pkg_info[1].split('-') + + module.exit_json( + changed=False, + name=installed.name, + current_version=installed.version, + current_release=installed.release, + new_version=new_ver, + new_release=new_rel) + else: + module.exit_json( + changed=False, + name=installed.name, + current_version=installed.version, + current_release=installed.release, + new_version=None, + new_release=None) + + +def main(): + module = AnsibleModule( + argument_spec=yaml_safe_load(DOCUMENTATION)['options'] + ) + + check_update(module, + module.params.get('package'), + module.params.get('pkg_mgr')) + + +if __name__ == '__main__': + main() diff --git a/library/haproxy_conf.py b/validations_common/library/haproxy_conf.py similarity index 100% rename from library/haproxy_conf.py rename to validations_common/library/haproxy_conf.py diff --git a/library/hiera.py b/validations_common/library/hiera.py similarity index 100% rename from library/hiera.py rename to validations_common/library/hiera.py diff --git a/library/validations_read_ini.py b/validations_common/library/validations_read_ini.py similarity index 100% rename from library/validations_read_ini.py rename to validations_common/library/validations_read_ini.py diff --git a/library/warn.py b/validations_common/library/warn.py similarity index 100% rename from library/warn.py rename to validations_common/library/warn.py diff --git a/roles/advanced_format_512e_support/molecule/default/Dockerfile.j2 b/validations_common/roles/advanced_format_512e_support/molecule/default/Dockerfile.j2 similarity index 100% rename from roles/advanced_format_512e_support/molecule/default/Dockerfile.j2 rename to validations_common/roles/advanced_format_512e_support/molecule/default/Dockerfile.j2 diff --git a/roles/advanced_format_512e_support/molecule/default/molecule.yml b/validations_common/roles/advanced_format_512e_support/molecule/default/molecule.yml similarity index 100% rename from roles/advanced_format_512e_support/molecule/default/molecule.yml rename to validations_common/roles/advanced_format_512e_support/molecule/default/molecule.yml diff --git a/roles/advanced_format_512e_support/molecule/default/playbook.yml b/validations_common/roles/advanced_format_512e_support/molecule/default/playbook.yml similarity index 100% rename from roles/advanced_format_512e_support/molecule/default/playbook.yml rename to validations_common/roles/advanced_format_512e_support/molecule/default/playbook.yml diff --git a/roles/advanced_format_512e_support/tasks/main.yml b/validations_common/roles/advanced_format_512e_support/tasks/main.yml similarity index 100% rename from roles/advanced_format_512e_support/tasks/main.yml rename to validations_common/roles/advanced_format_512e_support/tasks/main.yml diff --git a/roles/advanced_format_512e_support/vars/main.yml b/validations_common/roles/advanced_format_512e_support/vars/main.yml similarity index 100% rename from roles/advanced_format_512e_support/vars/main.yml rename to validations_common/roles/advanced_format_512e_support/vars/main.yml diff --git a/roles/check_latest_packages_version/defaults/main.yml b/validations_common/roles/check_latest_packages_version/defaults/main.yml similarity index 100% rename from roles/check_latest_packages_version/defaults/main.yml rename to validations_common/roles/check_latest_packages_version/defaults/main.yml diff --git a/roles/check_latest_packages_version/molecule/default/Dockerfile.j2 b/validations_common/roles/check_latest_packages_version/molecule/default/Dockerfile.j2 similarity index 100% rename from roles/check_latest_packages_version/molecule/default/Dockerfile.j2 rename to validations_common/roles/check_latest_packages_version/molecule/default/Dockerfile.j2 diff --git a/roles/check_latest_packages_version/molecule/default/molecule.yml b/validations_common/roles/check_latest_packages_version/molecule/default/molecule.yml similarity index 100% rename from roles/check_latest_packages_version/molecule/default/molecule.yml rename to validations_common/roles/check_latest_packages_version/molecule/default/molecule.yml diff --git a/roles/check_latest_packages_version/molecule/default/playbook.yml b/validations_common/roles/check_latest_packages_version/molecule/default/playbook.yml similarity index 100% rename from roles/check_latest_packages_version/molecule/default/playbook.yml rename to validations_common/roles/check_latest_packages_version/molecule/default/playbook.yml diff --git a/roles/check_latest_packages_version/molecule/default/prepare.yml b/validations_common/roles/check_latest_packages_version/molecule/default/prepare.yml similarity index 100% rename from roles/check_latest_packages_version/molecule/default/prepare.yml rename to validations_common/roles/check_latest_packages_version/molecule/default/prepare.yml diff --git a/roles/check_latest_packages_version/tasks/main.yml b/validations_common/roles/check_latest_packages_version/tasks/main.yml similarity index 100% rename from roles/check_latest_packages_version/tasks/main.yml rename to validations_common/roles/check_latest_packages_version/tasks/main.yml diff --git a/roles/check_latest_packages_version/vars/main.yml b/validations_common/roles/check_latest_packages_version/vars/main.yml similarity index 100% rename from roles/check_latest_packages_version/vars/main.yml rename to validations_common/roles/check_latest_packages_version/vars/main.yml diff --git a/roles/dns/defaults/main.yml b/validations_common/roles/dns/defaults/main.yml similarity index 100% rename from roles/dns/defaults/main.yml rename to validations_common/roles/dns/defaults/main.yml diff --git a/roles/dns/molecule/default/Dockerfile.j2 b/validations_common/roles/dns/molecule/default/Dockerfile.j2 similarity index 100% rename from roles/dns/molecule/default/Dockerfile.j2 rename to validations_common/roles/dns/molecule/default/Dockerfile.j2 diff --git a/roles/dns/molecule/default/molecule.yml b/validations_common/roles/dns/molecule/default/molecule.yml similarity index 100% rename from roles/dns/molecule/default/molecule.yml rename to validations_common/roles/dns/molecule/default/molecule.yml diff --git a/roles/dns/molecule/default/playbook.yml b/validations_common/roles/dns/molecule/default/playbook.yml similarity index 100% rename from roles/dns/molecule/default/playbook.yml rename to validations_common/roles/dns/molecule/default/playbook.yml diff --git a/roles/dns/tasks/main.yml b/validations_common/roles/dns/tasks/main.yml similarity index 100% rename from roles/dns/tasks/main.yml rename to validations_common/roles/dns/tasks/main.yml diff --git a/roles/dns/vars/main.yml b/validations_common/roles/dns/vars/main.yml similarity index 100% rename from roles/dns/vars/main.yml rename to validations_common/roles/dns/vars/main.yml diff --git a/roles/haproxy/README.md b/validations_common/roles/haproxy/README.md similarity index 100% rename from roles/haproxy/README.md rename to validations_common/roles/haproxy/README.md diff --git a/roles/haproxy/defaults/main.yml b/validations_common/roles/haproxy/defaults/main.yml similarity index 100% rename from roles/haproxy/defaults/main.yml rename to validations_common/roles/haproxy/defaults/main.yml diff --git a/roles/haproxy/molecule/default/Dockerfile.j2 b/validations_common/roles/haproxy/molecule/default/Dockerfile.j2 similarity index 100% rename from roles/haproxy/molecule/default/Dockerfile.j2 rename to validations_common/roles/haproxy/molecule/default/Dockerfile.j2 diff --git a/roles/haproxy/molecule/default/molecule.yml b/validations_common/roles/haproxy/molecule/default/molecule.yml similarity index 100% rename from roles/haproxy/molecule/default/molecule.yml rename to validations_common/roles/haproxy/molecule/default/molecule.yml diff --git a/roles/haproxy/molecule/default/playbook.yml b/validations_common/roles/haproxy/molecule/default/playbook.yml similarity index 100% rename from roles/haproxy/molecule/default/playbook.yml rename to validations_common/roles/haproxy/molecule/default/playbook.yml diff --git a/roles/haproxy/tasks/main.yml b/validations_common/roles/haproxy/tasks/main.yml similarity index 100% rename from roles/haproxy/tasks/main.yml rename to validations_common/roles/haproxy/tasks/main.yml diff --git a/roles/haproxy/vars/main.yml b/validations_common/roles/haproxy/vars/main.yml similarity index 100% rename from roles/haproxy/vars/main.yml rename to validations_common/roles/haproxy/vars/main.yml diff --git a/roles/no_op/tasks/main.yml b/validations_common/roles/no_op/tasks/main.yml similarity index 100% rename from roles/no_op/tasks/main.yml rename to validations_common/roles/no_op/tasks/main.yml diff --git a/roles/no_op/vars/main.yml b/validations_common/roles/no_op/vars/main.yml similarity index 100% rename from roles/no_op/vars/main.yml rename to validations_common/roles/no_op/vars/main.yml diff --git a/roles/ntp/molecule/default/Dockerfile.j2 b/validations_common/roles/ntp/molecule/default/Dockerfile.j2 similarity index 100% rename from roles/ntp/molecule/default/Dockerfile.j2 rename to validations_common/roles/ntp/molecule/default/Dockerfile.j2 diff --git a/roles/ntp/molecule/default/molecule.yml b/validations_common/roles/ntp/molecule/default/molecule.yml similarity index 100% rename from roles/ntp/molecule/default/molecule.yml rename to validations_common/roles/ntp/molecule/default/molecule.yml diff --git a/roles/ntp/molecule/default/playbook.yml b/validations_common/roles/ntp/molecule/default/playbook.yml similarity index 100% rename from roles/ntp/molecule/default/playbook.yml rename to validations_common/roles/ntp/molecule/default/playbook.yml diff --git a/roles/ntp/tasks/main.yml b/validations_common/roles/ntp/tasks/main.yml similarity index 100% rename from roles/ntp/tasks/main.yml rename to validations_common/roles/ntp/tasks/main.yml diff --git a/roles/ntp/vars/main.yml b/validations_common/roles/ntp/vars/main.yml similarity index 100% rename from roles/ntp/vars/main.yml rename to validations_common/roles/ntp/vars/main.yml diff --git a/roles/service_status/defaults/main.yaml b/validations_common/roles/service_status/defaults/main.yaml similarity index 100% rename from roles/service_status/defaults/main.yaml rename to validations_common/roles/service_status/defaults/main.yaml diff --git a/roles/service_status/molecule/default/Dockerfile.j2 b/validations_common/roles/service_status/molecule/default/Dockerfile.j2 similarity index 100% rename from roles/service_status/molecule/default/Dockerfile.j2 rename to validations_common/roles/service_status/molecule/default/Dockerfile.j2 diff --git a/roles/service_status/molecule/default/molecule.yml b/validations_common/roles/service_status/molecule/default/molecule.yml similarity index 100% rename from roles/service_status/molecule/default/molecule.yml rename to validations_common/roles/service_status/molecule/default/molecule.yml diff --git a/roles/service_status/molecule/default/playbook.yml b/validations_common/roles/service_status/molecule/default/playbook.yml similarity index 100% rename from roles/service_status/molecule/default/playbook.yml rename to validations_common/roles/service_status/molecule/default/playbook.yml diff --git a/roles/service_status/molecule/docker/Dockerfile.j2 b/validations_common/roles/service_status/molecule/docker/Dockerfile.j2 similarity index 100% rename from roles/service_status/molecule/docker/Dockerfile.j2 rename to validations_common/roles/service_status/molecule/docker/Dockerfile.j2 diff --git a/roles/service_status/molecule/docker/molecule.yml b/validations_common/roles/service_status/molecule/docker/molecule.yml similarity index 100% rename from roles/service_status/molecule/docker/molecule.yml rename to validations_common/roles/service_status/molecule/docker/molecule.yml diff --git a/roles/service_status/molecule/docker/playbook.yml b/validations_common/roles/service_status/molecule/docker/playbook.yml similarity index 100% rename from roles/service_status/molecule/docker/playbook.yml rename to validations_common/roles/service_status/molecule/docker/playbook.yml diff --git a/roles/service_status/molecule/docker/prepare.yml b/validations_common/roles/service_status/molecule/docker/prepare.yml similarity index 100% rename from roles/service_status/molecule/docker/prepare.yml rename to validations_common/roles/service_status/molecule/docker/prepare.yml diff --git a/roles/service_status/molecule/podman/Dockerfile.j2 b/validations_common/roles/service_status/molecule/podman/Dockerfile.j2 similarity index 100% rename from roles/service_status/molecule/podman/Dockerfile.j2 rename to validations_common/roles/service_status/molecule/podman/Dockerfile.j2 diff --git a/roles/service_status/molecule/podman/bolt_state.db b/validations_common/roles/service_status/molecule/podman/bolt_state.db similarity index 100% rename from roles/service_status/molecule/podman/bolt_state.db rename to validations_common/roles/service_status/molecule/podman/bolt_state.db diff --git a/roles/service_status/molecule/podman/molecule.yml b/validations_common/roles/service_status/molecule/podman/molecule.yml similarity index 100% rename from roles/service_status/molecule/podman/molecule.yml rename to validations_common/roles/service_status/molecule/podman/molecule.yml diff --git a/roles/service_status/molecule/podman/playbook.yml b/validations_common/roles/service_status/molecule/podman/playbook.yml similarity index 100% rename from roles/service_status/molecule/podman/playbook.yml rename to validations_common/roles/service_status/molecule/podman/playbook.yml diff --git a/roles/service_status/molecule/podman/prepare.yml b/validations_common/roles/service_status/molecule/podman/prepare.yml similarity index 100% rename from roles/service_status/molecule/podman/prepare.yml rename to validations_common/roles/service_status/molecule/podman/prepare.yml diff --git a/roles/service_status/molecule/systemd/Dockerfile.j2 b/validations_common/roles/service_status/molecule/systemd/Dockerfile.j2 similarity index 100% rename from roles/service_status/molecule/systemd/Dockerfile.j2 rename to validations_common/roles/service_status/molecule/systemd/Dockerfile.j2 diff --git a/roles/service_status/molecule/systemd/molecule.yml b/validations_common/roles/service_status/molecule/systemd/molecule.yml similarity index 100% rename from roles/service_status/molecule/systemd/molecule.yml rename to validations_common/roles/service_status/molecule/systemd/molecule.yml diff --git a/roles/service_status/molecule/systemd/playbook.yml b/validations_common/roles/service_status/molecule/systemd/playbook.yml similarity index 100% rename from roles/service_status/molecule/systemd/playbook.yml rename to validations_common/roles/service_status/molecule/systemd/playbook.yml diff --git a/roles/service_status/molecule/systemd/prepare.yml b/validations_common/roles/service_status/molecule/systemd/prepare.yml similarity index 100% rename from roles/service_status/molecule/systemd/prepare.yml rename to validations_common/roles/service_status/molecule/systemd/prepare.yml diff --git a/roles/service_status/tasks/containers.yaml b/validations_common/roles/service_status/tasks/containers.yaml similarity index 100% rename from roles/service_status/tasks/containers.yaml rename to validations_common/roles/service_status/tasks/containers.yaml diff --git a/roles/service_status/tasks/main.yaml b/validations_common/roles/service_status/tasks/main.yaml similarity index 100% rename from roles/service_status/tasks/main.yaml rename to validations_common/roles/service_status/tasks/main.yaml diff --git a/roles/service_status/tasks/systemd.yaml b/validations_common/roles/service_status/tasks/systemd.yaml similarity index 100% rename from roles/service_status/tasks/systemd.yaml rename to validations_common/roles/service_status/tasks/systemd.yaml diff --git a/roles/stonith_exists/molecule/default/Dockerfile.j2 b/validations_common/roles/stonith_exists/molecule/default/Dockerfile.j2 similarity index 100% rename from roles/stonith_exists/molecule/default/Dockerfile.j2 rename to validations_common/roles/stonith_exists/molecule/default/Dockerfile.j2 diff --git a/roles/stonith_exists/molecule/default/molecule.yml b/validations_common/roles/stonith_exists/molecule/default/molecule.yml similarity index 100% rename from roles/stonith_exists/molecule/default/molecule.yml rename to validations_common/roles/stonith_exists/molecule/default/molecule.yml diff --git a/roles/stonith_exists/molecule/default/playbook.yml b/validations_common/roles/stonith_exists/molecule/default/playbook.yml similarity index 100% rename from roles/stonith_exists/molecule/default/playbook.yml rename to validations_common/roles/stonith_exists/molecule/default/playbook.yml diff --git a/roles/stonith_exists/molecule/default/prepare.yml b/validations_common/roles/stonith_exists/molecule/default/prepare.yml similarity index 100% rename from roles/stonith_exists/molecule/default/prepare.yml rename to validations_common/roles/stonith_exists/molecule/default/prepare.yml diff --git a/roles/stonith_exists/tasks/main.yml b/validations_common/roles/stonith_exists/tasks/main.yml similarity index 100% rename from roles/stonith_exists/tasks/main.yml rename to validations_common/roles/stonith_exists/tasks/main.yml diff --git a/roles/stonith_exists/vars/main.yml b/validations_common/roles/stonith_exists/vars/main.yml similarity index 100% rename from roles/stonith_exists/vars/main.yml rename to validations_common/roles/stonith_exists/vars/main.yml diff --git a/roles/undercloud_cpu/README.md b/validations_common/roles/undercloud_cpu/README.md similarity index 100% rename from roles/undercloud_cpu/README.md rename to validations_common/roles/undercloud_cpu/README.md diff --git a/roles/undercloud_cpu/defaults/main.yml b/validations_common/roles/undercloud_cpu/defaults/main.yml similarity index 100% rename from roles/undercloud_cpu/defaults/main.yml rename to validations_common/roles/undercloud_cpu/defaults/main.yml diff --git a/roles/undercloud_cpu/molecule/default/Dockerfile.j2 b/validations_common/roles/undercloud_cpu/molecule/default/Dockerfile.j2 similarity index 100% rename from roles/undercloud_cpu/molecule/default/Dockerfile.j2 rename to validations_common/roles/undercloud_cpu/molecule/default/Dockerfile.j2 diff --git a/roles/undercloud_cpu/molecule/default/molecule.yml b/validations_common/roles/undercloud_cpu/molecule/default/molecule.yml similarity index 100% rename from roles/undercloud_cpu/molecule/default/molecule.yml rename to validations_common/roles/undercloud_cpu/molecule/default/molecule.yml diff --git a/roles/undercloud_cpu/molecule/default/playbook.yml b/validations_common/roles/undercloud_cpu/molecule/default/playbook.yml similarity index 100% rename from roles/undercloud_cpu/molecule/default/playbook.yml rename to validations_common/roles/undercloud_cpu/molecule/default/playbook.yml diff --git a/roles/undercloud_cpu/tasks/main.yml b/validations_common/roles/undercloud_cpu/tasks/main.yml similarity index 100% rename from roles/undercloud_cpu/tasks/main.yml rename to validations_common/roles/undercloud_cpu/tasks/main.yml diff --git a/roles/undercloud_cpu/vars/main.yaml b/validations_common/roles/undercloud_cpu/vars/main.yaml similarity index 100% rename from roles/undercloud_cpu/vars/main.yaml rename to validations_common/roles/undercloud_cpu/vars/main.yaml diff --git a/roles/undercloud_disk_space/README.md b/validations_common/roles/undercloud_disk_space/README.md similarity index 100% rename from roles/undercloud_disk_space/README.md rename to validations_common/roles/undercloud_disk_space/README.md diff --git a/roles/undercloud_disk_space/defaults/main.yml b/validations_common/roles/undercloud_disk_space/defaults/main.yml similarity index 100% rename from roles/undercloud_disk_space/defaults/main.yml rename to validations_common/roles/undercloud_disk_space/defaults/main.yml diff --git a/roles/undercloud_disk_space/molecule/default/Dockerfile.j2 b/validations_common/roles/undercloud_disk_space/molecule/default/Dockerfile.j2 similarity index 100% rename from roles/undercloud_disk_space/molecule/default/Dockerfile.j2 rename to validations_common/roles/undercloud_disk_space/molecule/default/Dockerfile.j2 diff --git a/roles/undercloud_disk_space/molecule/default/molecule.yml b/validations_common/roles/undercloud_disk_space/molecule/default/molecule.yml similarity index 100% rename from roles/undercloud_disk_space/molecule/default/molecule.yml rename to validations_common/roles/undercloud_disk_space/molecule/default/molecule.yml diff --git a/roles/undercloud_disk_space/molecule/default/playbook.yml b/validations_common/roles/undercloud_disk_space/molecule/default/playbook.yml similarity index 100% rename from roles/undercloud_disk_space/molecule/default/playbook.yml rename to validations_common/roles/undercloud_disk_space/molecule/default/playbook.yml diff --git a/roles/undercloud_disk_space/tasks/main.yml b/validations_common/roles/undercloud_disk_space/tasks/main.yml similarity index 100% rename from roles/undercloud_disk_space/tasks/main.yml rename to validations_common/roles/undercloud_disk_space/tasks/main.yml diff --git a/roles/undercloud_disk_space/vars/main.yaml b/validations_common/roles/undercloud_disk_space/vars/main.yaml similarity index 100% rename from roles/undercloud_disk_space/vars/main.yaml rename to validations_common/roles/undercloud_disk_space/vars/main.yaml diff --git a/roles/undercloud_ram/README.md b/validations_common/roles/undercloud_ram/README.md similarity index 100% rename from roles/undercloud_ram/README.md rename to validations_common/roles/undercloud_ram/README.md diff --git a/roles/undercloud_ram/defaults/main.yml b/validations_common/roles/undercloud_ram/defaults/main.yml similarity index 100% rename from roles/undercloud_ram/defaults/main.yml rename to validations_common/roles/undercloud_ram/defaults/main.yml diff --git a/roles/undercloud_ram/molecule/default/Dockerfile.j2 b/validations_common/roles/undercloud_ram/molecule/default/Dockerfile.j2 similarity index 100% rename from roles/undercloud_ram/molecule/default/Dockerfile.j2 rename to validations_common/roles/undercloud_ram/molecule/default/Dockerfile.j2 diff --git a/roles/undercloud_ram/molecule/default/molecule.yml b/validations_common/roles/undercloud_ram/molecule/default/molecule.yml similarity index 100% rename from roles/undercloud_ram/molecule/default/molecule.yml rename to validations_common/roles/undercloud_ram/molecule/default/molecule.yml diff --git a/roles/undercloud_ram/molecule/default/playbook.yml b/validations_common/roles/undercloud_ram/molecule/default/playbook.yml similarity index 100% rename from roles/undercloud_ram/molecule/default/playbook.yml rename to validations_common/roles/undercloud_ram/molecule/default/playbook.yml diff --git a/roles/undercloud_ram/tasks/main.yml b/validations_common/roles/undercloud_ram/tasks/main.yml similarity index 100% rename from roles/undercloud_ram/tasks/main.yml rename to validations_common/roles/undercloud_ram/tasks/main.yml diff --git a/roles/undercloud_ram/vars/main.yaml b/validations_common/roles/undercloud_ram/vars/main.yaml similarity index 100% rename from roles/undercloud_ram/vars/main.yaml rename to validations_common/roles/undercloud_ram/vars/main.yaml diff --git a/roles/undercloud_selinux_mode/README.md b/validations_common/roles/undercloud_selinux_mode/README.md similarity index 100% rename from roles/undercloud_selinux_mode/README.md rename to validations_common/roles/undercloud_selinux_mode/README.md diff --git a/roles/undercloud_selinux_mode/molecule/default/Dockerfile.j2 b/validations_common/roles/undercloud_selinux_mode/molecule/default/Dockerfile.j2 similarity index 100% rename from roles/undercloud_selinux_mode/molecule/default/Dockerfile.j2 rename to validations_common/roles/undercloud_selinux_mode/molecule/default/Dockerfile.j2 diff --git a/roles/undercloud_selinux_mode/molecule/default/molecule.yml b/validations_common/roles/undercloud_selinux_mode/molecule/default/molecule.yml similarity index 100% rename from roles/undercloud_selinux_mode/molecule/default/molecule.yml rename to validations_common/roles/undercloud_selinux_mode/molecule/default/molecule.yml diff --git a/roles/undercloud_selinux_mode/molecule/default/playbook.yml b/validations_common/roles/undercloud_selinux_mode/molecule/default/playbook.yml similarity index 100% rename from roles/undercloud_selinux_mode/molecule/default/playbook.yml rename to validations_common/roles/undercloud_selinux_mode/molecule/default/playbook.yml diff --git a/roles/undercloud_selinux_mode/tasks/main.yml b/validations_common/roles/undercloud_selinux_mode/tasks/main.yml similarity index 100% rename from roles/undercloud_selinux_mode/tasks/main.yml rename to validations_common/roles/undercloud_selinux_mode/tasks/main.yml diff --git a/roles/undercloud_selinux_mode/vars/main.yml b/validations_common/roles/undercloud_selinux_mode/vars/main.yml similarity index 100% rename from roles/undercloud_selinux_mode/vars/main.yml rename to validations_common/roles/undercloud_selinux_mode/vars/main.yml diff --git a/roles/undercloud_service_status/README.md b/validations_common/roles/undercloud_service_status/README.md similarity index 100% rename from roles/undercloud_service_status/README.md rename to validations_common/roles/undercloud_service_status/README.md diff --git a/roles/undercloud_service_status/defaults/main.yml b/validations_common/roles/undercloud_service_status/defaults/main.yml similarity index 100% rename from roles/undercloud_service_status/defaults/main.yml rename to validations_common/roles/undercloud_service_status/defaults/main.yml diff --git a/roles/undercloud_service_status/tasks/main.yml b/validations_common/roles/undercloud_service_status/tasks/main.yml similarity index 100% rename from roles/undercloud_service_status/tasks/main.yml rename to validations_common/roles/undercloud_service_status/tasks/main.yml diff --git a/roles/undercloud_service_status/vars/main.yaml b/validations_common/roles/undercloud_service_status/vars/main.yaml similarity index 100% rename from roles/undercloud_service_status/vars/main.yaml rename to validations_common/roles/undercloud_service_status/vars/main.yaml diff --git a/roles/validate_selinux/defaults/main.yml b/validations_common/roles/validate_selinux/defaults/main.yml similarity index 100% rename from roles/validate_selinux/defaults/main.yml rename to validations_common/roles/validate_selinux/defaults/main.yml diff --git a/roles/validate_selinux/handlers/main.yml b/validations_common/roles/validate_selinux/handlers/main.yml similarity index 100% rename from roles/validate_selinux/handlers/main.yml rename to validations_common/roles/validate_selinux/handlers/main.yml diff --git a/roles/validate_selinux/molecule/default/Dockerfile b/validations_common/roles/validate_selinux/molecule/default/Dockerfile similarity index 100% rename from roles/validate_selinux/molecule/default/Dockerfile rename to validations_common/roles/validate_selinux/molecule/default/Dockerfile diff --git a/roles/validate_selinux/molecule/default/molecule.yml b/validations_common/roles/validate_selinux/molecule/default/molecule.yml similarity index 100% rename from roles/validate_selinux/molecule/default/molecule.yml rename to validations_common/roles/validate_selinux/molecule/default/molecule.yml diff --git a/roles/validate_selinux/molecule/default/playbook.yml b/validations_common/roles/validate_selinux/molecule/default/playbook.yml similarity index 100% rename from roles/validate_selinux/molecule/default/playbook.yml rename to validations_common/roles/validate_selinux/molecule/default/playbook.yml diff --git a/roles/validate_selinux/molecule/default/prepare.yml b/validations_common/roles/validate_selinux/molecule/default/prepare.yml similarity index 100% rename from roles/validate_selinux/molecule/default/prepare.yml rename to validations_common/roles/validate_selinux/molecule/default/prepare.yml diff --git a/roles/validate_selinux/molecule/default/verify.yml b/validations_common/roles/validate_selinux/molecule/default/verify.yml similarity index 100% rename from roles/validate_selinux/molecule/default/verify.yml rename to validations_common/roles/validate_selinux/molecule/default/verify.yml diff --git a/roles/validate_selinux/tasks/main.yml b/validations_common/roles/validate_selinux/tasks/main.yml similarity index 100% rename from roles/validate_selinux/tasks/main.yml rename to validations_common/roles/validate_selinux/tasks/main.yml diff --git a/roles/validate_selinux/templates/skip-list.j2 b/validations_common/roles/validate_selinux/templates/skip-list.j2 similarity index 100% rename from roles/validate_selinux/templates/skip-list.j2 rename to validations_common/roles/validate_selinux/templates/skip-list.j2 diff --git a/roles/validate_selinux/vars/main.yml b/validations_common/roles/validate_selinux/vars/main.yml similarity index 100% rename from roles/validate_selinux/vars/main.yml rename to validations_common/roles/validate_selinux/vars/main.yml diff --git a/roles/xfs_check_ftype/molecule/default/Dockerfile.j2 b/validations_common/roles/xfs_check_ftype/molecule/default/Dockerfile.j2 similarity index 100% rename from roles/xfs_check_ftype/molecule/default/Dockerfile.j2 rename to validations_common/roles/xfs_check_ftype/molecule/default/Dockerfile.j2 diff --git a/roles/xfs_check_ftype/molecule/default/molecule.yml b/validations_common/roles/xfs_check_ftype/molecule/default/molecule.yml similarity index 100% rename from roles/xfs_check_ftype/molecule/default/molecule.yml rename to validations_common/roles/xfs_check_ftype/molecule/default/molecule.yml diff --git a/roles/xfs_check_ftype/molecule/default/playbook.yml b/validations_common/roles/xfs_check_ftype/molecule/default/playbook.yml similarity index 100% rename from roles/xfs_check_ftype/molecule/default/playbook.yml rename to validations_common/roles/xfs_check_ftype/molecule/default/playbook.yml diff --git a/roles/xfs_check_ftype/molecule/default/prepare.yml b/validations_common/roles/xfs_check_ftype/molecule/default/prepare.yml similarity index 100% rename from roles/xfs_check_ftype/molecule/default/prepare.yml rename to validations_common/roles/xfs_check_ftype/molecule/default/prepare.yml diff --git a/roles/xfs_check_ftype/molecule/default/verify.yml b/validations_common/roles/xfs_check_ftype/molecule/default/verify.yml similarity index 100% rename from roles/xfs_check_ftype/molecule/default/verify.yml rename to validations_common/roles/xfs_check_ftype/molecule/default/verify.yml diff --git a/roles/xfs_check_ftype/tasks/main.yml b/validations_common/roles/xfs_check_ftype/tasks/main.yml similarity index 100% rename from roles/xfs_check_ftype/tasks/main.yml rename to validations_common/roles/xfs_check_ftype/tasks/main.yml diff --git a/roles/xfs_check_ftype/vars/main.yml b/validations_common/roles/xfs_check_ftype/vars/main.yml similarity index 100% rename from roles/xfs_check_ftype/vars/main.yml rename to validations_common/roles/xfs_check_ftype/vars/main.yml diff --git a/validations_common/tests/library/test_check_package_update.py b/validations_common/tests/library/test_check_package_update.py new file mode 100644 index 0000000..9990db2 --- /dev/null +++ b/validations_common/tests/library/test_check_package_update.py @@ -0,0 +1,95 @@ +# -*- coding: utf-8 -*- + +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from mock import MagicMock +from mock import patch + +from validations_common.library.check_package_update import check_update +from validations_common.library.check_package_update import get_package_details +from validations_common.tests import base + + +PKG_INSTALLED = "foo-package|6.1.5|1|x86_64" + +PKG_AVAILABLE = """\ +Available Packages +foo-package.x86_64 8.0.0-1 foo-stable +""" + + +class TestGetPackageDetails(base.TestCase): + def setUp(self): + super(TestGetPackageDetails, self).setUp() + self.entry = get_package_details("foo-package|6.2.0|1|x86_64") + + def test_name(self): + self.assertEqual(self.entry.name, 'foo-package') + + def test_arch(self): + self.assertEqual(self.entry.arch, 'x86_64') + + def test_version(self): + self.assertEqual(self.entry.version, '6.2.0') + + def test_release(self): + self.assertEqual(self.entry.release, '1') + + +class TestCheckUpdate(base.TestCase): + def setUp(self): + super(TestCheckUpdate, self).setUp() + self.module = MagicMock() + + def test_unsupported_pkg_mgr_fails(self): + check_update(self.module, 'foo-package', 'apt') + self.module.fail_json.assert_called_with( + msg='Package manager "apt" is not supported.') + + @patch('validations_common.library.check_package_update._command') + def test_fails_if_installed_package_not_found(self, mock_command): + mock_command.side_effect = [ + ['', 'No package found.'], + ] + check_update(self.module, 'foo-package', 'yum') + self.module.fail_json.assert_called_with( + msg='No package found.') + + @patch('validations_common.library.check_package_update._command') + def test_returns_current_and_available_versions(self, mock_command): + mock_command.side_effect = [ + [PKG_INSTALLED, ''], + [PKG_AVAILABLE, ''], + ] + + check_update(self.module, 'foo-package', 'yum') + self.module.exit_json.assert_called_with(changed=False, + name='foo-package', + current_version='6.1.5', + current_release='1', + new_version='8.0.0', + new_release='1') + + @patch('validations_common.library.check_package_update._command') + def test_returns_current_version_if_no_updates(self, mock_command): + mock_command.side_effect = [ + [PKG_INSTALLED, ''], + ['', 'No packages found'], + ] + check_update(self.module, 'foo-package', 'yum') + self.module.exit_json.assert_called_with(changed=False, + name='foo-package', + current_version='6.1.5', + current_release='1', + new_version=None, + new_release=None) diff --git a/validations_common/tests/library/test_validations_read_ini.py b/validations_common/tests/library/test_validations_read_ini.py index b699567..09875c9 100644 --- a/validations_common/tests/library/test_validations_read_ini.py +++ b/validations_common/tests/library/test_validations_read_ini.py @@ -23,7 +23,7 @@ Tests for `validations_read_ini` module. import os import tempfile -import library.validations_read_ini as validation +import validations_common.library.validations_read_ini as validation from validations_common.tests import base