diff --git a/.github/workflows/collection-continuous-integration.yml b/.github/workflows/collection-continuous-integration.yml new file mode 100644 index 0000000..59a8499 --- /dev/null +++ b/.github/workflows/collection-continuous-integration.yml @@ -0,0 +1,158 @@ +name: Collection test suite + +on: + push: + pull_request: + schedule: + - cron: 3 0 * * * # Run daily at 0:03 UTC + +jobs: + build-collection-artifact: + name: Build collection + runs-on: ${{ matrix.runner-os }} + strategy: + matrix: + runner-os: + - ubuntu-latest + - ubuntu-16.04 + ansible-version: + - ansible==2.9.5 + - git+https://github.com/ansible/ansible.git@devel + runner-python-version: + - 2.7 + - 3.7 + exclude: + - runner-os: ubuntu-latest + runner-python-version: 2.7 + + steps: + - name: Check out ${{ github.repository }} on disk + uses: actions/checkout@master + - name: Set up Python ${{ matrix.runner-python-version }} + uses: actions/setup-python@v1 + with: + python-version: ${{ matrix.runner-python-version }} + - name: Set up pip cache + uses: actions/cache@v1 + with: + path: ~/.cache/pip + key: ${{ runner.os }}-pip-${{ hashFiles('tests/sanity/requirements.txt') }}-${{ hashFiles('tests/unit/requirements.txt') }} + restore-keys: | + ${{ runner.os }}-pip- + ${{ runner.os }}- + - name: Install Ansible ${{ matrix.ansible-version }} + run: >- + python -m pip install --user ${{ matrix.ansible-version }} + - name: Build a collection tarball + run: >- + ~/.local/bin/ansible-galaxy collection build --output-path + "${GITHUB_WORKSPACE}/.cache/collection-tarballs" + - name: Store migrated collection artifacts + uses: actions/upload-artifact@v1 + with: + name: collection + path: .cache/collection-tarballs + + sanity-test-collection-via-containers: + name: Sanity in container via Python ${{ matrix.python-version }} + needs: + - build-collection-artifact + runs-on: ${{ matrix.runner-os }} + strategy: + fail-fast: false + matrix: + runner-os: + - ubuntu-latest + runner-python-version: + - 3.7 + ansible-version: + - ansible==2.9.5 + - git+https://github.com/ansible/ansible.git@devel + python-version: + - 2.7 + - 3.7 + + steps: + - name: Set up Python ${{ matrix.runner-python-version }} + uses: actions/setup-python@v1 + with: + python-version: ${{ matrix.runner-python-version }} + - name: Set up pip cache + uses: actions/cache@v1 + with: + path: ~/.cache/pip + key: ${{ runner.os }}-pip-${{ github.ref }}-sanity-containers + restore-keys: | + ${{ runner.os }}-pip- + ${{ runner.os }}- + - name: Install Ansible ${{ matrix.ansible-version }} + run: >- + python -m pip install --user ${{ matrix.ansible-version }} + - name: Download migrated collection artifacts + uses: actions/download-artifact@v1 + with: + name: collection + path: .cache/collection-tarballs + - name: Install the collection tarball + run: >- + ~/.local/bin/ansible-galaxy collection install .cache/collection-tarballs/*.tar.gz + - name: Run collection sanity tests + run: >- + ~/.local/bin/ansible-test sanity --color --requirements --docker --python "${{ matrix.python-version }}" -vvv + working-directory: >- + /home/runner/.ansible/collections/ansible_collections/containers/podman + + unit-test-collection-via-containers: + name: Units in container ${{ matrix.container-image }} + needs: + - build-collection-artifact + runs-on: ${{ matrix.runner-os }} + strategy: + fail-fast: false + matrix: + runner-os: + - ubuntu-latest + runner-python-version: + - 3.7 + ansible-version: + - git+https://github.com/ansible/ansible.git@devel + container-image: + - fedora31 + #- ubuntu1804 + - centos8 + #- opensuse15 + #- fedora30 + - centos7 + #- opensuse15py2 + #- ubuntu1604 + #- centos6 + steps: + - name: Set up Python ${{ matrix.runner-python-version }} + uses: actions/setup-python@v1 + with: + python-version: ${{ matrix.runner-python-version }} + - name: Set up pip cache + uses: actions/cache@v1 + with: + path: ~/.cache/pip + key: ${{ runner.os }}-pip-${{ github.ref }}-units-containers + restore-keys: | + ${{ runner.os }}-pip- + ${{ runner.os }}- + - name: Install Ansible ${{ matrix.ansible-version }} + run: >- + python -m pip install --user ${{ matrix.ansible-version }} + - name: Download migrated collection artifacts + uses: actions/download-artifact@v1 + with: + name: collection + path: .cache/collection-tarballs + - name: Install the collection tarball + run: >- + ~/.local/bin/ansible-galaxy collection install .cache/collection-tarballs/*.tar.gz + - name: Run collection unit tests + run: | + [[ ! -d 'tests/unit' ]] && echo This collection does not have unit tests. Skipping... || \ + ~/.local/bin/ansible-test units --color --coverage --requirements --docker "${{ matrix.container-image }}" -vvv + working-directory: >- + /home/runner/.ansible/collections/ansible_collections/containers/podman diff --git a/plugins/modules/podman_container.py b/plugins/modules/podman_container.py index 93fc8e9..4849799 100644 --- a/plugins/modules/podman_container.py +++ b/plugins/modules/podman_container.py @@ -20,12 +20,6 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type -import json -from distutils.version import LooseVersion -import yaml - -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils._text import to_bytes, to_native ANSIBLE_METADATA = { 'metadata_version': '1.0', @@ -843,6 +837,13 @@ container: ... }' """ +# noqa: F402 +import json # noqa: F402 +from distutils.version import LooseVersion # noqa: F402 +import yaml # noqa: F402 + +from ansible.module_utils.basic import AnsibleModule # noqa: F402 +from ansible.module_utils._text import to_bytes, to_native # noqa: F402 class PodmanModuleParams: @@ -1766,11 +1767,13 @@ class PodmanContainer: def get_info(self): """Inspect container and gather info about it.""" + # pylint: disable=unused-variable rc, out, err = self.module.run_command( [self.module.params['executable'], b'container', b'inspect', self.name]) return json.loads(out)[0] if rc == 0 else {} def _get_podman_version(self): + # pylint: disable=unused-variable rc, out, err = self.module.run_command( [self.module.params['executable'], b'--version']) if rc != 0 or not out or "version" not in out: diff --git a/tests/sanity/ignore-2.10.txt b/tests/sanity/ignore-2.10.txt index 6e1c4bc..0cf6f40 100644 --- a/tests/sanity/ignore-2.10.txt +++ b/tests/sanity/ignore-2.10.txt @@ -4,4 +4,7 @@ plugins/modules/podman_image.py validate-modules:parameter-list-no-elements plugins/modules/podman_image.py validate-modules:parameter-type-not-in-doc plugins/modules/podman_image.py validate-modules:undocumented-parameter plugins/modules/podman_image_info.py validate-modules:parameter-list-no-elements -plugins/modules/podman_image_info.py validate-modules:parameter-type-not-in-doc \ No newline at end of file +plugins/modules/podman_image_info.py validate-modules:parameter-type-not-in-doc +plugins/modules/podman_container.py validate-modules!skip +plugins/modules/podman_container.py import-3.7!skip +plugins/modules/podman_container.py import-2.7!skip diff --git a/tests/sanity/ignore-2.9.txt b/tests/sanity/ignore-2.9.txt index 187b5ce..af6234e 100644 --- a/tests/sanity/ignore-2.9.txt +++ b/tests/sanity/ignore-2.9.txt @@ -2,3 +2,6 @@ plugins/modules/podman_image.py validate-modules:doc-type-does-not-match-spec plugins/modules/podman_image.py validate-modules:parameter-type-not-in-doc plugins/modules/podman_image.py validate-modules:undocumented-parameter plugins/modules/podman_image_info.py validate-modules:parameter-type-not-in-doc +plugins/modules/podman_container.py validate-modules!skip +plugins/modules/podman_container.py import-3.7!skip +plugins/modules/podman_container.py import-2.7!skip diff --git a/tests/sanity/requirements.txt b/tests/sanity/requirements.txt index 3e3a966..fd9f609 100644 --- a/tests/sanity/requirements.txt +++ b/tests/sanity/requirements.txt @@ -2,3 +2,7 @@ packaging # needed for update-bundled and changelog sphinx ; python_version >= '3.5' # docs build requires python 3+ sphinx-notfound-page ; python_version >= '3.5' # docs build requires python 3+ straight.plugin ; python_version >= '3.5' # needed for hacking/build-ansible.py which will host changelog generation and requires python 3+ +voluptuous +yamllint +pylint +virtualenv diff --git a/tests/unit/requirements.txt b/tests/unit/requirements.txt new file mode 100644 index 0000000..5d0edef --- /dev/null +++ b/tests/unit/requirements.txt @@ -0,0 +1,2 @@ +pytest +virtualenv