onceover 3.15.2 → 3.16.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -13,6 +13,7 @@ Onceover is a tool to automatically run basic tests on an entire Puppet controlr
13
13
  - [onceover.yaml](#onceoveryaml)
14
14
  - [factsets](#factsets)
15
15
  - [Hiera Data](#hiera-data)
16
+ - [r10k](#r10k)
16
17
  - [Spec testing](#spec-testing)
17
18
  - [Adding your own spec tests](#adding-your-own-spec-tests)
18
19
  - [Using Workarounds](#using-workarounds)
@@ -272,6 +273,21 @@ If you have hiera data inside your controlrepo (or somewhere else) Onceover can
272
273
 
273
274
  It is also worth noting that any hiera hierarchies that are based on custom facts will not work unless those facts are part of your factsets. Trusted facts will also not work at all as the catalogs are being compiled without the node's certificate. In these instances it may be worth creating a hierarchy level that simply includes dummy data for testing purposes in order to avoid hiera lookup errors.
274
275
 
276
+ ### r10k
277
+
278
+ If you have custom r10k config that you want to use, place the `r10k.yaml` file in one of the following locations:
279
+
280
+ - `{repo root}/r10k.yaml`
281
+ - `{repo root}/spec/r10k.yaml`
282
+
283
+ A good use of this is [enabling multi threading](https://github.com/puppetlabs/r10k/blob/master/doc/dynamic-environments/configuration.mkd#pool_size) by creating the following in `r10k.yaml`:
284
+
285
+ ```yaml
286
+ # spec/r10k.yaml
287
+ ---
288
+ pool_size: 20
289
+ ```
290
+
275
291
  #### Creating the config file
276
292
 
277
293
  If your `hiera.yaml` is version 4 or 5 and lives in the root of the controlrepo (as it should), Onceover will pick this up automatically. If you would like to make changes to this file for testing purposes, create a copy under `spec/hiera.yaml`. Onceover will use this version of the hiera config file first if it exists.
data/bin/onceover CHANGED
@@ -6,12 +6,12 @@ require 'colored'
6
6
  begin
7
7
  Onceover::CLI.command.run(ARGV)
8
8
  rescue Interrupt
9
- $stderr.puts "Aborted!".red
9
+ warn "Aborted!".red
10
10
  exit(1)
11
11
  rescue SystemExit => e
12
12
  exit(e.status)
13
13
  rescue Exception => e
14
- $stderr.puts "\nError while running: #{e.inspect}".red
15
- $stderr.puts e.backtrace.join("\n").red if ARGV.include? '--trace'
14
+ warn "\nError while running: #{e.inspect}".red
15
+ warn e.backtrace.join("\n").red if ARGV.include? '--trace'
16
16
  exit(1)
17
17
  end
data/features/run.feature CHANGED
@@ -27,6 +27,11 @@ Feature: Run rspec and acceptance test suites
27
27
  When I run onceover command "run spec"
28
28
  Then I should see message pattern "apache::params"
29
29
 
30
+ Scenario: Checking that r10k config works
31
+ Given initialized control repo "caching"
32
+ When I run onceover command "run spec --debug"
33
+ Then I should see message pattern "r10k.yaml"
34
+
30
35
  Scenario: Run spec tests with misspelled module in Puppetfile
31
36
  Given initialized control repo "basic"
32
37
  And in Puppetfile is misspelled module's name
@@ -26,7 +26,7 @@ Given(/^control repo "([^"]*)" without "([^"]*)"$/) do |controlrepo_name, filena
26
26
  end
27
27
 
28
28
  When(/^I run onceover command "([^"]*)"$/) do |command|
29
- @cmd.command = command
29
+ @cmd.command = "#{command} --debug"
30
30
  puts @cmd
31
31
  @cmd.run
32
32
  end
@@ -1,3 +1,6 @@
1
+ # rubocop:disable Style/RescueStandardError
2
+ # ^^ I canlt be bothered fixing this because all of this code is deprecated
3
+
1
4
  class Onceover
2
5
  class Beaker
3
6
  # WARNING: All of this functionality is deprecated. It will be left around
@@ -232,7 +235,10 @@ class Onceover
232
235
  end
233
236
 
234
237
  raise "The networkmanager created too many machines! Only expecting one" if hosts.count > 1
238
+
235
239
  @nwm.instance_variable_get(:@hosts)[0]
236
240
  end
237
241
  end
238
242
  end
243
+
244
+ # rubocop:enable Style/RescueStandardError
data/lib/onceover/cli.rb CHANGED
@@ -3,7 +3,7 @@ require 'cri'
3
3
  class Onceover
4
4
  class CLI
5
5
  def self.command
6
- @cmd ||= Cri::Command.define do
6
+ @command ||= Cri::Command.define do
7
7
  name 'onceover'
8
8
  usage 'onceover <subcommand> [options]'
9
9
  summary 'Tool for testing Puppet controlrepos'
@@ -9,7 +9,7 @@ class Onceover
9
9
  class CLI
10
10
  class Init
11
11
  def self.command
12
- @cmd ||= Cri::Command.define do
12
+ @command ||= Cri::Command.define do
13
13
  name 'init'
14
14
  usage 'init'
15
15
  summary 'Sets up a controlrepo for testing from scratch'
@@ -10,7 +10,7 @@ class Onceover
10
10
  class CLI
11
11
  class Run
12
12
  def self.command
13
- @cmd ||= Cri::Command.define do
13
+ @command ||= Cri::Command.define do
14
14
  name 'run'
15
15
  usage 'run [spec|acceptance]'
16
16
  summary 'Runs either the spec or acceptance tests'
@@ -35,7 +35,7 @@ This includes deploying using r10k and running all custom tests.
35
35
 
36
36
  class Spec
37
37
  def self.command
38
- @cmd ||= Cri::Command.define do
38
+ @command ||= Cri::Command.define do
39
39
  name 'spec'
40
40
  usage 'spec'
41
41
  summary 'Runs spec tests'
@@ -56,7 +56,7 @@ This includes deploying using r10k and running all custom tests.
56
56
 
57
57
  class Acceptance
58
58
  def self.command
59
- @cmd ||= Cri::Command.define do
59
+ @command ||= Cri::Command.define do
60
60
  name 'acceptance'
61
61
  usage 'acceptance'
62
62
  summary 'Runs acceptance tests'
@@ -7,7 +7,7 @@ class Onceover
7
7
  class CLI
8
8
  class Show
9
9
  def self.command
10
- @cmd ||= Cri::Command.define do
10
+ @command ||= Cri::Command.define do
11
11
  name 'show'
12
12
  usage 'show [controlrepo|puppetfile]'
13
13
  summary 'Shows the current state of things'
@@ -25,7 +25,7 @@ Shows the state of either the controlrepo or the Puppetfile
25
25
 
26
26
  class Repo
27
27
  def self.command
28
- @cmd ||= Cri::Command.define do
28
+ @command ||= Cri::Command.define do
29
29
  name 'repo'
30
30
  usage 'repo [options]'
31
31
  summary 'Shows the current state of the Controlrepo'
@@ -50,7 +50,7 @@ Useful for debugging.
50
50
 
51
51
  class Puppetfile
52
52
  def self.command
53
- @cmd ||= Cri::Command.define do
53
+ @command ||= Cri::Command.define do
54
54
  name 'puppetfile'
55
55
  usage 'puppetfile [options]'
56
56
  summary 'Shows the current state of the puppetfile'
@@ -7,7 +7,7 @@ class Onceover
7
7
  class CLI
8
8
  class Update
9
9
  def self.command
10
- @cmd ||= Cri::Command.define do
10
+ @command ||= Cri::Command.define do
11
11
  name 'update'
12
12
  usage 'update puppetfile'
13
13
  summary 'Updates stuff, currently only the Puppetfile'
@@ -22,7 +22,7 @@ class Onceover
22
22
 
23
23
  class Puppetfile
24
24
  def self.command
25
- @cmd ||= Cri::Command.define do
25
+ @command ||= Cri::Command.define do
26
26
  name 'puppetfile'
27
27
  usage 'puppetfile'
28
28
  summary 'Update all modules in the Puppetfile'
@@ -3,7 +3,6 @@ require 'erb'
3
3
  require 'yaml'
4
4
  require 'find'
5
5
  require 'pathname'
6
- require 'thread'
7
6
  require 'multi_json'
8
7
  require 'onceover/beaker'
9
8
  require 'onceover/logger'
@@ -115,7 +114,7 @@ class Onceover
115
114
  @environment_conf = opts[:environment_conf] || File.expand_path('./environment.conf', @root)
116
115
  @spec_dir = opts[:spec_dir] || File.expand_path('./spec', @root)
117
116
  @facts_dir = opts[:facts_dir] || File.expand_path('factsets', @spec_dir)
118
- _facts_dirs = [@facts_dir, File.expand_path('../../../factsets', __FILE__)]
117
+ _facts_dirs = [@facts_dir, File.expand_path('../../factsets', __dir__)]
119
118
  _facts_files = opts[:facts_files] || _facts_dirs.map{|d| File.join(d, '*.json')}
120
119
  @facts_files = _facts_files.map{|_path| Dir[_path]}.flatten
121
120
 
@@ -134,7 +133,7 @@ class Onceover
134
133
  def to_s
135
134
  require 'colored'
136
135
 
137
- <<-END.gsub(/^\s{4}/,'')
136
+ <<-REPO.gsub(/^\s{4}/,'')
138
137
  #{'puppetfile'.green} #{@puppetfile}
139
138
  #{'environment_conf'.green} #{@environment_conf}
140
139
  #{'facts_dir'.green} #{@facts_dir}
@@ -144,7 +143,7 @@ class Onceover
144
143
  #{'roles'.green} #{roles}
145
144
  #{'profiles'.green} #{profiles}
146
145
  #{'onceover.yaml'.green} #{@onceover_yaml}
147
- END
146
+ REPO
148
147
  end
149
148
 
150
149
  def roles
@@ -190,6 +189,7 @@ class Onceover
190
189
  if filter
191
190
  # Allow us to pass a hash of facts to filter by
192
191
  raise "Filter param must be a hash" unless filter.is_a?(Hash)
192
+
193
193
  all_facts.keep_if do |hash|
194
194
  matches = []
195
195
  filter.each do |filter_fact,value|
@@ -254,13 +254,15 @@ class Onceover
254
254
 
255
255
  threads.map(&:join)
256
256
 
257
- tp output_array,
257
+ tp(
258
+ output_array,
258
259
  {:full_name => {:display_name => "Full Name"}},
259
260
  {:current_version => {:display_name => "Current Version"}},
260
261
  {:latest_version => {:display_name => "Latest Version"}},
261
262
  {:out_of_date => {:display_name => "Out of Date?"}},
262
263
  {:endorsement => {:display_name => "Endorsement"}},
263
264
  {:superseded_by => {:display_name => "Superseded by"}}
265
+ )
264
266
  end
265
267
 
266
268
  def update_puppetfile
@@ -305,6 +307,7 @@ class Onceover
305
307
  # Load up the Puppetfile using R10k
306
308
  puppetfile = R10K::Puppetfile.new(@root)
307
309
  fail 'Could not load Puppetfile' unless puppetfile.load
310
+
308
311
  modules = puppetfile.modules
309
312
 
310
313
  # Iterate over everything and seperate it out for the sake of readability
@@ -395,6 +398,7 @@ class Onceover
395
398
  possibe_datadirs = Dir["#{@root}/*/"]
396
399
  possibe_datadirs.keep_if { |dir| dir =~ /hiera(?:.*data)?/i }
397
400
  raise "There were too many directories that looked like hiera data: #{possibe_datadirs}" if possibe_datadirs.count > 1
401
+
398
402
  File.expand_path(possibe_datadirs[0])
399
403
  end
400
404
 
@@ -417,7 +421,7 @@ class Onceover
417
421
  # Finally, split the modulepath values and return
418
422
  begin
419
423
  environment_config['modulepath'] = environment_config['modulepath'].split(':')
420
- rescue
424
+ rescue StandardError
421
425
  raise "modulepath was not found in environment.conf, don't know where to look for roles & profiles"
422
426
  end
423
427
 
@@ -118,8 +118,10 @@ class Onceover
118
118
  prod_dir = "#{repo.tempdir}/#{repo.environmentpath}/production"
119
119
  Dir.chdir(prod_dir) do
120
120
  install_cmd = []
121
- install_cmd << "r10k puppetfile install --verbose --color --puppetfile #{repo.puppetfile}"
121
+ install_cmd << "r10k puppetfile install --color --puppetfile #{repo.puppetfile}"
122
122
  install_cmd << "--force" if force
123
+ install_cmd << "--config #{repo.r10k_config_file}" if repo.r10k_config_file
124
+ install_cmd << (logger.level > 0 ? "--verbose" : "--verbose debug") # Enable debugging if we're debugging
123
125
  install_cmd = install_cmd.join(' ')
124
126
  logger.debug "Running #{install_cmd} from #{prod_dir}"
125
127
  system(install_cmd)
@@ -71,7 +71,7 @@ class Onceover
71
71
  else
72
72
  return false
73
73
  end
74
- rescue
74
+ rescue StandardErroor
75
75
  return false
76
76
  end
77
77
  end
@@ -4,7 +4,8 @@ module Onceover::Logger
4
4
  def logger
5
5
  unless $logger
6
6
  # here we setup a color scheme called 'bright'
7
- Logging.color_scheme('bright',
7
+ Logging.color_scheme(
8
+ 'bright',
8
9
  :levels => {
9
10
  :debug => :cyan,
10
11
  :info => :green,
@@ -8,9 +8,10 @@ require 'pathname'
8
8
  desc 'Writes a `fixtures.yml` file based on the Puppetfile'
9
9
  task :generate_fixtures do
10
10
  repo = Onceover::Controlrepo.new
11
- if File.exists?(File.expand_path('./.fixtures.yml', repo.root))
11
+ if File.exist?(File.expand_path('./.fixtures.yml', repo.root))
12
12
  raise ".fixtures.yml already exits, we won't overwrite because we are scared"
13
13
  end
14
+
14
15
  File.write(File.expand_path('./.fixtures.yml', repo.root), repo.fixtures)
15
16
  end
16
17
 
@@ -2,8 +2,14 @@ require 'rspec'
2
2
  require 'pathname'
3
3
 
4
4
  class OnceoverFormatter
5
- RSpec::Core::Formatters.register self, :example_group_started,
6
- :example_passed, :example_failed, :example_pending, :dump_failures#, :dump_summary
5
+ RSpec::Core::Formatters.register(
6
+ self,
7
+ :example_group_started,
8
+ :example_passed,
9
+ :example_failed,
10
+ :example_pending,
11
+ :dump_failures,
12
+ )
7
13
 
8
14
  COMPILATION_ERROR = %r{error during compilation: (?<error>.*)}
9
15
  ERROR_WITH_LOCATION = %r{(?<error>.*?)\s(at )?(\((file: (?<file>.*?), )?line: (?<line>\d+)(, column: (?<column>\d+))?\))(; )?}
@@ -218,8 +224,14 @@ end
218
224
  class OnceoverFormatterParallel < OnceoverFormatter
219
225
  require 'yaml'
220
226
 
221
- RSpec::Core::Formatters.register self, :example_group_started,
222
- :example_passed, :example_failed, :example_pending, :dump_failures
227
+ RSpec::Core::Formatters.register(
228
+ self,
229
+ :example_group_started,
230
+ :example_passed,
231
+ :example_failed,
232
+ :example_pending,
233
+ :dump_failures,
234
+ )
223
235
 
224
236
  def example_group_started notification
225
237
  # Do nothing
@@ -287,7 +299,7 @@ class FailureCollector
287
299
  end
288
300
 
289
301
  def dump_failures(failures)
290
- open(File.expand_path("#{RSpec.configuration.onceover_tempdir}/failures.out"), 'a') { |f|
302
+ File.open(File.expand_path("#{RSpec.configuration.onceover_tempdir}/failures.out"), 'a') { |f|
291
303
  failures.failed_examples.each do |fe|
292
304
  f.puts
293
305
  f.puts "#{fe.metadata[:description]}"
@@ -53,8 +53,10 @@ class Onceover
53
53
  @config.acceptance_tests.each { |test| @config.verify_acceptance_test(@repo, test) }
54
54
 
55
55
  # Write them out
56
- @config.write_acceptance_tests("#{@repo.tempdir}/spec/acceptance",
57
- @config.run_filters(Onceover::Test.deduplicate(@config.acceptance_tests)))
56
+ @config.write_acceptance_tests(
57
+ "#{@repo.tempdir}/spec/acceptance",
58
+ @config.run_filters(Onceover::Test.deduplicate(@config.acceptance_tests))
59
+ )
58
60
  end
59
61
 
60
62
  # Parse the current hiera config, modify, and write it to the temp dir
@@ -104,12 +104,12 @@ class Onceover
104
104
  def to_s
105
105
  require 'colored'
106
106
 
107
- <<-END.gsub(/^\s{4}/,'')
107
+ <<-TESTCONF.gsub(/^\s{4}/,'')
108
108
  #{'classes'.green} #{@classes.map{|c|c.name}}
109
109
  #{'nodes'.green} #{@nodes.map{|n|n.name}}
110
110
  #{'class_groups'.green} #{@class_groups}
111
111
  #{'node_groups'.green} #{@node_groups.map{|g|g.name}}
112
- END
112
+ TESTCONF
113
113
  end
114
114
 
115
115
  def self.find_list(thing)
@@ -177,30 +177,38 @@ class Onceover
177
177
  puppetcode << File.read(condition_file)
178
178
  end
179
179
  return nil if puppetcode.count.zero?
180
+
180
181
  puppetcode.join("\n")
181
182
  end
182
183
 
183
184
  def write_spec_test(location, test)
184
185
  # Use an ERB template to write a spec test
185
- File.write("#{location}/#{test.to_s}_spec.rb",
186
- Onceover::Controlrepo.evaluate_template('test_spec.rb.erb', binding))
186
+ File.write(
187
+ "#{location}/#{test.to_s}_spec.rb",
188
+ Onceover::Controlrepo.evaluate_template('test_spec.rb.erb', binding)
189
+ )
187
190
  end
188
191
 
189
192
  def write_acceptance_tests(location, tests)
190
193
  warn "[DEPRECATION] #{__method__} is deprecated due to the removal of Beaker"
191
194
 
192
- File.write("#{location}/acceptance_spec.rb",
195
+ File.write(
196
+ "#{location}/acceptance_spec.rb",
193
197
  Onceover::Controlrepo.evaluate_template('acceptance_test_spec.rb.erb', binding))
194
198
  end
195
199
 
196
200
  def write_spec_helper_acceptance(location, repo)
197
- File.write("#{location}/spec_helper_acceptance.rb",
198
- Onceover::Controlrepo.evaluate_template('spec_helper_acceptance.rb.erb', binding))
201
+ File.write(
202
+ "#{location}/spec_helper_acceptance.rb",
203
+ Onceover::Controlrepo.evaluate_template('spec_helper_acceptance.rb.erb', binding)
204
+ )
199
205
  end
200
206
 
201
207
  def write_rakefile(location, pattern)
202
- File.write("#{location}/Rakefile",
203
- Onceover::Controlrepo.evaluate_template('testconfig_Rakefile.erb', binding))
208
+ File.write(
209
+ "#{location}/Rakefile",
210
+ Onceover::Controlrepo.evaluate_template('testconfig_Rakefile.erb', binding)
211
+ )
204
212
  end
205
213
 
206
214
  def write_spec_helper(location, repo)
@@ -222,8 +230,10 @@ class Onceover
222
230
  repo.temp_modulepath = modulepath
223
231
 
224
232
  # Use an ERB template to write a spec test
225
- File.write("#{location}/spec_helper.rb",
226
- Onceover::Controlrepo.evaluate_template('spec_helper.rb.erb', binding))
233
+ File.write(
234
+ "#{location}/spec_helper.rb",
235
+ Onceover::Controlrepo.evaluate_template('spec_helper.rb.erb', binding)
236
+ )
227
237
  end
228
238
 
229
239
  def create_fixtures_symlinks(repo)
data/onceover.gemspec CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "onceover"
7
- s.version = "3.15.2"
7
+ s.version = "3.16.0"
8
8
  s.authors = ["Dylan Ratcliffe"]
9
9
  s.email = ["dylan.ratcliffe@puppet.com"]
10
10
  s.homepage = "https://github.com/dylanratcliffe/onceover"
@@ -18,28 +18,23 @@ Gem::Specification.new do |s|
18
18
  s.executables = 'onceover'
19
19
 
20
20
  # Runtime dependencies, but also probably dependencies of requiring projects
21
- s.add_runtime_dependency 'rake', '>= 10.0.0'
22
- s.add_runtime_dependency 'multi_json', '~> 1.10'
23
21
  s.add_runtime_dependency 'backticks', '>= 1.0.2'
24
- s.add_runtime_dependency 'rspec-puppet', ">= 2.4.0"
25
- s.add_runtime_dependency 'parallel_tests', ">= 2.0.0"
26
- s.add_runtime_dependency 'puppetlabs_spec_helper', ">= 0.4.0"
27
- s.add_runtime_dependency 'rspec', '>= 3.0.0'
28
- s.add_runtime_dependency 'r10k', '>=2.1.0'
29
- s.add_runtime_dependency 'puppet', '>=3.4.0'
22
+ s.add_runtime_dependency 'colored', '~> 1.2'
23
+ s.add_runtime_dependency 'cri', '>= 2.6'
24
+ s.add_runtime_dependency 'deep_merge', '>= 1.0.0'
30
25
  s.add_runtime_dependency 'facter', '< 4.0.0'
31
26
  s.add_runtime_dependency 'git'
32
- s.add_runtime_dependency 'cri', '>= 2.6'
33
- s.add_runtime_dependency 'colored', '~> 1.2'
34
27
  s.add_runtime_dependency 'logging', '>= 2.0.0'
35
- s.add_runtime_dependency 'deep_merge', '>= 1.0.0'
28
+ s.add_runtime_dependency 'multi_json', '~> 1.10'
29
+ s.add_runtime_dependency 'parallel_tests', ">= 2.0.0"
30
+ s.add_runtime_dependency 'puppet', '>=4.0'
31
+ s.add_runtime_dependency 'puppetlabs_spec_helper', ">= 0.4.0"
32
+ s.add_runtime_dependency 'r10k', '>=2.1.0'
33
+ s.add_runtime_dependency 'rake', '>= 10.0.0'
34
+ s.add_runtime_dependency 'rspec', '>= 3.0.0'
35
+ s.add_runtime_dependency 'rspec-puppet', ">= 2.4.0"
36
+ s.add_runtime_dependency 'rspec_junit_formatter', '>= 0.2.0'
36
37
  s.add_runtime_dependency 'table_print', '>= 1.0.0'
37
38
  s.add_runtime_dependency 'versionomy', '>= 0.5.0'
38
- s.add_runtime_dependency 'rspec_junit_formatter', '>= 0.2.0'
39
39
 
40
- # Development
41
- s.add_development_dependency 'rubocop', '~> 0.49.0'
42
- s.add_development_dependency 'rubygems-tasks', '~> 0.2.0'
43
- s.add_development_dependency 'pry', '~> 0.10.0'
44
- s.add_development_dependency 'cucumber', '~> 2.0'
45
40
  end