health_inspector 0.3.0 → 0.3.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.
data/HISTORY.md CHANGED
@@ -1,6 +1,10 @@
1
+ ## 0.3.1 ( 2012-09-27 )
2
+
3
+ * Stop shelling out for knife commands, use Chef API directly for everything.
4
+
1
5
  ## 0.3.0 ( 2012-09-26 )
2
6
 
3
- * Add new check for cookbooks: checksum comparison for each file
7
+ * Add new check for cookbooks: checksum comparison for each file.
4
8
 
5
9
  ## 0.2.1 ( 2012-09-26 )
6
10
 
@@ -15,8 +19,8 @@
15
19
  ## 0.1.0 ( 2012-09-24 )
16
20
 
17
21
  * Bump Chef dependency version up to 10.14
18
- * Add support for JSON environments
19
- * Add support for JSON roles
22
+ * Add support for JSON environments.
23
+ * Add support for JSON roles.
20
24
  * Display the diff between JSONs when JSON data doesn't match.
21
25
 
22
26
  ## 0.0.6 ( 2012-05-23 )
@@ -26,20 +30,20 @@
26
30
 
27
31
  ## 0.0.5 ( 2012-04-13 )
28
32
 
29
- * Fix #2, exception when a data bag item json file doesn't exist locally
33
+ * Fix #2, exception when a data bag item json file doesn't exist locally.
30
34
 
31
35
  ## 0.0.4 ( 2012-04-09 )
32
36
 
33
- * Add checks for data bags, data bag items, environments, and roles
37
+ * Add checks for data bags, data bag items, environments, and roles.
34
38
 
35
39
  ## 0.0.3 ( 2012-03-27 )
36
40
 
37
- * Read cookbook paths from knife config file instead of hardcoding /cookbooks
41
+ * Read cookbook paths from knife config file instead of hardcoding /cookbooks.
38
42
 
39
43
  ## 0.0.2 ( 2012-03-27 )
40
44
 
41
- * Make sure we iterate over actual cookbooks in cookbooks folder
45
+ * Make sure we iterate over actual cookbooks in cookbooks folder.
42
46
 
43
47
  ## 0.0.1 ( 2012-03-27 )
44
48
 
45
- * Initial release
49
+ * Initial release.
data/README.md CHANGED
@@ -23,7 +23,3 @@ So far it checks if...
23
23
  * your data bag items are in sync
24
24
  * your environments are in sync
25
25
  * your roles are in sync
26
-
27
- ## Assumptions
28
-
29
- * Your roles and environments are written using the ruby DSL.
@@ -77,9 +77,8 @@ module HealthInspector
77
77
  end
78
78
  end
79
79
 
80
- def chef_rest
81
- @rest ||= Chef::REST.new(@context.configure[:chef_server_url], @context.configure[:node_name],
82
- @context.configure[:client_key])
80
+ def chef_rest
81
+ @context.chef_rest
83
82
  end
84
83
 
85
84
  def run_check(check, item)
@@ -73,9 +73,8 @@ module HealthInspector
73
73
  end
74
74
 
75
75
  def cookbooks_on_server
76
- Yajl::Parser.parse( @context.knife_command("cookbook list -Fj") ).inject({}) do |hsh, c|
77
- name, version = c.split
78
- hsh[name] = version
76
+ chef_rest.get_rest("/cookbooks").inject({}) do |hsh, (name,version)|
77
+ hsh[name] = version["versions"].first["version"]
79
78
  hsh
80
79
  end
81
80
  end
@@ -100,30 +99,35 @@ module HealthInspector
100
99
  path ? File.join(path, name) : nil
101
100
  end
102
101
 
103
- def checksum_compare(name,version)
102
+ # TODO: Check files that exist locally but not in manifest on server
103
+ def checksum_compare(name, version)
104
104
  begin
105
105
  cookbook = chef_rest.get_rest("/cookbooks/#{name}/#{version}")
106
106
  rescue Net::HTTPServerException => e
107
107
  return ["Could not find cookbook #{name} on the server"]
108
108
  end
109
109
 
110
- cookbook.manifest.inject([]) do |memo, (key,value)|
111
- if value.kind_of? Array
112
- value.each do |file|
113
- path = cookbook_path("#{name}/#{file["path"]}")
114
-
115
- if path
116
- checksum = Chef::ChecksumCache.generate_md5_checksum_for_file(path)
117
- memo << "#{file['path']}" if checksum != file['checksum']
118
- else
119
- memo << "#{file['path']} does not exist in the repo"
120
- end
110
+ bad_files = []
111
+
112
+ Chef::CookbookVersion::COOKBOOK_SEGMENTS.each do |segment|
113
+ cookbook.manifest[segment].each do |manifest_record|
114
+ path = cookbook_path("#{name}/#{manifest_record["path"]}")
115
+
116
+ if path
117
+ checksum = checksum_cookbook_file(path)
118
+ bad_files << "#{manifest_record['path']}" if checksum != manifest_record['checksum']
119
+ else
120
+ bad_files << "#{manifest_record['path']} does not exist in the repo"
121
121
  end
122
122
  end
123
- memo
124
123
  end
124
+
125
+ bad_files
125
126
  end
126
127
 
128
+ def checksum_cookbook_file(filepath)
129
+ Chef::CookbookVersion.checksum_cookbook_file(filepath)
130
+ end
127
131
  end
128
132
  end
129
133
  end
@@ -2,10 +2,6 @@ require "chef/config"
2
2
 
3
3
  module HealthInspector
4
4
  class Context < Struct.new(:repo_path, :config_path)
5
- def knife_command(subcommnad)
6
- `cd #{repo_path} && knife #{subcommnad} -c #{config_path}`
7
- end
8
-
9
5
  def cookbook_path
10
6
  Array( config.cookbook_path )
11
7
  end
@@ -18,5 +14,9 @@ module HealthInspector
18
14
  Chef::Config.from_file(config_path)
19
15
  Chef::Config
20
16
  end
17
+
18
+ def chef_rest
19
+ @chef_rest ||= Chef::REST.new( config[:chef_server_url], config[:node_name], config[:client_key] )
20
+ end
21
21
  end
22
- end
22
+ end
@@ -1,3 +1,3 @@
1
1
  module HealthInspector
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
@@ -6,9 +6,11 @@ describe "HealthInspector::Checklists::DataBagItems" do
6
6
  end
7
7
 
8
8
  it "should detect if a data bag item does not exist locally" do
9
- subject.expects(:data_bag_items_on_server).returns( ["apps/app1"] )
10
- subject.expects(:load_item_from_server).with("apps/app1").returns({})
11
- failures = subject.run_checks(subject.items.first)
9
+ item = HealthInspector::Checklists::DataBagItems::DataBagItem.new(
10
+ :name => "apps", :server => ["apps/app1"], :local => nil
11
+ )
12
+
13
+ failures = subject.run_checks(item)
12
14
  failures.first.include?("exists on server but not locally").must_equal true
13
15
  end
14
16
  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.3.0
4
+ version: 0.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-09-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: minitest
16
- requirement: &70140548345560 !ruby/object:Gem::Requirement
16
+ requirement: &70329253887600 !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: *70140548345560
24
+ version_requirements: *70329253887600
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: mocha
27
- requirement: &70140548344640 !ruby/object:Gem::Requirement
27
+ requirement: &70329253886680 !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: *70140548344640
35
+ version_requirements: *70329253886680
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: thor
38
- requirement: &70140548344100 !ruby/object:Gem::Requirement
38
+ requirement: &70329253886140 !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: *70140548344100
46
+ version_requirements: *70329253886140
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: chef
49
- requirement: &70140548343560 !ruby/object:Gem::Requirement
49
+ requirement: &70329253885600 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '10.14'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70140548343560
57
+ version_requirements: *70329253885600
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: yajl-ruby
60
- requirement: &70140548343140 !ruby/object:Gem::Requirement
60
+ requirement: &70329253885180 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: '0'
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *70140548343140
68
+ version_requirements: *70329253885180
69
69
  description: A tool to inspect your chef repo as is compares to what is on your chef
70
70
  server
71
71
  email: