Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add kitchen and fix logging #98

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
*.swp
.kitchen
.kitchen.local.yml
.cache
junit-*.xml
__pycache__
38 changes: 38 additions & 0 deletions .kitchen.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
driver:
name: vagrant

platforms:
- name: bento/debian-9
- name: bento/debian-8
- name: bento/ubuntu-18.04
- name: bento/centos-7

provisioner:
salt_version: latest
name: salt_solo
formula: openvpn
require_chef: false
pillars:
top.sls:
base:
'*':
- test

suites:
- name: config
provisioner:
pillars_from_files:
test.sls: test/config/pillars.sls
state_top:
base:
'*':
- openvpn.config

lifecycle:
post_converge:
- local: sleep 10

verifier:
name: shell
command: py.test -vvv --junit-xml junit-$KITCHEN_INSTANCE.xml test/$KITCHEN_SUITE
14 changes: 14 additions & 0 deletions openvpn/config.sls
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,14 @@ openvpn_{{ type }}_{{ name }}_log_file:
file.managed:
- name: {{ config.log }}
- makedirs: True
- replace: False
{{ _permissions(640) }}
- require_in:
{%- if map.multi_services %}
- service: openvpn_{{name}}_service
{%- else %}
- service: openvpn_service
{%- endif %}
{% endif %}

{% if config.log_append is defined %}
Expand All @@ -177,7 +184,14 @@ openvpn_{{ type }}_{{ name }}_log_file_append:
file.managed:
- name: {{ config.log_append }}
- makedirs: True
- replace: False
{{ _permissions(640) }}
- require_in:
{%- if map.multi_services %}
- service: openvpn_{{name}}_service
{%- else %}
- service: openvpn_service
{%- endif %}
{% endif %}

{% if config.client_config_dir is defined %}
Expand Down
86 changes: 86 additions & 0 deletions test/config/pillars.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
openvpn:
lookup:
{% if ( grains.os == "Debian" and grains.osmajorrelease >= 9 ) %}
user: root
group: root
{% else %}
user: openvpn
group: openvpn
{% endif %}
manage_user: True
manage_group: True
external_repo_enabled: True
dh_files: ['512']
server:
myserver1:
local: 127.0.0.1
port: 2000
proto: udp
topology: p2p
dev: tun
comp_lzo: "yes"
ifconfig: 169.254.0.1 169.254.0.2
log_append: /var/log/openvpn/myserver1.log
secret: /etc/openvpn/myserver1_secret.key
# /usr/sbin/openvpn --genkey --secret /dev/stdout
secret_content: |
#
# 2048 bit OpenVPN static key
#
-----BEGIN OpenVPN Static key V1-----
6b3e7b098232e9c885f8deed5c069b02
47a966595178cc30ebcd4e1042e019ef
fdfbed752e26ef7b0877e0e0a6e4e38b
ffed3fd9da205ff6cd39825d0f8a99ec
324848682062676868b57e4474791042
4dc4ad7f3ff7ba8815e31f950c7443c8
b52441384936cbf50d2f4d051d0c889a
f118dec5c749398cdce859fced60a4eb
4e78abb9939f8dbe1cbdbbcaa914b539
6258235dce1a8ef044a29f8ce018f183
4b83f17a42b788c583cf006cccb5050f
a1c53b22688d98a2092fcd23b160b01a
064d84f1355c605287b30b140c3c5fa7
b5e2a0a8def6eb46b3ab4a11b5cb4c96
4c099bf8e74b8bf4e6509de69b7a79ad
7391b6cf3f4ae296ecf8b552144a2947
-----END OpenVPN Static key V1-----
client:
myclient1:
remote:
- 127.0.0.1 2000
lport: 62000
proto: udp
topology: p2p
dev: tun
comp_lzo: "yes"
pull: False
tls_client: False
nobind: False
ifconfig: 169.254.0.2 169.254.0.1
log_append: /var/log/openvpn/myclient1.log
secret: /etc/openvpn/myclient1_secret.key
# /usr/sbin/openvpn --genkey --secret /dev/stdout
secret_content: |
#
# 2048 bit OpenVPN static key
#
-----BEGIN OpenVPN Static key V1-----
6b3e7b098232e9c885f8deed5c069b02
47a966595178cc30ebcd4e1042e019ef
fdfbed752e26ef7b0877e0e0a6e4e38b
ffed3fd9da205ff6cd39825d0f8a99ec
324848682062676868b57e4474791042
4dc4ad7f3ff7ba8815e31f950c7443c8
b52441384936cbf50d2f4d051d0c889a
f118dec5c749398cdce859fced60a4eb
4e78abb9939f8dbe1cbdbbcaa914b539
6258235dce1a8ef044a29f8ce018f183
4b83f17a42b788c583cf006cccb5050f
a1c53b22688d98a2092fcd23b160b01a
064d84f1355c605287b30b140c3c5fa7
b5e2a0a8def6eb46b3ab4a11b5cb4c96
4c099bf8e74b8bf4e6509de69b7a79ad
7391b6cf3f4ae296ecf8b552144a2947
-----END OpenVPN Static key V1-----

15 changes: 15 additions & 0 deletions test/config/testinfra/test_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
def test_myserver1_service(host):
service = host.service("openvpn@myserver1.service")
assert service.is_running
assert service.is_enabled

def test_myserver1_log(host):
assert host.file("/var/log/openvpn/myserver1.log").contains("Initialization Sequence Completed")

def test_myclient1_service(host):
service = host.service("openvpn@myclient1.service")
assert service.is_running
assert service.is_enabled

def test_myclient1_log(host):
assert host.file("/var/log/openvpn/myclient1.log").contains("Initialization Sequence Completed")
31 changes: 31 additions & 0 deletions test/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import pytest
import testinfra
from testinfra.backend.base import BaseBackend
from testinfra.backend import parse_hostspec
import os

SSH_CONFIG = '.ssh-config'
SSH_CONFIG_MAP = {
'KITCHEN_HOSTNAME': 'Hostname',
'KITCHEN_USERNAME': 'User',
'KITCHEN_PORT': 'Port',
'KITCHEN_SSH_KEY': 'IdentityFile',
}

@pytest.fixture
def host(request, tmpdir_factory):
# Override the TestinfraBackend fixture,
# all testinfra fixtures (i.e. modules) depend on it.
tmpdir = tmpdir_factory.mktemp(str(id(request)))
image, kw = parse_hostspec(os.environ['KITCHEN_INSTANCE'])
ssh_config = ['Host {0}'.format(os.environ['KITCHEN_INSTANCE'])]
for key in SSH_CONFIG_MAP.keys():
if key in os.environ:
ssh_config.append('{0} {1}'.format(SSH_CONFIG_MAP[key], os.environ[key]))
ssh_config_file = tmpdir.join(SSH_CONFIG)
ssh_config_file.write('\n'.join(ssh_config))

# Return a dynamic created backend
host = testinfra.host.get_host(os.environ['KITCHEN_INSTANCE'], ssh_config=str(ssh_config_file), sudo=True)
host.backend.get_hostname = lambda: image
return host