Skip to content

Commit 96c3001

Browse files
committed
test(windows): add local testing of Windows using Vagrant/Virtualbox
* use `rspec-retry` to make retrying the logfile test platform-independent * do some DRYing of the inspec control files
1 parent 3ebcbe9 commit 96c3001

File tree

9 files changed

+112
-94
lines changed

9 files changed

+112
-94
lines changed

.rubocop.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ Metrics/LineLength:
88
Max: 88
99

1010
# Any offenses that should be fixed, e.g. collected via. `rubocop --auto-gen-config`
11+
Metrics/BlockLength:
12+
Max: 36

.yamllint

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ ignore: |
1212
node_modules/
1313
test/**/states/**/*.sls
1414
.kitchen/
15+
test/salt/pillar/default.sls
1516
1617
yaml-files:
1718
# Default settings

Gemfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
source 'https://rubygems.org'
44

5+
gem 'inspec'
56
gem 'kitchen-docker', '>= 2.9'
67
gem 'kitchen-inspec', '>= 1.1'
78
gem 'kitchen-salt', '>= 0.6.0'
9+
gem 'rspec-retry'
10+
11+
group :vagrant do
12+
gem 'kitchen-vagrant'
13+
end

kitchen.vagrant.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# -*- coding: utf-8 -*-
2+
# vim: ft=yaml
3+
---
4+
driver:
5+
name: vagrant
6+
7+
platforms:
8+
- name: windows-81-2019-2-py3
9+
driver:
10+
box: techneg/win81x64-pro-salt
11+
gui: false
12+
linked_clone: true
13+
provisioner:
14+
init_environment: >
15+
salt-call --local state.single file.managed
16+
C:\Users\vagrant\AppData\Local\Temp\kitchen\srv\salt\win\repo-ng\openvpn.sls
17+
source=https://github.com/saltstack/salt-winrepo-ng/raw/master/openvpn.sls
18+
skip_verify=True makedirs=True
Lines changed: 31 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,45 @@
1-
# Overide by OS
1+
# frozen_string_literal: true
2+
3+
if os[:family] == 'windows'
4+
conf_dir = 'C:\\Program Files\\OpenVPN\\config'
5+
conf_ext = 'ovpn'
6+
else
7+
conf_dir = '/etc/openvpn'
8+
conf_ext = 'conf'
9+
end
10+
211
user = 'root'
312
group = 'openvpn'
413

5-
control 'OpenVPN server configuration' do
6-
title 'should match desired lines'
7-
14+
%w[server client].each do |role|
815
cfgfile =
916
case os[:name]
10-
when 'debian'
11-
'/etc/openvpn/server/myserver1.conf'
12-
when 'fedora'
13-
'/etc/openvpn/server/myserver1.conf'
14-
when 'ubuntu'
15-
'/etc/openvpn/server/myserver1.conf'
17+
when 'debian', 'fedora', 'ubuntu'
18+
"#{conf_dir}/#{role}/my#{role}1.#{conf_ext}"
1619
else
17-
'/etc/openvpn/myserver1.conf'
20+
"#{conf_dir}/my#{role}1.#{conf_ext}"
1821
end
1922

20-
describe file(cfgfile) do
21-
it { should be_file }
22-
it { should be_owned_by user }
23-
it { should be_grouped_into group }
24-
its('mode') { should cmp '0640' }
25-
its('content') { should include '# OpenVPN server configuration' }
26-
its('content') { should include '# Managed by Salt' }
27-
its('content') { should include 'user' }
23+
control "OpenVPN #{role} configuration" do
24+
title 'should match desired lines'
25+
26+
describe file(cfgfile) do
27+
it { should be_file }
28+
its('content') { should include "# OpenVPN #{role} configuration" }
29+
its('content') { should include '# Managed by Salt' }
30+
its('content') { should include 'user' }
31+
end
2832
end
29-
end
3033

31-
control 'OpenVPN client configuration' do
32-
title 'should match desired lines'
34+
control "OpenVPN #{role} configuration file permissions" do
35+
title 'should be correct'
3336

34-
cfgfile =
35-
case os[:name]
36-
when 'debian'
37-
'/etc/openvpn/client/myclient1.conf'
38-
when 'fedora'
39-
'/etc/openvpn/client/myclient1.conf'
40-
when 'ubuntu'
41-
'/etc/openvpn/client/myclient1.conf'
42-
else
43-
'/etc/openvpn/myclient1.conf'
44-
end
37+
only_if('Skip on Windows') { os[:family] != 'windows' }
4538

46-
describe file(cfgfile) do
47-
it { should be_file }
48-
it { should be_owned_by user }
49-
it { should be_grouped_into group }
50-
its('mode') { should cmp '0640' }
51-
its('content') { should include '# OpenVPN client configuration' }
52-
its('content') { should include '# Managed by Salt' }
53-
its('content') { should include 'user' }
39+
describe file(cfgfile) do
40+
it { should be_owned_by user }
41+
it { should be_grouped_into group }
42+
its('mode') { should cmp '0640' }
43+
end
5444
end
5545
end

test/integration/default/controls/packages_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
control 'OpenVPN package' do
24
title 'should be installed'
35

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,45 @@
1+
# frozen_string_literal: true
2+
13
control 'OpenVPN service' do
24
impact 0.5
35
title 'should be running and enabled'
46

5-
# single service
6-
if os[:name] == 'centos' && os[:release].start_with?('6')
7-
describe service("openvpn") do
8-
it { should be_enabled }
9-
it { should be_running }
10-
end
7+
require 'rspec/retry'
118

12-
# multiple services
13-
else
14-
%w(server client).each do |role|
9+
log_dir = '/var/log/openvpn/'
1510

11+
if os[:name] == 'centos' && os[:release].start_with?('6')
12+
services = ['openvpn']
13+
elsif os[:family] == 'windows'
14+
log_dir = 'C:\\Program Files\\OpenVPN\\log\\'
15+
services = ['OpenVPNService']
16+
else
17+
services = []
18+
%w[server client].each do |role|
1619
prefix =
1720
case os[:name]
18-
when 'debian'
19-
"openvpn-#{role}"
20-
when 'fedora'
21-
"openvpn-#{role}"
22-
when 'ubuntu'
21+
when 'debian', 'fedora', 'ubuntu'
2322
"openvpn-#{role}"
2423
else
2524
'openvpn'
2625
end
27-
28-
describe service("#{prefix}@my#{role}1.service") do
29-
it { should be_enabled }
30-
it { should be_running }
31-
end
26+
services << "#{prefix}@my#{role}1.service"
3227
end
3328
end
3429

35-
%w(server client).each do |role|
36-
logfile = "/var/log/openvpn/my#{role}1.log"
30+
services.each do |service|
31+
describe service(service) do
32+
it { should be_enabled }
33+
it { should be_running }
34+
end
35+
end
3736

38-
describe command("sh -c 'for i in $(seq 1 60); do if grep \"Initialization Sequence Completed\" #{logfile}; then exit 0; fi; echo -n '.'; sleep 1; done; cat #{logfile}; exit 1'") do
39-
its('exit_status') { should be 0 }
40-
its('stdout') { should include "Initialization Sequence Completed" }
37+
%w[server client].each do |role|
38+
logfile = "#{log_dir}my#{role}1.log"
39+
describe 'Initialization' do
40+
it 'should be completed', retry: 60, retry_wait: 1 do
41+
expect(file(logfile).content).to include 'Initialization Sequence Completed'
42+
end
4143
end
4244
end
4345
end

test/integration/default/inspec.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ supports:
1616
- platform-name: freebsd
1717
- platform-name: amazon
1818
- platform-name: arch
19+
- platform: windows

test/salt/pillar/default.sls

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
11
# -*- coding: utf-8 -*-
22
# vim: ft=yaml
33
---
4+
{%- if grains['os_family'] == 'Windows' %}
5+
{%- set log_dir = 'C:\\Program Files\\OpenVPN\log\\' %}
6+
{%- set conf_dir = 'C:\\ProgramData\\OpenVPN\config\\' %}
7+
{%- else %}
8+
{%- set log_dir = '/var/log/openvpn/' %}
9+
{%- set conf_dir = '/etc/openvpn/' %}
10+
{%- endif %}
411
openvpn:
512
lookup:
13+
{%- if not grains['os_family'] == 'Windows' %}
614
user: openvpn
715
group: openvpn
816
manage_user: true
917
manage_group: true
1018
external_repo_enabled: true
19+
{%- else %}
20+
service: OpenVPNService
21+
{%- endif %}
1122
dh_files: ['512']
1223
server:
1324
myserver1:
@@ -16,13 +27,16 @@ openvpn:
1627
proto: udp
1728
topology: p2p
1829
dev: tun
30+
{%- if grains['os_family'] == 'Windows' %}
31+
dev_node: myserver1
32+
{%- endif %}
1933
comp_lzo: "yes"
2034
ifconfig: 169.254.0.1 169.254.0.2
21-
log_append: /var/log/openvpn/myserver1.log
22-
status: /var/log/openvpn/myserver1-status.log
23-
secret: /etc/openvpn/myserver1_secret.key
35+
log_append: '''{{ log_dir }}myserver1.log'''
36+
status: '''{{ log_dir }}myserver1-status.log'''
37+
secret: '''{{ conf_dir }}myserver1_secret.key'''
2438
# /usr/sbin/openvpn --genkey --secret /dev/stdout
25-
secret_content: |
39+
secret_content: &secret_key |
2640
#
2741
# 2048 bit OpenVPN static key
2842
#
@@ -52,34 +66,16 @@ openvpn:
5266
proto: udp
5367
topology: p2p
5468
dev: tun
69+
{%- if grains['os_family'] == 'Windows' %}
70+
dev_node: myclient1
71+
{%- endif %}
5572
comp_lzo: "yes"
5673
pull: false
5774
tls_client: false
5875
nobind: false
5976
ifconfig: 169.254.0.2 169.254.0.1
60-
status: /var/log/openvpn/myclient1-status.log
61-
log_append: /var/log/openvpn/myclient1.log
62-
secret: /etc/openvpn/myclient1_secret.key
77+
status: '''{{ log_dir }}myclient1-status.log'''
78+
log_append: '''{{ log_dir }}myclient1.log'''
79+
secret: '''{{ conf_dir }}myclient1_secret.key'''
6380
# /usr/sbin/openvpn --genkey --secret /dev/stdout
64-
secret_content: |
65-
#
66-
# 2048 bit OpenVPN static key
67-
#
68-
-----BEGIN OpenVPN Static key V1-----
69-
6b3e7b098232e9c885f8deed5c069b02
70-
47a966595178cc30ebcd4e1042e019ef
71-
fdfbed752e26ef7b0877e0e0a6e4e38b
72-
ffed3fd9da205ff6cd39825d0f8a99ec
73-
324848682062676868b57e4474791042
74-
4dc4ad7f3ff7ba8815e31f950c7443c8
75-
b52441384936cbf50d2f4d051d0c889a
76-
f118dec5c749398cdce859fced60a4eb
77-
4e78abb9939f8dbe1cbdbbcaa914b539
78-
6258235dce1a8ef044a29f8ce018f183
79-
4b83f17a42b788c583cf006cccb5050f
80-
a1c53b22688d98a2092fcd23b160b01a
81-
064d84f1355c605287b30b140c3c5fa7
82-
b5e2a0a8def6eb46b3ab4a11b5cb4c96
83-
4c099bf8e74b8bf4e6509de69b7a79ad
84-
7391b6cf3f4ae296ecf8b552144a2947
85-
-----END OpenVPN Static key V1-----
81+
secret_content: *secret_key

0 commit comments

Comments
 (0)