Skip to content

Commit 9c5ee26

Browse files
Pascal Liehnealxwr
authored andcommitted
ci(kitchen): add kitchen file + testinfra
1 parent 9b71fcf commit 9c5ee26

File tree

5 files changed

+170
-0
lines changed

5 files changed

+170
-0
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
11
*.swp
2+
.kitchen
3+
.kitchen.local.yml
4+
.cache
5+
junit-*.xml
6+
__pycache__

.kitchen.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
driver:
3+
name: vagrant
4+
5+
platforms:
6+
- name: bento/debian-9
7+
- name: bento/debian-8
8+
- name: bento/ubuntu-18.04
9+
- name: bento/centos-7
10+
11+
provisioner:
12+
salt_version: latest
13+
name: salt_solo
14+
formula: openvpn
15+
require_chef: false
16+
pillars:
17+
top.sls:
18+
base:
19+
'*':
20+
- test
21+
22+
suites:
23+
- name: config
24+
provisioner:
25+
pillars_from_files:
26+
test.sls: test/config/pillars
27+
state_top:
28+
base:
29+
'*':
30+
- openvpn.config
31+
32+
lifecycle:
33+
post_converge:
34+
- local: sleep 10
35+
36+
verifier:
37+
name: shell
38+
command: py.test -vvv --junit-xml junit-$KITCHEN_INSTANCE.xml test/$KITCHEN_SUITE

test/config/pillars

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
openvpn:
2+
lookup:
3+
user: openvpn
4+
group: openvpn
5+
manage_user: True
6+
manage_group: True
7+
external_repo_enabled: True
8+
dh_files: ['512']
9+
server:
10+
myserver1:
11+
local: 127.0.0.1
12+
port: 2000
13+
proto: udp
14+
topology: p2p
15+
dev: tun
16+
comp_lzo: "yes"
17+
ifconfig: 169.254.0.1 169.254.0.2
18+
log_append: /var/log/openvpn/myserver1.log
19+
secret: /etc/openvpn/myserver1_secret.key
20+
# /usr/sbin/openvpn --genkey --secret /dev/stdout
21+
secret_content: |
22+
#
23+
# 2048 bit OpenVPN static key
24+
#
25+
-----BEGIN OpenVPN Static key V1-----
26+
6b3e7b098232e9c885f8deed5c069b02
27+
47a966595178cc30ebcd4e1042e019ef
28+
fdfbed752e26ef7b0877e0e0a6e4e38b
29+
ffed3fd9da205ff6cd39825d0f8a99ec
30+
324848682062676868b57e4474791042
31+
4dc4ad7f3ff7ba8815e31f950c7443c8
32+
b52441384936cbf50d2f4d051d0c889a
33+
f118dec5c749398cdce859fced60a4eb
34+
4e78abb9939f8dbe1cbdbbcaa914b539
35+
6258235dce1a8ef044a29f8ce018f183
36+
4b83f17a42b788c583cf006cccb5050f
37+
a1c53b22688d98a2092fcd23b160b01a
38+
064d84f1355c605287b30b140c3c5fa7
39+
b5e2a0a8def6eb46b3ab4a11b5cb4c96
40+
4c099bf8e74b8bf4e6509de69b7a79ad
41+
7391b6cf3f4ae296ecf8b552144a2947
42+
-----END OpenVPN Static key V1-----
43+
client:
44+
myclient1:
45+
remote:
46+
- 127.0.0.1 2000
47+
lport: 62000
48+
proto: udp
49+
topology: p2p
50+
dev: tun
51+
comp_lzo: "yes"
52+
pull: False
53+
tls_client: False
54+
nobind: False
55+
ifconfig: 169.254.0.2 169.254.0.1
56+
log_append: /var/log/openvpn/myclient1.log
57+
secret: /etc/openvpn/myclient1_secret.key
58+
# /usr/sbin/openvpn --genkey --secret /dev/stdout
59+
secret_content: |
60+
#
61+
# 2048 bit OpenVPN static key
62+
#
63+
-----BEGIN OpenVPN Static key V1-----
64+
6b3e7b098232e9c885f8deed5c069b02
65+
47a966595178cc30ebcd4e1042e019ef
66+
fdfbed752e26ef7b0877e0e0a6e4e38b
67+
ffed3fd9da205ff6cd39825d0f8a99ec
68+
324848682062676868b57e4474791042
69+
4dc4ad7f3ff7ba8815e31f950c7443c8
70+
b52441384936cbf50d2f4d051d0c889a
71+
f118dec5c749398cdce859fced60a4eb
72+
4e78abb9939f8dbe1cbdbbcaa914b539
73+
6258235dce1a8ef044a29f8ce018f183
74+
4b83f17a42b788c583cf006cccb5050f
75+
a1c53b22688d98a2092fcd23b160b01a
76+
064d84f1355c605287b30b140c3c5fa7
77+
b5e2a0a8def6eb46b3ab4a11b5cb4c96
78+
4c099bf8e74b8bf4e6509de69b7a79ad
79+
7391b6cf3f4ae296ecf8b552144a2947
80+
-----END OpenVPN Static key V1-----
81+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
def test_myserver1_service(host):
2+
service = host.service("[email protected]")
3+
assert service.is_running
4+
assert service.is_enabled
5+
6+
def test_myserver1_log(host):
7+
assert host.file("/var/log/openvpn/myserver1.log").contains("Initialization Sequence Completed")
8+
9+
def test_myclient1_service(host):
10+
service = host.service("[email protected]")
11+
assert service.is_running
12+
assert service.is_enabled
13+
14+
def test_myclient1_log(host):
15+
assert host.file("/var/log/openvpn/myclient1.log").contains("Initialization Sequence Completed")

test/conftest.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import pytest
2+
import testinfra
3+
from testinfra.backend.base import BaseBackend
4+
from testinfra.backend import parse_hostspec
5+
import os
6+
7+
SSH_CONFIG = '.ssh-config'
8+
SSH_CONFIG_MAP = {
9+
'KITCHEN_HOSTNAME': 'Hostname',
10+
'KITCHEN_USERNAME': 'User',
11+
'KITCHEN_PORT': 'Port',
12+
'KITCHEN_SSH_KEY': 'IdentityFile',
13+
}
14+
15+
@pytest.fixture
16+
def host(request, tmpdir_factory):
17+
# Override the TestinfraBackend fixture,
18+
# all testinfra fixtures (i.e. modules) depend on it.
19+
tmpdir = tmpdir_factory.mktemp(str(id(request)))
20+
image, kw = parse_hostspec(os.environ['KITCHEN_INSTANCE'])
21+
ssh_config = ['Host {0}'.format(os.environ['KITCHEN_INSTANCE'])]
22+
for key in SSH_CONFIG_MAP.keys():
23+
if key in os.environ:
24+
ssh_config.append('{0} {1}'.format(SSH_CONFIG_MAP[key], os.environ[key]))
25+
ssh_config_file = tmpdir.join(SSH_CONFIG)
26+
ssh_config_file.write('\n'.join(ssh_config))
27+
28+
# Return a dynamic created backend
29+
host = testinfra.host.get_host(os.environ['KITCHEN_INSTANCE'], ssh_config=str(ssh_config_file), sudo=True)
30+
host.backend.get_hostname = lambda: image
31+
return host

0 commit comments

Comments
 (0)