pull_request:
paths:
- 'library/**.py'
+ - 'module_utils/**.py'
- 'tests/conftest.py'
- 'tests/library/**.py'
+ - 'tests/module_utils/**.py'
- 'tests/functional/tests/**.py'
jobs:
build:
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/
pull_request:
paths:
- 'library/**.py'
+ - 'module_utils/**.py'
- 'plugins/filter/**.py'
- 'tests/library/**.py'
+ - 'tests/module_utils/**.py'
- 'tests/plugins/filter/**.py'
jobs:
build:
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"
+++ /dev/null
-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
--- /dev/null
+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