Skip to content

basework for https://github.com/puppetlabs/puppetlabs-peadm/issues/50 #52

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Feb 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .fixtures.yml
Original file line number Diff line number Diff line change
@@ -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}"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@
.project
.envrc
/inventory.yaml
.rerun.json
3 changes: 3 additions & 0 deletions .sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
Rakefile:
extras:
- 'PuppetSyntax.exclude_paths = ["plans/**/*.pp", "vendor/**/*"]'
.gitignore:
paths:
- '.rerun.json'
146 changes: 146 additions & 0 deletions documentation/pre_post_checks.md
Original file line number Diff line number Diff line change
@@ -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:<target || nodes>
# 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
```


4 changes: 2 additions & 2 deletions metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
19 changes: 19 additions & 0 deletions provision.yaml
Original file line number Diff line number Diff line change
@@ -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']
15 changes: 15 additions & 0 deletions spec/acceptance/peadm_spec.rb
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions spec/spec_helper_acceptance.rb
Original file line number Diff line number Diff line change
@@ -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!
11 changes: 11 additions & 0 deletions spec/spec_helper_acceptance_local.rb
Original file line number Diff line number Diff line change
@@ -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