Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from abuxton/add-litmus
basework for #50
- Loading branch information
Showing
9 changed files
with
215 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,3 +25,4 @@ | |
.project | ||
.envrc | ||
/inventory.yaml | ||
.rerun.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |