diff --git a/.fixtures.yml b/.fixtures.yml new file mode 100644 index 00000000..73aadb36 --- /dev/null +++ b/.fixtures.yml @@ -0,0 +1,12 @@ +--- +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' + 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 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/.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 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 +``` + + diff --git a/metadata.json b/metadata.json index 7e304f2b..836a905f 100644 --- a/metadata.json +++ b/metadata.json @@ -51,7 +51,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" } 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 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_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 diff --git a/spec/spec_helper_acceptance_local.rb b/spec/spec_helper_acceptance_local.rb new file mode 100644 index 00000000..68937dca --- /dev/null +++ b/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