Skip to content

Commit 1fb02e2

Browse files
authored
Merge pull request #54 from myii/feat/add-freebsd-support
feat(freebsd): add FreeBSD support (recover abandoned PR #32)
2 parents 52eec77 + 208e31b commit 1fb02e2

File tree

19 files changed

+338
-28
lines changed

19 files changed

+338
-28
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# -*- coding: utf-8 -*-
2+
# vim: ft=yaml
3+
---
4+
name: 'Kitchen Vagrant (FreeBSD)'
5+
'on': ['push', 'pull_request']
6+
7+
env:
8+
KITCHEN_LOCAL_YAML: 'kitchen.vagrant.yml'
9+
10+
jobs:
11+
test:
12+
runs-on: 'macos-10.15'
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
instance:
17+
# - prod-server-freebsd-130-master-py3
18+
- freebsd-130-master-py3
19+
# - prod-server-freebsd-123-master-py3
20+
- freebsd-123-master-py3
21+
# - prod-server-freebsd-130-3004-0-py3
22+
# - prod-server-freebsd-123-3004-0-py3
23+
steps:
24+
- name: 'Check out code'
25+
uses: 'actions/checkout@v2'
26+
- name: 'Set up Bundler cache'
27+
uses: 'actions/cache@v1'
28+
with:
29+
path: 'vendor/bundle'
30+
key: "${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}"
31+
restore-keys: "${{ runner.os }}-gems-"
32+
- name: 'Run Bundler'
33+
run: |
34+
ruby --version
35+
bundle config path vendor/bundle
36+
bundle install --jobs 4 --retry 3
37+
- name: 'Run Test Kitchen'
38+
run: 'bundle exec kitchen verify ${{ matrix.instance }}'

.salt-lint

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
# vim: ft=yaml
33
---
44
exclude_paths: []
5-
rules: {}
5+
rules:
6+
204: # Lines should be no longer that 160 chars
7+
ignore: |
8+
vault/files/vault.service.fbsd.j2
69
skip_list:
710
# Using `salt-lint` for linting other files as well, such as Jinja macros/templates
811
- 205 # Use ".sls" as a Salt State file extension

Gemfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,7 @@ gem 'kitchen-docker', git: 'https://gitlab.com/saltstack-formulas/infrastructure
1717

1818
gem 'kitchen-inspec', '>= 2.5.0'
1919
gem 'kitchen-salt', '>= 0.7.2'
20+
21+
group :vagrant do
22+
gem 'kitchen-vagrant'
23+
end

Gemfile.lock

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,8 @@ GEM
387387
kitchen-salt (0.7.2)
388388
hashie (>= 3.5)
389389
test-kitchen (>= 1.4)
390+
kitchen-vagrant (1.11.0)
391+
test-kitchen (>= 1.4, < 4)
390392
license-acceptance (2.1.13)
391393
pastel (~> 0.7)
392394
tomlrb (>= 1.2, < 3.0)
@@ -669,6 +671,7 @@ DEPENDENCIES
669671
kitchen-docker!
670672
kitchen-inspec (>= 2.5.0)
671673
kitchen-salt (>= 0.7.2)
674+
kitchen-vagrant
672675

673676
BUNDLED WITH
674677
2.1.2

docs/README.rst

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ Requirements
105105
``kitchen converge``
106106
^^^^^^^^^^^^^^^^^^^^
107107

108-
Creates the docker instance and runs the ``template`` main state, ready for testing.
108+
Creates the docker instance and runs the ``vault`` main states, ready for testing.
109109

110110
``kitchen verify``
111111
^^^^^^^^^^^^^^^^^^
@@ -126,3 +126,65 @@ Runs all of the stages above in one go: i.e. ``destroy`` + ``converge`` + ``veri
126126
^^^^^^^^^^^^^^^^^
127127

128128
Gives you SSH access to the instance for manual testing.
129+
130+
Testing with Vagrant
131+
--------------------
132+
133+
Windows/FreeBSD/OpenBSD testing is done with ``kitchen-salt``.
134+
135+
Requirements
136+
^^^^^^^^^^^^
137+
138+
* Ruby
139+
* Virtualbox
140+
* Vagrant
141+
142+
Setup
143+
^^^^^
144+
145+
.. code-block:: bash
146+
147+
$ gem install bundler
148+
$ bundle install --with=vagrant
149+
$ bin/kitchen test [platform]
150+
151+
Where ``[platform]`` is the platform name defined in ``kitchen.vagrant.yml``,
152+
e.g. ``windows-81-latest-py3``.
153+
154+
Note
155+
^^^^
156+
157+
When testing using Vagrant you must set the environment variable ``KITCHEN_LOCAL_YAML`` to ``kitchen.vagrant.yml``. For example:
158+
159+
.. code-block:: bash
160+
161+
$ KITCHEN_LOCAL_YAML=kitchen.vagrant.yml bin/kitchen test # Alternatively,
162+
$ export KITCHEN_LOCAL_YAML=kitchen.vagrant.yml
163+
$ bin/kitchen test
164+
165+
Then run the following commands as needed.
166+
167+
``bin/kitchen converge``
168+
^^^^^^^^^^^^^^^^^^^^^^^^
169+
170+
Creates the Vagrant instance and runs the ``vault`` main states, ready for testing.
171+
172+
``bin/kitchen verify``
173+
^^^^^^^^^^^^^^^^^^^^^^
174+
175+
Runs the ``inspec`` tests on the actual instance.
176+
177+
``bin/kitchen destroy``
178+
^^^^^^^^^^^^^^^^^^^^^^^
179+
180+
Removes the Vagrant instance.
181+
182+
``bin/kitchen test``
183+
^^^^^^^^^^^^^^^^^^^^
184+
185+
Runs all of the stages above in one go: i.e. ``destroy`` + ``converge`` + ``verify`` + ``destroy``.
186+
187+
``bin/kitchen login``
188+
^^^^^^^^^^^^^^^^^^^^^
189+
190+
Gives you RDP/SSH access to the instance for manual testing.

kitchen.vagrant.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# -*- coding: utf-8 -*-
2+
# vim: ft=yaml
3+
---
4+
driver:
5+
name: vagrant
6+
cache_directory: false
7+
customize:
8+
usbxhci: 'off'
9+
gui: false
10+
ssh:
11+
shell: /bin/sh
12+
<% unless ENV['CI'] %>
13+
linked_clone: true
14+
synced_folders:
15+
- - '.kitchen/kitchen-vagrant/%{instance_name}/vagrant'
16+
- '/vagrant'
17+
- 'create: true, disabled: false'
18+
<% end %>
19+
20+
platforms:
21+
- name: freebsd-130-master-py3
22+
driver:
23+
box: myii/freebsd-13.0-master-py3
24+
- name: freebsd-123-master-py3
25+
driver:
26+
box: myii/freebsd-12.3-master-py3
27+
- name: freebsd-130-3004-0-py3
28+
driver:
29+
box: myii/freebsd-13.0-3004.0-py3
30+
- name: freebsd-123-3004-0-py3
31+
driver:
32+
box: myii/freebsd-12.3-3004.0-py3

test/integration/dev_server/controls/vault_spec.rb

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
# frozen_string_literal: true
22

3+
config_json, service_cmd =
4+
case system.platform[:family]
5+
when 'bsd'
6+
['/usr/local/etc/vault/conf.d/config.json', 'service vault status']
7+
else
8+
['/etc/vault/conf.d/config.json', 'journalctl -u vault']
9+
end
10+
311
describe command('/usr/local/bin/vault -version') do
412
its(:exit_status) { should eq 0 }
513
its(:stderr) { should be_empty }
14+
# https://rubular.com/r/vVeCVuHAmtTYt3
615
its(:stdout) { should match(/^Vault v[0-9.]+ \('[0-9a-f]+'\)/) }
716
end
817

@@ -15,27 +24,40 @@
1524
describe file('/etc/init/vault.conf') do
1625
it { should be_a_file }
1726
end
27+
28+
describe file('/usr/local/etc/rc.d/vault') do
29+
it { should be_a_file }
30+
end
1831
end
1932

2033
describe service('vault') do
34+
it { should be_installed }
2135
it { should be_enabled }
2236
it { should be_running }
2337
end
2438

25-
describe file('/etc/vault/conf.d/config.json') do
39+
describe file(config_json) do
2640
it { should_not be_a_file }
2741
end
2842

29-
describe.one do
30-
describe command('journalctl -u vault') do
31-
its(:exit_status) { should eq 0 }
32-
its(:stderr) { should be_empty }
33-
its(:stdout) { should match(/WARNING! dev mode is enabled!/) }
43+
control 'vault.service' do
44+
title 'dev mode warning message should be displayed and logged'
45+
46+
only_if('Warning message is not displayed on FreeBSD') do
47+
!%w[freebsd].include?(system.platform[:name])
3448
end
3549

36-
describe file('/var/log/vault.log') do
37-
it { should be_a_file }
38-
its(:content) { should match(/WARNING! dev mode is enabled!/) }
50+
describe.one do
51+
describe command(service_cmd) do
52+
its(:exit_status) { should eq 0 }
53+
its(:stderr) { should be_empty }
54+
its(:stdout) { should match(/WARNING! dev mode is enabled!/) }
55+
end
56+
57+
describe file('/var/log/vault.log') do
58+
it { should be_a_file }
59+
its(:content) { should match(/WARNING! dev mode is enabled!/) }
60+
end
3961
end
4062
end
4163

test/integration/prod_server/controls/vault_spec.rb

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,42 @@
11
# frozen_string_literal: true
22

3+
config_json, service_cmd, path_to_etc_vault =
4+
case system.platform[:family]
5+
when 'bsd'
6+
['/usr/local/etc/vault/conf.d/config.json', 'service vault status',
7+
'/usr/local/etc/vault']
8+
else
9+
['/etc/vault/conf.d/config.json', 'journalctl -u vault', '/etc/vault']
10+
end
11+
312
describe command('/usr/local/bin/vault -version') do
413
its(:exit_status) { should eq 0 }
514
its(:stderr) { should be_empty }
615
# https://rubular.com/r/vVeCVuHAmtTYt3
716
its(:stdout) { should match(/^Vault v[0-9.]+ \('[0-9a-f]+'\)/) }
817
end
918

10-
describe command('getcap $(readlink -f /usr/local/bin/vault)') do
11-
its(:exit_status) { should eq 0 }
12-
its(:stderr) { should be_empty }
13-
# https://rubular.com/r/JApIMY1oNqGRZ8
14-
its(:stdout) { should match(%r{/vault\s?=? cap_ipc_lock[+=]ep$}) }
19+
control 'vault.package.install' do
20+
title 'Linux capabilities should be set'
21+
22+
only_if('`getcap` not available on FreeBSD') do
23+
!%w[freebsd].include?(system.platform[:name])
24+
end
25+
26+
describe command('getcap $(readlink -f /usr/local/bin/vault)') do
27+
its(:exit_status) { should eq 0 }
28+
its(:stderr) { should be_empty }
29+
# https://rubular.com/r/JApIMY1oNqGRZ8
30+
its(:stdout) { should match(%r{/vault\s?=? cap_ipc_lock[+=]ep$}) }
31+
end
1532
end
1633

1734
describe user('vault') do
1835
it { should exist }
1936
its('group') { should eq 'vault' }
2037
end
2138

22-
describe file('/etc/vault/conf.d/config.json') do
39+
describe file(config_json) do
2340
it { should be_a_file }
2441
its('owner') { should eq 'root' }
2542
its('group') { should eq 'vault' }
@@ -35,6 +52,10 @@
3552
describe file('/etc/init/vault.conf') do
3653
it { should be_a_file }
3754
end
55+
56+
describe file('/usr/local/etc/rc.d/vault') do
57+
it { should be_a_file }
58+
end
3859
end
3960

4061
describe service('vault') do
@@ -44,10 +65,10 @@
4465
end
4566

4667
describe.one do
47-
describe command('journalctl -u vault') do
68+
describe command(service_cmd) do
4869
its(:exit_status) { should eq 0 }
4970
its(:stderr) { should be_empty }
50-
its(:stdout) { should match(/Vault server started/) }
71+
its(:stdout) { should match(/Vault server started|vault is running as pid \d+/) }
5172
end
5273

5374
describe file('/var/log/vault.log') do
@@ -70,10 +91,10 @@
7091
its('sealed') { should eq true }
7192
end
7293

73-
describe file('/etc/vault/localhost.pem') do
94+
describe file("#{path_to_etc_vault}/localhost.pem") do
7495
it { should be_a_file }
7596
end
7697

77-
describe file('/etc/vault/localhost-nopass.key') do
98+
describe file("#{path_to_etc_vault}/localhost-nopass.key") do
7899
it { should be_a_file }
79100
end

test/salt/pillar/prod_server.sls

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ vault:
66
storage:
77
file:
88
path: /var/lib/vault/data
9+
# `disable_mlock` is only needed for FreeBSD (Vagrant)
10+
# Doesn't appear to cause a problem for other instances but use an `if`
11+
# block if it does
12+
disable_mlock: true
913
tls_disable: 1
1014
self_signed_cert:
1115
enabled: true

vault/config/clean.sls

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# -*- coding: utf-8 -*-
22
# vim: ft=sls syntax=yaml softtabstop=2 tabstop=2 shiftwidth=2 expandtab autoindent
3+
{% from "vault/map.jinja" import vault with context %}
34

45
vault-config-clean-file-absent:
56
file.absent:
6-
- name: /etc/vault
7+
- name: {{ vault.config_path }}/vault

0 commit comments

Comments
 (0)