beaker-testmode_switcher 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e6ae9b72921551c471f35351e450aef008b10f53
4
- data.tar.gz: 825aa5ae1c2dd6decad2b64763149d2e1ac4c124
3
+ metadata.gz: e11986d5a67ffd960f9c786ff8536b2b505d5b81
4
+ data.tar.gz: b0c43f008a61c19804a16f41f3470bcdb7cd4c41
5
5
  SHA512:
6
- metadata.gz: f373d1afbf2f2e985bbf8df6ac7e3e1d1283c1d009bce8697e18bb2df1cd99f3ee2e2ec3d568c42a7227320ed202ea0f0df4d9f5bb2d8bd8bc5b12a61fd51e68
7
- data.tar.gz: 4ccceec2ffa5f6de7992f6e601496cb82b7c4e234107df27f3a9237dded4a405b7f3cd8b8c61993bd458cb8a0e5ae24860773395bb88ffb1f4ab8f7de4c9d0bb
6
+ metadata.gz: 6ed863db3115f3166f1b64ac59e110d5f70652f17a61ea864654c2e710728471acdcaaa7139c1a3c770c889beb6596948dee28b570f09b8b798990f88a8653d8
7
+ data.tar.gz: 6306bad36cc1db0b325b55e5d9a77eb3bee9a75ef504e8f48853bc93956d1b2b9837e50f962fca4be7da59dec79fe09e791e0f5ea46044b12e8a4e929dfb5b72
data/.rubocop.yml CHANGED
@@ -1,4 +1,7 @@
1
1
  # increase the default metric limits to more realistic levels
2
+ Metrics/BlockLength:
3
+ Max: 200
4
+
2
5
  Metrics/LineLength:
3
6
  Max: 200
4
7
 
@@ -25,3 +28,32 @@ Style/PercentLiteralDelimiters:
25
28
  Style/StringLiterals:
26
29
  Enabled: false
27
30
 
31
+ Style/MultilineMethodCallBraceLayout:
32
+ Enabled: false
33
+
34
+ Style/FrozenStringLiteralComment:
35
+ Enabled: false
36
+
37
+ Style/SafeNavigation:
38
+ Enabled: false
39
+
40
+ # Disabling unrealistic rubocop RSpec cops
41
+ RSpec/HookArgument:
42
+ Enabled: false
43
+
44
+ RSpec/InstanceVariable:
45
+ Enabled: false
46
+
47
+ RSpec/NamedSubject:
48
+ Enabled: false
49
+
50
+ RSpec/DescribedClass:
51
+ Enabled: false
52
+
53
+ # We want to call gem files multiple times if they have a ruby version dependency
54
+ Bundler/DuplicatedGem:
55
+ Enabled: false
56
+
57
+ # When there are dependencies we have duplicate gems so they cant be ordered
58
+ Bundler/OrderedGems:
59
+ Enabled: false
data/.travis.yml CHANGED
@@ -2,5 +2,8 @@ language: ruby
2
2
  cache: bundler
3
3
  bundler_args: --without development
4
4
  rvm:
5
- - 2.2.0
6
- - 2.0.0
5
+ - 2.3.1
6
+ - 2.1.6
7
+ env:
8
+ - TEST_FRAMEWORK="beaker-rspec"
9
+ - TEST_FRAMEWORK="beaker"
data/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
1
  # Version 0.1.0
2
2
 
3
3
  Initial release.
4
+
5
+ # 2017-01-19 - Version 0.1.1
6
+ ###Summary
7
+
8
+ This release adds a feature that provides control of specific nodes you would like to run an agent run on. Previously it was only possible to run on the default node.
9
+
10
+ ###Features
11
+ - Add execute_manifest_on() function
12
+ - Add MAINTAINERS file
13
+ - Addressing Rubocop errors
data/Gemfile CHANGED
@@ -3,12 +3,19 @@ source 'https://rubygems.org'
3
3
  gemspec
4
4
 
5
5
  group :test do
6
+ gem 'beaker' if RUBY_VERSION > '2.1.6'
7
+ gem 'beaker', '2.42.0' if RUBY_VERSION <= '2.1.6'
8
+ gem 'bundler', '~> 1.9'
9
+ gem 'rake', '~> 10.0'
10
+ gem 'rspec', '~> 3' unless ENV['TEST_FRAMEWORK'] && ENV['TEST_FRAMEWORK'] == 'beaker' # Don't install rpsec if the module is in beaker only mode
6
11
  gem 'rubocop', require: false
7
12
  end
8
13
 
9
14
  group :development do
10
15
  gem 'guard'
11
16
  gem 'guard-rake'
12
- gem 'guard-rspec'
17
+ gem 'guard-rspec' unless ENV['TEST_FRAMEWORK'] && ENV['TEST_FRAMEWORK'] == 'beaker'
18
+ gem 'listen', '= 3.0.7' # last version to support ruby 1.9; the proper fix would be to not install the development group in our internal CI
19
+ gem 'pry'
13
20
  gem 'pry-coolline'
14
21
  end
data/MAINTAINERS ADDED
@@ -0,0 +1,16 @@
1
+ {
2
+ "version": 1,
3
+ "file_format": "This MAINTAINERS file format is described at http://pup.pt/maintainers",
4
+ "people": [
5
+ {
6
+ "github": "pmcmaw",
7
+ "email": "paula@puppet.com",
8
+ "name": "Paula McMaw"
9
+ },
10
+ {
11
+ "github": "HelenCampbell",
12
+ "email": "helen@puppet.com",
13
+ "name": "Helen Campbell"
14
+ }
15
+ ]
16
+ }
data/README.md CHANGED
@@ -26,18 +26,33 @@ The `BEAKER_TESTMODE` environment variable determines how the tests are run:
26
26
  * `apply`: VMs are provisioned as normal (determined by the nodeset) and tests are run with `puppet apply` on the specified node. This mode only requires a single VM and is great for running the tests in an isolated environment. When the nodeset has more than one node, exactly one has to have the 'default' role assigned. This will be the node to execute the manifests.
27
27
  * `agent`: VMs are provisioned as normal (determined by the nodeset). When running tests, the manifest is uploaded to the master and a full `puppet agent` run is kicked off on the specified node. This mode requires multiple VMs and a more involved provisioning step, but the tests run in a very production-like environment to ensure highest fidelity of the test results. The nodeset needs to contain one node with the 'master' role assigned. This will be the node to receive the manifest. When the nodeset has more than one node, exactly one has to have the 'default' role assigned. This will be the node to execute the puppet agent.
28
28
 
29
+ ## Acceptance tests
30
+
31
+ Beaker and Beaker-rspec frameworks are supported. The environment variable `TEST_FRAMEWORK` MUST be set before the gem/bundle install.
32
+
33
+ The `TEST_FRAMEWORK` environment variable determines the gem support for the test run:
34
+ * `beaker` Beaker only support.
35
+ * `beaker-rspec` Beaker-rspec support.
36
+
37
+ The acceptance tests will immediately fail if the environment variable is not set.
38
+
39
+ To run the tests `bundle exec rake`
40
+
29
41
  ## Reference
30
42
 
31
43
  This experimental version supports only a minimal set of functionality from the beaker DSL:
32
44
 
33
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.
34
46
 
35
- * `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`.
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.
36
48
  `opts` keys:
37
49
  * `:debug`, `:trace`, `:noop`: set to true to enable the puppet option of the same name.
38
50
  * `:dry_run`: set to true to skip executing the actual command.
39
51
  * `:environment`: pass environment variables for the command as a hash.
40
52
 
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
+ `opts` This makes use of `execute_manifest_on(hosts, manifest, opts = {})`.
55
+
41
56
  * `resource(type, name, opts = {})`: Runs `puppet resource` with the specified `type` and `name` arguments.
42
57
  `opts` keys:
43
58
  * `:debug`, `:trace`, `:noop`: set to true to enable the puppet option of the same name.
data/Rakefile CHANGED
@@ -1,13 +1,36 @@
1
1
  require "bundler/gem_tasks"
2
2
 
3
- begin
3
+ def beaker_command
4
+ cmd_parts = []
5
+ cmd_parts << "beaker"
6
+ cmd_parts << "--debug"
7
+ cmd_parts << "--test spec/test"
8
+ cmd_parts << "--load-path lib"
9
+ cmd_parts.flatten.join(" ")
10
+ end
11
+
12
+ if ENV['TEST_FRAMEWORK'] && ENV['TEST_FRAMEWORK'] == 'beaker'
13
+ task spec: [:beaker]
14
+ else
15
+ task spec: [:rspec]
16
+ end
17
+
18
+ task :rspec do
4
19
  require 'rspec/core/rake_task'
5
20
  RSpec::Core::RakeTask.new(:spec)
21
+ end
22
+
23
+ task :beaker do
24
+ abort "Beaker test failed" unless system(beaker_command) == true
25
+ end
6
26
 
27
+ task :rubocop do
7
28
  require 'rubocop/rake_task'
8
29
  RuboCop::RakeTask.new
30
+ end
9
31
 
32
+ begin
10
33
  task default: [:spec, :rubocop]
11
- rescue LoadError # rubocop:disable Lint/HandleExceptions: rspec is optional
12
- # no rspec available
34
+ rescue LoadError => error
35
+ raise "LoadError for default rake target. [#{error}] "
13
36
  end
@@ -6,7 +6,7 @@ require 'beaker/testmode_switcher/version'
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "beaker-testmode_switcher"
8
8
  spec.version = Beaker::TestmodeSwitcher::VERSION
9
- spec.authors = ["Puppet Labs", "David Schmitt", "Gareth Rushgrove", "Greg Hardy"]
9
+ spec.authors = ["Puppet Labs", "David Schmitt", "Gareth Rushgrove", "Greg Hardy", "Paula McMaw"]
10
10
  spec.email = ["modules-team@puppetlabs.com"]
11
11
 
12
12
  spec.summary = "Let's you run your puppet module tests in master/agent, apply or local mode."
@@ -19,9 +19,4 @@ Gem::Specification.new do |spec|
19
19
 
20
20
  spec.add_dependency "beaker"
21
21
  spec.add_dependency "master_manipulator"
22
-
23
- spec.add_development_dependency "bundler", "~> 1.9"
24
- spec.add_development_dependency "pry"
25
- spec.add_development_dependency "rake", "~> 10.0"
26
- spec.add_development_dependency "rspec", "~> 3"
27
22
  end
@@ -7,28 +7,25 @@ module Beaker
7
7
  # returns the current test mode
8
8
  def self.testmode
9
9
  mode = ENV['BEAKER_TESTMODE'] || 'apply'
10
- if %w(apply agent local).include? mode
11
- return mode.to_sym
12
- else
13
- fail ArgumentError, "Unknown BEAKER_TESTMODE supplied: '#{mode}'"
14
- end
10
+ return mode.to_sym if %w(apply agent local).include? mode
11
+ raise ArgumentError, "Unknown BEAKER_TESTMODE supplied: '#{mode}'"
15
12
  end
16
13
 
17
14
  # creates a test runner implementing the specified mode
18
- def self.create_runner(mode)
15
+ def self.create_runner(mode, hosts, logger)
19
16
  case mode
20
17
  when :apply then
21
- BeakerApplyRunner.new
18
+ BeakerApplyRunner.new hosts, logger
22
19
  when :agent then
23
- BeakerAgentRunner.new
20
+ BeakerAgentRunner.new hosts, logger
24
21
  when :local
25
22
  LocalRunner.new
26
23
  end
27
24
  end
28
25
 
29
26
  # returns the current runner
30
- def self.runner
31
- @runner ||= create_runner(testmode)
27
+ def self.runner(hosts, logger)
28
+ @runner ||= create_runner testmode, hosts, logger
32
29
  end
33
30
  end
34
31
  end
@@ -8,14 +8,21 @@ module Beaker
8
8
  class BeakerRunnerBase
9
9
  include Beaker::DSL
10
10
 
11
+ attr_accessor :hosts, :logger
12
+
13
+ def initialize(hosts, logger)
14
+ self.hosts = hosts
15
+ self.logger = logger
16
+ end
17
+
11
18
  # create a remote file (using puppet apply) on the default host
12
19
  def create_remote_file_ex(file_path, file_content, options = {})
13
20
  mode = options[:mode] || '0644'
14
21
  user = options[:user] || 'root'
15
22
  group = options[:group] || 'root'
16
- file_content.gsub!(/\\/, '\\')
17
- file_content.gsub!(/'/, "\\'")
18
- file_content.gsub!(/\n/, '\\n')
23
+ file_content.tr!(/\\/, '\\')
24
+ file_content.tr!(/'/, "\\'")
25
+ file_content.tr!(/\n/, '\\n')
19
26
  apply_manifest_on default, "file { '#{file_path}': ensure => present, content => '#{file_content}', mode => '#{mode}', user => '#{user}', group => '#{group}' }", catch_failures: true
20
27
  end
21
28
 
@@ -44,7 +51,7 @@ module Beaker
44
51
 
45
52
  # copy a file using beaker's scp_to to all hosts
46
53
  def scp_to_ex(from, to)
47
- hosts.each do |host|
54
+ @hosts.each do |host|
48
55
  scp_to host, from, to
49
56
  end
50
57
  end
@@ -63,6 +70,12 @@ module Beaker
63
70
  # upload the manifest to the master and inject it into the site.pp
64
71
  # then run a puppet agent on the default host
65
72
  def execute_manifest(manifest, opts = {})
73
+ execute_manifest_on(default, manifest, opts)
74
+ end
75
+
76
+ # upload the manifest to the master and inject it into the site.pp
77
+ # then run a puppet agent on all hosts
78
+ def execute_manifest_on(hosts, manifest, opts = {})
66
79
  environment_base_path = on(master, puppet('config', 'print', 'environmentpath')).stdout.rstrip
67
80
  prod_env_site_pp_path = File.join(environment_base_path, 'production', 'manifests', 'site.pp')
68
81
  site_pp = create_site_pp(master, manifest: manifest)
@@ -75,12 +88,11 @@ module Beaker
75
88
 
76
89
  # acceptable_exit_codes are passed because we want detailed-exit-codes but want to
77
90
  # make our own assertions about the responses
78
- on(default,
91
+ on(hosts,
79
92
  puppet(*cmd),
80
93
  dry_run: opts[:dry_run],
81
94
  environment: opts[:environment] || {},
82
- acceptable_exit_codes: (0...256)
83
- )
95
+ acceptable_exit_codes: (0...256))
84
96
  end
85
97
  end
86
98
 
@@ -5,9 +5,9 @@ module Beaker
5
5
  # include this module into your namespace to access the DSL parts of TestmodeSwitcher
6
6
  module DSL
7
7
  # pass through methods to the runner
8
- [:create_remote_file_ex, :scp_to_ex, :shell_ex, :resource, :execute_manifest].each do |name|
8
+ [:create_remote_file_ex, :scp_to_ex, :shell_ex, :resource, :execute_manifest, :execute_manifest_on].each do |name|
9
9
  define_method(name) do |*args|
10
- Beaker::TestmodeSwitcher.runner.send(name, *args)
10
+ Beaker::TestmodeSwitcher.runner(hosts, logger).send(name, *args)
11
11
  end
12
12
  end
13
13
  end
@@ -1,6 +1,6 @@
1
1
  module Beaker
2
2
  # central definition of this gem's version
3
3
  module TestmodeSwitcher
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1".freeze
5
5
  end
6
6
  end
metadata CHANGED
@@ -1,102 +1,47 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: beaker-testmode_switcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Puppet Labs
8
8
  - David Schmitt
9
9
  - Gareth Rushgrove
10
10
  - Greg Hardy
11
+ - Paula McMaw
11
12
  autorequire:
12
13
  bindir: exe
13
14
  cert_chain: []
14
- date: 2016-01-06 00:00:00.000000000 Z
15
+ date: 2017-01-19 00:00:00.000000000 Z
15
16
  dependencies:
16
17
  - !ruby/object:Gem::Dependency
17
18
  name: beaker
18
19
  requirement: !ruby/object:Gem::Requirement
19
20
  requirements:
20
- - - '>='
21
+ - - ">="
21
22
  - !ruby/object:Gem::Version
22
23
  version: '0'
23
24
  type: :runtime
24
25
  prerelease: false
25
26
  version_requirements: !ruby/object:Gem::Requirement
26
27
  requirements:
27
- - - '>='
28
+ - - ">="
28
29
  - !ruby/object:Gem::Version
29
30
  version: '0'
30
31
  - !ruby/object:Gem::Dependency
31
32
  name: master_manipulator
32
33
  requirement: !ruby/object:Gem::Requirement
33
34
  requirements:
34
- - - '>='
35
+ - - ">="
35
36
  - !ruby/object:Gem::Version
36
37
  version: '0'
37
38
  type: :runtime
38
39
  prerelease: false
39
40
  version_requirements: !ruby/object:Gem::Requirement
40
41
  requirements:
41
- - - '>='
42
+ - - ">="
42
43
  - !ruby/object:Gem::Version
43
44
  version: '0'
44
- - !ruby/object:Gem::Dependency
45
- name: bundler
46
- requirement: !ruby/object:Gem::Requirement
47
- requirements:
48
- - - ~>
49
- - !ruby/object:Gem::Version
50
- version: '1.9'
51
- type: :development
52
- prerelease: false
53
- version_requirements: !ruby/object:Gem::Requirement
54
- requirements:
55
- - - ~>
56
- - !ruby/object:Gem::Version
57
- version: '1.9'
58
- - !ruby/object:Gem::Dependency
59
- name: pry
60
- requirement: !ruby/object:Gem::Requirement
61
- requirements:
62
- - - '>='
63
- - !ruby/object:Gem::Version
64
- version: '0'
65
- type: :development
66
- prerelease: false
67
- version_requirements: !ruby/object:Gem::Requirement
68
- requirements:
69
- - - '>='
70
- - !ruby/object:Gem::Version
71
- version: '0'
72
- - !ruby/object:Gem::Dependency
73
- name: rake
74
- requirement: !ruby/object:Gem::Requirement
75
- requirements:
76
- - - ~>
77
- - !ruby/object:Gem::Version
78
- version: '10.0'
79
- type: :development
80
- prerelease: false
81
- version_requirements: !ruby/object:Gem::Requirement
82
- requirements:
83
- - - ~>
84
- - !ruby/object:Gem::Version
85
- version: '10.0'
86
- - !ruby/object:Gem::Dependency
87
- name: rspec
88
- requirement: !ruby/object:Gem::Requirement
89
- requirements:
90
- - - ~>
91
- - !ruby/object:Gem::Version
92
- version: '3'
93
- type: :development
94
- prerelease: false
95
- version_requirements: !ruby/object:Gem::Requirement
96
- requirements:
97
- - - ~>
98
- - !ruby/object:Gem::Version
99
- version: '3'
100
45
  description:
101
46
  email:
102
47
  - modules-team@puppetlabs.com
@@ -104,14 +49,15 @@ executables: []
104
49
  extensions: []
105
50
  extra_rdoc_files: []
106
51
  files:
107
- - .gitignore
108
- - .rspec
109
- - .rubocop.yml
110
- - .travis.yml
52
+ - ".gitignore"
53
+ - ".rspec"
54
+ - ".rubocop.yml"
55
+ - ".travis.yml"
111
56
  - CHANGELOG.md
112
57
  - Gemfile
113
58
  - Guardfile
114
59
  - LICENSE
60
+ - MAINTAINERS
115
61
  - README.md
116
62
  - Rakefile
117
63
  - beaker-testmode_switcher.gemspec
@@ -131,17 +77,17 @@ require_paths:
131
77
  - lib
132
78
  required_ruby_version: !ruby/object:Gem::Requirement
133
79
  requirements:
134
- - - '>='
80
+ - - ">="
135
81
  - !ruby/object:Gem::Version
136
82
  version: '0'
137
83
  required_rubygems_version: !ruby/object:Gem::Requirement
138
84
  requirements:
139
- - - '>='
85
+ - - ">="
140
86
  - !ruby/object:Gem::Version
141
87
  version: '0'
142
88
  requirements: []
143
89
  rubyforge_project:
144
- rubygems_version: 2.0.14
90
+ rubygems_version: 2.6.8
145
91
  signing_key:
146
92
  specification_version: 4
147
93
  summary: Let's you run your puppet module tests in master/agent, apply or local mode.