Skip to content

Commit

Permalink
Remove symlinks for molecule tests
Browse files Browse the repository at this point in the history
We are seeing failures with newer versions of Ansible due to the
presence of symlinks. For example:

```
error: can't copy 'ansible/roles/mrlesmithjr.manage_lvm/molecule/kvm/tests': doesn't exist or not a regular file
```
  • Loading branch information
MoteHue committed May 21, 2024
1 parent 433b7ca commit 5540f7f
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 3 deletions.
1 change: 0 additions & 1 deletion molecule/kvm/tests

This file was deleted.

20 changes: 20 additions & 0 deletions molecule/kvm/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""PyTest Fixtures."""
from __future__ import absolute_import
import os
import pytest


def pytest_runtest_setup(item):
"""Run tests only when under molecule with testinfra installed."""
try:
import testinfra
except ImportError:
pytest.skip("Test requires testinfra", allow_module_level=True)
if "MOLECULE_INVENTORY_FILE" in os.environ:
pytest.testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
os.environ["MOLECULE_INVENTORY_FILE"]
).get_hosts("all")
else:
pytest.skip(
"Test should run only from inside molecule.", allow_module_level=True
)
33 changes: 33 additions & 0 deletions molecule/kvm/tests/test_default.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""Role testing files using testinfra."""


def test_lvm_package_shall_be_installed(host):
assert host.package("lvm2").is_installed


def test_non_persistent_volume_group_is_created(host):
command = """sudo vgdisplay | grep -c 'my_vg'"""
cmd = host.run(command)
assert "1" in cmd.stdout


def test_mylv_logical_volume_is_created(host):
command = """sudo lvs -o lv_name my_vg --separator='|' --noheadings \
| grep -c 'my_lv'"""
cmd = host.run(command)
assert int(cmd.stdout.rstrip()) >= 1


def test_mylv_logical_volume2_is_created(host):
command = """sudo lvs -o lv_name my_vg --separator='|' --noheadings \
| grep -c 'my_lw'"""
cmd = host.run(command)
assert int(cmd.stdout.rstrip()) >= 1


def test_volume_is_mounted(host):
host.file("/var/lib/mountpoint").mode == 0o731


def test_volume2_is_mounted(host):
host.file("/var/lib/mountpoint2").mode == 0o731
1 change: 0 additions & 1 deletion molecule/kvmonlyvg/tests/conftest.py

This file was deleted.

20 changes: 20 additions & 0 deletions molecule/kvmonlyvg/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""PyTest Fixtures."""
from __future__ import absolute_import
import os
import pytest


def pytest_runtest_setup(item):
"""Run tests only when under molecule with testinfra installed."""
try:
import testinfra
except ImportError:
pytest.skip("Test requires testinfra", allow_module_level=True)
if "MOLECULE_INVENTORY_FILE" in os.environ:
pytest.testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
os.environ["MOLECULE_INVENTORY_FILE"]
).get_hosts("all")
else:
pytest.skip(
"Test should run only from inside molecule.", allow_module_level=True
)
1 change: 0 additions & 1 deletion molecule/kvmsinglelv/tests/conftest.py

This file was deleted.

20 changes: 20 additions & 0 deletions molecule/kvmsinglelv/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""PyTest Fixtures."""
from __future__ import absolute_import
import os
import pytest


def pytest_runtest_setup(item):
"""Run tests only when under molecule with testinfra installed."""
try:
import testinfra
except ImportError:
pytest.skip("Test requires testinfra", allow_module_level=True)
if "MOLECULE_INVENTORY_FILE" in os.environ:
pytest.testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
os.environ["MOLECULE_INVENTORY_FILE"]
).get_hosts("all")
else:
pytest.skip(
"Test should run only from inside molecule.", allow_module_level=True
)

0 comments on commit 5540f7f

Please sign in to comment.