From d19e5e70a676da3f5d667069e89da159c3d05ed0 Mon Sep 17 00:00:00 2001 From: Adam Buxton Date: Fri, 17 Jan 2020 10:11:06 +0000 Subject: [PATCH 1/9] pdk update --- metadata.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/metadata.json b/metadata.json index ee7a2b0b..f568bbd4 100644 --- a/metadata.json +++ b/metadata.json @@ -49,7 +49,7 @@ "version_requirement": ">= 6.0.2 < 7.0.0" } ], - "pdk-version": "1.13.0", + "pdk-version": "1.15.0", "template-url": "https://github.com/puppetlabs/pdk-templates.git#1.13.0", - "template-ref": "1.13.0-0-g66e1443" + "template-ref": "tags/1.13.0-0-g66e1443" } From 62eaa721d408757e7d572bce5a5488e9c0eacee7 Mon Sep 17 00:00:00 2001 From: Adam Buxton Date: Fri, 17 Jan 2020 10:32:25 +0000 Subject: [PATCH 2/9] litmus config --- .fixtures.yml | 6 ++++++ spec/spec/spec_helper_acceptance_local.rb | 11 +++++++++++ spec/spec_helper_acceptance.rb | 6 ++++++ 3 files changed, 23 insertions(+) create mode 100644 .fixtures.yml create mode 100644 spec/spec/spec_helper_acceptance_local.rb create mode 100644 spec/spec_helper_acceptance.rb diff --git a/.fixtures.yml b/.fixtures.yml new file mode 100644 index 00000000..41807a28 --- /dev/null +++ b/.fixtures.yml @@ -0,0 +1,6 @@ +--- +fixtures: + repositories: + facts: 'https://github.com/puppetlabs/puppetlabs-facts.git' + puppet_agent: 'https://github.com/puppetlabs/puppetlabs-puppet_agent.git' + provision: 'https://github.com/puppetlabs/provision.git' \ No newline at end of file diff --git a/spec/spec/spec_helper_acceptance_local.rb b/spec/spec/spec_helper_acceptance_local.rb new file mode 100644 index 00000000..68937dca --- /dev/null +++ b/spec/spec/spec_helper_acceptance_local.rb @@ -0,0 +1,11 @@ +require 'puppet_litmus' +require 'singleton' + +class Helper + include Singleton + include PuppetLitmus +end + +def some_helper_method + Helper.instance.bolt_run_script('path/to/file') +end \ No newline at end of file diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb new file mode 100644 index 00000000..d0768543 --- /dev/null +++ b/spec/spec_helper_acceptance.rb @@ -0,0 +1,6 @@ +# frozen_string_literal: true + +require 'puppet_litmus' +require 'spec_helper_acceptance_local' if File.file?(File.join(File.dirname(__FILE__), 'spec_helper_acceptance_local.rb')) + +PuppetLitmus.configure! \ No newline at end of file From 5969583c801bed7aa617818153ac8bbe23338235 Mon Sep 17 00:00:00 2001 From: Adam Buxton Date: Fri, 17 Jan 2020 10:57:17 +0000 Subject: [PATCH 3/9] litmus config --- provision.yaml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 provision.yaml diff --git a/provision.yaml b/provision.yaml new file mode 100644 index 00000000..ca016415 --- /dev/null +++ b/provision.yaml @@ -0,0 +1,19 @@ +--- +default: + provisioner: docker + images: ['waffleimage/centos7'] +travis_deb: + provisioner: docker + images: ['debian:8', 'debian:9', 'ubuntu:14.04', 'ubuntu:16.04', 'ubuntu:18.04'] +waffle_deb: + provisioner: docker + images: ['waffleimage/debian8', 'waffleimage/debian9', 'waffleimage/ubuntu14.04', 'waffleimage/ubuntu16.04', 'waffleimage/ubuntu18.04'] +travis_el: + provisioner: docker + images: ['centos:6', 'centos:7', 'oraclelinux:6', 'oraclelinux:7', 'scientificlinux/sl:6', 'scientificlinux/sl:7'] +waffle_el: + provisioner: docker + images: ['waffleimage/centos6', 'waffleimage/centos7', 'waffleimage/oraclelinux6', 'waffleimage/oraclelinux7', 'waffleimage/scientificlinux6', 'waffleimage/scientificlinux7'] +release_checks: + provisioner: vmpooler + images: ['redhat-6-x86_64', 'redhat-7-x86_64', 'centos-6-x86_64', 'centos-7-x86_64', 'oracle-6-x86_64', 'oracle-7-x86_64', 'scientific-6-x86_64', 'scientific-7-x86_64', 'debian-8-x86_64', 'debian-9-x86_64', 'sles-11-x86_64', 'ubuntu-1404-x86_64', 'ubuntu-1604-x86_64', 'ubuntu-1804-x86_64', 'win-2008r2-x86_64', 'win-2012r2-x86_64', 'win-2016-x86_64', 'win-10-pro-x86_64'] \ No newline at end of file From fdb7531f930b29d07b146a9a9fbfdfb8ed4824da Mon Sep 17 00:00:00 2001 From: Adam Buxton Date: Fri, 17 Jan 2020 11:05:46 +0000 Subject: [PATCH 4/9] litmus config bolt.yaml --- bolt.yaml | 1 + 1 file changed, 1 insertion(+) create mode 100644 bolt.yaml diff --git a/bolt.yaml b/bolt.yaml new file mode 100644 index 00000000..ae559bf2 --- /dev/null +++ b/bolt.yaml @@ -0,0 +1 @@ +# this file is here to make bolt behave as if this is a `bolt project` and respect the inventory.yaml you provide for litmus testing. \ No newline at end of file From 542d2efc2d767111b070e966fb9fb94e37bd3c1b Mon Sep 17 00:00:00 2001 From: Adam Buxton Date: Fri, 17 Jan 2020 11:35:53 +0000 Subject: [PATCH 5/9] remove bolt.yaml update .gitignore for litmus --- .gitignore | 1 + bolt.yaml | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) delete mode 100644 bolt.yaml diff --git a/.gitignore b/.gitignore index 2767022c..fbd9ff9b 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,4 @@ .project .envrc /inventory.yaml +.rerun.json \ No newline at end of file diff --git a/bolt.yaml b/bolt.yaml deleted file mode 100644 index ae559bf2..00000000 --- a/bolt.yaml +++ /dev/null @@ -1 +0,0 @@ -# this file is here to make bolt behave as if this is a `bolt project` and respect the inventory.yaml you provide for litmus testing. \ No newline at end of file From 433ace35461dd33f4b799f01ea0d0b848164c789 Mon Sep 17 00:00:00 2001 From: Adam Buxton Date: Fri, 17 Jan 2020 12:03:17 +0000 Subject: [PATCH 6/9] update for litmus config --- .sync.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.sync.yml b/.sync.yml index 32c89d9c..1e643ff6 100644 --- a/.sync.yml +++ b/.sync.yml @@ -2,3 +2,6 @@ Rakefile: extras: - 'PuppetSyntax.exclude_paths = ["plans/**/*.pp", "vendor/**/*"]' +.gitignore: + paths: + - '.rerun.json' \ No newline at end of file From 698b8eec19e5cc30a779b87f3274f5ad8f17b960 Mon Sep 17 00:00:00 2001 From: Adam Buxton Date: Fri, 17 Jan 2020 12:17:26 +0000 Subject: [PATCH 7/9] update dependecies --- .fixtures.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.fixtures.yml b/.fixtures.yml index 41807a28..73aadb36 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -3,4 +3,10 @@ fixtures: repositories: facts: 'https://github.com/puppetlabs/puppetlabs-facts.git' puppet_agent: 'https://github.com/puppetlabs/puppetlabs-puppet_agent.git' - provision: 'https://github.com/puppetlabs/provision.git' \ No newline at end of file + provision: 'https://github.com/puppetlabs/provision.git' + stdlib: 'https://github.com/puppetlabs/puppetlabs-stdlib.git' + node_manager: 'https://github.com/WhatsARanjit/puppet-node_manager' + apply_helpers: 'https://github.com/puppetlabs/puppetlabs-apply_helpers' + bolt_shim: 'https://github.com/puppetlabs/puppetlabs-bolt_shim' + symlinks: + "peadm": "#{source_dir}" \ No newline at end of file From b201d99b4e3ca2e045b064ff97f5fff464c07061 Mon Sep 17 00:00:00 2001 From: Adam Buxton Date: Fri, 17 Jan 2020 13:00:11 +0000 Subject: [PATCH 8/9] erroneus placemnet corrected --- spec/acceptance/peadm_spec.rb | 15 +++++++++++++++ spec/{spec => }/spec_helper_acceptance_local.rb | 0 2 files changed, 15 insertions(+) create mode 100644 spec/acceptance/peadm_spec.rb rename spec/{spec => }/spec_helper_acceptance_local.rb (100%) diff --git a/spec/acceptance/peadm_spec.rb b/spec/acceptance/peadm_spec.rb new file mode 100644 index 00000000..462822f4 --- /dev/null +++ b/spec/acceptance/peadm_spec.rb @@ -0,0 +1,15 @@ +require 'spec_helper_acceptance' +# @summary: default test does nothing +def test_peadm() + + #return unless os[:family] != 'windows' + return unless os[:family] != 'Darwin' +end + +describe 'default' do + context 'example acceptance do nothing' do + it do + test_peadm() + end + end +end \ No newline at end of file diff --git a/spec/spec/spec_helper_acceptance_local.rb b/spec/spec_helper_acceptance_local.rb similarity index 100% rename from spec/spec/spec_helper_acceptance_local.rb rename to spec/spec_helper_acceptance_local.rb From 1b0d5d1e47e4ebab75dd6eabf1c7096cf773fa6f Mon Sep 17 00:00:00 2001 From: Adam Buxton Date: Fri, 17 Jan 2020 15:18:22 +0000 Subject: [PATCH 9/9] initail help doco --- documentation/pre_post_checks.md | 146 +++++++++++++++++++++++++++++++ 1 file changed, 146 insertions(+) create mode 100644 documentation/pre_post_checks.md diff --git a/documentation/pre_post_checks.md b/documentation/pre_post_checks.md new file mode 100644 index 00000000..85760c70 --- /dev/null +++ b/documentation/pre_post_checks.md @@ -0,0 +1,146 @@ +#pre and post flight testing + +The module as been updated to be supported by Puppetlabs [Litmus](https://github.com/puppetlabs/puppet_litmus/wiki/Overview-of-Litmus#provision). + +The module [ServerSpec](https://serverspec.org/) tests for the Bolt Tasks and Plans provided can be used agains a deployment infrastrcuture run as Post flight checks if desired. + +Additionally some stand a lone preflight checks will be added presently. + +## Setup + +The module as been converted to Litmus as the directions found at https://github.com/puppetlabs/puppet_litmus/wiki/Converting-a-module-to-use-Litmus that means the following files have been added. +``` shell +\. +├── spec +│ │ +│ ├── spec_helper_acceptance_local.rb +│ ├── spec_helper.rb +│ └── spec_helper_acceptance.rb +└── provision.yaml +``` + +An update to .gitignore for the Litmus generated `.rerun.json` has also been made via `.sync.yaml` PDK functionality. + +## Usage + +Litmus can provision local testing via provisioning and generation of a Bolt inventory.yaml, see https://github.com/puppetlabs/puppet_litmus/wiki/Tutorial:-use-Litmus-to-execute-acceptance-tests-with-a-sample-module-(MoTD)#provision-a-target-to-test-against for an example. + +### Inventory +when testing locally with Vagrant or VMpooler you can use the `litmus:provision` rake task to generate an inventory.yml. + +You will normally need to create an `inventory.yaml` for your target puppet infrastructure, and you may want to group your puppet infrastructure related to the Puppet Console classification node groups. A possible example `inventory.yaml` is illustrated. + +Note that if you are using Litmus against a host once the agent is installed (not for pre deployment checks of peadm) you will want to add `features: ['puppet-agent']` to your inventory.yaml this resolves several error messages otherwise encountered. + +``` yaml + +--- +groups: +- name: peserver + nodes: + - master.puppet.example.net + features: ['puppet-agent'] + config: + transport: ssh + ssh: + host-key-check: false + user: centos + run-as: root + private-key: "~/.ssh/example.pem" +- name: "compilers" + nodes: + - compiler00.puppet.example.net + features: ['puppet-agent'] + config: + transport: ssh + ssh: + host-key-check: false + user: centos + run-as: root + private-key: "~/.ssh/example.pem" +- name: ha + nodes: + - ha-master.puppet.example.net + features: ['puppet-agent'] + config: + transport: ssh + ssh: + host-key-check: false + user: centos + run-as: root + private-key: "~/.ssh/example.pem" +- name: windowsagents + nodes: + - win0.example.net + features: ['puppet-agent'] + config: + transport: winrm + winrm: + user: domainadminaccount + password: "@example" + ssl: false +- name: linuxagents + nodes: + - nix0.example.net + features: ['puppet-agent'] + config: + transport: ssh + ssh: + host-key-check: false + user: centos + run-as: root + private-key: "~/.ssh/example.pem" +``` + +### Tests and Checks + +One you have the module deployed any Pre or Post deployment checks can be developed as standard ServerSpec tests and orchestrated using Bolt and Litmus. + +A default check exists in `peadm_spec.rb`, note the test is constrained using the os[:family] fact. The example test simply prints it's context and will not fail. + +``` shell +spec +├── acceptance + └── peadm_spec.rb + + +require 'spec_helper_acceptance' +# @summary: default test does nothing +def test_peadm() + + #return unless os[:family] != 'windows' + return unless os[:family] != 'Darwin' +end + +describe 'default' do + context 'example acceptance do nothing' do + it do + test_peadm() + end + end +end + +``` + +For running the tests review the standard usage of Litmusfor installing and running tests https://github.com/puppetlabs/puppet_litmus/wiki/Tutorial:-use-Litmus-to-execute-acceptance-tests-with-a-sample-module-(MoTD)#run-the-tests +remember we are doing these actions from within the context of the PDK `pdk bundle exec rake ` has several sub commands. + +```shell +rake litmus:acceptance: +# Run serverspec against targets:name +rake litmus:acceptance:localhost # Run serverspec against localhost, USE WITH CAUTION, this action can be potentially dangerous +rake litmus:acceptance:parallel # Run tests in parallel against all machines in the inventory file +rake litmus:acceptance:serial # Run tests in serial against all machines in the inventory file +rake litmus:install_agent[collection,target_node_name] # install puppet agent, [:collection, :target_node_name] +rake litmus:install_module[target_node_name] # install_module - build and install module +rake litmus:install_modules_from_directory[source,target_node_name] # install_module - build and install module +rake litmus:metadata # print all supported OSes from metadata +rake litmus:provision[provisioner,platform,inventory_vars] # provision container/VM - abs/docker/vagrant/vmpooler eg 'bundle exec rake 'litmus:provision[vmpooler, ubuntu-160... +rake litmus:provision_install[key,collection] # provision_install - provision a list of machines, install an agent, and the module +rake litmus:provision_list[key] # provision list of machines from provision.yaml file +rake litmus:reinstall_module[target_node_name] # reinstall_module - reinstall module +rake litmus:tear_down[target] # tear-down - decommission machines +rake litmus:uninstall_module[target_node_name,module_name] # uninstall_module - uninstall module +``` + +