mirror of
https://github.com/mrlesmithjr/ansible-manage-lvm.git
synced 2026-02-04 08:49:13 +03:00
molecule test and idempotence
This commit is contained in:
28
molecule/default/converge.yml
Normal file
28
molecule/default/converge.yml
Normal file
@@ -0,0 +1,28 @@
|
||||
---
|
||||
- name: Converge
|
||||
hosts: all
|
||||
vars:
|
||||
lvm_groups:
|
||||
- vgname: my_vg
|
||||
disks:
|
||||
- /dev/sdb1
|
||||
create: true
|
||||
lvnames:
|
||||
- lvname: my_lv
|
||||
size: 40%VG
|
||||
opts: "--wipesignatures y"
|
||||
create: true
|
||||
filesystem: ext4
|
||||
mntp: "/var/lib/mountpoint"
|
||||
- lvname: my_lv2
|
||||
size: 10%VG
|
||||
opts: "--wipesignatures y"
|
||||
create: true
|
||||
filesystem: ext4
|
||||
mntp: "/var/lib/mountpoint2"
|
||||
manage_lvm: true
|
||||
|
||||
tasks:
|
||||
- name: "Include lvm"
|
||||
include_role:
|
||||
name: "ansible-manage-lvm"
|
||||
27
molecule/default/molecule.yml
Normal file
27
molecule/default/molecule.yml
Normal file
@@ -0,0 +1,27 @@
|
||||
---
|
||||
driver:
|
||||
name: vagrant
|
||||
provider:
|
||||
name: virtualbox
|
||||
lint: yamllint . && flake8 && ansible-lint --exclude=meta
|
||||
platforms:
|
||||
- name: Fedora-Molecule-LVM
|
||||
box: bento/fedora-31
|
||||
# box-url: ${platform_root}/packer/bento/builds/fedora-31-x86_64.virtualbox.box
|
||||
provider_override_args:
|
||||
- "persistent_storage.enabled = true"
|
||||
- "persistent_storage.location = 'molecule-lvm.vdi'"
|
||||
- "persistent_storage.size = 100"
|
||||
- "persistent_storage.mount = false"
|
||||
- "persistent_storage.diskdevice = '/dev/sdb'"
|
||||
provisioner:
|
||||
name: ansible
|
||||
inventory:
|
||||
group_vars:
|
||||
lvm:
|
||||
verifier:
|
||||
name: testinfra
|
||||
env:
|
||||
PYTHONWARNINGS: "ignore:.*U.*mode is deprecated:DeprecationWarning"
|
||||
options:
|
||||
v: 1
|
||||
Binary file not shown.
Binary file not shown.
21
molecule/default/tests/conftest.py
Normal file
21
molecule/default/tests/conftest.py
Normal file
@@ -0,0 +1,21 @@
|
||||
"""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
|
||||
)
|
||||
22
molecule/default/tests/test_default.py
Normal file
22
molecule/default/tests/test_default.py
Normal file
@@ -0,0 +1,22 @@
|
||||
"""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_volume_is_mounted(host):
|
||||
host.file("/var/lib/mountpoint").mode == 0o731
|
||||
Reference in New Issue
Block a user