Skip to content

Commit 0fa616e

Browse files
committed
resync
1 parent 003b0a7 commit 0fa616e

File tree

5 files changed

+178
-0
lines changed

5 files changed

+178
-0
lines changed

molecule/default/Vagrantfile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Vagrant.configure(2) do |config|
2+
config.vm.provider :libvirt do |libvirt|
3+
libvirt.memory = "512"
4+
libvirt.cpus = 1
5+
libvirt.driver = "kvm"
6+
libvirt.graphics_type = 'none'
7+
end
8+
config.ssh.insert_key = false
9+
config.vm.box = "fedora/33-cloud-base"
10+
config.vm.synced_folder ".", "/vagrant", disabled: true
11+
12+
config.vm.define "myvm" do |myvm|
13+
# myvm.vm.network :public_network,
14+
# :dev => "virbr0",
15+
# :mode => "bridge",
16+
# :type => "bridge"
17+
end
18+
end

molecule/default/converge.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
---
2+
- name: Converge
3+
hosts: all
4+
vars:
5+
manage_lvm: true
6+
lvm_groups:
7+
- vgname: libvirt_vg
8+
disks:
9+
- /dev/sdb1
10+
create: true
11+
users_group_list:
12+
- name: libvirt
13+
systemusers_user_list:
14+
- name: libvirt
15+
group: libvirt
16+
groups: wheel
17+
libvirt_host_pools:
18+
- name: libvirtpool
19+
type: lvm2
20+
source: libvirt_vg
21+
libvirt_host_networks:
22+
- name: ansible-virtualization-bridge
23+
mode: bridge
24+
bridge: bridge0
25+
tasks:
26+
- name: "Include ansible-role-libvirt-host"
27+
include_role:
28+
name: "ansible-role-libvirt-host"
29+
30+
- name: "Post converge - Install vagrant"
31+
package:
32+
name:
33+
- qemu
34+
- ruby-devel
35+
- gcc
36+
- qemu-kvm
37+
- libxml2-devel
38+
- libxslt-devel
39+
- libguestfs-tools-c
40+
- vagrant
41+
- daemonize
42+
state: present
43+
become: true
44+
45+
- name: Copy vagrant file
46+
copy:
47+
src: Vagrantfile
48+
dest: /home/vagrant/Vagrantfile
49+
owner: vagrant
50+
group: vagrant
51+
mode: '0644'
52+
53+
- name: Execute Vagrant as daemon
54+
command:
55+
cmd: "daemonize -e /home/vagrant/myvmerr.log -o /home/vagrant/myvm.log -c /home/vagrant /usr/bin/vagrant up --provider=libvirt"
56+
chdir: /home/vagrant
57+
creates: /home/vagrant/myvm.log
58+
59+
- name: Wait until the string "auth" is in the vagrant log
60+
wait_for:
61+
path: /home/vagrant/myvmerr.log
62+
search_regex: SSH\sis\sready
63+
timeout: 1000

molecule/default/molecule.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
dependency:
3+
name: galaxy
4+
options:
5+
role-file: requirements.yml
6+
roles-path: ../community
7+
driver:
8+
name: vagrant
9+
provider:
10+
name: virtualbox
11+
12+
lint: yamllint . && flake8 && ansible-lint --exclude=meta
13+
platforms:
14+
- name: Fedora-Molecule-libvirt-host
15+
box: fedora/33-cloud-base
16+
memory: 8000
17+
cpus: 4
18+
provider_raw_config_args:
19+
- "customize ['modifyvm', :id, '--nested-hw-virt', 'on']"
20+
provider_override_args:
21+
- "persistent_storage.enabled = true"
22+
- "persistent_storage.location = 'molecule-libvirt-host.vdi'"
23+
- "persistent_storage.size = 100"
24+
- "persistent_storage.mount = false"
25+
- "persistent_storage.diskdevice = '/dev/sdb'"
26+
provisioner:
27+
name: ansible
28+
env:
29+
ANSIBLE_ROLES_PATH: ../../..:../../../community
30+
verifier:
31+
name: testinfra
32+
env:
33+
PYTHONWARNINGS: "ignore:.*U.*mode is deprecated:DeprecationWarning"
34+
options:
35+
v: 1

molecule/default/tests/conftest.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""PyTest Fixtures."""
2+
from __future__ import absolute_import
3+
import os
4+
import pytest
5+
6+
7+
def pytest_runtest_setup(item):
8+
"""Run tests only when under molecule with testinfra installed."""
9+
try:
10+
import testinfra
11+
except ImportError:
12+
pytest.skip("Test requires testinfra", allow_module_level=True)
13+
if "MOLECULE_INVENTORY_FILE" in os.environ:
14+
pytest.testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
15+
os.environ["MOLECULE_INVENTORY_FILE"]
16+
).get_hosts("all")
17+
else:
18+
pytest.skip(
19+
"Test should run only from inside molecule.",
20+
allow_module_level=True
21+
)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
"""Role testing files using testinfra."""
2+
3+
4+
def test_vagrant_machine_is_fully_up(host):
5+
command = """cat myvm.log | grep -c 'myvm: SSH auth method: private key'"""
6+
cmd = host.run(command)
7+
assert '1' in cmd.stdout
8+
9+
10+
def test_vagrant_machine_is_running(host):
11+
command = r"""vagrant status | egrep -c 'myvm\s*running\s\(libvirt\)'"""
12+
cmd = host.run(command)
13+
assert '1' in cmd.stdout
14+
15+
16+
def test_pool_is_started(host):
17+
command = r""" sudo virsh pool-list --all |
18+
cut -d " " -f 5 | tail -n +3 | head -n +1 | egrep -c '^active$'"""
19+
cmd = host.run(command)
20+
assert '1' in cmd.stdout
21+
22+
23+
def test_pool_is_autostarted(host):
24+
command = r""" sudo virsh pool-list --all |
25+
cut -d " " -f 8 | tail -n +3 | head -n +1 | egrep -c '^yes$'"""
26+
cmd = host.run(command)
27+
assert '1' in cmd.stdout
28+
29+
30+
def test_net_is_started(host):
31+
command = r""" sudo virsh net-list --all |
32+
cut -d " " -f 5 | tail -n +3 | head -n +1 | egrep -c '^active$'"""
33+
cmd = host.run(command)
34+
assert '1' in cmd.stdout
35+
36+
37+
def test_net_is_autostarted(host):
38+
command = r""" sudo virsh net-list --all |
39+
cut -d " " -f 8 | tail -n +3 | head -n +1 | egrep -c '^yes$'"""
40+
cmd = host.run(command)
41+
assert '1' in cmd.stdout

0 commit comments

Comments
 (0)