chef-handler-serverspec 0.1.2
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 +7 -0
- data/LICENSE +21 -0
- data/lib/chef/handler/resources/cookbook_file.rb +17 -0
- data/lib/chef/handler/resources/cron.rb +14 -0
- data/lib/chef/handler/resources/directory.rb +23 -0
- data/lib/chef/handler/resources/file.rb +28 -0
- data/lib/chef/handler/resources/gem_package.rb +14 -0
- data/lib/chef/handler/resources/group.rb +28 -0
- data/lib/chef/handler/resources/link.rb +24 -0
- data/lib/chef/handler/resources/package.rb +20 -0
- data/lib/chef/handler/resources/resource.rb +10 -0
- data/lib/chef/handler/resources/service.rb +29 -0
- data/lib/chef/handler/resources/template.rb +22 -0
- data/lib/chef/handler/resources/user.rb +29 -0
- data/lib/chef/handler/serverspec.rb +55 -0
- metadata +57 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5dbf0297b44f71aeaf43906781c346867f85f5cf
|
4
|
+
data.tar.gz: d948939e46fe07c03879cc788fba9dbb60ad15ee
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b0024d5704917d453cd863354b1086c804d604601943127b56876b33ee9db831337976610f928690266cf2392c5714b198efbf08b70a7045162bb18d1a077475
|
7
|
+
data.tar.gz: efe2f01604341eb00377a3d55733635f74115434eeb3646ffd96065a448e003bc3aaef0fa88d4294f35587498a7c51e27fb391d6408aa505b0b9778e75c1ed12
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) Jose Coelho
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class Chef
|
2
|
+
class Resource
|
3
|
+
class CookbookFile < Chef::Resource::File
|
4
|
+
def to_serverspec
|
5
|
+
<<-EOT
|
6
|
+
|
7
|
+
describe file('#{path}') do
|
8
|
+
it { should be_file }
|
9
|
+
it { should be_mode '#{mode}' }
|
10
|
+
it { should be_owned_by '#{owner}' }
|
11
|
+
it { should be_grouped_into '#{group}' }
|
12
|
+
end
|
13
|
+
EOT
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class Chef
|
2
|
+
class Resource
|
3
|
+
class Cron < Chef::Resource
|
4
|
+
def to_serverspec
|
5
|
+
<<-EOT
|
6
|
+
|
7
|
+
describe cron do
|
8
|
+
it { should have_entry('#{minute} #{hour} #{day} #{month} #{weekday} #{command}').with_user('#{user}') }
|
9
|
+
end
|
10
|
+
EOT
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class Chef
|
2
|
+
class Resource
|
3
|
+
class Directory < Chef::Resource
|
4
|
+
def to_serverspec
|
5
|
+
ERB.new(
|
6
|
+
<<-EOT,
|
7
|
+
|
8
|
+
describe file('#{path}') do
|
9
|
+
<%- unless action.include? :delete -%>
|
10
|
+
it { should be_directory }
|
11
|
+
it { should be_mode '#{mode}' }
|
12
|
+
it { should be_owned_by '#{owner}' }
|
13
|
+
it { should be_grouped_into '#{group}' }
|
14
|
+
<%- else -%>
|
15
|
+
it { should_not be_directory }
|
16
|
+
<%- end -%>
|
17
|
+
end
|
18
|
+
EOT
|
19
|
+
safe_level = nil, trim_mode = '-').result(binding)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
class Chef
|
2
|
+
class Resource
|
3
|
+
class File < Chef::Resource
|
4
|
+
def to_serverspec
|
5
|
+
ERB.new(
|
6
|
+
<<-EOT,
|
7
|
+
|
8
|
+
describe file('#{path}') do
|
9
|
+
<%- unless action.include? :delete -%>
|
10
|
+
it { should be_file }
|
11
|
+
it { should be_mode '#{mode}' }
|
12
|
+
it { should be_owned_by '#{owner}' }
|
13
|
+
it { should be_grouped_into '#{group}' }
|
14
|
+
its(:content) do
|
15
|
+
should match <<EOF
|
16
|
+
#{::File.read(path) if ::File.exist?(path)}
|
17
|
+
EOF
|
18
|
+
end
|
19
|
+
<%- else -%>
|
20
|
+
it { should_not be_file }
|
21
|
+
<%- end -%>
|
22
|
+
end
|
23
|
+
EOT
|
24
|
+
safe_level = nil, trim_mode = '-').result(binding)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class Chef
|
2
|
+
class Resource
|
3
|
+
class GemPackage < Chef::Resource::Package
|
4
|
+
def to_serverspec
|
5
|
+
<<-EOT
|
6
|
+
|
7
|
+
describe package('#{package_name}') do
|
8
|
+
it { should be_installed.by('gem')#{'.with_version(\'' + version + '\')' unless version.nil?} }
|
9
|
+
end
|
10
|
+
EOT
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'erb'
|
2
|
+
|
3
|
+
class Chef
|
4
|
+
class Resource
|
5
|
+
class Group < Chef::Resource
|
6
|
+
def to_serverspec
|
7
|
+
ERB.new(
|
8
|
+
<<-EOT,
|
9
|
+
|
10
|
+
describe group('#{group_name}') do
|
11
|
+
<%- unless action.include? :remove -%>
|
12
|
+
it { should exist }
|
13
|
+
it { should have_gid #{gid} }
|
14
|
+
<%- else -%>
|
15
|
+
it { should_not exist }
|
16
|
+
<%- end -%>
|
17
|
+
end
|
18
|
+
<% users.each do |user| %>
|
19
|
+
describe user('<%= user %>') do
|
20
|
+
it { should belong_to_group '#{group_name}' }
|
21
|
+
end
|
22
|
+
<% end %>
|
23
|
+
EOT
|
24
|
+
safe_level = nil, trim_mode = '-').result(binding)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class Chef
|
2
|
+
class Resource
|
3
|
+
class Link < Chef::Resource
|
4
|
+
def to_serverspec
|
5
|
+
ERB.new(
|
6
|
+
<<-EOT,
|
7
|
+
|
8
|
+
describe file('#{target_file}') do
|
9
|
+
<%- unless action.include? :delete -%>
|
10
|
+
it { should be_symlink }
|
11
|
+
it { should be_linked_to '#{to}' }
|
12
|
+
it { should be_mode '#{mode}' }
|
13
|
+
it { should be_owned_by '#{owner}' }
|
14
|
+
it { should be_grouped_into '#{group}' }
|
15
|
+
<%- else -%>
|
16
|
+
it { should_not be_symlink }
|
17
|
+
<%- end -%>
|
18
|
+
end
|
19
|
+
EOT
|
20
|
+
safe_level = nil, trim_mode = '-').result(binding)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class Chef
|
2
|
+
class Resource
|
3
|
+
class Package < Chef::Resource
|
4
|
+
def to_serverspec
|
5
|
+
ERB.new(
|
6
|
+
<<-EOT,
|
7
|
+
|
8
|
+
describe package('#{package_name}') do
|
9
|
+
<%- unless action.include? :remove -%>
|
10
|
+
it { should be_installed#{'.with_version(\'' + version + '\')' unless version.nil?} }
|
11
|
+
<%- else -%>
|
12
|
+
it { should_not be_installed }
|
13
|
+
<%- end -%>
|
14
|
+
end
|
15
|
+
EOT
|
16
|
+
safe_level = nil, trim_mode = '-').result(binding)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'erb'
|
2
|
+
|
3
|
+
class Chef
|
4
|
+
class Resource
|
5
|
+
class Service < Chef::Resource
|
6
|
+
def to_serverspec
|
7
|
+
ERB.new(
|
8
|
+
<<-EOT,
|
9
|
+
|
10
|
+
describe service('<%= name %>') do
|
11
|
+
<%- if action.include? :enable -%>
|
12
|
+
it { should be_enabled }
|
13
|
+
<%- end -%>
|
14
|
+
<%- if action.include? :disable -%>
|
15
|
+
it { should_not be_enabled }
|
16
|
+
<%- end -%>
|
17
|
+
<%- if action.include? :start -%>
|
18
|
+
it { should be_running }
|
19
|
+
<%- end -%>
|
20
|
+
<%- if action.include? :stop -%>
|
21
|
+
it { should_not be_running }
|
22
|
+
<%- end -%>
|
23
|
+
end
|
24
|
+
EOT
|
25
|
+
safe_level = nil, trim_mode = '-').result(binding)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class Chef
|
2
|
+
class Resource
|
3
|
+
class Template < Chef::Resource::File
|
4
|
+
def to_serverspec
|
5
|
+
<<-EOT
|
6
|
+
|
7
|
+
describe file('#{path}') do
|
8
|
+
it { should be_file }
|
9
|
+
it { should be_mode '#{mode}' }
|
10
|
+
it { should be_owned_by '#{owner}' }
|
11
|
+
it { should be_grouped_into '#{group}' }
|
12
|
+
its(:content) do
|
13
|
+
should match <<-EOF
|
14
|
+
#{::File.read(path) if ::File.exist?(path)}
|
15
|
+
EOF
|
16
|
+
end
|
17
|
+
end
|
18
|
+
EOT
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
class Chef
|
2
|
+
class Resource
|
3
|
+
class User < Chef::Resource
|
4
|
+
def to_serverspec
|
5
|
+
ERB.new(
|
6
|
+
<<-EOT,
|
7
|
+
|
8
|
+
describe user('#{username}') do
|
9
|
+
<%- unless action.include? :remove -%>
|
10
|
+
it { should exist }
|
11
|
+
<%- if uid -%>
|
12
|
+
it { should have_uid #{uid} }
|
13
|
+
<%- end -%>
|
14
|
+
<%- if shell -%>
|
15
|
+
it { should have_login_shell '#{shell}' }
|
16
|
+
<%- end -%>
|
17
|
+
<%- if home -%>
|
18
|
+
it { should have_home_directory '#{home}' }
|
19
|
+
<%- end -%>
|
20
|
+
<%- else -%>
|
21
|
+
it { should_not exist }
|
22
|
+
<%- end -%>
|
23
|
+
end
|
24
|
+
EOT
|
25
|
+
safe_level = nil, trim_mode = '-').result(binding)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'chef/log'
|
3
|
+
require 'chef/mash'
|
4
|
+
require 'chef/handler'
|
5
|
+
|
6
|
+
Dir[File.dirname(__FILE__) + '/resources/*.rb'].each { |file| require file }
|
7
|
+
|
8
|
+
class Chef
|
9
|
+
class Handler
|
10
|
+
# Serverspec handler
|
11
|
+
class Serverspec < Chef::Handler
|
12
|
+
attr_reader :config
|
13
|
+
|
14
|
+
def initialize(config = {})
|
15
|
+
@config = Mash.new(config)
|
16
|
+
@config[:output_dir] ||= '/tmp/serverspec'
|
17
|
+
@config
|
18
|
+
end
|
19
|
+
|
20
|
+
def report
|
21
|
+
resource_tree.each do |cookbook, recipes|
|
22
|
+
recipes.each do |recipe, resources|
|
23
|
+
spec_dir = File.join(@config[:output_dir], cookbook)
|
24
|
+
build_output_dir(spec_dir)
|
25
|
+
|
26
|
+
File.open(File.join(spec_dir, "#{recipe}_spec.rb"), 'w') do |file|
|
27
|
+
file.write("context 'recipe[#{cookbook}::#{recipe}]' do\n")
|
28
|
+
resources.each do |r|
|
29
|
+
file.write(r.to_serverspec)
|
30
|
+
end
|
31
|
+
file.write("end\n")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def build_output_dir(name)
|
38
|
+
unless File.exist?(name)
|
39
|
+
FileUtils.mkdir_p(name)
|
40
|
+
File.chmod(00700, name)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def resource_tree
|
45
|
+
resources = Hash.new { |h, k| h[k] = Hash.new { |h, k| h[k] = [] } }
|
46
|
+
|
47
|
+
all_resources.each do |r|
|
48
|
+
resources[r.cookbook_name || 'none'][r.recipe_name || 'none'] << r
|
49
|
+
end
|
50
|
+
|
51
|
+
resources
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
metadata
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: chef-handler-serverspec
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jose Coelho
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-06-11 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Chef report handler
|
14
|
+
email: jose.alberto.coelho@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- LICENSE
|
20
|
+
- lib/chef/handler/resources/cookbook_file.rb
|
21
|
+
- lib/chef/handler/resources/cron.rb
|
22
|
+
- lib/chef/handler/resources/directory.rb
|
23
|
+
- lib/chef/handler/resources/file.rb
|
24
|
+
- lib/chef/handler/resources/gem_package.rb
|
25
|
+
- lib/chef/handler/resources/group.rb
|
26
|
+
- lib/chef/handler/resources/link.rb
|
27
|
+
- lib/chef/handler/resources/package.rb
|
28
|
+
- lib/chef/handler/resources/resource.rb
|
29
|
+
- lib/chef/handler/resources/service.rb
|
30
|
+
- lib/chef/handler/resources/template.rb
|
31
|
+
- lib/chef/handler/resources/user.rb
|
32
|
+
- lib/chef/handler/serverspec.rb
|
33
|
+
homepage: http://github.com/jacoelho
|
34
|
+
licenses:
|
35
|
+
- MIT
|
36
|
+
metadata: {}
|
37
|
+
post_install_message:
|
38
|
+
rdoc_options: []
|
39
|
+
require_paths:
|
40
|
+
- lib
|
41
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
requirements: []
|
52
|
+
rubyforge_project:
|
53
|
+
rubygems_version: 2.5.1
|
54
|
+
signing_key:
|
55
|
+
specification_version: 4
|
56
|
+
summary: Chef report handler
|
57
|
+
test_files: []
|