reagan 0.6.0 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -1
- data/bin/reagan +2 -2
- data/lib/change.rb +10 -12
- data/lib/config.rb +1 -0
- data/lib/reagan.rb +28 -11
- data/lib/test_version.rb +6 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e6d0ac4c6953b8002c591704a429494fb946235e
|
4
|
+
data.tar.gz: 317e69c6027b0e9bc36b1eb0821480ca754f1f4d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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, :
|
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 =
|
31
|
+
@files = changed_files
|
32
32
|
end
|
33
33
|
|
34
|
-
# return hash of
|
35
|
-
def
|
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[
|
49
|
-
files['cookbooks'] = @@config['flags']['override_cookbooks']
|
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[
|
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
|
-
|
90
|
-
files['
|
91
|
-
|
92
|
-
|
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
data/lib/reagan.rb
CHANGED
@@ -38,17 +38,31 @@ class Reagan
|
|
38
38
|
puts "\n"
|
39
39
|
end
|
40
40
|
|
41
|
-
#
|
42
|
-
def
|
43
|
-
|
44
|
-
|
45
|
-
|
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
|
-
|
50
|
-
|
51
|
-
|
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
|
-
|
61
|
-
|
62
|
-
|
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
|
-
|
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.
|
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-
|
11
|
+
date: 2014-10-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: octokit
|