From 1eca9c75519d9ad97dc6526fa83a56477da16579 Mon Sep 17 00:00:00 2001 From: Dafydd Jones Date: Thu, 11 Jun 2020 02:16:21 +0100 Subject: [PATCH 1/4] ci(github): add Windows testing using Actions --- .github/workflows/kitchen.yml | 39 ++++++++++++++++++++++++++++++++++ kitchen.github.yml | 40 +++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 .github/workflows/kitchen.yml create mode 100644 kitchen.github.yml diff --git a/.github/workflows/kitchen.yml b/.github/workflows/kitchen.yml new file mode 100644 index 0000000..f910a03 --- /dev/null +++ b/.github/workflows/kitchen.yml @@ -0,0 +1,39 @@ +--- +name: CI + +'on': [push, pull_request] + +env: + machine_user: kitchen + machine_pass: Pass@word1 + machine_port: 5985 + KITCHEN_LOCAL_YAML: kitchen.github.yml + +jobs: + build: + runs-on: windows-latest + + steps: + - uses: actions/checkout@v2 + - uses: actions/cache@v1 + with: + path: vendor/bundle + key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }} + restore-keys: | + ${{ runner.os }}-gems- + - shell: powershell + run: | + $password = ConvertTo-SecureString $env:machine_pass -AsPlainText -Force + New-LocalUser $env:machine_user -Password $password + Add-LocalGroupMember -Group "Administrators" -Member $env:machine_user + - shell: powershell + run: > + Set-WSManQuickConfig -Force; + Set-WSManInstance -ResourceURI winrm/config/service + -ValueSet @{AllowUnencrypted="true"} + - run: gem install bundler --quiet --no-document + - name: Bundle install + run: | + bundle config path vendor/bundle + bundle install --jobs 4 --retry 3 + - run: bundle exec kitchen test diff --git a/kitchen.github.yml b/kitchen.github.yml new file mode 100644 index 0000000..87357fe --- /dev/null +++ b/kitchen.github.yml @@ -0,0 +1,40 @@ +--- +driver: + name: proxy + host: localhost + reset_command: "exit 0" + port: 5985 + username: kitchen + password: Pass@word1 + +platforms: + - name: windows + +provisioner: + salt_install: bootstrap + salt_bootstrap_options: -pythonVersion 3 -version 3000.3 + init_environment: > + C:\salt\salt-call --local state.single file.managed + C:\Users\kitchen\AppData\Local\Temp\kitchen\srv\salt\win\repo-ng\salt-minion-py3.sls + source=https://github.com/saltstack/salt-winrepo-ng/raw/master/salt-minion-py3.sls + skip_verify=True makedirs=True + +suites: + - name: v3000-py3 + provisioner: + state_top: + base: + '*': + - salt.minion + pillars: + top.sls: + base: + '*': + - salt + - v3000-py3 + pillars_from_files: + salt.sls: test/salt/pillar/salt.sls + v3000-py3.sls: test/salt/pillar/v3000-py3.sls + verifier: + inspec_tests: + - path: test/integration/v3000-py3 From 0465af72dac6d8609f918ce32796c91157422358 Mon Sep 17 00:00:00 2001 From: Dafydd Jones Date: Thu, 11 Jun 2020 02:21:18 +0100 Subject: [PATCH 2/4] test(windows): add local testing of Windows using Vagrant/Virtualbox --- Gemfile | 4 ++ docs/README.rst | 62 +++++++++++++++++++ kitchen.vagrant.yml | 38 ++++++++++++ .../v3000-py3/controls/pkgs_spec.rb | 13 ++-- .../v3000-py3/controls/service_spec.rb | 13 ++-- test/integration/v3000-py3/inspec.yml | 1 + 6 files changed, 123 insertions(+), 8 deletions(-) create mode 100644 kitchen.vagrant.yml diff --git a/Gemfile b/Gemfile index 5a232b6..414db6d 100644 --- a/Gemfile +++ b/Gemfile @@ -5,3 +5,7 @@ source 'https://rubygems.org' gem 'kitchen-docker', '>= 2.9' gem 'kitchen-inspec', '>= 1.1' gem 'kitchen-salt', '>= 0.6.0' + +group :vagrant do + gem 'kitchen-vagrant' +end diff --git a/docs/README.rst b/docs/README.rst index fa8d29c..fde8eb3 100644 --- a/docs/README.rst +++ b/docs/README.rst @@ -251,3 +251,65 @@ Runs all of the stages above in one go: i.e. ``destroy`` + ``converge`` + ``veri ^^^^^^^^^^^^^^^^^^^^^ Gives you SSH access to the instance for manual testing. + +Testing with Vagrant +-------------------- + +Windows testing is done with ``kitchen-salt``. + +Requirements +^^^^^^^^^^^^ + +* Ruby +* Virtualbox +* Vagrant + +Setup +^^^^^ + +.. code-block:: bash + + $ gem install bundler + $ bundle install --with=vagrant + $ bin/kitchen test [platform] + +Where ``[platform]`` is the platform name defined in ``kitchen.yml``, +e.g. ``windows``. + +Note +^^^^ + +When testing using Vagrant you must set the environment variable ``KITCHEN_LOCAL_YAML`` to ``kitchen.vagrant.yml``. For example: + +.. code-block:: bash + + $ KITCHEN_LOCAL_YAML=kitchen.vagrant.yml bin/kitchen test # Alternatively, + $ export KITCHEN_LOCAL_YAML=kitchen.vagrant.yml + $ bin/kitchen test + +Then run the following commands as needed. + +``bin/kitchen converge`` +^^^^^^^^^^^^^^^^^^^^^^^^ + +Creates the Vagrant instance and runs the ``salt.minion`` main state, ready for testing. + +``bin/kitchen verify`` +^^^^^^^^^^^^^^^^^^^^^^ + +Runs the ``inspec`` tests on the actual instance. + +``bin/kitchen destroy`` +^^^^^^^^^^^^^^^^^^^^^^^ + +Removes the Vagrant instance. + +``bin/kitchen test`` +^^^^^^^^^^^^^^^^^^^^ + +Runs all of the stages above in one go: i.e. ``destroy`` + ``converge`` + ``verify`` + ``destroy``. + +``bin/kitchen login`` +^^^^^^^^^^^^^^^^^^^^^ + +Gives you RDP access to the instance for manual testing. diff --git a/kitchen.vagrant.yml b/kitchen.vagrant.yml new file mode 100644 index 0000000..3b6cda7 --- /dev/null +++ b/kitchen.vagrant.yml @@ -0,0 +1,38 @@ +# -*- coding: utf-8 -*- +# vim: ft=yaml +--- +driver: + name: vagrant + +platforms: + - name: windows-81 + driver: + box: techneg/win81x64-pro-salt + gui: false + linked_clone: true + provisioner: + init_environment: > + salt-call --local state.single file.managed + C:\Users\vagrant\AppData\Local\Temp\kitchen\srv\salt\win\repo-ng\salt-minion-py3.sls + source=https://github.com/saltstack/salt-winrepo-ng/raw/master/salt-minion-py3.sls + skip_verify=True makedirs=True + +suites: + - name: v3000-py3 + provisioner: + state_top: + base: + '*': + - salt.minion + pillars: + top.sls: + base: + '*': + - salt + - v3000-py3 + pillars_from_files: + salt.sls: test/salt/pillar/salt.sls + v3000-py3.sls: test/salt/pillar/v3000-py3.sls + verifier: + inspec_tests: + - path: test/integration/v3000-py3 diff --git a/test/integration/v3000-py3/controls/pkgs_spec.rb b/test/integration/v3000-py3/controls/pkgs_spec.rb index d583f13..00f1191 100644 --- a/test/integration/v3000-py3/controls/pkgs_spec.rb +++ b/test/integration/v3000-py3/controls/pkgs_spec.rb @@ -1,14 +1,19 @@ # frozen_string_literal: true +pkgs = + case platform[:family] + when 'windows' + %w[Salt\ Minion] + else + %w[salt-master salt-minion] + end + control 'salt packages' do title 'should be installed' version = '3000.3' - %w[ - salt-master - salt-minion - ].each do |p| + pkgs.each do |p| describe package(p) do it { should be_installed } its('version') { should match(/^#{version}/) } diff --git a/test/integration/v3000-py3/controls/service_spec.rb b/test/integration/v3000-py3/controls/service_spec.rb index 9d99883..303b136 100644 --- a/test/integration/v3000-py3/controls/service_spec.rb +++ b/test/integration/v3000-py3/controls/service_spec.rb @@ -1,12 +1,17 @@ # frozen_string_literal: true +services = + case platform[:family] + when 'windows' + %w[salt-minion] + else + %w[salt-master salt-minion] + end + control 'salt services' do title 'should be running' - %w[ - salt-master - salt-minion - ].each do |p| + services.each do |p| describe service(p) do it { should be_installed } it { should be_enabled } diff --git a/test/integration/v3000-py3/inspec.yml b/test/integration/v3000-py3/inspec.yml index c26d2ff..c0da1ca 100644 --- a/test/integration/v3000-py3/inspec.yml +++ b/test/integration/v3000-py3/inspec.yml @@ -17,3 +17,4 @@ supports: - platform-name: amazon - platform-name: oracle - platform-name: arch + - platform: windows From 62f6d39d63cc2e5c134571e20518f7da8c17e09e Mon Sep 17 00:00:00 2001 From: Dafydd Jones Date: Thu, 11 Jun 2020 03:04:24 +0100 Subject: [PATCH 3/4] fix(windows): `py2` should still be default like other platforms * add `-` if someone supplies `py3` in pillar, like other platforms --- salt/osfamilymap.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/salt/osfamilymap.yaml b/salt/osfamilymap.yaml index 8fcba19..1a530d8 100644 --- a/salt/osfamilymap.yaml +++ b/salt/osfamilymap.yaml @@ -127,7 +127,7 @@ OpenBSD: python_git: py-GitPython Windows: - salt_minion: salt-minion{{ py_ver_repr or '-py3' }} + salt_minion: salt-minion{{ '-' ~ py_ver_repr if py_ver_repr else '' }} config_path: 'C:\salt\conf' minion_service: salt-minion From 9a882436245246f2622eaaddc437e2205eaa990b Mon Sep 17 00:00:00 2001 From: Dafydd Jones Date: Tue, 23 Jun 2020 14:52:59 +0100 Subject: [PATCH 4/4] chore(gemfile.lock): update for `kitchen-vagrant` --- Gemfile.lock | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Gemfile.lock b/Gemfile.lock index 6233285..969e3a7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -287,6 +287,8 @@ GEM kitchen-salt (0.6.3) hashie (>= 3.5) test-kitchen (>= 1.4) + kitchen-vagrant (1.6.1) + test-kitchen (>= 1.4, < 3) libyajl2 (1.2.0) license-acceptance (1.0.19) pastel (~> 0.7) @@ -526,6 +528,7 @@ DEPENDENCIES kitchen-docker (>= 2.9) kitchen-inspec (>= 1.1) kitchen-salt (>= 0.6.0) + kitchen-vagrant BUNDLED WITH 2.1.2