serverspec 0.2.14 → 0.2.15
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +1 -0
- data/lib/serverspec.rb +9 -1
- data/lib/serverspec/filter.rb +19 -0
- data/lib/serverspec/setup.rb +13 -28
- data/lib/serverspec/subject.rb +12 -0
- data/lib/serverspec/version.rb +1 -1
- data/spec/debian/matchers_spec.rb +2 -0
- data/spec/gentoo/matchers_spec.rb +2 -0
- data/spec/redhat/matchers_spec.rb +2 -0
- data/spec/spec_helper.rb +3 -1
- data/spec/support/shared_matcher_examples.rb +18 -0
- metadata +4 -2
data/.travis.yml
CHANGED
data/lib/serverspec.rb
CHANGED
@@ -5,6 +5,8 @@ require 'serverspec/matchers'
|
|
5
5
|
require 'serverspec/backend'
|
6
6
|
require 'serverspec/helper'
|
7
7
|
require 'serverspec/setup'
|
8
|
+
require 'serverspec/filter'
|
9
|
+
require 'serverspec/subject'
|
8
10
|
require 'serverspec/commands/base'
|
9
11
|
require 'serverspec/commands/redhat'
|
10
12
|
require 'serverspec/commands/debian'
|
@@ -12,7 +14,6 @@ require 'serverspec/commands/gentoo'
|
|
12
14
|
require 'serverspec/commands/solaris'
|
13
15
|
|
14
16
|
RSpec.configure do |c|
|
15
|
-
c.include(Serverspec::Helper::Ssh)
|
16
17
|
c.include(Serverspec::Helper::RedHat, :os => :redhat)
|
17
18
|
c.include(Serverspec::Helper::Debian, :os => :debian)
|
18
19
|
c.include(Serverspec::Helper::Gentoo, :os => :gentoo)
|
@@ -21,4 +22,11 @@ RSpec.configure do |c|
|
|
21
22
|
c.add_setting :host, :default => nil
|
22
23
|
c.add_setting :ssh, :default => nil
|
23
24
|
c.add_setting :sudo_password, :default => nil
|
25
|
+
c.before :each do
|
26
|
+
if subject == 'value'
|
27
|
+
def subject
|
28
|
+
Serverspec::Filter.filter_subject example
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
24
32
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Serverspec
|
2
|
+
class Filter
|
3
|
+
def self.filter_subject example
|
4
|
+
description_args = example.metadata[:example_group][:example_group][:description_args].join(' ')
|
5
|
+
|
6
|
+
# Linux kernel parameters
|
7
|
+
%w( abi crypto debug dev fs kernel net sunrpc vm ).each do |param|
|
8
|
+
if description_args.match(/^#{param}\./)
|
9
|
+
ret = backend(Serverspec::Commands::Base).do_check("sysctl -q -n #{description_args}")
|
10
|
+
subject = Serverspec::Subject.new
|
11
|
+
subject.value(ret[:stdout].strip.to_i)
|
12
|
+
return subject
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
example.metadata[:example_group][:description_args].join(' ')
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/serverspec/setup.rb
CHANGED
@@ -24,25 +24,6 @@ EOF
|
|
24
24
|
@hostname = 'localhost'
|
25
25
|
end
|
26
26
|
|
27
|
-
prompt = <<-EOF
|
28
|
-
|
29
|
-
Select OS type of target host:
|
30
|
-
|
31
|
-
1) Auto Detect
|
32
|
-
2) Red Hat
|
33
|
-
3) Debian
|
34
|
-
4) Gentoo
|
35
|
-
5) Solaris
|
36
|
-
|
37
|
-
Select number:
|
38
|
-
EOF
|
39
|
-
|
40
|
-
print prompt.chop
|
41
|
-
num = gets.to_i - 1
|
42
|
-
puts
|
43
|
-
|
44
|
-
@os_type = [ 'DetectOS', 'RedHat', 'Debian', 'Gentoo', 'Solaris' ][num]
|
45
|
-
|
46
27
|
[ 'spec', "spec/#{@hostname}" ].each { |dir| safe_mkdir(dir) }
|
47
28
|
safe_create_spec
|
48
29
|
safe_create_spec_helper
|
@@ -100,6 +81,9 @@ require 'serverspec'
|
|
100
81
|
require 'pathname'
|
101
82
|
### include requirements ###
|
102
83
|
|
84
|
+
### include backend helper ###
|
85
|
+
include Serverspec::Helper::DetectOS
|
86
|
+
|
103
87
|
RSpec.configure do |c|
|
104
88
|
if ENV['ASK_SUDO_PASSWORD']
|
105
89
|
require 'highline/import'
|
@@ -107,19 +91,23 @@ RSpec.configure do |c|
|
|
107
91
|
else
|
108
92
|
c.sudo_password = ENV['SUDO_PASSWORD']
|
109
93
|
end
|
110
|
-
### include backend helper ###
|
111
|
-
### include os helper ###
|
112
94
|
### include backend conf ###
|
113
95
|
end
|
114
96
|
EOF
|
115
97
|
|
116
98
|
if not @backend_type.nil?
|
117
|
-
content.gsub!(/### include backend helper ###/, "
|
99
|
+
content.gsub!(/### include backend helper ###/, "include Serverspec::Helper::#{@backend_type}")
|
118
100
|
case @backend_type
|
119
101
|
when 'Ssh'
|
120
102
|
content.gsub!(/### include requirements ###/, "require 'net/ssh'")
|
121
|
-
content.gsub!(/### include backend conf ###/, "c.before do
|
122
|
-
|
103
|
+
content.gsub!(/### include backend conf ###/, "c.before :all do
|
104
|
+
block = self.class.metadata[:example_group_block]
|
105
|
+
if RUBY_VERSION.start_with?('1.8')
|
106
|
+
file = block.to_s.match(/.*@(.*):[0-9]+>/)[1]
|
107
|
+
else
|
108
|
+
file = block.source_location.first
|
109
|
+
end
|
110
|
+
host = File.basename(Pathname.new(file).dirname)
|
123
111
|
if c.host != host
|
124
112
|
c.ssh.close if c.ssh
|
125
113
|
c.host = host
|
@@ -130,7 +118,7 @@ EOF
|
|
130
118
|
end
|
131
119
|
end")
|
132
120
|
when 'Exec'
|
133
|
-
content.gsub!(/### include backend conf ###/, "c.before do
|
121
|
+
content.gsub!(/### include backend conf ###/, "c.before :all do
|
134
122
|
c.os = backend(Serverspec::Commands::Base).check_os
|
135
123
|
end")
|
136
124
|
when 'Puppet'
|
@@ -138,9 +126,6 @@ EOF
|
|
138
126
|
")
|
139
127
|
end
|
140
128
|
end
|
141
|
-
if not @os_type.nil?
|
142
|
-
content.gsub!(/### include os helper ###/, "c.include(Serverspec::Helper::#{@os_type})")
|
143
|
-
end
|
144
129
|
|
145
130
|
if File.exists? 'spec/spec_helper.rb'
|
146
131
|
old_content = File.read('spec/spec_helper.rb')
|
data/lib/serverspec/version.rb
CHANGED
@@ -57,4 +57,6 @@ describe 'Serverspec matchers of Debian family', :os => :debian do
|
|
57
57
|
|
58
58
|
it_behaves_like 'support return_stderr matcher', 'cat /foo', 'cat: /foo: No such file or directory'
|
59
59
|
it_behaves_like 'support return_stderr matcher with regexp', 'cat /foo', /No such file or directory/
|
60
|
+
|
61
|
+
it_behaves_like 'support linux kernel parameter checking', 'net.ipv4.tcp_syncookies'
|
60
62
|
end
|
@@ -58,4 +58,6 @@ describe 'Serverspec matchers of Gentoo family', :os => :gentoo do
|
|
58
58
|
|
59
59
|
it_behaves_like 'support return_stderr matcher', 'cat /foo', 'cat: /foo: No such file or directory'
|
60
60
|
it_behaves_like 'support return_stderr matcher with regexp', 'cat /foo', /No such file or directory/
|
61
|
+
|
62
|
+
it_behaves_like 'support linux kernel parameter checking', 'net.ipv4.tcp_syncookies'
|
61
63
|
end
|
@@ -63,4 +63,6 @@ describe 'Serverspec matchers of Red Hat family', :os => :redhat do
|
|
63
63
|
|
64
64
|
it_behaves_like 'support return_stderr matcher', 'cat /foo', 'cat: /foo: No such file or directory'
|
65
65
|
it_behaves_like 'support return_stderr matcher with regexp', 'cat /foo', /No such file or directory/
|
66
|
+
|
67
|
+
it_behaves_like 'support linux kernel parameter checking', 'net.ipv4.tcp_syncookies'
|
66
68
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,13 +1,15 @@
|
|
1
1
|
require 'serverspec'
|
2
2
|
require 'pathname'
|
3
3
|
|
4
|
+
include Serverspec::Helper::Exec
|
5
|
+
|
4
6
|
PROJECT_ROOT = (Pathname.new(File.dirname(__FILE__)) + '..').expand_path
|
5
7
|
|
6
8
|
Dir[PROJECT_ROOT.join("spec/support/**/*.rb")].each { |file| require(file) }
|
7
9
|
|
8
10
|
module Serverspec
|
9
11
|
module Backend
|
10
|
-
class
|
12
|
+
class Exec
|
11
13
|
def do_check(cmd)
|
12
14
|
if cmd =~ /invalid/
|
13
15
|
{
|
@@ -790,3 +790,21 @@ shared_examples_for 'support return_stderr matcher with regexp' do |command, con
|
|
790
790
|
end
|
791
791
|
end
|
792
792
|
end
|
793
|
+
|
794
|
+
shared_examples_for 'support linux kernel parameter checking' do |param|
|
795
|
+
describe 'linux kernel parameter' do
|
796
|
+
before :all do
|
797
|
+
RSpec.configure do |c|
|
798
|
+
c.stdout = "1\n"
|
799
|
+
end
|
800
|
+
end
|
801
|
+
|
802
|
+
context param do
|
803
|
+
its(:value) { should eq 1 }
|
804
|
+
end
|
805
|
+
|
806
|
+
context param do
|
807
|
+
its(:value) { should_not eq 0 }
|
808
|
+
end
|
809
|
+
end
|
810
|
+
end
|
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.2.
|
4
|
+
version: 0.2.15
|
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-04-
|
12
|
+
date: 2013-04-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: net-ssh
|
@@ -117,6 +117,7 @@ files:
|
|
117
117
|
- lib/serverspec/commands/gentoo.rb
|
118
118
|
- lib/serverspec/commands/redhat.rb
|
119
119
|
- lib/serverspec/commands/solaris.rb
|
120
|
+
- lib/serverspec/filter.rb
|
120
121
|
- lib/serverspec/helper.rb
|
121
122
|
- lib/serverspec/helper/debian.rb
|
122
123
|
- lib/serverspec/helper/detect_os.rb
|
@@ -161,6 +162,7 @@ files:
|
|
161
162
|
- lib/serverspec/matchers/return_stderr.rb
|
162
163
|
- lib/serverspec/matchers/return_stdout.rb
|
163
164
|
- lib/serverspec/setup.rb
|
165
|
+
- lib/serverspec/subject.rb
|
164
166
|
- lib/serverspec/version.rb
|
165
167
|
- serverspec.gemspec
|
166
168
|
- spec/debian/commands_spec.rb
|