testing singl lv and only vg

This commit is contained in:
Charlie Mordant
2020-05-11 16:35:00 +02:00
parent 0621cadde8
commit c40f9b7d03
13 changed files with 185 additions and 3 deletions

View File

@@ -26,5 +26,7 @@ before_install:
script:
- |
sudo molecule test --scenario-name kvm
sudo molecule test --scenario-name kvmsinglelv
sudo molecule test --scenario-name kvmonlyvg
notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/

View File

@@ -15,7 +15,7 @@
filesystem: ext4
mount: true
mntp: "/var/lib/mountpoint"
- lvname: my_lv2
- lvname: my_lw
size: 20%VG
opts: "--wipesignatures y"
mount: true

View File

@@ -18,6 +18,13 @@ def test_mylv_logical_volume_is_created(host):
assert int(cmd.stdout.rstrip()) >= 1
def test_mylv_logical_volume_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

View File

@@ -15,7 +15,7 @@
filesystem: ext4
mount: true
mntp: "/var/lib/mountpoint"
- lvname: my_lv2
- lvname: my_lw
size: 20%VG
opts: "--wipesignatures y"
mount: true

View File

@@ -0,0 +1,14 @@
---
- name: Converge
hosts: all
vars:
lvm_groups:
- vgname: my_vg
disks:
- /dev/vdb
create: true
manage_lvm: true
tasks:
- name: "Include lvm"
include_role:
name: "ansible-manage-lvm"

View File

@@ -0,0 +1,29 @@
---
driver:
name: vagrant
provider:
name: libvirt
lint: yamllint . && flake8 && ansible-lint
platforms:
- name: Fedora-Molecule-Volumes-KVM
box: fedora/31-cloud-base
cpu: 2
memory: 2048
provider_raw_config_args:
- "storage :file, :size => '1G', :device => 'vdb'"
provisioner:
name: ansible
config_options:
defaults:
forks: 20
ssh_connection:
pipelining: true
ssh_args: -o ControlMaster=auto -o ControlPersist=600s
verifier:
name: testinfra
env:
PYTHONWARNINGS: "ignore:.*U.*mode is deprecated:DeprecationWarning"
options:
v: 1
scenario:
name: kvm

View 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
)

View File

@@ -0,0 +1,11 @@
"""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

View File

@@ -0,0 +1,22 @@
---
- name: Converge
hosts: all
vars:
lvm_groups:
- vgname: my_vg
disks:
- /dev/vdb
create: true
lvnames:
- lvname: my_lv
size: 40%VG
opts: "--wipesignatures y"
create: true
filesystem: ext4
mount: true
mntp: "/var/lib/mountpoint"
manage_lvm: true
tasks:
- name: "Include lvm"
include_role:
name: "ansible-manage-lvm"

View File

@@ -0,0 +1,29 @@
---
driver:
name: vagrant
provider:
name: libvirt
lint: yamllint . && flake8 && ansible-lint
platforms:
- name: Fedora-Molecule-Volumes-KVM
box: fedora/31-cloud-base
cpu: 2
memory: 2048
provider_raw_config_args:
- "storage :file, :size => '1G', :device => 'vdb'"
provisioner:
name: ansible
config_options:
defaults:
forks: 20
ssh_connection:
pipelining: true
ssh_args: -o ControlMaster=auto -o ControlPersist=600s
verifier:
name: testinfra
env:
PYTHONWARNINGS: "ignore:.*U.*mode is deprecated:DeprecationWarning"
options:
v: 1
scenario:
name: kvm

View 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
)

View File

@@ -0,0 +1,26 @@
"""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
def test_volume2_is_mounted(host):
host.file("/var/lib/mountpoint2").mode == 0o731

View File

@@ -41,7 +41,7 @@
)
# unable to resize xfs: looks like we've to reference the mountpoint instead of the device
- name: lvm | check already converted
- name: manage_lvm | check already converted
# at least xfs is executed twice if the partition has changed in the meantime
# then it tries to recreate the fs on the mounted fs which indeed fails...
shell: "xfs_info {{ lv.mntp }} | grep -c 'ftype=1'"