Skip to content

Commit a21720a

Browse files
committed
molecule test
1 parent 7013358 commit a21720a

File tree

18 files changed

+445
-33
lines changed

18 files changed

+445
-33
lines changed

.github/workflows/molecule.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
# This is a basic workflow to help you get started with Actions
3+
name: Molecule
4+
5+
# Controls when the action will run. Triggers the workflow on push or pull request
6+
# events but only for the master branch
7+
on:
8+
push:
9+
pull_request:
10+
branches:
11+
- master
12+
- tags/*
13+
14+
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
15+
jobs:
16+
# This workflow contains a single job called "build"
17+
lint:
18+
# The type of runner that the job will run on
19+
runs-on: ubuntu-latest
20+
21+
# Steps represent a sequence of tasks that will be executed as part of the job
22+
steps:
23+
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
24+
- uses: actions/checkout@v2
25+
26+
- name: install lint prerequisite
27+
run: |
28+
sudo apt-get update
29+
sudo apt -y install python3-setuptools ansible-lint vagrant
30+
31+
- name: Install molecule
32+
run: |
33+
sudo apt update
34+
sudo apt -y install python3-setuptools python3 python3-pip
35+
sudo pip3 install wheel
36+
sudo pip3 install molecule testinfra yamllint ansible-lint flake8 molecule-vagrant
37+
38+
- name: molecule lint
39+
run: |
40+
molecule lint
41+
42+
requirements:
43+
# The type of runner that the job will run on
44+
runs-on: ubuntu-latest
45+
# Steps represent a sequence of tasks that will be executed as part of the job
46+
steps:
47+
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
48+
- uses: actions/checkout@v2
49+
- name: install prereq
50+
run: |
51+
ansible-galaxy role install -r requirements.yml

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
**/__pychache__

.travis.yml

Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,27 @@
11
---
2-
language: python
3-
python: "2.7"
4-
5-
# Use the new container infrastructure
6-
sudo: false
7-
8-
# Install ansible
9-
addons:
10-
apt:
11-
packages:
12-
- python-pip
13-
14-
install:
15-
# Install ansible
16-
- pip install ansible ansible-lint
17-
18-
# Check ansible version
19-
- ansible --version
202

21-
# Create ansible.cfg with correct roles_path
22-
- printf '[defaults]\nroles_path=../' >ansible.cfg
3+
dist: bionic
234

24-
# Compensate for repo name being different to the role
25-
- ln -s $(pwd) ../stackhpc.libvirt-host
26-
27-
script:
28-
# Run Ansible lint against the role
29-
- ansible-lint tasks/main.yml
30-
31-
# Basic role syntax check
32-
- ansible-playbook tests/test.yml -i tests/inventory --syntax-check
33-
34-
notifications:
35-
webhooks: https://galaxy.ansible.com/api/v1/notifications/
5+
language: python
6+
python:
7+
- "3.8"
8+
9+
before_install:
10+
- |
11+
sudo apt -y install bridge-utils dnsmasq-base ebtables libvirt-bin libvirt-dev qemu-kvm qemu-utils ruby-dev
12+
13+
- |
14+
wget https://releases.hashicorp.com/vagrant/2.2.7/vagrant_2.2.7_x86_64.deb
15+
sudo apt -y install ./vagrant_2.2.7_x86_64.deb
16+
sudo vagrant plugin install vagrant-libvirt
17+
18+
- |
19+
sudo apt-get -y purge python3-openssl && sudo apt-get -y autoremove
20+
sudo apt-get update && sudo apt-get install -y ca-certificates curl gcc iproute2 python3 python3-dev sudo
21+
curl -skL https://bootstrap.pypa.io/get-pip.py | sudo -H python3
22+
sudo pip3 install wheel
23+
sudo pip3 install netaddr python-vagrant yamllint testinfra flake8
24+
sudo pip3 install ansible ansible-lint
25+
sudo pip3 install -I molecule molecule-vagrant
26+
27+
script: travis_wait 30 sudo molecule test --scenario-name kvm

.yamllint

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
# Based on ansible-lint config
3+
extends: default
4+
5+
rules:
6+
braces:
7+
max-spaces-inside: 1
8+
level: error
9+
brackets:
10+
max-spaces-inside: 1
11+
level: error
12+
colons:
13+
max-spaces-after: -1
14+
level: error
15+
commas:
16+
max-spaces-after: -1
17+
level: error
18+
comments: disable
19+
comments-indentation: disable
20+
document-start: disable
21+
empty-lines:
22+
max: 3
23+
level: error
24+
hyphens:
25+
level: error
26+
indentation: disable
27+
key-duplicates: enable
28+
line-length: disable
29+
new-line-at-end-of-file: disable
30+
new-lines:
31+
type: unix
32+
trailing-spaces: disable
33+
truthy: disable

handlers/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
service:
55
name: libvirtd
66
state: restarted
7+
enabled: yes
78
become: true

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

molecule/default/molecule.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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-Virtualization
15+
box: fedora/31-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-virtualization.vdi'"
23+
- "persistent_storage.size = 100"
24+
- "persistent_storage.mount = false"
25+
- "persistent_storage.diskdevice = '/dev/sdb'"
26+
volumes:
27+
- /sys/fs/cgroup:/sys/fs/cgroup:ro
28+
privileged: yes
29+
pre_build_image: yes
30+
provisioner:
31+
name: ansible
32+
env:
33+
ANSIBLE_ROLES_PATH: ../../..:../../../community
34+
verifier:
35+
name: testinfra
36+
env:
37+
PYTHONWARNINGS: "ignore:.*U.*mode is deprecated:DeprecationWarning"
38+
options:
39+
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: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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

molecule/kvm/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+
9+
config.vm.box = "fedora/31-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

0 commit comments

Comments
 (0)