knife-inspect 0.6.2 → 0.7.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 93d11b775e0d0a9c62affe93ccf80f97e76ba075
4
+ data.tar.gz: 0840a56e0c61e3e8aeae5964fd861f55719124cc
5
+ SHA512:
6
+ metadata.gz: 5437694f23d11c9c5eb948e32f8532c29f77d52fc30acf275552fdd16572d293563deaa36af45483c1040f2860f3fc0e017abbb4d3331b552cebbfb9a4051833
7
+ data.tar.gz: b9e3d09b260fc0762c20215eece40f710a511e94c34dc5793192e17239b9dc266468b3067d0960874e35779838d1016c681248ccc3a6d70b22a789475c049bb5
data/.gitignore CHANGED
@@ -3,3 +3,4 @@
3
3
  Gemfile.lock
4
4
  pkg/*
5
5
  !.gitkeep
6
+ /coverage/
data/.travis.yml ADDED
@@ -0,0 +1,11 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ env:
5
+ - CHEF_VERSION=10.24.0
6
+ - CHEF_VERSION=10.26.0
7
+ - CHEF_VERSION=11.4.0
8
+ - CHEF_VERSION=11.4.4
9
+ - CHEF_VERSION=11.6.0
10
+ before_script:
11
+ - chef-client --version
data/Gemfile CHANGED
@@ -1,4 +1,3 @@
1
- source "http://rubygems.org"
1
+ source 'https://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in health_inspector.gemspec
4
3
  gemspec
data/HISTORY.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## 0.7.0 ( 2014-01-03 )
2
+
3
+ > It's alive! Thanks a lot to Ben Marini for starting this project!
4
+ > I'm happy to be the new maintainer of knife-inspect, this is an essential
5
+ > tool for all users Chef Server users.
6
+ >
7
+ > -- [Greg Karékinian](https://github.com/gregkare)
8
+
9
+ * The plugin is now compatible with Chef 11 ([#6][#6])
10
+ * Fix inspect for something non-existent ([#2][#2])
11
+ * Exit with the proper status (0 for success, 1 for failure) ([#14][#14])
12
+ * Remove dependency on thor ([#15][#15])
13
+ * Specify version of the yajl-ruby gem (same as Chef)
14
+
1
15
  ## 0.6.2 ( 2013-02-27 )
2
16
 
3
17
  * Be indifferent about symbols and strings for hash keys when diff'ing
@@ -89,4 +103,10 @@
89
103
 
90
104
  ## 0.0.1 ( 2012-03-27 )
91
105
 
92
- * Initial release.
106
+ * Initial release.
107
+
108
+
109
+ [#15]: https://github.com/bmarini/knife-inspect/issues/15
110
+ [#14]: https://github.com/bmarini/knife-inspect/issues/14
111
+ [#6]: https://github.com/bmarini/knife-inspect/issues/6
112
+ [#2]: https://github.com/bmarini/knife-inspect/issues/2
@@ -2,26 +2,31 @@
2
2
  $:.push File.expand_path("../lib", __FILE__)
3
3
  require "health_inspector/version"
4
4
 
5
+ # Allow to pass an arbitrary chef version. Useful for testing for example.
6
+ chef_version = if ENV.key?('CHEF_VERSION')
7
+ "= #{ENV['CHEF_VERSION']}"
8
+ else
9
+ ['>= 10', '<= 12']
10
+ end
11
+
5
12
  Gem::Specification.new do |s|
6
- s.name = "knife-inspect"
13
+ s.name = 'knife-inspect'
7
14
  s.version = HealthInspector::VERSION
8
- s.authors = ["Ben Marini"]
9
- s.email = ["bmarini@gmail.com"]
10
- s.homepage = "https://github.com/bmarini/knife-inspect"
11
- s.summary = %q{Inspect your chef repo as is compares to what is on your chef server}
12
- s.description = %q{Inspect your chef repo as is compares to what is on your chef server}
13
-
14
- s.rubyforge_project = "knife-inspect"
15
+ s.authors = ['Greg Karékinian', 'Ben Marini']
16
+ s.email = ['greg@karekinian.com']
17
+ s.license = 'MIT'
18
+ s.homepage = 'https://github.com/bmarini/knife-inspect'
19
+ s.summary = 'Inspect your chef repo as it is compared to what is on your chef server'
20
+ s.description = 'knife-inspect is a knife plugin to compare the content of your Chef repository and Chef server'
15
21
 
16
22
  s.files = `git ls-files`.split("\n")
17
23
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
24
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
- s.require_paths = ["lib"]
20
25
 
21
- s.add_development_dependency "rake"
22
- s.add_development_dependency "rspec"
26
+ s.add_development_dependency 'rake', '~> 10.1'
27
+ s.add_development_dependency 'rspec', '~> 2.14'
28
+ s.add_development_dependency 'simplecov', '~> 0.8'
23
29
 
24
- s.add_runtime_dependency "thor"
25
- s.add_runtime_dependency "chef", "~> 10.14"
26
- s.add_runtime_dependency "yajl-ruby"
30
+ s.add_runtime_dependency 'chef', chef_version
31
+ s.add_runtime_dependency 'yajl-ruby', '~> 1.1'
27
32
  end
@@ -13,7 +13,7 @@ class Chef
13
13
 
14
14
  banner "knife cookbook inspect [COOKBOOK] (options)"
15
15
 
16
- def run
16
+ def run
17
17
  case @name_args.length
18
18
  when 1 # We are inspecting a cookbook
19
19
  cookbook_name = @name_args[0]
@@ -22,9 +22,9 @@ class Chef
22
22
  # api_endpoint = env ? "environments/#{env}/cookbooks/#{cookbook_name}" : "cookbooks/#{cookbook_name}"
23
23
 
24
24
  validator = HealthInspector::Checklists::Cookbooks.new(self)
25
- validator.validate_item( validator.load_item(cookbook_name) )
25
+ exit validator.validate_item( validator.load_item(cookbook_name) )
26
26
  when 0 # We are inspecting all the cookbooks
27
- HealthInspector::Checklists::Cookbooks.run(self)
27
+ exit HealthInspector::Checklists::Cookbooks.run(self)
28
28
  end
29
29
  end
30
30
  end
@@ -17,17 +17,17 @@ class Chef
17
17
  item_name = @name_args[1]
18
18
 
19
19
  validator = HealthInspector::Checklists::DataBagItems.new(self)
20
- validator.validate_item( validator.load_item("#{bag_name}/#{item_name}") )
20
+ exit validator.validate_item( validator.load_item("#{bag_name}/#{item_name}") )
21
21
 
22
22
  when 1 # We are inspecting a data bag
23
23
  bag_name = @name_args[0]
24
24
 
25
25
  validator = HealthInspector::Checklists::DataBags.new(self)
26
- validator.validate_item( validator.load_item(bag_name) )
26
+ exit validator.validate_item( validator.load_item(bag_name) )
27
27
 
28
28
  when 0 # We are inspecting all the data bags
29
29
  HealthInspector::Checklists::DataBags.run(self)
30
- HealthInspector::Checklists::DataBagItems.run(self)
30
+ exit HealthInspector::Checklists::DataBagItems.run(self)
31
31
  end
32
32
  end
33
33
  end
@@ -10,14 +10,14 @@ class Chef
10
10
 
11
11
  banner "knife environment inspect [ENVIRONMENT] (options)"
12
12
 
13
- def run
13
+ def run
14
14
  case @name_args.length
15
15
  when 1 # We are inspecting a environment
16
16
  environment_name = @name_args[0]
17
17
  validator = HealthInspector::Checklists::Environments.new(self)
18
- validator.validate_item( validator.load_item(environment_name) )
18
+ exit validator.validate_item( validator.load_item(environment_name) )
19
19
  when 0 # We are inspecting all the environments
20
- HealthInspector::Checklists::Environments.run(self)
20
+ exit HealthInspector::Checklists::Environments.run(self)
21
21
  end
22
22
  end
23
23
  end
@@ -4,6 +4,8 @@ class Chef
4
4
  class Knife
5
5
  class Inspect < Knife
6
6
 
7
+ CHECKLISTS = %w[Cookbooks DataBags DataBagItems Environments Roles]
8
+
7
9
  deps do
8
10
  require "health_inspector"
9
11
  end
@@ -11,9 +13,11 @@ class Chef
11
13
  banner "knife inspect"
12
14
 
13
15
  def run
14
- %w[ Cookbooks DataBags DataBagItems Environments Roles ].each do |checklist|
16
+ results = CHECKLISTS.map do |checklist|
15
17
  HealthInspector::Checklists.const_get(checklist).run(self)
16
18
  end
19
+
20
+ exit ! results.include?(false)
17
21
  end
18
22
  end
19
23
  end
@@ -10,14 +10,14 @@ class Chef
10
10
 
11
11
  banner "knife role inspect [ROLE] (options)"
12
12
 
13
- def run
13
+ def run
14
14
  case @name_args.length
15
15
  when 1 # We are inspecting a role
16
16
  role_name = @name_args[0]
17
17
  validator = HealthInspector::Checklists::Roles.new(self)
18
- validator.validate_item( validator.load_item(role_name) )
18
+ exit validator.validate_item( validator.load_item(role_name) )
19
19
  when 0 # We are inspecting all the roles
20
- HealthInspector::Checklists::Roles.run(self)
20
+ exit HealthInspector::Checklists::Roles.run(self)
21
21
  end
22
22
  end
23
23
  end
@@ -11,7 +11,6 @@ require "health_inspector/checklists/data_bag_items"
11
11
  require "health_inspector/checklists/environments"
12
12
  require "health_inspector/checklists/roles"
13
13
  require 'chef/rest'
14
- require 'chef/checksum_cache'
15
14
  require 'chef/version'
16
15
 
17
16
  module HealthInspector
@@ -41,9 +41,13 @@ module HealthInspector
41
41
  def run
42
42
  banner "Inspecting #{self.class.title}"
43
43
 
44
+ results = []
45
+
44
46
  each_item do |item|
45
- validate_item(item)
47
+ results << validate_item(item)
46
48
  end
49
+
50
+ return ! results.include?(false)
47
51
  end
48
52
 
49
53
  def validate_item(item)
@@ -52,8 +56,12 @@ module HealthInspector
52
56
 
53
57
  if failures.empty?
54
58
  print_success(item.name) # unless @context.quiet_success
59
+
60
+ true
55
61
  else
56
62
  print_failures(item.name, failures)
63
+
64
+ false
57
65
  end
58
66
  end
59
67
 
@@ -103,7 +111,7 @@ module HealthInspector
103
111
  print value["server"]
104
112
  print "\n"
105
113
  print indent( color('bright fail',"local value = "), depth + 1 )
106
- print value["local"]
114
+ print value["local"]
107
115
  print "\n\n"
108
116
  end
109
117
 
@@ -6,6 +6,7 @@ module HealthInspector
6
6
  include ExistenceValidations
7
7
  include JsonValidations
8
8
 
9
+ private
9
10
  # Override to ignore _default environment if it is missing locally
10
11
  def validate_local_copy_exists
11
12
  super unless name == '_default'
@@ -41,14 +41,14 @@ module HealthInspector
41
41
  def hash_diff(original, other)
42
42
  recursive_diff(stringify_hash_keys(original), stringify_hash_keys(other))
43
43
  end
44
-
44
+
45
45
  def stringify_hash_keys(original)
46
46
  original.keys.inject({}) do |original_strkey, key|
47
47
  original_strkey[key.to_s] = stringify_item(original[key])
48
48
  original_strkey
49
49
  end
50
50
  end
51
-
51
+
52
52
  def stringify_item(item)
53
53
  if item.kind_of?(Hash)
54
54
  stringify_hash_keys(item)
@@ -58,7 +58,7 @@ module HealthInspector
58
58
  item
59
59
  end
60
60
  end
61
-
61
+
62
62
  def recursive_diff(original, other)
63
63
  (original.keys + other.keys).uniq.inject({}) do |memo, key|
64
64
  unless original[key] == other[key]
@@ -76,6 +76,17 @@ module HealthInspector
76
76
 
77
77
  # Mixins for common validations across pairings
78
78
  module ExistenceValidations
79
+ def validate_existence
80
+ if local.nil? && server.nil?
81
+ errors.add "does not exist locally or on server"
82
+ return
83
+ end
84
+
85
+ validate_local_copy_exists
86
+ validate_server_copy_exists
87
+ end
88
+
89
+ private
79
90
  def validate_local_copy_exists
80
91
  errors.add "exists on server but not locally" if local.nil?
81
92
  end
@@ -93,4 +104,4 @@ module HealthInspector
93
104
  end
94
105
  end
95
106
  end
96
- end
107
+ end
@@ -1,3 +1,3 @@
1
1
  module HealthInspector
2
- VERSION = "0.6.2"
2
+ VERSION = '0.7.0'
3
3
  end
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,10 @@
1
+ if RUBY_VERSION > '1.9'
2
+ require 'simplecov'
3
+ SimpleCov.start do
4
+ add_filter "/spec/"
5
+ end
6
+ end
7
+
1
8
  require 'rubygems'
2
9
  require 'bundler/setup'
3
10
  require 'health_inspector'
@@ -32,6 +39,14 @@ shared_examples "a chef model" do
32
39
  pairing.errors.should_not be_empty
33
40
  pairing.errors.first.should == "exists locally but not on server"
34
41
  end
42
+
43
+ it "should detect if an item does not exist locally or on server" do
44
+ pairing.server = nil
45
+ pairing.local = nil
46
+ pairing.validate
47
+
48
+ pairing.errors.to_a.should == ["does not exist locally or on server"]
49
+ end
35
50
  end
36
51
 
37
52
  shared_examples "a chef model that can be respresented in json" do
@@ -41,64 +56,64 @@ shared_examples "a chef model that can be respresented in json" do
41
56
  pairing.server = {"foo" => "bar"}
42
57
  pairing.local = {"foo" => "baz"}
43
58
  pairing.validate
44
-
59
+
45
60
  pairing.errors.should_not be_empty
46
61
  pairing.errors.first.should == {"foo"=>{"server"=>"bar", "local"=>"baz"}}
47
62
  end
48
-
63
+
49
64
  it "should detect if an item is the same" do
50
65
  pairing.server = {"foo" => "bar"}
51
66
  pairing.local = {"foo" => "bar"}
52
67
  pairing.validate
53
-
68
+
54
69
  pairing.errors.should be_empty
55
70
  end
56
-
71
+
57
72
  it "should detect if an string and symbol keys convert to the same values" do
58
73
  pairing.server = {"foo" => "bar"}
59
74
  pairing.local = {:foo => "bar"}
60
75
  pairing.validate
61
-
76
+
62
77
  pairing.errors.should be_empty
63
78
  end
64
-
79
+
65
80
  it "should detect if matching hashes are the same" do
66
81
  pairing.server = {"foo" => {"bar" => "fizz"}}
67
82
  pairing.local = {"foo" => {"bar" => "fizz"}}
68
83
  pairing.validate
69
-
84
+
70
85
  pairing.errors.should be_empty
71
86
  end
72
-
87
+
73
88
  it "should detect if matching hashes with mismatched symbols and keys are the same" do
74
89
  pairing.server = {"foo" => {"bar" => "fizz"}}
75
90
  pairing.local = {:foo => {:bar => "fizz"}}
76
91
  pairing.validate
77
-
92
+
78
93
  pairing.errors.should be_empty
79
94
  end
80
-
95
+
81
96
  it "should detect if matching arrays are the same" do
82
97
  pairing.server = {"foo" => ["bar", "fizz"]}
83
98
  pairing.local = {"foo" => ["bar", "fizz"]}
84
99
  pairing.validate
85
-
100
+
86
101
  pairing.errors.should be_empty
87
102
  end
88
-
103
+
89
104
  it "should detect if matching arrays with hashes are the same" do
90
105
  pairing.server = {"foo" => ["bar", {"fizz" => "buzz"}]}
91
106
  pairing.local = {"foo" => ["bar", {"fizz" => "buzz"}]}
92
107
  pairing.validate
93
-
108
+
94
109
  pairing.errors.should be_empty
95
110
  end
96
-
111
+
97
112
  it "should detect if matching arrays with hashes containing symbols/strings are the same" do
98
113
  pairing.server = {"foo" => ["bar", {"fizz" => "buzz"}]}
99
114
  pairing.local = {"foo" => ["bar", {:fizz => "buzz"}]}
100
115
  pairing.validate
101
-
116
+
102
117
  pairing.errors.should be_empty
103
118
  end
104
- end
119
+ end
metadata CHANGED
@@ -1,104 +1,102 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knife-inspect
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
5
- prerelease:
4
+ version: 0.7.0
6
5
  platform: ruby
7
6
  authors:
7
+ - Greg Karékinian
8
8
  - Ben Marini
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-28 00:00:00.000000000 Z
12
+ date: 2014-01-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
16
16
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
17
  requirements:
19
- - - ! '>='
18
+ - - "~>"
20
19
  - !ruby/object:Gem::Version
21
- version: '0'
20
+ version: '10.1'
22
21
  type: :development
23
22
  prerelease: false
24
23
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
24
  requirements:
27
- - - ! '>='
25
+ - - "~>"
28
26
  - !ruby/object:Gem::Version
29
- version: '0'
27
+ version: '10.1'
30
28
  - !ruby/object:Gem::Dependency
31
29
  name: rspec
32
30
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
31
  requirements:
35
- - - ! '>='
32
+ - - "~>"
36
33
  - !ruby/object:Gem::Version
37
- version: '0'
34
+ version: '2.14'
38
35
  type: :development
39
36
  prerelease: false
40
37
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
38
  requirements:
43
- - - ! '>='
39
+ - - "~>"
44
40
  - !ruby/object:Gem::Version
45
- version: '0'
41
+ version: '2.14'
46
42
  - !ruby/object:Gem::Dependency
47
- name: thor
43
+ name: simplecov
48
44
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
45
  requirements:
51
- - - ! '>='
46
+ - - "~>"
52
47
  - !ruby/object:Gem::Version
53
- version: '0'
54
- type: :runtime
48
+ version: '0.8'
49
+ type: :development
55
50
  prerelease: false
56
51
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
52
  requirements:
59
- - - ! '>='
53
+ - - "~>"
60
54
  - !ruby/object:Gem::Version
61
- version: '0'
55
+ version: '0.8'
62
56
  - !ruby/object:Gem::Dependency
63
57
  name: chef
64
58
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
59
  requirements:
67
- - - ~>
60
+ - - ">="
68
61
  - !ruby/object:Gem::Version
69
- version: '10.14'
62
+ version: '10'
63
+ - - "<="
64
+ - !ruby/object:Gem::Version
65
+ version: '12'
70
66
  type: :runtime
71
67
  prerelease: false
72
68
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
69
  requirements:
75
- - - ~>
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '10'
73
+ - - "<="
76
74
  - !ruby/object:Gem::Version
77
- version: '10.14'
75
+ version: '12'
78
76
  - !ruby/object:Gem::Dependency
79
77
  name: yajl-ruby
80
78
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
79
  requirements:
83
- - - ! '>='
80
+ - - "~>"
84
81
  - !ruby/object:Gem::Version
85
- version: '0'
82
+ version: '1.1'
86
83
  type: :runtime
87
84
  prerelease: false
88
85
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
86
  requirements:
91
- - - ! '>='
87
+ - - "~>"
92
88
  - !ruby/object:Gem::Version
93
- version: '0'
94
- description: Inspect your chef repo as is compares to what is on your chef server
89
+ version: '1.1'
90
+ description: knife-inspect is a knife plugin to compare the content of your Chef repository
91
+ and Chef server
95
92
  email:
96
- - bmarini@gmail.com
93
+ - greg@karekinian.com
97
94
  executables: []
98
95
  extensions: []
99
96
  extra_rdoc_files: []
100
97
  files:
101
- - .gitignore
98
+ - ".gitignore"
99
+ - ".travis.yml"
102
100
  - Gemfile
103
101
  - HISTORY.md
104
102
  - MIT-LICENSE
@@ -131,29 +129,29 @@ files:
131
129
  - spec/role_spec.rb
132
130
  - spec/spec_helper.rb
133
131
  homepage: https://github.com/bmarini/knife-inspect
134
- licenses: []
132
+ licenses:
133
+ - MIT
134
+ metadata: {}
135
135
  post_install_message:
136
136
  rdoc_options: []
137
137
  require_paths:
138
138
  - lib
139
139
  required_ruby_version: !ruby/object:Gem::Requirement
140
- none: false
141
140
  requirements:
142
- - - ! '>='
141
+ - - ">="
143
142
  - !ruby/object:Gem::Version
144
143
  version: '0'
145
144
  required_rubygems_version: !ruby/object:Gem::Requirement
146
- none: false
147
145
  requirements:
148
- - - ! '>='
146
+ - - ">="
149
147
  - !ruby/object:Gem::Version
150
148
  version: '0'
151
149
  requirements: []
152
- rubyforge_project: knife-inspect
153
- rubygems_version: 1.8.23
150
+ rubyforge_project:
151
+ rubygems_version: 2.2.0
154
152
  signing_key:
155
- specification_version: 3
156
- summary: Inspect your chef repo as is compares to what is on your chef server
153
+ specification_version: 4
154
+ summary: Inspect your chef repo as it is compared to what is on your chef server
157
155
  test_files:
158
156
  - spec/chef-repo/.chef/client.pem
159
157
  - spec/chef-repo/.chef/knife.rb
@@ -163,4 +161,3 @@ test_files:
163
161
  - spec/environment_spec.rb
164
162
  - spec/role_spec.rb
165
163
  - spec/spec_helper.rb
166
- has_rdoc: