health_inspector 0.0.6 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -2,3 +2,4 @@
2
2
  .bundle
3
3
  Gemfile.lock
4
4
  pkg/*
5
+ !.gitkeep
data/HISTORY.md CHANGED
@@ -1,4 +1,11 @@
1
- ## 0.0.6 ( 2012-05-23)
1
+ ## 0.1.0 ( 2012-09-24 )
2
+
3
+ * Bump Chef dependency version up to 10.14
4
+ * Add support for JSON environments
5
+ * Add support for JSON roles
6
+ * Display the diff between JSONs when JSON data doesn't match.
7
+
8
+ ## 0.0.6 ( 2012-05-23 )
2
9
 
3
10
  * Depend on Chef 0.10.8, since it depends on a later version of the json gem.
4
11
  An earlier version of the json gem was throwing incorrect parse errors.
@@ -21,5 +21,5 @@ Gem::Specification.new do |s|
21
21
  s.add_development_dependency "minitest"
22
22
  s.add_development_dependency "mocha"
23
23
  s.add_runtime_dependency "thor"
24
- s.add_runtime_dependency "chef", "~> 0.10.8"
24
+ s.add_runtime_dependency "chef", "~> 10.14"
25
25
  end
@@ -1,4 +1,5 @@
1
1
  # encoding: UTF-8
2
+ require "pathname"
2
3
 
3
4
  module HealthInspector
4
5
  module Checklists
@@ -49,7 +50,7 @@ module HealthInspector
49
50
  end
50
51
 
51
52
  class CheckContext
52
- include Check
53
+ include Check, Color
53
54
  attr_accessor :item, :context
54
55
 
55
56
  def initialize(check, item, context)
@@ -61,6 +62,19 @@ module HealthInspector
61
62
  def call
62
63
  instance_eval(&@check)
63
64
  end
65
+
66
+ def diff(original, other)
67
+ (original.keys + other.keys).uniq.inject({}) do |memo, key|
68
+ unless original[key] == other[key]
69
+ if original[key].kind_of?(Hash) && other[key].kind_of?(Hash)
70
+ memo[key] = diff(original[key], other[key])
71
+ else
72
+ memo[key] = [original[key], other[key]]
73
+ end
74
+ end
75
+ memo
76
+ end
77
+ end
64
78
  end
65
79
 
66
80
  def run_check(check, item)
@@ -87,6 +101,26 @@ module HealthInspector
87
101
  end
88
102
  end
89
103
 
104
+ def load_ruby_or_json_from_local(chef_class, folder, name)
105
+ path_template = "#{@context.repo_path}/#{folder}/#{name}.%s"
106
+ ruby_pathname = Pathname.new(path_template % "rb")
107
+ json_pathname = Pathname.new(path_template % "json")
108
+ js_pathname = Pathname.new(path_template % "js")
109
+
110
+ if ruby_pathname.exist?
111
+ instance = chef_class.new
112
+ instance.from_file(ruby_pathname.to_s)
113
+ elsif json_pathname.exist?
114
+ instance = chef_class.json_create( JSON.parse( json_pathname.read ) )
115
+ elsif js_pathname.exist?
116
+ instance = chef_class.json_create( JSON.parse( js_pathname.read ) )
117
+ end
118
+
119
+ instance ? instance.to_hash : nil
120
+ rescue IOError
121
+ nil
122
+ end
123
+
90
124
  end
91
125
  end
92
126
  end
@@ -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
+ environment_diff = diff(item.server,item.local)
19
+ failure "#{environment_diff}\n" unless environment_diff.empty?
19
20
  end
20
21
  end
21
22
 
@@ -41,7 +42,7 @@ module HealthInspector
41
42
 
42
43
  def items_in_repo
43
44
  Dir.chdir("#{@context.repo_path}/environments") do
44
- Dir["*.rb"].map { |e| e.gsub('.rb', '') }
45
+ Dir["*.{rb,json,js}"].map { |e| e.gsub(/\.(rb|json|js)/,"") }
45
46
  end
46
47
  end
47
48
 
@@ -53,11 +54,7 @@ module HealthInspector
53
54
  end
54
55
 
55
56
  def load_item_from_local(name)
56
- env = Chef::Environment.new
57
- env.from_file( "#{@context.repo_path}/environments/#{name}.rb" )
58
- env.to_hash
59
- rescue IOError
60
- nil
57
+ load_ruby_or_json_from_local(Chef::Environment, "environments", name)
61
58
  end
62
59
  end
63
60
 
@@ -5,6 +5,8 @@ module HealthInspector
5
5
  class Roles < Base
6
6
  title "roles"
7
7
 
8
+ require 'yajl'
9
+
8
10
  add_check "local copy exists" do
9
11
  failure "exists on server but not locally" unless item.local
10
12
  end
@@ -41,7 +43,7 @@ module HealthInspector
41
43
 
42
44
  def items_in_repo
43
45
  Dir.chdir("#{@context.repo_path}/roles") do
44
- Dir["*.rb"].map { |e| e.gsub('.rb', '') }
46
+ Dir["*.{rb,json,js}"].map { |e| e.gsub(/\.(rb|json|js)/, '') }
45
47
  end
46
48
  end
47
49
 
@@ -53,11 +55,7 @@ module HealthInspector
53
55
  end
54
56
 
55
57
  def load_item_from_local(name)
56
- role = Chef::Role.new
57
- role.from_file( "#{@context.repo_path}/roles/#{name}.rb" )
58
- role.to_hash
59
- rescue IOError
60
- nil
58
+ load_ruby_or_json_from_local(Chef::Role, "roles", name)
61
59
  end
62
60
  end
63
61
 
@@ -5,7 +5,7 @@ module HealthInspector
5
5
  end
6
6
 
7
7
  def initialize(repo_path, config_path)
8
- @context = Context.new( repo_path, File.join(repo_path, config_path) )
8
+ @context = Context.new( repo_path, config_path )
9
9
  @context.configure
10
10
  end
11
11
 
@@ -1,3 +1,3 @@
1
1
  module HealthInspector
2
- VERSION = "0.0.6"
2
+ VERSION = "0.1.0"
3
3
  end
File without changes
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.0.6
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-23 00:00:00.000000000 Z
12
+ date: 2012-09-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: minitest
16
- requirement: &2152269080 !ruby/object:Gem::Requirement
16
+ requirement: &70344534419540 !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: *2152269080
24
+ version_requirements: *70344534419540
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: mocha
27
- requirement: &2152267660 !ruby/object:Gem::Requirement
27
+ requirement: &70344534418600 !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: *2152267660
35
+ version_requirements: *70344534418600
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: thor
38
- requirement: &2152265580 !ruby/object:Gem::Requirement
38
+ requirement: &70344534418140 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,18 +43,18 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *2152265580
46
+ version_requirements: *70344534418140
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: chef
49
- requirement: &2152262860 !ruby/object:Gem::Requirement
49
+ requirement: &70344534417520 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
53
53
  - !ruby/object:Gem::Version
54
- version: 0.10.8
54
+ version: '10.14'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *2152262860
57
+ version_requirements: *70344534417520
58
58
  description: A tool to inspect your chef repo as is compares to what is on your chef
59
59
  server
60
60
  email:
@@ -87,6 +87,7 @@ files:
87
87
  - lib/health_inspector/version.rb
88
88
  - spec/chef-repo/.chef/client.pem
89
89
  - spec/chef-repo/.chef/knife.rb
90
+ - spec/chef-repo/data_bags/.gitkeep
90
91
  - spec/data_bag_item_spec.rb
91
92
  - spec/spec_helper.rb
92
93
  homepage: https://github.com/bmarini/health_inspector
@@ -116,5 +117,6 @@ summary: A tool to inspect your chef repo as is compares to what is on your chef
116
117
  test_files:
117
118
  - spec/chef-repo/.chef/client.pem
118
119
  - spec/chef-repo/.chef/knife.rb
120
+ - spec/chef-repo/data_bags/.gitkeep
119
121
  - spec/data_bag_item_spec.rb
120
122
  - spec/spec_helper.rb