beaker-testmode_switcher 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -2
- data/README.md +15 -2
- data/lib/beaker/testmode_switcher/beaker_runners.rb +17 -11
- data/lib/beaker/testmode_switcher/local_runner.rb +7 -2
- data/lib/beaker/testmode_switcher/runner_base.rb +35 -0
- data/lib/beaker/testmode_switcher/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0b6fa280da0e2d74f94c99172bbdc84a0fd136eb
|
4
|
+
data.tar.gz: b7d5add69806870c20e23ee07e24412678c98dae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 43b4c25be5bdd16a76c56d57e7e8935ccc5e58cb83fa275f57404fc20218d8f93c876389ed5e367d99622fdf161313f0a6922d54efb1f1bfc5fde0242f6318d2
|
7
|
+
data.tar.gz: bb9b824bfd40e4dd11da7ca1bf3948cc83a3c1b61ab97c89ab96c48f706aec78f2f183418020ec3d0bd72d1b7c1a1a323f1b52063bf49ca7f0cd2e31ef3f4617
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,10 @@
|
|
1
|
-
# Version 0.
|
1
|
+
# 2017-03-03 Version 0.2.0
|
2
|
+
### Summary
|
3
|
+
Make use of catch_changes, catch_failures, expect_changes and expect_failures. This makes beaker-testmode_switcher easier to integrate into modules.
|
2
4
|
|
3
|
-
|
5
|
+
### Features
|
6
|
+
- Implement catch_changes, catch_failures, expect_changes and expect_failures in beaker_runners
|
7
|
+
- Fix docs issue where `execute_manifest` options were listed under `resource
|
4
8
|
|
5
9
|
# 2017-01-19 - Version 0.1.1
|
6
10
|
###Summary
|
@@ -11,3 +15,7 @@ This release adds a feature that provides control of specific nodes you would li
|
|
11
15
|
- Add execute_manifest_on() function
|
12
16
|
- Add MAINTAINERS file
|
13
17
|
- Addressing Rubocop errors
|
18
|
+
|
19
|
+
# Version 0.1.0
|
20
|
+
|
21
|
+
Initial release.
|
data/README.md
CHANGED
@@ -45,13 +45,26 @@ This experimental version supports only a minimal set of functionality from the
|
|
45
45
|
* `create_remote_file_ex(file_path, file_content, opts = {})`: Creates a file at `file_path` with the content specified in `file_content` on the default node. `opts` can have the keys `:mode`, `:user`, and `:group` to specify the permissions, owner, and group respectively.
|
46
46
|
|
47
47
|
* `execute_manifest_on(hosts, manifest, opts = {})`: Execute the manifest on all nodes. This will only work when `BEAKER_TESTMODE`, is set to `agent` and it will run a `puppet agent` run.
|
48
|
+
|
48
49
|
`opts` keys:
|
49
50
|
* `:debug`, `:trace`, `:noop`: set to true to enable the puppet option of the same name.
|
50
51
|
* `:dry_run`: set to true to skip executing the actual command.
|
51
52
|
* `:environment`: pass environment variables for the command as a hash.
|
53
|
+
* `:catch_failures` enables detailed exit codes and causes a test failure if the puppet run indicates there was a failure during its execution.
|
54
|
+
* `:catch_changes` enables detailed exit codes and causes a test failure if the puppet run indicates that there were changes or failures during its execution.
|
55
|
+
* `:expect_changes` enables detailed exit codes and causes a test failure if the puppet run indicates that there were no resource changes during its execution.
|
56
|
+
* `:expect_failures` enables detailed exit codes and causes a test failure if the puppet run indicates there were no failure during its execution.
|
52
57
|
|
53
|
-
* `execute_manifest(manifest, opts = {})`: Execute the manifest on the default node. Depending on the `BEAKER_TESTMODE` environment variable, this may use `puppet agent` or `puppet apply`.
|
54
|
-
|
58
|
+
* `execute_manifest(manifest, opts = {})`: Execute the manifest on the default node. Depending on the `BEAKER_TESTMODE` environment variable, this may use `puppet agent` or `puppet apply`. Calls execute_manifest_on when `BEAKER_TESTMODE`=`agent`
|
59
|
+
|
60
|
+
`opts` keys:
|
61
|
+
* `:debug`, `:trace`, `:noop`: set to true to enable the puppet option of the same name.
|
62
|
+
* `:dry_run`: set to true to skip executing the actual command.
|
63
|
+
* `:environment`: pass environment variables for the command as a hash.
|
64
|
+
* `:catch_failures` enables detailed exit codes and causes a test failure if the puppet run indicates there was a failure during its execution.
|
65
|
+
* `:catch_changes` enables detailed exit codes and causes a test failure if the puppet run indicates that there were changes or failures during its execution.
|
66
|
+
* `:expect_changes` enables detailed exit codes and causes a test failure if the puppet run indicates that there were no resource changes during its execution.
|
67
|
+
* `:expect_failures` enables detailed exit codes and causes a test failure if the puppet run indicates there were no failure during its execution.
|
55
68
|
|
56
69
|
* `resource(type, name, opts = {})`: Runs `puppet resource` with the specified `type` and `name` arguments.
|
57
70
|
`opts` keys:
|
@@ -1,11 +1,12 @@
|
|
1
1
|
require 'beaker'
|
2
2
|
require 'shellwords'
|
3
3
|
require 'open3'
|
4
|
+
require_relative 'runner_base'
|
4
5
|
|
5
6
|
module Beaker
|
6
7
|
module TestmodeSwitcher
|
7
8
|
# Re-used functionality for all beaker runners
|
8
|
-
class BeakerRunnerBase
|
9
|
+
class BeakerRunnerBase < RunnerBase
|
9
10
|
include Beaker::DSL
|
10
11
|
|
11
12
|
attr_accessor :hosts, :logger
|
@@ -81,18 +82,21 @@ module Beaker
|
|
81
82
|
site_pp = create_site_pp(master, manifest: manifest)
|
82
83
|
inject_site_pp(master, prod_env_site_pp_path, site_pp)
|
83
84
|
|
84
|
-
cmd = ['agent', '--test', '--environment production']
|
85
|
+
cmd = ['agent', '--test', '--environment production', '--detailed-exitcodes']
|
85
86
|
cmd << "--debug" if opts[:debug]
|
86
87
|
cmd << "--noop" if opts[:noop]
|
87
88
|
cmd << "--trace" if opts[:trace]
|
88
89
|
|
89
90
|
# acceptable_exit_codes are passed because we want detailed-exit-codes but want to
|
90
91
|
# make our own assertions about the responses
|
91
|
-
on(hosts,
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
92
|
+
res = on(hosts,
|
93
|
+
puppet(*cmd),
|
94
|
+
dry_run: opts[:dry_run],
|
95
|
+
environment: opts[:environment] || {},
|
96
|
+
acceptable_exit_codes: (0...256))
|
97
|
+
|
98
|
+
handle_puppet_run_returned_exit_code(get_acceptable_puppet_run_exit_codes(opts), res.exit_code)
|
99
|
+
res
|
96
100
|
end
|
97
101
|
end
|
98
102
|
|
@@ -102,16 +106,18 @@ module Beaker
|
|
102
106
|
def execute_manifest(manifest, opts = {})
|
103
107
|
# acceptable_exit_codes and expect_changes are passed because we want detailed-exit-codes but want to
|
104
108
|
# make our own assertions about the responses
|
105
|
-
apply_manifest(
|
109
|
+
res = apply_manifest(
|
106
110
|
manifest,
|
107
|
-
expect_changes: true,
|
108
111
|
debug: opts[:debug],
|
109
112
|
dry_run: opts[:dry_run],
|
110
113
|
environment: opts[:environment] || {},
|
111
114
|
noop: opts[:noop],
|
112
115
|
trace: opts[:trace],
|
113
|
-
|
114
|
-
|
116
|
+
expect_failures: true,
|
117
|
+
acceptable_exit_codes: (0...256))
|
118
|
+
|
119
|
+
handle_puppet_run_returned_exit_code(get_acceptable_puppet_run_exit_codes(opts), res.exit_code)
|
120
|
+
res
|
115
121
|
end
|
116
122
|
end
|
117
123
|
end
|
@@ -1,10 +1,11 @@
|
|
1
1
|
require 'shellwords'
|
2
2
|
require 'open3'
|
3
|
+
require_relative 'runner_base'
|
3
4
|
|
4
5
|
module Beaker
|
5
6
|
module TestmodeSwitcher
|
6
7
|
# All functionality specific to running in 'local' mode
|
7
|
-
class LocalRunner
|
8
|
+
class LocalRunner < RunnerBase
|
8
9
|
# creates the file on the local machine and adjusts permissions
|
9
10
|
# the opts hash allows the following keys: :mode, :user, :group
|
10
11
|
def create_remote_file_ex(file_path, file_content, opts = {})
|
@@ -31,7 +32,11 @@ module Beaker
|
|
31
32
|
cmd << "--debug" if opts[:debug]
|
32
33
|
cmd << "--noop" if opts[:noop]
|
33
34
|
cmd << "--trace" if opts[:trace]
|
34
|
-
|
35
|
+
|
36
|
+
res = use_local_shell(cmd.join(' '), opts)
|
37
|
+
handle_puppet_run_returned_exit_code(get_acceptable_puppet_run_exit_codes(opts), res.exit_code)
|
38
|
+
|
39
|
+
res
|
35
40
|
end
|
36
41
|
|
37
42
|
# build and execute complex puppet resource commands locally
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Beaker
|
2
|
+
module TestmodeSwitcher
|
3
|
+
# A standard error to be raised by runner classes when an unexpected exit code is returned
|
4
|
+
class UnacceptableExitCodeError < RuntimeError
|
5
|
+
end
|
6
|
+
|
7
|
+
# Contains functions used in both local runner and beaker runners
|
8
|
+
class RunnerBase
|
9
|
+
def get_acceptable_puppet_run_exit_codes(opts = {})
|
10
|
+
# Ensure only one option given
|
11
|
+
if [opts[:catch_changes], opts[:catch_failures], opts[:expect_failures], opts[:expect_changes]].compact.length > 1
|
12
|
+
raise(ArgumentError,
|
13
|
+
'Cannot specify more than one of `catch_failures`, \
|
14
|
+
`catch_changes`, `expect_failures`, or `expect_changes` \
|
15
|
+
for a single manifest')
|
16
|
+
end
|
17
|
+
|
18
|
+
# Return appropriate exit code
|
19
|
+
return [0] if opts[:catch_changes]
|
20
|
+
return [0, 2] if opts[:catch_failures]
|
21
|
+
return [1, 4, 6] if opts[:expect_failures]
|
22
|
+
return [2] if opts[:expect_changes]
|
23
|
+
|
24
|
+
# If no option supplied, return all exit codes, as an array,
|
25
|
+
# as acceptable so beaker returns a detailed output
|
26
|
+
(0...256)
|
27
|
+
end
|
28
|
+
|
29
|
+
def handle_puppet_run_returned_exit_code(acceptable_exit_codes, returned_exit_code)
|
30
|
+
return if acceptable_exit_codes.include?(returned_exit_code)
|
31
|
+
raise UnacceptableExitCodeError, "Unacceptable exit code returned: #{returned_exit_code}. Acceptable code(s): #{acceptable_exit_codes.join(', ')}"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: beaker-testmode_switcher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Puppet Labs
|
@@ -12,7 +12,7 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: exe
|
14
14
|
cert_chain: []
|
15
|
-
date: 2017-
|
15
|
+
date: 2017-03-03 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: beaker
|
@@ -67,6 +67,7 @@ files:
|
|
67
67
|
- lib/beaker/testmode_switcher/beaker_runners.rb
|
68
68
|
- lib/beaker/testmode_switcher/dsl.rb
|
69
69
|
- lib/beaker/testmode_switcher/local_runner.rb
|
70
|
+
- lib/beaker/testmode_switcher/runner_base.rb
|
70
71
|
- lib/beaker/testmode_switcher/version.rb
|
71
72
|
homepage: https://github.com/puppetlabs/beaker-testmode_switcher
|
72
73
|
licenses: []
|