serverspec 0.6.15 → 0.6.16

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -2,6 +2,7 @@
2
2
  *.rbc
3
3
  *.swp
4
4
  .bundle
5
+ .rvmrc
5
6
  .config
6
7
  .yardoc
7
8
  .rspec
data/lib/serverspec.rb CHANGED
@@ -12,6 +12,7 @@ require 'serverspec/commands/redhat'
12
12
  require 'serverspec/commands/debian'
13
13
  require 'serverspec/commands/gentoo'
14
14
  require 'serverspec/commands/solaris'
15
+ require 'serverspec/commands/smartos'
15
16
  require 'serverspec/commands/darwin'
16
17
  require 'serverspec/configuration'
17
18
  require 'rspec/core/formatters/base_formatter'
@@ -32,6 +33,7 @@ RSpec.configure do |c|
32
33
  c.include(Serverspec::Helper::Debian, :os => :debian)
33
34
  c.include(Serverspec::Helper::Gentoo, :os => :gentoo)
34
35
  c.include(Serverspec::Helper::Solaris, :os => :solaris)
36
+ c.include(Serverspec::Helper::SmartOS, :os => :smartos)
35
37
  c.include(Serverspec::Helper::Darwin, :os => :darwin)
36
38
  c.add_setting :os, :default => nil
37
39
  c.add_setting :host, :default => nil
@@ -182,7 +182,11 @@ module Serverspec
182
182
  elsif run_command('ls /etc/gentoo-release')[:exit_status] == 0
183
183
  'Gentoo'
184
184
  elsif run_command('uname -s')[:stdout] =~ /SunOS/i
185
- 'Solaris'
185
+ if run_command('grep -q SmartOS /etc/release')
186
+ 'SmartOS'
187
+ else
188
+ 'Solaris'
189
+ end
186
190
  elsif run_command('uname -s')[:stdout] =~ /Darwin/i
187
191
  'Darwin'
188
192
  else
@@ -0,0 +1,13 @@
1
+ module Serverspec
2
+ module Commands
3
+ class SmartOS < Serverspec::Commands::Solaris
4
+ def check_installed(package, version=nil)
5
+ cmd = "/opt/local/bin/pkgin list 2> /dev/null | grep -qw ^#{escape(package)}"
6
+ if version
7
+ cmd = "#{cmd}-#{escape(version)}"
8
+ end
9
+ cmd
10
+ end
11
+ end
12
+ end
13
+ end
@@ -2,7 +2,7 @@ module Serverspec
2
2
  module Commands
3
3
  class Solaris < Base
4
4
  def check_enabled(service, level=3)
5
- "svcs -l #{escape(service)} 2> /dev/null | grep 'enabled true'"
5
+ "svcs -l #{escape(service)} 2> /dev/null | grep -wx '^enabled.*true$'"
6
6
  end
7
7
 
8
8
  def check_installed(package, version=nil)
@@ -19,7 +19,7 @@ module Serverspec
19
19
  end
20
20
 
21
21
  def check_running(service)
22
- "svcs -l #{escape(service)} status 2> /dev/null |grep 'state online'"
22
+ "svcs -l #{escape(service)} status 2> /dev/null |grep -wx '^state.*online$'"
23
23
  end
24
24
 
25
25
  def check_cron_entry(user, entry)
@@ -10,6 +10,7 @@ require 'serverspec/helper/redhat'
10
10
  require 'serverspec/helper/debian'
11
11
  require 'serverspec/helper/gentoo'
12
12
  require 'serverspec/helper/solaris'
13
+ require 'serverspec/helper/smartos'
13
14
  require 'serverspec/helper/darwin'
14
15
  require 'serverspec/helper/detect_os'
15
16
 
@@ -0,0 +1,10 @@
1
+ module Serverspec
2
+ module Helper
3
+ module SmartOS
4
+ def commands
5
+ Serverspec::Commands::SmartOS.new
6
+ end
7
+ end
8
+ end
9
+ end
10
+
@@ -1,3 +1,3 @@
1
1
  module Serverspec
2
- VERSION = "0.6.15"
2
+ VERSION = "0.6.16"
3
3
  end
@@ -0,0 +1,193 @@
1
+ require 'spec_helper'
2
+
3
+ include Serverspec::Helper::SmartOS
4
+
5
+ describe 'Serverspec commands of Solaris family specified SmartOS' do
6
+ it_behaves_like 'support command check_file', '/etc/passwd'
7
+ it_behaves_like 'support command check_directory', '/var/log'
8
+ it_behaves_like 'support command check_socket', '/var/run/unicorn.sock'
9
+
10
+ it_behaves_like 'support command check_installed_by_gem', 'jekyll'
11
+ it_behaves_like 'support command check_installed_by_gem with_version', 'jekyll', '1.0.2'
12
+
13
+ it_behaves_like 'support command check_installed_by_npm', 'hubot'
14
+ it_behaves_like 'support command check_installed_by_npm with_version', 'hubot', '1.0.2'
15
+
16
+ it_behaves_like 'support command check_installed_by_pecl', 'mongo'
17
+ it_behaves_like 'support command check_installed_by_pecl with_version', 'mongo', '1.4.1'
18
+
19
+ it_behaves_like 'support command check_mounted', '/'
20
+
21
+ it_behaves_like 'support command check_routing_table', '192.168.100.1/24'
22
+ it_behaves_like 'support command check_resolvable'
23
+
24
+ it_behaves_like 'support command check_user', 'root'
25
+ it_behaves_like 'support command check_user', 'wheel'
26
+
27
+ it_behaves_like 'support command check_file_md5checksum', '/etc/passewd', '96c8c50f81a29965f7af6de371ab4250'
28
+
29
+ it_behaves_like 'support command check_running_under_supervisor', 'httpd'
30
+ it_behaves_like 'support command check_process', 'httpd'
31
+
32
+ it_behaves_like 'support command check_file_contain', '/etc/passwd', 'root'
33
+
34
+ it_behaves_like 'support command check_mode', '/etc/sudoers', 440
35
+ it_behaves_like 'support command check_owner', '/etc/sudoers', 'root'
36
+ it_behaves_like 'support command check_grouped', '/etc/sudoers', 'wheel'
37
+
38
+ it_behaves_like 'support command check_link', '/etc/system-release', '/etc/redhat-release'
39
+
40
+ it_behaves_like 'support command check_uid', 'root', 0
41
+
42
+ it_behaves_like 'support command check_login_shell', 'root', '/bin/bash'
43
+ it_behaves_like 'support command check_home_directory', 'root', '/root'
44
+
45
+ it_behaves_like 'support command check_authorized_key'
46
+
47
+ it_behaves_like 'support command get_mode'
48
+ end
49
+
50
+ describe 'check_enabled' do
51
+ subject { commands.check_enabled('httpd') }
52
+ it { should eq "svcs -l httpd 2> /dev/null | grep -wx '^enabled.*true$'" }
53
+ end
54
+
55
+ ## SmartOS
56
+ describe 'check_installed' do
57
+ subject { commands.check_installed('httpd') }
58
+ it { should eq '/opt/local/bin/pkgin list 2> /dev/null | grep -qw ^httpd' }
59
+ end
60
+
61
+ ## SmartOS
62
+ describe 'check_installed' do
63
+ subject { commands.check_installed('httpd', '2.2') }
64
+ it { should eq '/opt/local/bin/pkgin list 2> /dev/null | grep -qw ^httpd-2.2' }
65
+ end
66
+
67
+ describe 'check_file_contain_within' do
68
+ context 'contain a pattern in the file' do
69
+ subject { commands.check_file_contain_within('Gemfile', 'rspec') }
70
+ it { should eq "sed -n 1,\\$p Gemfile | grep -q -- rspec /dev/stdin" }
71
+ end
72
+
73
+ context 'contain a pattern after a line in a file' do
74
+ subject { commands.check_file_contain_within('Gemfile', 'rspec', '/^group :test do/') }
75
+ it { should eq "sed -n /\\^group\\ :test\\ do/,\\$p Gemfile | grep -q -- rspec /dev/stdin" }
76
+ end
77
+
78
+ context 'contain a pattern before a line in a file' do
79
+ subject {commands.check_file_contain_within('Gemfile', 'rspec', nil, '/^end/') }
80
+ it { should eq "sed -n 1,/\\^end/p Gemfile | grep -q -- rspec /dev/stdin" }
81
+ end
82
+
83
+ context 'contain a pattern from within a line and another line in a file' do
84
+ subject { commands.check_file_contain_within('Gemfile', 'rspec', '/^group :test do/', '/^end/') }
85
+ it { should eq "sed -n /\\^group\\ :test\\ do/,/\\^end/p Gemfile | grep -q -- rspec /dev/stdin" }
86
+ end
87
+ end
88
+
89
+ describe 'check_listening' do
90
+ subject { commands.check_listening(80) }
91
+ it { should eq "netstat -an 2> /dev/null | egrep 'LISTEN|Idle' | grep -- .80\\ " }
92
+ end
93
+
94
+ describe 'check_running' do
95
+ subject { commands.check_running('httpd') }
96
+ it { should eq "svcs -l httpd status 2> /dev/null |grep -wx '^state.*online$'" }
97
+ end
98
+
99
+ describe 'check_cron_entry' do
100
+ context 'specify root user' do
101
+ subject { commands.check_cron_entry('root', '* * * * * /usr/local/bin/batch.sh') }
102
+ it { should eq 'crontab -l root | grep -- \\\\\\*\\ \\\\\\*\\ \\\\\\*\\ \\\\\\*\\ \\\\\\*\\ /usr/local/bin/batch.sh' }
103
+ end
104
+
105
+ context 'no specified user' do
106
+ subject { commands.check_cron_entry(nil, '* * * * * /usr/local/bin/batch.sh') }
107
+ it { should eq 'crontab -l | grep -- \\\\\\*\\ \\\\\\*\\ \\\\\\*\\ \\\\\\*\\ \\\\\\*\\ /usr/local/bin/batch.sh' }
108
+ end
109
+ end
110
+
111
+ describe 'check_belonging_group' do
112
+ subject { commands.check_belonging_group('root', 'wheel') }
113
+ it { should eq "id -Gn root | grep -- wheel" }
114
+ end
115
+
116
+ describe 'check_gid' do
117
+ subject { commands.check_gid('root', 0) }
118
+ it { should eq "getent group | grep -- \\^root: | cut -f 3 -d ':' | grep -w -- 0" }
119
+ end
120
+
121
+ describe 'check_zfs' do
122
+ context 'check without properties' do
123
+ subject { commands.check_zfs('rpool') }
124
+ it { should eq "zfs list -H rpool" }
125
+ end
126
+
127
+ context 'check with a property' do
128
+ subject { commands.check_zfs('rpool', { 'mountpoint' => '/rpool' }) }
129
+ it { should eq "zfs list -H -o mountpoint rpool | grep -- \\^/rpool\\$" }
130
+ end
131
+
132
+ context 'check with multiple properties' do
133
+ subject { commands.check_zfs('rpool', { 'mountpoint' => '/rpool', 'compression' => 'off' }) }
134
+ it { should eq "zfs list -H -o compression rpool | grep -- \\^off\\$ && zfs list -H -o mountpoint rpool | grep -- \\^/rpool\\$" }
135
+ end
136
+ end
137
+
138
+ describe 'check_ip_filter_rule' do
139
+ subject { commands.check_ipfilter_rule('pass in quick on lo0 all') }
140
+ it { should eq "ipfstat -io 2> /dev/null | grep -- pass\\ in\\ quick\\ on\\ lo0\\ all" }
141
+ end
142
+
143
+ describe 'check_ipnat_rule' do
144
+ subject { commands.check_ipnat_rule('map net1 192.168.0.0/24 -> 0.0.0.0/32') }
145
+ it { should eq "ipnat -l 2> /dev/null | grep -- \\^map\\ net1\\ 192.168.0.0/24\\ -\\>\\ 0.0.0.0/32\\$" }
146
+ end
147
+
148
+ describe 'check_svcprop' do
149
+ subject { commands.check_svcprop('svc:/network/http:apache22', 'httpd/enable_64bit','false') }
150
+ it { should eq "svcprop -p httpd/enable_64bit svc:/network/http:apache22 | grep -- \\^false\\$" }
151
+ end
152
+
153
+ describe 'check_svcprops' do
154
+ subject {
155
+ commands.check_svcprops('svc:/network/http:apache22', {
156
+ 'httpd/enable_64bit' => 'false',
157
+ 'httpd/server_type' => 'worker',
158
+ })
159
+ }
160
+ it { should eq "svcprop -p httpd/enable_64bit svc:/network/http:apache22 | grep -- \\^false\\$ && svcprop -p httpd/server_type svc:/network/http:apache22 | grep -- \\^worker\\$" }
161
+ end
162
+
163
+ describe 'check_access_by_user' do
164
+ context 'read access' do
165
+ subject {commands.check_access_by_user '/tmp/something', 'dummyuser1', 'r'}
166
+ it { should eq 'su dummyuser1 -c "test -r /tmp/something"' }
167
+ end
168
+
169
+ context 'write access' do
170
+ subject {commands.check_access_by_user '/tmp/somethingw', 'dummyuser2', 'w'}
171
+ it { should eq 'su dummyuser2 -c "test -w /tmp/somethingw"' }
172
+ end
173
+
174
+ context 'execute access' do
175
+ subject {commands.check_access_by_user '/tmp/somethingx', 'dummyuser3', 'x'}
176
+ it { should eq 'su dummyuser3 -c "test -x /tmp/somethingx"' }
177
+ end
178
+ end
179
+
180
+ describe 'check_reachable' do
181
+ context "connect with name from /etc/services to localhost" do
182
+ subject { commands.check_reachable('localhost', 'ssh', 'tcp', 1) }
183
+ it { should eq "nc -vvvvzt -w 1 localhost ssh" }
184
+ end
185
+ context "connect with ip and port 11111 and timeout of 5" do
186
+ subject { commands.check_reachable('127.0.0.1', '11111', 'udp', 5) }
187
+ it { should eq "nc -vvvvzu -w 5 127.0.0.1 11111" }
188
+ end
189
+ context "do a ping" do
190
+ subject { commands.check_reachable('127.0.0.1', nil, 'icmp', 1) }
191
+ it { should eq "ping -n 127.0.0.1 1" }
192
+ end
193
+ end
@@ -49,7 +49,7 @@ end
49
49
 
50
50
  describe 'check_enabled' do
51
51
  subject { commands.check_enabled('httpd') }
52
- it { should eq "svcs -l httpd 2> /dev/null | grep 'enabled true'" }
52
+ it { should eq "svcs -l httpd 2> /dev/null | grep -wx '^enabled.*true$'" }
53
53
  end
54
54
 
55
55
  describe 'check_installed' do
@@ -91,7 +91,7 @@ end
91
91
 
92
92
  describe 'check_running' do
93
93
  subject { commands.check_running('httpd') }
94
- it { should eq "svcs -l httpd status 2> /dev/null |grep 'state online'" }
94
+ it { should eq "svcs -l httpd status 2> /dev/null |grep -wx '^state.*online$'" }
95
95
  end
96
96
 
97
97
  describe 'check_cron_entry' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: serverspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.15
4
+ version: 0.6.16
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-29 00:00:00.000000000 Z
12
+ date: 2013-06-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: net-ssh
@@ -150,6 +150,7 @@ files:
150
150
  - lib/serverspec/commands/gentoo.rb
151
151
  - lib/serverspec/commands/linux.rb
152
152
  - lib/serverspec/commands/redhat.rb
153
+ - lib/serverspec/commands/smartos.rb
153
154
  - lib/serverspec/commands/solaris.rb
154
155
  - lib/serverspec/configuration.rb
155
156
  - lib/serverspec/helper.rb
@@ -163,6 +164,7 @@ files:
163
164
  - lib/serverspec/helper/gentoo.rb
164
165
  - lib/serverspec/helper/puppet.rb
165
166
  - lib/serverspec/helper/redhat.rb
167
+ - lib/serverspec/helper/smartos.rb
166
168
  - lib/serverspec/helper/solaris.rb
167
169
  - lib/serverspec/helper/ssh.rb
168
170
  - lib/serverspec/helper/type.rb
@@ -275,6 +277,7 @@ files:
275
277
  - spec/redhat/service_spec.rb
276
278
  - spec/redhat/user_spec.rb
277
279
  - spec/redhat/yumrepo_spec.rb
280
+ - spec/smartos/commands_spec.rb
278
281
  - spec/solaris/command_spec.rb
279
282
  - spec/solaris/commands_spec.rb
280
283
  - spec/solaris/cron_spec.rb
@@ -401,6 +404,7 @@ test_files:
401
404
  - spec/redhat/service_spec.rb
402
405
  - spec/redhat/user_spec.rb
403
406
  - spec/redhat/yumrepo_spec.rb
407
+ - spec/smartos/commands_spec.rb
404
408
  - spec/solaris/command_spec.rb
405
409
  - spec/solaris/commands_spec.rb
406
410
  - spec/solaris/cron_spec.rb