Skip to content

Commit

Permalink
testing singl lv and only vg
Browse files Browse the repository at this point in the history
  • Loading branch information
Tcharl committed May 11, 2020
1 parent 0621cad commit c40f9b7
Show file tree
Hide file tree
Showing 13 changed files with 185 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/
2 changes: 1 addition & 1 deletion molecule/default/converge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions molecule/default/tests/test_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion molecule/kvm/converge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions molecule/kvmonlyvg/converge.yml
Original file line number Diff line number Diff line change
@@ -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"
29 changes: 29 additions & 0 deletions molecule/kvmonlyvg/molecule.yml
Original file line number Diff line number Diff line change
@@ -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
21 changes: 21 additions & 0 deletions molecule/kvmonlyvg/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -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
)
11 changes: 11 additions & 0 deletions molecule/kvmonlyvg/tests/test_default.py
Original file line number Diff line number Diff line change
@@ -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
22 changes: 22 additions & 0 deletions molecule/kvmsinglelv/converge.yml
Original file line number Diff line number Diff line change
@@ -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"
29 changes: 29 additions & 0 deletions molecule/kvmsinglelv/molecule.yml
Original file line number Diff line number Diff line change
@@ -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
21 changes: 21 additions & 0 deletions molecule/kvmsinglelv/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -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
)
26 changes: 26 additions & 0 deletions molecule/kvmsinglelv/tests/test_default.py
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion tasks/create_fs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'"
Expand Down

0 comments on commit c40f9b7

Please sign in to comment.