]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-ansible.git/commitdiff
tests: add module_utils directory to flake8/pytest
authorDimitri Savineau <dsavinea@redhat.com>
Thu, 26 Nov 2020 19:59:29 +0000 (14:59 -0500)
committerGuillaume Abrioux <gabrioux@redhat.com>
Fri, 27 Nov 2020 05:35:56 +0000 (06:35 +0100)
This adds the module_utils and associated test directory into the flake8
and pytest workflow configuration.
It also moves the ca_common module_utils test file from tests/library to
it's own directory tests/module_utils.

Signed-off-by: Dimitri Savineau <dsavinea@redhat.com>
.github/workflows/flake8.yml
.github/workflows/pytest.yml
tests/library/test_ca_common.py [deleted file]
tests/module_utils/test_ca_common.py [new file with mode: 0644]

index 6814b2dd132c8019168a1ef4abdf4100c7f78a21..4d6c704c79255a8cccedda951cdb33e786d912d1 100644 (file)
@@ -3,8 +3,10 @@ on:
   pull_request:
     paths:
       - 'library/**.py'
+      - 'module_utils/**.py'
       - 'tests/conftest.py'
       - 'tests/library/**.py'
+      - 'tests/module_utils/**.py'
       - 'tests/functional/tests/**.py'
 jobs:
   build:
@@ -17,4 +19,4 @@ jobs:
           python-version: 3.8
           architecture: x64
       - run: pip install flake8
-      - run: flake8 --max-line-length 160 ./library/ ./tests/library/ ./tests/conftest.py ./tests/functional/tests/
+      - run: flake8 --max-line-length 160 ./library/ ./module_utils/ ./tests/library/ ./tests/module_utils/ ./tests/conftest.py ./tests/functional/tests/
index 2bf351383531f073a15bd8abc9ee2f7717061df8..63c194c6f33cc78a7637ad8c0d7a2d510fd067c5 100644 (file)
@@ -3,8 +3,10 @@ on:
   pull_request:
     paths:
       - 'library/**.py'
+      - 'module_utils/**.py'
       - 'plugins/filter/**.py'
       - 'tests/library/**.py'
+      - 'tests/module_utils/**.py'
       - 'tests/plugins/filter/**.py'
 jobs:
   build:
@@ -21,6 +23,6 @@ jobs:
           python-version: ${{ matrix.python-version }}
           architecture: x64
       - run: pip install -r tests/requirements.txt
-      - run: pytest --cov=library/ --cov=plugins/filter/ -vvvv tests/library/ tests/plugins/filter/
+      - 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"
diff --git a/tests/library/test_ca_common.py b/tests/library/test_ca_common.py
deleted file mode 100644 (file)
index 23c8508..0000000
+++ /dev/null
@@ -1,130 +0,0 @@
-from mock.mock import patch
-import os
-import ca_common
-import pytest
-
-fake_container_binary = 'podman'
-fake_container_image = 'docker.io/ceph/daemon:latest'
-
-
-class TestCommon(object):
-
-    def setup_method(self):
-        self.fake_binary = 'ceph'
-        self.fake_cluster = 'ceph'
-        self.fake_container_cmd = [
-            fake_container_binary,
-            'run',
-            '--rm',
-            '--net=host',
-            '-v', '/etc/ceph:/etc/ceph:z',
-            '-v', '/var/lib/ceph/:/var/lib/ceph/:z',
-            '-v', '/var/log/ceph/:/var/log/ceph/:z',
-            '--entrypoint=' + self.fake_binary,
-            fake_container_image
-        ]
-
-    @patch.dict(os.environ, {'CEPH_CONTAINER_BINARY': fake_container_binary})
-    def test_container_exec(self):
-        cmd = ca_common.container_exec(self.fake_binary, fake_container_image)
-        assert cmd == self.fake_container_cmd
-
-    def test_not_is_containerized(self):
-        assert ca_common.is_containerized() is None
-
-    @patch.dict(os.environ, {'CEPH_CONTAINER_IMAGE': fake_container_image})
-    def test_is_containerized(self):
-        assert ca_common.is_containerized() == fake_container_image
-
-    @pytest.mark.parametrize('image', [None, fake_container_image])
-    @patch.dict(os.environ, {'CEPH_CONTAINER_BINARY': fake_container_binary})
-    def test_pre_generate_ceph_cmd(self, image):
-        if image:
-            expected_cmd = self.fake_container_cmd
-        else:
-            expected_cmd = [self.fake_binary]
-
-        assert ca_common.pre_generate_ceph_cmd(image) == expected_cmd
-
-    @pytest.mark.parametrize('image', [None, fake_container_image])
-    @patch.dict(os.environ, {'CEPH_CONTAINER_BINARY': fake_container_binary})
-    def test_generate_ceph_cmd(self, image):
-        sub_cmd = ['osd', 'pool']
-        args = ['create', 'foo']
-        if image:
-            expected_cmd = self.fake_container_cmd
-        else:
-            expected_cmd = [self.fake_binary]
-
-        expected_cmd.extend([
-            '-n', 'client.admin',
-            '-k', '/etc/ceph/ceph.client.admin.keyring',
-            '--cluster',
-            self.fake_cluster,
-            'osd', 'pool',
-            'create', 'foo'
-        ])
-        assert ca_common.generate_ceph_cmd(sub_cmd, args, cluster=self.fake_cluster, container_image=image) == expected_cmd
-
-    @pytest.mark.parametrize('image', [None, fake_container_image])
-    @patch.dict(os.environ, {'CEPH_CONTAINER_BINARY': fake_container_binary})
-    def test_generate_ceph_cmd_different_cluster_name(self, image):
-        sub_cmd = ['osd', 'pool']
-        args = ['create', 'foo']
-        if image:
-            expected_cmd = self.fake_container_cmd
-        else:
-            expected_cmd = [self.fake_binary]
-
-        expected_cmd.extend([
-            '-n', 'client.admin',
-            '-k', '/etc/ceph/foo.client.admin.keyring',
-            '--cluster',
-            'foo',
-            'osd', 'pool',
-            'create', 'foo'
-        ])
-        result = ca_common.generate_ceph_cmd(sub_cmd, args, cluster='foo', container_image=image)
-        assert result == expected_cmd
-
-    @pytest.mark.parametrize('image', [None, fake_container_image])
-    @patch.dict(os.environ, {'CEPH_CONTAINER_BINARY': fake_container_binary})
-    def test_generate_ceph_cmd_different_cluster_name_and_user(self, image):
-        sub_cmd = ['osd', 'pool']
-        args = ['create', 'foo']
-        if image:
-            expected_cmd = self.fake_container_cmd
-        else:
-            expected_cmd = [self.fake_binary]
-
-        expected_cmd.extend([
-            '-n', 'client.foo',
-            '-k', '/etc/ceph/foo.client.foo.keyring',
-            '--cluster',
-            'foo',
-            'osd', 'pool',
-            'create', 'foo'
-        ])
-        result = ca_common.generate_ceph_cmd(sub_cmd, args, cluster='foo', user='client.foo', container_image=image)
-        assert result == expected_cmd
-
-    @pytest.mark.parametrize('image', [None, fake_container_image])
-    @patch.dict(os.environ, {'CEPH_CONTAINER_BINARY': fake_container_binary})
-    def test_generate_ceph_cmd_different_user(self, image):
-        sub_cmd = ['osd', 'pool']
-        args = ['create', 'foo']
-        if image:
-            expected_cmd = self.fake_container_cmd
-        else:
-            expected_cmd = [self.fake_binary]
-
-        expected_cmd.extend([
-            '-n', 'client.foo',
-            '-k', '/etc/ceph/ceph.client.foo.keyring',
-            '--cluster',
-            'ceph',
-            'osd', 'pool',
-            'create', 'foo'
-        ])
-        result = ca_common.generate_ceph_cmd(sub_cmd, args, user='client.foo', container_image=image)
-        assert result == expected_cmd
diff --git a/tests/module_utils/test_ca_common.py b/tests/module_utils/test_ca_common.py
new file mode 100644 (file)
index 0000000..23c8508
--- /dev/null
@@ -0,0 +1,130 @@
+from mock.mock import patch
+import os
+import ca_common
+import pytest
+
+fake_container_binary = 'podman'
+fake_container_image = 'docker.io/ceph/daemon:latest'
+
+
+class TestCommon(object):
+
+    def setup_method(self):
+        self.fake_binary = 'ceph'
+        self.fake_cluster = 'ceph'
+        self.fake_container_cmd = [
+            fake_container_binary,
+            'run',
+            '--rm',
+            '--net=host',
+            '-v', '/etc/ceph:/etc/ceph:z',
+            '-v', '/var/lib/ceph/:/var/lib/ceph/:z',
+            '-v', '/var/log/ceph/:/var/log/ceph/:z',
+            '--entrypoint=' + self.fake_binary,
+            fake_container_image
+        ]
+
+    @patch.dict(os.environ, {'CEPH_CONTAINER_BINARY': fake_container_binary})
+    def test_container_exec(self):
+        cmd = ca_common.container_exec(self.fake_binary, fake_container_image)
+        assert cmd == self.fake_container_cmd
+
+    def test_not_is_containerized(self):
+        assert ca_common.is_containerized() is None
+
+    @patch.dict(os.environ, {'CEPH_CONTAINER_IMAGE': fake_container_image})
+    def test_is_containerized(self):
+        assert ca_common.is_containerized() == fake_container_image
+
+    @pytest.mark.parametrize('image', [None, fake_container_image])
+    @patch.dict(os.environ, {'CEPH_CONTAINER_BINARY': fake_container_binary})
+    def test_pre_generate_ceph_cmd(self, image):
+        if image:
+            expected_cmd = self.fake_container_cmd
+        else:
+            expected_cmd = [self.fake_binary]
+
+        assert ca_common.pre_generate_ceph_cmd(image) == expected_cmd
+
+    @pytest.mark.parametrize('image', [None, fake_container_image])
+    @patch.dict(os.environ, {'CEPH_CONTAINER_BINARY': fake_container_binary})
+    def test_generate_ceph_cmd(self, image):
+        sub_cmd = ['osd', 'pool']
+        args = ['create', 'foo']
+        if image:
+            expected_cmd = self.fake_container_cmd
+        else:
+            expected_cmd = [self.fake_binary]
+
+        expected_cmd.extend([
+            '-n', 'client.admin',
+            '-k', '/etc/ceph/ceph.client.admin.keyring',
+            '--cluster',
+            self.fake_cluster,
+            'osd', 'pool',
+            'create', 'foo'
+        ])
+        assert ca_common.generate_ceph_cmd(sub_cmd, args, cluster=self.fake_cluster, container_image=image) == expected_cmd
+
+    @pytest.mark.parametrize('image', [None, fake_container_image])
+    @patch.dict(os.environ, {'CEPH_CONTAINER_BINARY': fake_container_binary})
+    def test_generate_ceph_cmd_different_cluster_name(self, image):
+        sub_cmd = ['osd', 'pool']
+        args = ['create', 'foo']
+        if image:
+            expected_cmd = self.fake_container_cmd
+        else:
+            expected_cmd = [self.fake_binary]
+
+        expected_cmd.extend([
+            '-n', 'client.admin',
+            '-k', '/etc/ceph/foo.client.admin.keyring',
+            '--cluster',
+            'foo',
+            'osd', 'pool',
+            'create', 'foo'
+        ])
+        result = ca_common.generate_ceph_cmd(sub_cmd, args, cluster='foo', container_image=image)
+        assert result == expected_cmd
+
+    @pytest.mark.parametrize('image', [None, fake_container_image])
+    @patch.dict(os.environ, {'CEPH_CONTAINER_BINARY': fake_container_binary})
+    def test_generate_ceph_cmd_different_cluster_name_and_user(self, image):
+        sub_cmd = ['osd', 'pool']
+        args = ['create', 'foo']
+        if image:
+            expected_cmd = self.fake_container_cmd
+        else:
+            expected_cmd = [self.fake_binary]
+
+        expected_cmd.extend([
+            '-n', 'client.foo',
+            '-k', '/etc/ceph/foo.client.foo.keyring',
+            '--cluster',
+            'foo',
+            'osd', 'pool',
+            'create', 'foo'
+        ])
+        result = ca_common.generate_ceph_cmd(sub_cmd, args, cluster='foo', user='client.foo', container_image=image)
+        assert result == expected_cmd
+
+    @pytest.mark.parametrize('image', [None, fake_container_image])
+    @patch.dict(os.environ, {'CEPH_CONTAINER_BINARY': fake_container_binary})
+    def test_generate_ceph_cmd_different_user(self, image):
+        sub_cmd = ['osd', 'pool']
+        args = ['create', 'foo']
+        if image:
+            expected_cmd = self.fake_container_cmd
+        else:
+            expected_cmd = [self.fake_binary]
+
+        expected_cmd.extend([
+            '-n', 'client.foo',
+            '-k', '/etc/ceph/ceph.client.foo.keyring',
+            '--cluster',
+            'ceph',
+            'osd', 'pool',
+            'create', 'foo'
+        ])
+        result = ca_common.generate_ceph_cmd(sub_cmd, args, user='client.foo', container_image=image)
+        assert result == expected_cmd