Skip to content

Commit 0465af7

Browse files
committed
test(windows): add local testing of Windows using Vagrant/Virtualbox
1 parent 1eca9c7 commit 0465af7

File tree

6 files changed

+123
-8
lines changed

6 files changed

+123
-8
lines changed

Gemfile

+4
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,7 @@ source 'https://rubygems.org'
55
gem 'kitchen-docker', '>= 2.9'
66
gem 'kitchen-inspec', '>= 1.1'
77
gem 'kitchen-salt', '>= 0.6.0'
8+
9+
group :vagrant do
10+
gem 'kitchen-vagrant'
11+
end

docs/README.rst

+62
Original file line numberDiff line numberDiff line change
@@ -251,3 +251,65 @@ Runs all of the stages above in one go: i.e. ``destroy`` + ``converge`` + ``veri
251251
^^^^^^^^^^^^^^^^^^^^^
252252

253253
Gives you SSH access to the instance for manual testing.
254+
255+
Testing with Vagrant
256+
--------------------
257+
258+
Windows testing is done with ``kitchen-salt``.
259+
260+
Requirements
261+
^^^^^^^^^^^^
262+
263+
* Ruby
264+
* Virtualbox
265+
* Vagrant
266+
267+
Setup
268+
^^^^^
269+
270+
.. code-block:: bash
271+
272+
$ gem install bundler
273+
$ bundle install --with=vagrant
274+
$ bin/kitchen test [platform]
275+
276+
Where ``[platform]`` is the platform name defined in ``kitchen.yml``,
277+
e.g. ``windows``.
278+
279+
Note
280+
^^^^
281+
282+
When testing using Vagrant you must set the environment variable ``KITCHEN_LOCAL_YAML`` to ``kitchen.vagrant.yml``. For example:
283+
284+
.. code-block:: bash
285+
286+
$ KITCHEN_LOCAL_YAML=kitchen.vagrant.yml bin/kitchen test # Alternatively,
287+
$ export KITCHEN_LOCAL_YAML=kitchen.vagrant.yml
288+
$ bin/kitchen test
289+
290+
Then run the following commands as needed.
291+
292+
``bin/kitchen converge``
293+
^^^^^^^^^^^^^^^^^^^^^^^^
294+
295+
Creates the Vagrant instance and runs the ``salt.minion`` main state, ready for testing.
296+
297+
``bin/kitchen verify``
298+
^^^^^^^^^^^^^^^^^^^^^^
299+
300+
Runs the ``inspec`` tests on the actual instance.
301+
302+
``bin/kitchen destroy``
303+
^^^^^^^^^^^^^^^^^^^^^^^
304+
305+
Removes the Vagrant instance.
306+
307+
``bin/kitchen test``
308+
^^^^^^^^^^^^^^^^^^^^
309+
310+
Runs all of the stages above in one go: i.e. ``destroy`` + ``converge`` + ``verify`` + ``destroy``.
311+
312+
``bin/kitchen login``
313+
^^^^^^^^^^^^^^^^^^^^^
314+
315+
Gives you RDP access to the instance for manual testing.

kitchen.vagrant.yml

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# -*- coding: utf-8 -*-
2+
# vim: ft=yaml
3+
---
4+
driver:
5+
name: vagrant
6+
7+
platforms:
8+
- name: windows-81
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\salt-minion-py3.sls
17+
source=https://github.com/saltstack/salt-winrepo-ng/raw/master/salt-minion-py3.sls
18+
skip_verify=True makedirs=True
19+
20+
suites:
21+
- name: v3000-py3
22+
provisioner:
23+
state_top:
24+
base:
25+
'*':
26+
- salt.minion
27+
pillars:
28+
top.sls:
29+
base:
30+
'*':
31+
- salt
32+
- v3000-py3
33+
pillars_from_files:
34+
salt.sls: test/salt/pillar/salt.sls
35+
v3000-py3.sls: test/salt/pillar/v3000-py3.sls
36+
verifier:
37+
inspec_tests:
38+
- path: test/integration/v3000-py3

test/integration/v3000-py3/controls/pkgs_spec.rb

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
# frozen_string_literal: true
22

3+
pkgs =
4+
case platform[:family]
5+
when 'windows'
6+
%w[Salt\ Minion]
7+
else
8+
%w[salt-master salt-minion]
9+
end
10+
311
control 'salt packages' do
412
title 'should be installed'
513

614
version = '3000.3'
715

8-
%w[
9-
salt-master
10-
salt-minion
11-
].each do |p|
16+
pkgs.each do |p|
1217
describe package(p) do
1318
it { should be_installed }
1419
its('version') { should match(/^#{version}/) }

test/integration/v3000-py3/controls/service_spec.rb

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
# frozen_string_literal: true
22

3+
services =
4+
case platform[:family]
5+
when 'windows'
6+
%w[salt-minion]
7+
else
8+
%w[salt-master salt-minion]
9+
end
10+
311
control 'salt services' do
412
title 'should be running'
513

6-
%w[
7-
salt-master
8-
salt-minion
9-
].each do |p|
14+
services.each do |p|
1015
describe service(p) do
1116
it { should be_installed }
1217
it { should be_enabled }

test/integration/v3000-py3/inspec.yml

+1
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ supports:
1717
- platform-name: amazon
1818
- platform-name: oracle
1919
- platform-name: arch
20+
- platform: windows

0 commit comments

Comments
 (0)