reagan 0.6.0 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 38f1709f20a9992d8685abf028ab706efc1fd584
4
- data.tar.gz: a20e5db170d66837c2711e3c9aae10f35616d885
3
+ metadata.gz: e6d0ac4c6953b8002c591704a429494fb946235e
4
+ data.tar.gz: 317e69c6027b0e9bc36b1eb0821480ca754f1f4d
5
5
  SHA512:
6
- metadata.gz: f112be2741f0cd51aaa0db555f011024edaa6d5403d9e59ed58b687c7f65acdb21c386011da6508da874d1e386d5a03c0a87e58bc134b2912557abbf5b0a9db7
7
- data.tar.gz: 399fc3e48f8c2d483eed5fb991f38cacbc54d22d3831ccace9871e68c529257f6eeb5b7ceef6c9af39cb227dd0e5dcae81b9e5074b0c008073c9344a72f2a4e2
6
+ metadata.gz: 96c72971adc53d14935b167ad37c7ec9192d975a07d330b171be8e45b1de19aff8e7099fb699178a64f813efe97366b81701b189393b6360952b2de1374e2cac
7
+ data.tar.gz: 56ccd982033fd749129f4c8296eac63ef4a91b0017cb703cabc7532ce60cea5ba766022a1cff35e382ea3a9f3e873fab46b2d902d397682d21542b77a35a6d0f
data/README.md CHANGED
@@ -1,11 +1,12 @@
1
1
  reagan
2
2
  ======
3
3
 
4
- Trust But Verify - Ruby Jenkins build script that automates the testing of individual Chef cookbooks in a monolithic chef-repo. Reagan allows you to test only the cookbooks that have changed in a particular pull request and includes the following tests:
4
+ Trust But Verify - Ruby Jenkins build script that automates the testing of individual items in a monolithic chef-repo. Reagan allows you to test only the cookbooks or roles/environments that have changed in a particular pull request and includes the following tests:
5
5
 
6
6
  * Ensure versions are bumped in cookbooks vs. the current version on the server
7
7
  * Validate ruby / templates according to knife cookbook test
8
8
  * Optionally run any commands in a per cookbook reagan_test.yml file (rubocop? foodcritic? chefspec?)
9
+ * Validate that JSON files parse
9
10
 
10
11
  ##Requirements
11
12
  * Ruby 1.9.3 (rbenv Jenkins plugin suggested to get more modern Ruby)
data/bin/reagan CHANGED
@@ -22,12 +22,12 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
22
22
  require 'reagan'
23
23
  require 'optparse'
24
24
 
25
- flags = { :pull => nil, :cookbooks => nil, :config => '/etc/reagan.yml' }
25
+ flags = { :pull => nil, :override_cookbooks => nil, :config => '/etc/reagan.yml' }
26
26
 
27
27
  parser = OptionParser.new do |opts|
28
28
  opts.banner = 'Usage: reagan [options]'
29
29
  opts.on('-o', '--override cb1,cb2', 'Comma separated list of cookbooks to test') do |cookbooks|
30
- flags[:override_cookbooks] = cookbooks
30
+ flags[:override_cookbooks] = cookbooks.split(',')
31
31
  end
32
32
 
33
33
  opts.on('-p', '--pull_num 123', 'Github pull number to test') do |pull|
data/lib/change.rb CHANGED
@@ -28,11 +28,11 @@ end
28
28
  class Change < Reagan
29
29
  attr_accessor :files
30
30
  def initialize
31
- @files = files_to_test
31
+ @files = changed_files
32
32
  end
33
33
 
34
- # return hash of json files / cookbooks that have been changed
35
- def files_to_test
34
+ # return hash of chef objects that have been changed
35
+ def changed_files
36
36
  if @@config['flags']['override_cookbooks']
37
37
  files_from_override
38
38
  else
@@ -45,8 +45,8 @@ class Change < Reagan
45
45
  # build a files hash based on the override cookbooks passed by the user
46
46
  def files_from_override
47
47
  files = {}
48
- files['json'] = []
49
- files['cookbooks'] = @@config['flags']['override_cookbooks'].split(',')
48
+ %w(environments roles data_bags).each { |object| files[object] = {} }
49
+ files['cookbooks'] = @@config['flags']['override_cookbooks']
50
50
  files
51
51
  end
52
52
 
@@ -81,16 +81,14 @@ class Change < Reagan
81
81
  # builds a hash of files / cookbooks that changed based on the pull data from GH
82
82
  def hash_builder(pull_files)
83
83
  files = {}
84
- files['json'] = []
85
- files['cookbooks'] = []
84
+ %w(environments roles data_bags cookbooks).each { |object| files[object] = [] }
86
85
  cookbooks = []
87
86
 
88
87
  pull_files.each do |file|
89
- # populate json array if file is json
90
- files['json'] << file && next if file.match('.json$')
91
-
92
- # populate cookbooks array if filename starts with cookbooks
93
- cookbooks << file.split('/')[1] if file.match('^cookbooks')
88
+ files['environments'] << file && next if file.match('^environments')
89
+ files['roles'] << file && next if file.match('^roles')
90
+ files['data_bags'] << file && next if file.match('^data_bags')
91
+ cookbooks << file.split('/')[1] if file.match('^cookbooks')
94
92
  end
95
93
  # set cookbooks array to set to dedupe list of cookbooks
96
94
  files['cookbooks'] = cookbooks.to_set
data/lib/config.rb CHANGED
@@ -54,4 +54,5 @@ class ReaganConfig
54
54
  @flags.each { |k, v| config['flags'][k.to_s] = v }
55
55
  config
56
56
  end
57
+
57
58
  end
data/lib/reagan.rb CHANGED
@@ -38,17 +38,31 @@ class Reagan
38
38
  puts "\n"
39
39
  end
40
40
 
41
- # run tests on each changed cookbook
42
- def run
43
- # exit with a friendly message if nothing we test has been changed
44
- if @changes['json'].empty? && @changes['cookbooks'].empty?
45
- pretty_print('Nothing to test in this change. Reagan approves')
41
+ # exit with a friendly message if nothing we test has been changed
42
+ def check_empty_update
43
+ objects_updated = false
44
+ %w(cookbooks roles environments data_bags).each do |object|
45
+ objects_updated = true unless @changes[object].empty?
46
+ end
47
+
48
+ unless objects_updated
49
+ pretty_print('No objects to test. Exiting')
46
50
  exit 0
47
51
  end
52
+ end
48
53
 
49
- pretty_print('The following cookbooks & json files will be tested')
50
- @changes['cookbooks'].each { |cb| puts cb }
51
- @changes['json'].each { |json| puts json }
54
+ # run tests on each changed cookbook
55
+ def run
56
+ check_empty_update
57
+
58
+ # print objects that will be tested
59
+ pretty_print('The following chef objects will be tested')
60
+ %w(cookbooks roles environments data_bags).each do |type|
61
+ unless @changes[type].empty?
62
+ puts "#{type}:"
63
+ @changes[type].each { |obj| puts ' ' + obj }
64
+ end
65
+ end
52
66
 
53
67
  results = []
54
68
  @changes['cookbooks'].each do |cookbook|
@@ -57,9 +71,12 @@ class Reagan
57
71
  results << TestVersion.new(cookbook).test
58
72
  results << TestReagan.new(cookbook).test
59
73
  end
60
- @changes['json'].each do |file|
61
- pretty_print("Testing JSON file #{file}")
62
- results << TestJSON.new(file).test
74
+
75
+ %w(data_bags roles environments).each do |type|
76
+ @changes[type].each do |file|
77
+ pretty_print("Testing #{type} file #{file}")
78
+ results << TestJSON.new(file).test
79
+ end
63
80
  end
64
81
 
65
82
  # print success or failure
data/lib/test_version.rb CHANGED
@@ -47,7 +47,12 @@ class TestVersion < Reagan
47
47
  client_key: @@config['chef']['pem_path'],
48
48
  ssl: { verify: false }
49
49
  )
50
- server_con.cookbook.all[@cookbook][0]
50
+ # return the version if the cookbook exists or return 0.0.0 if it's a new coobook not yet on the server
51
+ if server_con.cookbook.all[@cookbook]
52
+ server_con.cookbook.all[@cookbook][0]
53
+ else
54
+ '0.0.0'
55
+ end
51
56
  rescue Ridley::Errors::ConnectionFailed
52
57
  puts ' ERROR: Failed to connect to the Chef server. Cannot continue'
53
58
  exit 1
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reagan
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Smith
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-16 00:00:00.000000000 Z
11
+ date: 2014-10-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: octokit