health_inspector 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/HISTORY.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 0.2.0 ( 2012-09-25 )
2
+
3
+ * Add a better diff output.
4
+ * Add diff output to data bag items.
5
+ * Switch to yajl-ruby to fix JSON parsing issues (Chef uses this also).
6
+
1
7
  ## 0.1.0 ( 2012-09-24 )
2
8
 
3
9
  * Bump Chef dependency version up to 10.14
@@ -20,6 +20,8 @@ Gem::Specification.new do |s|
20
20
 
21
21
  s.add_development_dependency "minitest"
22
22
  s.add_development_dependency "mocha"
23
+
23
24
  s.add_runtime_dependency "thor"
24
25
  s.add_runtime_dependency "chef", "~> 10.14"
26
+ s.add_runtime_dependency "yajl-ruby"
25
27
  end
@@ -69,7 +69,7 @@ module HealthInspector
69
69
  if original[key].kind_of?(Hash) && other[key].kind_of?(Hash)
70
70
  memo[key] = diff(original[key], other[key])
71
71
  else
72
- memo[key] = [original[key], other[key]]
72
+ memo[key] = {"server" => original[key],"local" => other[key]}
73
73
  end
74
74
  end
75
75
  memo
@@ -97,10 +97,42 @@ module HealthInspector
97
97
  puts color('bright fail', "- #{subject}")
98
98
 
99
99
  failures.each do |message|
100
- puts color('bright yellow', " #{message}")
100
+ if message.kind_of? Hash
101
+ puts color('bright yellow'," has the following values mismatched on the server and repo\n")
102
+ print_failures_from_hash(message)
103
+ else
104
+ puts color('bright yellow', " #{message}")
105
+ end
106
+ end
107
+ end
108
+
109
+ def print_failures_from_hash(message, depth=2)
110
+ message.keys.each do |key|
111
+ print_key(key,depth)
112
+
113
+ if message[key].include? "server"
114
+ print_value_diff(message[key],depth)
115
+ message[key].delete_if { |k,v| k == "server" || "local" }
116
+ print_failures_from_hash(message[key], depth + 1) unless message[key].empty?
117
+ else
118
+ print_failures_from_hash(message[key], depth + 1)
119
+ end
101
120
  end
102
121
  end
103
122
 
123
+ def print_key(key, depth)
124
+ puts indent( color('bright yellow',"#{key} : "), depth )
125
+ end
126
+
127
+ def print_value_diff(value, depth)
128
+ print indent( color('bright fail',"server value = "), depth + 1 )
129
+ print value["server"]
130
+ print "\n"
131
+ print indent( color('bright fail',"local value = "), depth + 1 )
132
+ print value["local"]
133
+ print "\n\n"
134
+ end
135
+
104
136
  def load_ruby_or_json_from_local(chef_class, folder, name)
105
137
  path_template = "#{@context.repo_path}/#{folder}/#{name}.%s"
106
138
  ruby_pathname = Pathname.new(path_template % "rb")
@@ -111,9 +143,9 @@ module HealthInspector
111
143
  instance = chef_class.new
112
144
  instance.from_file(ruby_pathname.to_s)
113
145
  elsif json_pathname.exist?
114
- instance = chef_class.json_create( JSON.parse( json_pathname.read ) )
146
+ instance = chef_class.json_create( Yajl::Parser.parse( json_pathname.read ) )
115
147
  elsif js_pathname.exist?
116
- instance = chef_class.json_create( JSON.parse( js_pathname.read ) )
148
+ instance = chef_class.json_create( Yajl::Parser.parse( js_pathname.read ) )
117
149
  end
118
150
 
119
151
  instance ? instance.to_hash : nil
@@ -121,6 +153,10 @@ module HealthInspector
121
153
  nil
122
154
  end
123
155
 
156
+ def indent(string, depth)
157
+ string.prepend(' ' * 2 * depth)
158
+ end
159
+
124
160
  end
125
161
  end
126
162
  end
@@ -62,7 +62,7 @@ module HealthInspector
62
62
  end
63
63
 
64
64
  def cookbooks_on_server
65
- JSON.parse( @context.knife_command("cookbook list -Fj") ).inject({}) do |hsh, c|
65
+ Yajl::Parser.parse( @context.knife_command("cookbook list -Fj") ).inject({}) do |hsh, c|
66
66
  name, version = c.split
67
67
  hsh[name] = version
68
68
  hsh
@@ -15,7 +15,8 @@ module HealthInspector
15
15
 
16
16
  add_check "items are the same" do
17
17
  if item.server && item.local
18
- failure "#{item.server}\n is not equal to\n #{item.local}" unless item.server == item.local
18
+ item_diff = diff(item.server, item.local)
19
+ failure item_diff unless item_diff.empty?
19
20
  end
20
21
  end
21
22
 
@@ -61,7 +62,7 @@ module HealthInspector
61
62
  end
62
63
 
63
64
  def load_item_from_local(name)
64
- JSON.parse( File.read("#{@context.repo_path}/data_bags/#{name}.json") )
65
+ Yajl::Parser.parse( File.read("#{@context.repo_path}/data_bags/#{name}.json") )
65
66
  rescue IOError, Errno::ENOENT
66
67
  nil
67
68
  end
@@ -15,8 +15,8 @@ module HealthInspector
15
15
 
16
16
  add_check "items are the same" do
17
17
  if item.server && item.local
18
- environment_diff = diff(item.server,item.local)
19
- failure "#{environment_diff}\n" unless environment_diff.empty?
18
+ item_diff = diff(item.server, item.local)
19
+ failure item_diff unless item_diff.empty?
20
20
  end
21
21
  end
22
22
 
@@ -17,7 +17,8 @@ module HealthInspector
17
17
 
18
18
  add_check "items are the same" do
19
19
  if item.server && item.local
20
- failure "#{item.server}\n is not equal to\n #{item.local}" unless item.server == item.local
20
+ item_diff = diff(item.server, item.local)
21
+ failure item_diff unless item_diff.empty?
21
22
  end
22
23
  end
23
24
 
@@ -1,3 +1,3 @@
1
1
  module HealthInspector
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: health_inspector
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-09-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: minitest
16
- requirement: &70344534419540 !ruby/object:Gem::Requirement
16
+ requirement: &70104583098760 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70344534419540
24
+ version_requirements: *70104583098760
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: mocha
27
- requirement: &70344534418600 !ruby/object:Gem::Requirement
27
+ requirement: &70104583097840 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70344534418600
35
+ version_requirements: *70104583097840
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: thor
38
- requirement: &70344534418140 !ruby/object:Gem::Requirement
38
+ requirement: &70104583097300 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70344534418140
46
+ version_requirements: *70104583097300
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: chef
49
- requirement: &70344534417520 !ruby/object:Gem::Requirement
49
+ requirement: &70104583096760 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,7 +54,18 @@ dependencies:
54
54
  version: '10.14'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70344534417520
57
+ version_requirements: *70104583096760
58
+ - !ruby/object:Gem::Dependency
59
+ name: yajl-ruby
60
+ requirement: &70104583096340 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :runtime
67
+ prerelease: false
68
+ version_requirements: *70104583096340
58
69
  description: A tool to inspect your chef repo as is compares to what is on your chef
59
70
  server
60
71
  email: