]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-ansible.git/commitdiff
improve plugins/filter testing
authorDimitri Savineau <dsavinea@redhat.com>
Fri, 27 Nov 2020 17:25:11 +0000 (12:25 -0500)
committerGuillaume Abrioux <gabrioux@redhat.com>
Mon, 30 Nov 2020 09:05:01 +0000 (10:05 +0100)
- The plugins/filter directory wasn't present in the flake8 workflow
configuration.
- Fix the flake8 syntax.
- Add the directory to PYTHONPATH environment variable for pytest
to avoid importing the plugin filter via sys.
- Add unittest on missing netaddr module import.

Signed-off-by: Dimitri Savineau <dsavinea@redhat.com>
.github/workflows/flake8.yml
.github/workflows/pytest.yml
plugins/filter/ipaddrs_in_ranges.py
tests/plugins/filter/test_ipaddrs_in_ranges.py

index 4d6c704c79255a8cccedda951cdb33e786d912d1..7ea7cf9e0bbfe2c685be90ecc0ee192f93be3a9e 100644 (file)
@@ -4,9 +4,11 @@ on:
     paths:
       - 'library/**.py'
       - 'module_utils/**.py'
+      - 'plugins/filter/**.py'
       - 'tests/conftest.py'
       - 'tests/library/**.py'
       - 'tests/module_utils/**.py'
+      - 'tests/plugins/filter/**.py'
       - 'tests/functional/tests/**.py'
 jobs:
   build:
@@ -19,4 +21,4 @@ jobs:
           python-version: 3.8
           architecture: x64
       - run: pip install flake8
-      - run: flake8 --max-line-length 160 ./library/ ./module_utils/ ./tests/library/ ./tests/module_utils/ ./tests/conftest.py ./tests/functional/tests/
+      - run: flake8 --max-line-length 160 ./library/ ./module_utils/ ./plugins/filter/ ./tests/library/ ./tests/module_utils/ ./tests/plugins/filter/ ./tests/conftest.py ./tests/functional/tests/
index 63c194c6f33cc78a7637ad8c0d7a2d510fd067c5..91e9f4ccb672bde595aac06171275f0e4c72d597 100644 (file)
@@ -25,4 +25,4 @@ jobs:
       - run: pip install -r tests/requirements.txt
       - run: pytest --cov=library/ --cov=module_utils/ --cov=plugins/filter/ -vvvv tests/library/ tests/module_utils/ tests/plugins/filter/
         env:
-          PYTHONPATH: "$PYTHONPATH:/home/runner/work/ceph-ansible/ceph-ansible/library:/home/runner/work/ceph-ansible/ceph-ansible/module_utils:/home/runner/work/ceph-ansible/ceph-ansible"
+          PYTHONPATH: "$PYTHONPATH:/home/runner/work/ceph-ansible/ceph-ansible/library:/home/runner/work/ceph-ansible/ceph-ansible/module_utils:/home/runner/work/ceph-ansible/ceph-ansible/plugins/filter:/home/runner/work/ceph-ansible/ceph-ansible"
index 92971fad7ae3c897aa7ad35dfb37a77707ac00f9..fdd4d7fd3c157410e3682de5031c7904f8d31a96 100644 (file)
@@ -1,3 +1,6 @@
+from __future__ import (absolute_import, division, print_function)
+__metaclass__ = type
+
 from ansible import errors
 
 try:
index 6357d93b7f9bbef855769dae2673a1d2b091452e..4b111e057ae8f4fd5c285bb61ff6eec2eb2607d9 100644 (file)
@@ -1,9 +1,16 @@
-import sys
-sys.path.append('./plugins/filter')
+from __future__ import (absolute_import, division, print_function)
+__metaclass__ = type
+
+from ansible.errors import AnsibleFilterError
+
 import ipaddrs_in_ranges
+import pytest
+
+pytest.importorskip('netaddr')
 
 filter_plugin = ipaddrs_in_ranges.FilterModule()
 
+
 class TestIpaddrsInRanges(object):
 
     def test_one_ip_one_range(self):
@@ -41,5 +48,16 @@ class TestIpaddrsInRanges(object):
         ips = ['10.10.20.1', '192.168.2.1', '172.16.10.1']
         ranges = ['192.168.1.0/24', '10.10.10.1/24', '172.16.17.0/24']
         result = filter_plugin.ips_in_ranges(ips, ranges)
-        assert result == []
+        assert len(result) == 0
+
+    def test_ips_in_ranges_in_filters_dict(self):
+        assert 'ips_in_ranges' in filter_plugin.filters()
+
+    def test_missing_netaddr_module(self):
+        ipaddrs_in_ranges.netaddr = None
+
+        with pytest.raises(AnsibleFilterError) as result:
+            filter_plugin.filters()
 
+        assert result.type == AnsibleFilterError
+        assert str(result.value) == "The ips_in_ranges filter requires python's netaddr be installed on the ansible controller."