knife-inspect 0.8.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/.travis.yml +3 -2
- data/HISTORY.md +12 -0
- data/README.md +10 -0
- data/knife-inspect.gemspec +2 -2
- data/lib/chef/knife/cookbook_inspect.rb +4 -27
- data/lib/chef/knife/data_bag_inspect.rb +7 -3
- data/lib/chef/knife/environment_inspect.rb +4 -16
- data/lib/chef/knife/inspect.rb +6 -5
- data/lib/chef/knife/role_inspect.rb +4 -16
- data/lib/health_inspector.rb +11 -10
- data/lib/health_inspector/checklists/base.rb +30 -27
- data/lib/health_inspector/checklists/cookbooks.rb +44 -52
- data/lib/health_inspector/checklists/data_bag_items.rb +11 -12
- data/lib/health_inspector/checklists/data_bags.rb +5 -6
- data/lib/health_inspector/checklists/environments.rb +8 -9
- data/lib/health_inspector/checklists/roles.rb +6 -7
- data/lib/health_inspector/color.rb +18 -19
- data/lib/health_inspector/context.rb +1 -1
- data/lib/health_inspector/pairing.rb +27 -32
- data/lib/health_inspector/runner.rb +29 -0
- data/lib/health_inspector/version.rb +1 -1
- data/spec/chef-repo/data_bags/data_bag_one/one.json +4 -0
- data/spec/chef-repo/data_bags/data_bag_two/two.json +1 -0
- data/spec/chef/knife/cookbook_inspect_spec.rb +10 -0
- data/spec/chef/knife/data_bag_inspect_spec.rb +79 -0
- data/spec/chef/knife/environment_inspect_spec.rb +10 -0
- data/spec/chef/knife/inspect_spec.rb +51 -0
- data/spec/chef/knife/role_inspect_spec.rb +10 -0
- data/spec/health_inspector/checklists/cookbook_spec.rb +23 -21
- data/spec/health_inspector/checklists/cookbooks_spec.rb +14 -12
- data/spec/health_inspector/checklists/data_bag_item_spec.rb +3 -3
- data/spec/health_inspector/checklists/data_bag_items_spec.rb +96 -10
- data/spec/health_inspector/checklists/data_bag_spec.rb +3 -3
- data/spec/health_inspector/checklists/data_bags_spec.rb +28 -11
- data/spec/health_inspector/checklists/environment_spec.rb +6 -7
- data/spec/health_inspector/checklists/environments_spec.rb +9 -11
- data/spec/health_inspector/checklists/role_spec.rb +3 -3
- data/spec/health_inspector/checklists/roles_spec.rb +9 -11
- data/spec/spec_helper.rb +122 -56
- metadata +37 -26
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
NDNkMTNlNWM5ODc3OGZhNmE0ZDI3ODliZTRmZGIzMGNiYTRkNjc0ZA==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 316a4b1c10a5933ca22aca053893070e92e0d6ce
|
4
|
+
data.tar.gz: 647775423040ddc38db71ec6fa0fefa242ae5322
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
YTJjOTA1MmRlZWIyYTE1NjdhNDUyMmYyNmYzYTZhZGU4ODM2YjdiNDE3ZWNj
|
11
|
-
Yzk5MjYzM2IyZmIwODM5ZDg5MjM5NzY4MWRjMWFkYWYzZDMyMDY=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
OWQ2NWRiYmYxMWIyMTg1YWRiMTc0MTljNzQ2NTkwYTgzZTcyZTcwMjFmNDc2
|
14
|
-
NzFkN2FkOWRmNDYxNTZhZjZmNDkwY2FhYjNiNzIzMmI1Y2ZhZTMyNThkNmZh
|
15
|
-
YTQyZjM0ZjdhNmU5MGI3OTdmZmIyOTJjMDFhMGEwNDg1Nzk3NmU=
|
6
|
+
metadata.gz: 6cc9b27c85c801807d98e22f255f3f0a4bbe7bdcfb747f521a1c06e9af7a55f4bbbebb66325950a029be16803377279766263e0e636aa81adc4b59112016939f
|
7
|
+
data.tar.gz: 69d5f911e727f954a8bdaea2ec182092e6bfcb6390b5ab9d5587ce3738c04961407ba9c9571166ea038540841538e192d0ab924b7c8a68ed9aabd1f9446b4008
|
data/.travis.yml
CHANGED
data/HISTORY.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
## 0.9.0 ( 2014-08-02 )
|
2
|
+
|
3
|
+
* Bug fix: update yajl-ruby dependency to 1.2, 1.1 segfaulted in some cases
|
4
|
+
([#22][#22])
|
5
|
+
* Feature: Make output not use unicode when stdout is not a TTY. (Ben Hughes)
|
6
|
+
([#21][#21])
|
7
|
+
* Bug fix: fix a bug with git submodules in some cases
|
8
|
+
([#7][#7])
|
9
|
+
|
1
10
|
## 0.8.0 ( 2014-01-10 )
|
2
11
|
|
3
12
|
* New feature: Support data bags, data bag items, environments and roles inside
|
@@ -122,3 +131,6 @@
|
|
122
131
|
[#14]: https://github.com/bmarini/knife-inspect/issues/14
|
123
132
|
[#6]: https://github.com/bmarini/knife-inspect/issues/6
|
124
133
|
[#2]: https://github.com/bmarini/knife-inspect/issues/2
|
134
|
+
[#21]: https://github.com/bmarini/knife-inspect/issues/21
|
135
|
+
[#22]: https://github.com/bmarini/knife-inspect/issues/22
|
136
|
+
[#7]: https://github.com/bmarini/knife-inspect/issues/7
|
data/README.md
CHANGED
@@ -48,6 +48,15 @@ So far it checks if...
|
|
48
48
|
You can use it with your favorite Continuous Integration tool, it returns 0
|
49
49
|
when everything is in sync or 1 if it's not.
|
50
50
|
|
51
|
+
## Frequently Asked Questions
|
52
|
+
|
53
|
+
### How is it different [from knife diff](http://docs.opscode.com/knife_diff.html)?
|
54
|
+
|
55
|
+
* It returns the proper return code, so you can [use it with a Continuous Integration tool](https://blog.5apps.com/2014/01/07/using-travis-to-make-sure-your-chef-repo-and-server-are-in-sync.html)
|
56
|
+
* `knife diff` seems to expect local roles to be json files, knife-inspect supports both JSON and Ruby.
|
57
|
+
* It's my personal opinion, but I think the output from knife-inspect is more readable. Also I don't understand some of the errors I'm getting with `knife diff` (`Only in .: clients` for example)
|
58
|
+
* I actually didn't know there was a built-in `knife diff` command.
|
59
|
+
|
51
60
|
## Contributors
|
52
61
|
|
53
62
|
(in alphabetical order)
|
@@ -56,6 +65,7 @@ when everything is in sync or 1 if it's not.
|
|
56
65
|
* Eric Saxby ([@sax](https://github.com/sax))
|
57
66
|
* Dan Buch ([@meatballhat](@https://github.com/meatballhat))
|
58
67
|
* Kirt Fitzpatrick ([@kirtfitzpatrick](https://github.com/kirtfitzpatrick))
|
68
|
+
* Ben Hughes ([@barn](https://github.com/barn))
|
59
69
|
|
60
70
|
## Contributing
|
61
71
|
|
data/knife-inspect.gemspec
CHANGED
@@ -24,10 +24,10 @@ Gem::Specification.new do |s|
|
|
24
24
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
25
25
|
|
26
26
|
s.add_development_dependency 'rake', '~> 10.1'
|
27
|
-
s.add_development_dependency 'rspec', '~>
|
27
|
+
s.add_development_dependency 'rspec', '~> 3.0.0'
|
28
28
|
s.add_development_dependency 'simplecov', '~> 0.8'
|
29
29
|
s.add_development_dependency 'coveralls', '~> 0.7'
|
30
30
|
|
31
31
|
s.add_runtime_dependency 'chef', chef_version
|
32
|
-
s.add_runtime_dependency 'yajl-ruby', '~> 1.
|
32
|
+
s.add_runtime_dependency 'yajl-ruby', '~> 1.2'
|
33
33
|
end
|
@@ -1,36 +1,13 @@
|
|
1
1
|
require 'chef/knife'
|
2
|
+
require 'health_inspector'
|
2
3
|
|
3
4
|
class Chef
|
4
5
|
class Knife
|
5
6
|
class CookbookInspect < Knife
|
7
|
+
include HealthInspector::Runner
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
-
require 'chef/json_compat'
|
10
|
-
require 'uri'
|
11
|
-
require 'chef/cookbook_version'
|
12
|
-
end
|
13
|
-
|
14
|
-
banner "knife cookbook inspect [COOKBOOK] (options)"
|
15
|
-
|
16
|
-
def run
|
17
|
-
case @name_args.length
|
18
|
-
when 1 # We are inspecting a cookbook
|
19
|
-
cookbook_name = @name_args[0]
|
20
|
-
# TODO: Support environments
|
21
|
-
# env = config[:environment]
|
22
|
-
# api_endpoint = env ? "environments/#{env}/cookbooks/#{cookbook_name}" : "cookbooks/#{cookbook_name}"
|
23
|
-
|
24
|
-
validator = HealthInspector::Checklists::Cookbooks.new(self)
|
25
|
-
exit validator.validate_item( validator.load_item(cookbook_name) )
|
26
|
-
when 0 # We are inspecting all the cookbooks
|
27
|
-
exit HealthInspector::Checklists::Cookbooks.run(self)
|
28
|
-
end
|
29
|
-
end
|
9
|
+
checklist HealthInspector::Checklists::Cookbooks
|
10
|
+
banner 'knife cookbook inspect [COOKBOOK] (options)'
|
30
11
|
end
|
31
12
|
end
|
32
13
|
end
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
@@ -3,11 +3,13 @@ require 'chef/knife'
|
|
3
3
|
class Chef
|
4
4
|
class Knife
|
5
5
|
class DataBagInspect < Knife
|
6
|
+
# :nocov:
|
6
7
|
deps do
|
7
8
|
require 'health_inspector'
|
8
9
|
end
|
10
|
+
# :nocov:
|
9
11
|
|
10
|
-
banner
|
12
|
+
banner 'knife data bag inspect [BAG] [ITEM] (options)'
|
11
13
|
|
12
14
|
def run
|
13
15
|
case @name_args.length
|
@@ -16,13 +18,15 @@ class Chef
|
|
16
18
|
item_name = @name_args[1]
|
17
19
|
|
18
20
|
validator = HealthInspector::Checklists::DataBagItems.new(self)
|
19
|
-
|
21
|
+
item = validator.load_item("#{bag_name}/#{item_name}")
|
22
|
+
exit validator.validate_item item
|
20
23
|
|
21
24
|
when 1 # We are inspecting a data bag
|
22
25
|
bag_name = @name_args[0]
|
23
26
|
|
24
27
|
validator = HealthInspector::Checklists::DataBags.new(self)
|
25
|
-
|
28
|
+
item = validator.load_item(bag_name)
|
29
|
+
exit validator.validate_item item
|
26
30
|
|
27
31
|
when 0 # We are inspecting all the data bags
|
28
32
|
exit HealthInspector::Checklists::DataBags.run(self) &&
|
@@ -1,25 +1,13 @@
|
|
1
1
|
require 'chef/knife'
|
2
|
+
require 'health_inspector'
|
2
3
|
|
3
4
|
class Chef
|
4
5
|
class Knife
|
5
6
|
class EnvironmentInspect < Knife
|
7
|
+
include HealthInspector::Runner
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
-
end
|
10
|
-
|
11
|
-
banner "knife environment inspect [ENVIRONMENT] (options)"
|
12
|
-
|
13
|
-
def run
|
14
|
-
case @name_args.length
|
15
|
-
when 1 # We are inspecting a environment
|
16
|
-
environment_name = @name_args[0]
|
17
|
-
validator = HealthInspector::Checklists::Environments.new(self)
|
18
|
-
exit validator.validate_item( validator.load_item(environment_name) )
|
19
|
-
when 0 # We are inspecting all the environments
|
20
|
-
exit HealthInspector::Checklists::Environments.run(self)
|
21
|
-
end
|
22
|
-
end
|
9
|
+
checklist HealthInspector::Checklists::Environments
|
10
|
+
banner 'knife environment inspect [ENVIRONMENT] (options)'
|
23
11
|
end
|
24
12
|
end
|
25
13
|
end
|
data/lib/chef/knife/inspect.rb
CHANGED
@@ -3,21 +3,22 @@ require 'chef/knife'
|
|
3
3
|
class Chef
|
4
4
|
class Knife
|
5
5
|
class Inspect < Knife
|
6
|
+
CHECKLISTS = %w(Cookbooks DataBags DataBagItems Environments Roles)
|
6
7
|
|
7
|
-
|
8
|
-
|
8
|
+
# :nocov:
|
9
9
|
deps do
|
10
|
-
require
|
10
|
+
require 'health_inspector'
|
11
11
|
end
|
12
|
+
# :nocov:
|
12
13
|
|
13
|
-
banner
|
14
|
+
banner 'knife inspect'
|
14
15
|
|
15
16
|
def run
|
16
17
|
results = CHECKLISTS.map do |checklist|
|
17
18
|
HealthInspector::Checklists.const_get(checklist).run(self)
|
18
19
|
end
|
19
20
|
|
20
|
-
exit !
|
21
|
+
exit !results.include?(false)
|
21
22
|
end
|
22
23
|
end
|
23
24
|
end
|
@@ -1,25 +1,13 @@
|
|
1
1
|
require 'chef/knife'
|
2
|
+
require 'health_inspector'
|
2
3
|
|
3
4
|
class Chef
|
4
5
|
class Knife
|
5
6
|
class RoleInspect < Knife
|
7
|
+
include HealthInspector::Runner
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
-
end
|
10
|
-
|
11
|
-
banner "knife role inspect [ROLE] (options)"
|
12
|
-
|
13
|
-
def run
|
14
|
-
case @name_args.length
|
15
|
-
when 1 # We are inspecting a role
|
16
|
-
role_name = @name_args[0]
|
17
|
-
validator = HealthInspector::Checklists::Roles.new(self)
|
18
|
-
exit validator.validate_item( validator.load_item(role_name) )
|
19
|
-
when 0 # We are inspecting all the roles
|
20
|
-
exit HealthInspector::Checklists::Roles.run(self)
|
21
|
-
end
|
22
|
-
end
|
9
|
+
checklist HealthInspector::Checklists::Roles
|
10
|
+
banner 'knife role inspect [ROLE] (options)'
|
23
11
|
end
|
24
12
|
end
|
25
13
|
end
|
data/lib/health_inspector.rb
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
# encoding: UTF-8
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
11
|
-
require
|
2
|
+
require 'health_inspector/version'
|
3
|
+
require 'health_inspector/color'
|
4
|
+
require 'health_inspector/context'
|
5
|
+
require 'health_inspector/pairing'
|
6
|
+
require 'health_inspector/runner'
|
7
|
+
require 'health_inspector/checklists/base'
|
8
|
+
require 'health_inspector/checklists/cookbooks'
|
9
|
+
require 'health_inspector/checklists/data_bags'
|
10
|
+
require 'health_inspector/checklists/data_bag_items'
|
11
|
+
require 'health_inspector/checklists/environments'
|
12
|
+
require 'health_inspector/checklists/roles'
|
12
13
|
require 'chef/rest'
|
13
14
|
require 'chef/version'
|
14
15
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# encoding: UTF-8
|
2
|
-
require
|
2
|
+
require 'pathname'
|
3
3
|
|
4
4
|
module HealthInspector
|
5
5
|
module Checklists
|
@@ -9,7 +9,7 @@ module HealthInspector
|
|
9
9
|
class << self
|
10
10
|
attr_reader :title
|
11
11
|
|
12
|
-
def title(val=nil)
|
12
|
+
def title(val = nil)
|
13
13
|
val.nil? ? @title : @title = val
|
14
14
|
end
|
15
15
|
end
|
@@ -27,11 +27,11 @@ module HealthInspector
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def server_items
|
30
|
-
|
30
|
+
fail NotImplementedError, 'You must implement this method in a subclass'
|
31
31
|
end
|
32
32
|
|
33
33
|
def local_items
|
34
|
-
|
34
|
+
fail NotImplementedError, 'You must implement this method in a subclass'
|
35
35
|
end
|
36
36
|
|
37
37
|
def all_item_names
|
@@ -53,7 +53,7 @@ module HealthInspector
|
|
53
53
|
results << validate_item(item)
|
54
54
|
end
|
55
55
|
|
56
|
-
|
56
|
+
!results.include?(false)
|
57
57
|
end
|
58
58
|
|
59
59
|
def validate_item(item)
|
@@ -61,7 +61,7 @@ module HealthInspector
|
|
61
61
|
failures = item.errors
|
62
62
|
|
63
63
|
if failures.empty?
|
64
|
-
print_success(item.name)
|
64
|
+
print_success(item.name)
|
65
65
|
|
66
66
|
true
|
67
67
|
else
|
@@ -72,13 +72,17 @@ module HealthInspector
|
|
72
72
|
end
|
73
73
|
|
74
74
|
def banner(message)
|
75
|
-
ui.msg
|
75
|
+
ui.msg ''
|
76
76
|
ui.msg message
|
77
|
-
ui.msg
|
77
|
+
ui.msg '-' * 80
|
78
78
|
end
|
79
79
|
|
80
80
|
def print_success(subject)
|
81
|
-
|
81
|
+
if $stdout.tty?
|
82
|
+
ui.msg color('bright pass', "✓") + " #{subject}"
|
83
|
+
else
|
84
|
+
ui.msg "Success #{subject}"
|
85
|
+
end
|
82
86
|
end
|
83
87
|
|
84
88
|
def print_failures(subject, failures)
|
@@ -86,7 +90,7 @@ module HealthInspector
|
|
86
90
|
|
87
91
|
failures.each do |message|
|
88
92
|
if message.is_a? Hash
|
89
|
-
puts color('bright yellow'," has the following values mismatched on the server and repo\n")
|
93
|
+
puts color('bright yellow', " has the following values mismatched on the server and repo\n")
|
90
94
|
print_failures_from_hash(message)
|
91
95
|
else
|
92
96
|
puts color('bright yellow', " #{message}")
|
@@ -94,13 +98,13 @@ module HealthInspector
|
|
94
98
|
end
|
95
99
|
end
|
96
100
|
|
97
|
-
def print_failures_from_hash(message, depth=2)
|
101
|
+
def print_failures_from_hash(message, depth = 2)
|
98
102
|
message.keys.each do |key|
|
99
|
-
print_key(key,depth)
|
103
|
+
print_key(key, depth)
|
100
104
|
|
101
|
-
if message[key].include?
|
102
|
-
print_value_diff(message[key],depth)
|
103
|
-
message[key].delete_if { |k,
|
105
|
+
if message[key].include? 'server'
|
106
|
+
print_value_diff(message[key], depth)
|
107
|
+
message[key].delete_if { |k, _| k == 'server' || 'local' }
|
104
108
|
print_failures_from_hash(message[key], depth + 1) unless message[key].empty?
|
105
109
|
else
|
106
110
|
print_failures_from_hash(message[key], depth + 1)
|
@@ -109,30 +113,30 @@ module HealthInspector
|
|
109
113
|
end
|
110
114
|
|
111
115
|
def print_key(key, depth)
|
112
|
-
ui.msg indent(color('bright yellow',"#{key} : "), depth)
|
116
|
+
ui.msg indent(color('bright yellow', "#{key} : "), depth)
|
113
117
|
end
|
114
118
|
|
115
119
|
def print_value_diff(value, depth)
|
116
|
-
print indent(color('bright fail',
|
117
|
-
print value[
|
120
|
+
print indent(color('bright fail', 'server value = '), depth + 1)
|
121
|
+
print value['server']
|
118
122
|
print "\n"
|
119
|
-
print indent(color('bright fail',
|
120
|
-
print value[
|
123
|
+
print indent(color('bright fail', 'local value = '), depth + 1)
|
124
|
+
print value['local']
|
121
125
|
print "\n\n"
|
122
126
|
end
|
123
127
|
|
124
128
|
def load_ruby_or_json_from_local(chef_class, folder, name)
|
125
129
|
path_template = "#{@context.repo_path}/#{folder}/**/#{name}.%s"
|
126
|
-
ruby_pathname = Pathname.glob(path_template %
|
127
|
-
json_pathname = Pathname.glob(path_template %
|
128
|
-
js_pathname = Pathname.glob(path_template %
|
130
|
+
ruby_pathname = Pathname.glob(path_template % 'rb')
|
131
|
+
json_pathname = Pathname.glob(path_template % 'json')
|
132
|
+
js_pathname = Pathname.glob(path_template % 'js')
|
129
133
|
|
130
|
-
if !
|
134
|
+
if !ruby_pathname.empty?
|
131
135
|
instance = chef_class.new
|
132
136
|
instance.from_file(ruby_pathname.first.to_s)
|
133
|
-
elsif !
|
137
|
+
elsif !json_pathname.empty?
|
134
138
|
instance = chef_class.json_create(Yajl::Parser.parse(json_pathname.first.read))
|
135
|
-
elsif !
|
139
|
+
elsif !js_pathname.empty?
|
136
140
|
instance = chef_class.json_create(Yajl::Parser.parse(js_pathname.first.read))
|
137
141
|
end
|
138
142
|
|
@@ -144,7 +148,6 @@ module HealthInspector
|
|
144
148
|
def indent(string, depth)
|
145
149
|
(' ' * 2 * depth) + string
|
146
150
|
end
|
147
|
-
|
148
151
|
end
|
149
152
|
end
|
150
153
|
end
|
@@ -1,66 +1,62 @@
|
|
1
1
|
module HealthInspector
|
2
2
|
module Checklists
|
3
|
-
|
4
3
|
class Cookbook < Pairing
|
5
4
|
include ExistenceValidations
|
6
5
|
|
7
6
|
def validate_versions
|
8
|
-
if versions_exist? && !
|
7
|
+
if versions_exist? && !versions_match?
|
9
8
|
errors.add "chef server has #{server} but local version is #{local}"
|
10
9
|
end
|
11
10
|
end
|
12
11
|
|
13
12
|
def validate_uncommited_changes
|
14
|
-
|
15
|
-
result = `cd #{cookbook_path} && git status -s`
|
13
|
+
return unless git_repo?
|
16
14
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
end
|
15
|
+
result = `cd #{cookbook_path} && git status -s`
|
16
|
+
|
17
|
+
errors.add "Uncommitted changes:\n#{result.chomp}" unless result.empty?
|
21
18
|
end
|
22
19
|
|
23
20
|
def validate_commits_not_pushed_to_remote
|
24
|
-
|
25
|
-
result = `cd #{cookbook_path} && git status`
|
21
|
+
return unless git_repo?
|
26
22
|
|
27
|
-
|
28
|
-
|
29
|
-
|
23
|
+
result = `cd #{cookbook_path} && git status`
|
24
|
+
|
25
|
+
if result =~ /Your branch is ahead of (.+)/
|
26
|
+
errors.add "ahead of #{Regexp.last_match[1]}"
|
30
27
|
end
|
31
28
|
end
|
32
29
|
|
33
30
|
# TODO: Check files that exist locally but not in manifest on server
|
34
31
|
def validate_changes_on_the_server_not_in_the_repo
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
32
|
+
return unless versions_exist? && versions_match?
|
33
|
+
|
34
|
+
begin
|
35
|
+
cookbook = context.rest.get_rest("/cookbooks/#{name}/#{local}")
|
36
|
+
messages = []
|
37
|
+
|
38
|
+
Chef::CookbookVersion::COOKBOOK_SEGMENTS.each do |segment|
|
39
|
+
cookbook.manifest[segment].each do |manifest_record|
|
40
|
+
path = cookbook_path.join("#{manifest_record['path']}")
|
41
|
+
next if path.basename.to_s == '.git'
|
42
|
+
|
43
|
+
if path.exist?
|
44
|
+
checksum = checksum_cookbook_file(path)
|
45
|
+
messages << "#{manifest_record['path']}" if checksum != manifest_record['checksum']
|
46
|
+
else
|
47
|
+
messages << "#{manifest_record['path']} does not exist in the repo"
|
51
48
|
end
|
52
49
|
end
|
50
|
+
end
|
53
51
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
end
|
59
|
-
|
60
|
-
rescue Net::HTTPServerException => e
|
61
|
-
errors.add "Could not find cookbook #{name} on the server"
|
52
|
+
unless messages.empty?
|
53
|
+
message = "has a checksum mismatch between server and repo in\n"
|
54
|
+
message << messages.map { |f| " #{f}" }.join("\n")
|
55
|
+
errors.add message
|
62
56
|
end
|
63
57
|
|
58
|
+
rescue Net::HTTPServerException
|
59
|
+
errors.add "Could not find cookbook #{name} on the server"
|
64
60
|
end
|
65
61
|
end
|
66
62
|
|
@@ -84,34 +80,31 @@ module HealthInspector
|
|
84
80
|
def checksum_cookbook_file(filepath)
|
85
81
|
Chef::CookbookVersion.checksum_cookbook_file(filepath)
|
86
82
|
end
|
87
|
-
|
88
83
|
end
|
89
84
|
|
90
85
|
class Cookbooks < Base
|
91
|
-
|
92
|
-
title "cookbooks"
|
86
|
+
title 'cookbooks'
|
93
87
|
|
94
88
|
def load_item(name)
|
95
89
|
Cookbook.new(@context,
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
)
|
90
|
+
name: name,
|
91
|
+
server: server_items[name],
|
92
|
+
local: local_items[name])
|
100
93
|
end
|
101
94
|
|
102
95
|
def server_items
|
103
|
-
@context.rest.get_rest(
|
104
|
-
hsh[name] = Chef::Version.new(version[
|
96
|
+
@context.rest.get_rest('/cookbooks').reduce({}) do |hsh, (name, version)|
|
97
|
+
hsh[name] = Chef::Version.new(version['versions'].first['version'])
|
105
98
|
hsh
|
106
99
|
end
|
107
100
|
end
|
108
101
|
|
109
102
|
def local_items
|
110
|
-
@context.cookbook_path
|
111
|
-
map { |path| Dir["#{path}/*"] }
|
112
|
-
flatten
|
113
|
-
select { |path| File.
|
114
|
-
|
103
|
+
@context.cookbook_path
|
104
|
+
.map { |path| Dir["#{path}/*"] }
|
105
|
+
.flatten
|
106
|
+
.select { |path| File.exist?("#{path}/metadata.rb") }
|
107
|
+
.reduce({}) do |hsh, path|
|
115
108
|
|
116
109
|
name = File.basename(path)
|
117
110
|
version = (`grep '^version' #{path}/metadata.rb`).split.last[1...-1]
|
@@ -124,7 +117,6 @@ module HealthInspector
|
|
124
117
|
def all_item_names
|
125
118
|
(server_items.keys + local_items.keys).uniq.sort
|
126
119
|
end
|
127
|
-
|
128
120
|
end
|
129
121
|
end
|
130
122
|
end
|