specinfra 1.27.5 → 2.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +18 -24
- data/lib/specinfra/backend/exec.rb +32 -48
- data/lib/specinfra/backend/powershell/support/find_iis_component.ps1 +5 -81
- data/lib/specinfra/backend/ssh.rb +9 -22
- data/lib/specinfra/command/arch.rb +4 -5
- data/lib/specinfra/command/base.rb +6 -35
- data/lib/specinfra/command/darwin.rb +0 -19
- data/lib/specinfra/command/debian.rb +2 -6
- data/lib/specinfra/command/freebsd.rb +0 -14
- data/lib/specinfra/command/linux.rb +1 -32
- data/lib/specinfra/command/openbsd.rb +2 -2
- data/lib/specinfra/command/redhat.rb +0 -4
- data/lib/specinfra/command/solaris.rb +2 -3
- data/lib/specinfra/command/ubuntu.rb +0 -14
- data/lib/specinfra/command/windows.rb +4 -81
- data/lib/specinfra/command.rb +0 -4
- data/lib/specinfra/configuration.rb +1 -9
- data/lib/specinfra/helper/detect_os.rb +7 -23
- data/lib/specinfra/helper/os.rb +0 -4
- data/lib/specinfra/version.rb +1 -1
- data/spec/backend/exec/build_command_spec.rb +89 -50
- data/spec/backend/ssh/build_command_spec.rb +91 -111
- data/spec/configuration_spec.rb +0 -5
- data/specinfra.gemspec +4 -2
- data/wercker.yml +14 -18
- metadata +34 -13
- data/lib/specinfra/backend/powershell/support/find_scheduled_task.ps1 +0 -7
- data/lib/specinfra/command/fedora.rb +0 -29
- data/lib/specinfra/command/nixos.rb +0 -28
- data/lib/specinfra/command/opensuse.rb +0 -14
- data/lib/specinfra/command/redhat7.rb +0 -9
- data/spec/helper/detect_os_spec.rb +0 -117
@@ -28,7 +28,7 @@ module SpecInfra
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def check_cron_entry(user, entry)
|
31
|
-
entry_escaped = entry.gsub(/\*/, '\\*')
|
31
|
+
entry_escaped = entry.gsub(/\*/, '\\*')
|
32
32
|
if user.nil?
|
33
33
|
"crontab -l | grep -- #{escape(entry_escaped)}"
|
34
34
|
else
|
@@ -76,10 +76,9 @@ module SpecInfra
|
|
76
76
|
from ||= '1'
|
77
77
|
to ||= '$'
|
78
78
|
sed = "sed -n #{escape(from)},#{escape(to)}p #{escape(file)}"
|
79
|
-
sed_end = "sed -n 1,#{escape(to)}p"
|
80
79
|
checker_with_regexp = check_file_contain_with_regexp("/dev/stdin", expected_pattern)
|
81
80
|
checker_with_fixed = check_file_contain_with_fixed_strings("/dev/stdin", expected_pattern)
|
82
|
-
"#{sed} | #{
|
81
|
+
"#{sed} | #{checker_with_regexp} || #{sed} | #{checker_with_fixed}"
|
83
82
|
end
|
84
83
|
|
85
84
|
def check_belonging_group(user, group)
|
@@ -4,20 +4,6 @@ module SpecInfra
|
|
4
4
|
def check_running(service)
|
5
5
|
"service #{escape(service)} status && service #{escape(service)} status | grep 'running'"
|
6
6
|
end
|
7
|
-
|
8
|
-
def check_ppa(package)
|
9
|
-
%Q{find /etc/apt/ -name \*.list | xargs grep -o "deb +http://ppa.launchpad.net/#{to_apt_line_uri(package)}"}
|
10
|
-
end
|
11
|
-
|
12
|
-
def check_ppa_enabled(package)
|
13
|
-
%Q{find /etc/apt/ -name \*.list | xargs grep -o "^deb +http://ppa.launchpad.net/#{to_apt_line_uri(package)}"}
|
14
|
-
end
|
15
|
-
|
16
|
-
private
|
17
|
-
|
18
|
-
def to_apt_line_uri(repo)
|
19
|
-
escape(repo.gsub(/^ppa:/,''))
|
20
|
-
end
|
21
7
|
end
|
22
8
|
end
|
23
9
|
end
|
@@ -53,7 +53,7 @@ module SpecInfra
|
|
53
53
|
|
54
54
|
def check_file_contain(file, pattern)
|
55
55
|
Backend::PowerShell::Command.new do
|
56
|
-
exec
|
56
|
+
exec "[Io.File]::ReadAllText('#{file}') -match '#{convert_regexp(pattern)}'"
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
@@ -62,12 +62,12 @@ module SpecInfra
|
|
62
62
|
to ||= '$'
|
63
63
|
Backend::PowerShell::Command.new do
|
64
64
|
using 'crop_text.ps1'
|
65
|
-
exec %Q
|
65
|
+
exec %Q[(CropText -text ([Io.File]::ReadAllText('#{file}')) -fromPattern '#{convert_regexp(from)}' -toPattern '#{convert_regexp(to)}') -match '#{pattern}']
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
69
69
|
def get_file_content(file)
|
70
|
-
|
70
|
+
"[Io.File]::ReadAllText('#{file}')"
|
71
71
|
end
|
72
72
|
|
73
73
|
def check_access_by_user(file, user, access)
|
@@ -290,27 +290,6 @@ module SpecInfra
|
|
290
290
|
exec "[System.Environment]::ExpandEnvironmentVariables( ( FindIISWebsite -name '#{name}' ).physicalPath ).replace('\\', '/' ) -eq ('#{path}'.trimEnd('/').replace('\\', '/'))"
|
291
291
|
end
|
292
292
|
end
|
293
|
-
|
294
|
-
def check_iis_website_binding(name, port, protocol, ipAddress, hostHeader)
|
295
|
-
Backend::PowerShell::Command.new do
|
296
|
-
using 'find_iis_component.ps1'
|
297
|
-
exec "(FindSiteBindings -name '#{name}' -protocol '#{protocol}' -hostHeader '#{hostHeader}' -port #{port} -ipAddress '#{ipAddress}').count -gt 0"
|
298
|
-
end
|
299
|
-
end
|
300
|
-
|
301
|
-
def check_iis_website_virtual_dir(name, vdir, path)
|
302
|
-
Backend::PowerShell::Command.new do
|
303
|
-
using 'find_iis_component.ps1'
|
304
|
-
exec "(FindSiteVirtualDir -name '#{name}' -vdir '#{vdir}' -path '#{path}') -eq $true"
|
305
|
-
end
|
306
|
-
end
|
307
|
-
|
308
|
-
def check_iis_website_application(name, app, pool, physicalPath)
|
309
|
-
Backend::PowerShell::Command.new do
|
310
|
-
using 'find_iis_component.ps1'
|
311
|
-
exec "(FindSiteApplication -name '#{name}' -app '#{app}' -pool '#{pool}' -physicalPath '#{physicalPath}') -eq $true"
|
312
|
-
end
|
313
|
-
end
|
314
293
|
|
315
294
|
def check_iis_app_pool(name)
|
316
295
|
Backend::PowerShell::Command.new do
|
@@ -326,66 +305,10 @@ module SpecInfra
|
|
326
305
|
end
|
327
306
|
end
|
328
307
|
|
329
|
-
def check_32bit_enabled(name)
|
330
|
-
Backend::PowerShell::Command.new do
|
331
|
-
using 'find_iis_component.ps1'
|
332
|
-
exec "(FindIISAppPool -name '#{name}').enable32BitAppOnWin64 -eq $true"
|
333
|
-
end
|
334
|
-
end
|
335
|
-
|
336
|
-
def check_managed_pipeline_mode(name, mode)
|
337
|
-
Backend::PowerShell::Command.new do
|
338
|
-
using 'find_iis_component.ps1'
|
339
|
-
exec "(FindIISAppPool -name '#{name}').managedPipelineMode -eq '#{mode}'"
|
340
|
-
end
|
341
|
-
end
|
342
|
-
|
343
|
-
def check_idle_timeout(name, minutes)
|
344
|
-
Backend::PowerShell::Command.new do
|
345
|
-
using 'find_iis_component.ps1'
|
346
|
-
exec "(FindIISAppPool -name '#{name}').processModel.idleTimeout.Minutes -eq #{minutes}"
|
347
|
-
end
|
348
|
-
end
|
349
|
-
|
350
|
-
def check_identity_type(name, type)
|
351
|
-
Backend::PowerShell::Command.new do
|
352
|
-
using 'find_iis_component.ps1'
|
353
|
-
exec "(FindIISAppPool -name '#{name}').processModel.identityType -eq '#{type}'"
|
354
|
-
end
|
355
|
-
end
|
356
|
-
|
357
|
-
def check_user_profile(name)
|
358
|
-
Backend::PowerShell::Command.new do
|
359
|
-
using 'find_iis_component.ps1'
|
360
|
-
exec "(FindIISAppPool -name '#{name}').processModel.loadUserProfile -eq $true"
|
361
|
-
end
|
362
|
-
end
|
363
|
-
|
364
|
-
def check_username(name, username)
|
365
|
-
Backend::PowerShell::Command.new do
|
366
|
-
using 'find_iis_component.ps1'
|
367
|
-
exec "(FindIISAppPool -name '#{name}').processModel.username -eq '#{username}'"
|
368
|
-
end
|
369
|
-
end
|
370
|
-
|
371
|
-
def check_periodic_restart(name, minutes)
|
372
|
-
Backend::PowerShell::Command.new do
|
373
|
-
using 'find_iis_component.ps1'
|
374
|
-
exec "(FindIISAppPool -name '#{name}').recycling.periodicRestart.time.TotalMinutes -eq #{minutes}"
|
375
|
-
end
|
376
|
-
end
|
377
|
-
|
378
|
-
def check_scheduled_task(name)
|
379
|
-
Backend::PowerShell::Command.new do
|
380
|
-
using 'find_scheduled_task.ps1'
|
381
|
-
exec "(FindScheduledTask -name '#{name}').TaskName -eq '\\#{name}'"
|
382
|
-
end
|
383
|
-
end
|
384
|
-
|
385
308
|
private
|
386
309
|
|
387
310
|
def item_has_attribute item, attribute
|
388
|
-
|
311
|
+
"((Get-Item -Path '#{item}' -Force).attributes.ToString() -Split ', ') -contains '#{attribute}'"
|
389
312
|
end
|
390
313
|
|
391
314
|
def convert_key_property_value property
|
data/lib/specinfra/command.rb
CHANGED
@@ -8,11 +8,7 @@ require "specinfra/command/ubuntu"
|
|
8
8
|
require "specinfra/command/gentoo"
|
9
9
|
require "specinfra/command/plamo"
|
10
10
|
require "specinfra/command/redhat"
|
11
|
-
require "specinfra/command/redhat7"
|
12
11
|
require "specinfra/command/suse"
|
13
|
-
require "specinfra/command/opensuse"
|
14
|
-
require "specinfra/command/fedora"
|
15
|
-
require "specinfra/command/nixos"
|
16
12
|
|
17
13
|
# Solaris
|
18
14
|
require "specinfra/command/solaris"
|
@@ -3,6 +3,7 @@ module SpecInfra
|
|
3
3
|
class << self
|
4
4
|
VALID_OPTIONS_KEYS = [
|
5
5
|
:path,
|
6
|
+
:shell,
|
6
7
|
:pre_command,
|
7
8
|
:stdout,
|
8
9
|
:stderr,
|
@@ -19,15 +20,6 @@ module SpecInfra
|
|
19
20
|
VALID_OPTIONS_KEYS.inject({}) { |o, k| o.merge!(k => send(k)) }
|
20
21
|
end
|
21
22
|
|
22
|
-
# Define os method explicitly to avoid stack level
|
23
|
-
# too deep caused by Helpet::DetectOS#os
|
24
|
-
def os
|
25
|
-
if @os.nil? && defined?(RSpec) && RSpec.configuration.respond_to?(:os)
|
26
|
-
@os = RSpec.configuration.os
|
27
|
-
end
|
28
|
-
@os
|
29
|
-
end
|
30
|
-
|
31
23
|
def method_missing(meth, val=nil)
|
32
24
|
key = meth.to_s
|
33
25
|
key.gsub!(/=$/, '')
|
@@ -2,34 +2,18 @@ module SpecInfra
|
|
2
2
|
module Helper
|
3
3
|
module DetectOS
|
4
4
|
def commands
|
5
|
-
self.class.const_get('SpecInfra').const_get('Command').const_get(os[:family]).new
|
6
|
-
end
|
7
|
-
|
8
|
-
def os
|
9
5
|
property[:os_by_host] = {} if ! property[:os_by_host]
|
10
|
-
|
6
|
+
host = SpecInfra.configuration.ssh ? SpecInfra.configuration.ssh.host : 'localhost'
|
11
7
|
|
12
|
-
if property[:os_by_host][
|
13
|
-
|
8
|
+
if property[:os_by_host][host]
|
9
|
+
os = property[:os_by_host][host]
|
14
10
|
else
|
15
11
|
# Set command object explicitly to avoid `stack too deep`
|
16
|
-
|
17
|
-
property[:os_by_host][
|
18
|
-
end
|
19
|
-
|
20
|
-
os_by_host
|
21
|
-
end
|
22
|
-
|
23
|
-
private
|
24
|
-
|
25
|
-
# put this in a module for better reuse
|
26
|
-
def current_host_and_port
|
27
|
-
if SpecInfra.configuration.ssh
|
28
|
-
[SpecInfra.configuration.ssh.host, SpecInfra.configuration.ssh.options[:port]]
|
29
|
-
else
|
30
|
-
['localhost', nil]
|
12
|
+
os = backend(SpecInfra::Command::Base.new).check_os
|
13
|
+
property[:os_by_host][host] = os
|
31
14
|
end
|
15
|
+
self.class.const_get('SpecInfra').const_get('Command').const_get(os[:family]).new
|
32
16
|
end
|
33
17
|
end
|
34
18
|
end
|
35
|
-
end
|
19
|
+
end
|
data/lib/specinfra/helper/os.rb
CHANGED
@@ -6,17 +6,13 @@ module SpecInfra
|
|
6
6
|
'Arch',
|
7
7
|
'Darwin',
|
8
8
|
'Debian',
|
9
|
-
'Fedora',
|
10
9
|
'FreeBSD',
|
11
10
|
'FreeBSD10',
|
12
11
|
'Gentoo',
|
13
|
-
'NixOS',
|
14
12
|
'OpenBSD',
|
15
13
|
'Plamo',
|
16
14
|
'RedHat',
|
17
|
-
'RedHat7',
|
18
15
|
'SuSE',
|
19
|
-
'OpenSUSE',
|
20
16
|
'SmartOS',
|
21
17
|
'Solaris',
|
22
18
|
'Solaris10',
|
data/lib/specinfra/version.rb
CHANGED
@@ -2,31 +2,74 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
include SpecInfra::Helper::Exec
|
4
4
|
|
5
|
-
describe
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
describe SpecInfra::Backend::Exec do
|
6
|
+
describe '#build_command' do
|
7
|
+
context 'with simple command' do
|
8
|
+
it 'should escape spaces' do
|
9
|
+
expect(backend.build_command('test -f /etc/passwd')).to eq '/bin/sh -c test\ -f\ /etc/passwd'
|
10
|
+
end
|
9
11
|
end
|
10
|
-
end
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
context 'with complex command' do
|
14
|
+
it 'should escape special chars' do
|
15
|
+
expect(backend.build_command('test ! -f /etc/selinux/config || (getenforce | grep -i -- disabled && grep -i -- ^SELINUX=disabled$ /etc/selinux/config)')).to eq '/bin/sh -c test\ \!\ -f\ /etc/selinux/config\ \|\|\ \(getenforce\ \|\ grep\ -i\ --\ disabled\ \&\&\ grep\ -i\ --\ \^SELINUX\=disabled\$\ /etc/selinux/config\)'
|
16
|
+
end
|
17
|
+
end
|
16
18
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
19
|
+
context 'with custom shell' do
|
20
|
+
before do
|
21
|
+
RSpec.configure {|c| c.shell = '/usr/local/bin/tcsh' }
|
22
|
+
end
|
21
23
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
24
|
+
after do
|
25
|
+
RSpec.configure {|c| c.shell = nil }
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should use custom shell' do
|
29
|
+
expect(backend.build_command('test -f /etc/passwd')).to eq '/usr/local/bin/tcsh -c test\ -f\ /etc/passwd'
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'with custom shell that needs escaping' do
|
34
|
+
before do
|
35
|
+
RSpec.configure {|c| c.shell = '/usr/test & spec/bin/sh' }
|
36
|
+
end
|
37
|
+
|
38
|
+
after do
|
39
|
+
RSpec.configure {|c| c.shell = nil }
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should use custom shell' do
|
43
|
+
expect(backend.build_command('test -f /etc/passwd')).to eq '/usr/test\ \&\ spec/bin/sh -c test\ -f\ /etc/passwd'
|
44
|
+
end
|
45
|
+
end
|
26
46
|
|
27
|
-
|
28
|
-
|
29
|
-
|
47
|
+
context 'with custom path' do
|
48
|
+
before do
|
49
|
+
RSpec.configure {|c| c.path = '/opt/bin:/opt/foo/bin' }
|
50
|
+
end
|
51
|
+
|
52
|
+
after do
|
53
|
+
RSpec.configure {|c| c.path = nil }
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'should use custom path' do
|
57
|
+
expect(backend.build_command('test -f /etc/passwd')).to eq 'env PATH=/opt/bin:/opt/foo/bin:"$PATH" /bin/sh -c test\ -f\ /etc/passwd'
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context 'with custom path that needs escaping' do
|
62
|
+
before do
|
63
|
+
RSpec.configure {|c| c.path = '/opt/bin:/opt/test & spec/bin' }
|
64
|
+
end
|
65
|
+
|
66
|
+
after do
|
67
|
+
RSpec.configure {|c| c.path = nil }
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'should use custom path' do
|
71
|
+
expect(backend.build_command('test -f /etc/passwd')).to eq 'env PATH=/opt/bin:/opt/test\ \&\ spec/bin:"$PATH" /bin/sh -c test\ -f\ /etc/passwd'
|
72
|
+
end
|
30
73
|
end
|
31
74
|
end
|
32
75
|
end
|
@@ -35,61 +78,57 @@ describe 'check_os' do
|
|
35
78
|
context 'test ubuntu with lsb_release command' do
|
36
79
|
subject { backend.check_os }
|
37
80
|
it do
|
81
|
+
mock_success_response = double(
|
82
|
+
:run_command_response,
|
83
|
+
:success? => true,
|
84
|
+
:stdout => "Distributor ID:\tUbuntu\nRelease:\t12.04\n"
|
85
|
+
)
|
86
|
+
mock_failure_response = double :run_command_response, :success? => false
|
38
87
|
backend.should_receive(:run_command).at_least(1).times do |args|
|
39
88
|
if ['ls /etc/debian_version', 'lsb_release -ir'].include? args
|
40
|
-
|
41
|
-
:run_command_response,
|
42
|
-
:success? => true,
|
43
|
-
:stdout => "Distributor ID:\tUbuntu\nRelease:\t12.04\n"
|
44
|
-
)
|
45
|
-
elsif args == 'uname -m'
|
46
|
-
double :run_command_response, :success? => true, :stdout => "x86_64\n"
|
89
|
+
mock_success_response
|
47
90
|
else
|
48
|
-
|
91
|
+
mock_failure_response
|
49
92
|
end
|
50
93
|
end
|
51
|
-
should eq({:family => 'Ubuntu', :release => '12.04'
|
94
|
+
should eq({:family => 'Ubuntu', :release => '12.04'})
|
52
95
|
end
|
53
96
|
end
|
54
97
|
|
55
98
|
context 'test ubuntu with /etc/lsb-release' do
|
56
99
|
subject { backend.check_os }
|
57
100
|
it do
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
:success? => true,
|
63
|
-
:stdout => <<-EOF
|
64
|
-
DISTRIB_ID=Ubuntu
|
101
|
+
mock_success_response = double(
|
102
|
+
:run_command_response,
|
103
|
+
:success? => true,
|
104
|
+
:stdout => %Q(DISTRIB_ID=Ubuntu
|
65
105
|
DISTRIB_RELEASE=12.04
|
66
106
|
DISTRIB_CODENAME=precise
|
67
107
|
DISTRIB_DESCRIPTION="Ubuntu 12.04.2 LTS"
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
108
|
+
)
|
109
|
+
)
|
110
|
+
mock_failure_response = double :run_command_response, :success? => false
|
111
|
+
backend.should_receive(:run_command).at_least(1).times do |args|
|
112
|
+
if ['ls /etc/debian_version', 'cat /etc/lsb-release'].include? args
|
113
|
+
mock_success_response
|
72
114
|
else
|
73
|
-
|
115
|
+
mock_failure_response
|
74
116
|
end
|
75
117
|
end
|
76
|
-
should eq({:family => 'Ubuntu', :release => '12.04'
|
118
|
+
should eq({:family => 'Ubuntu', :release => '12.04'})
|
77
119
|
end
|
78
120
|
end
|
79
121
|
|
80
122
|
context 'test debian (no lsb_release or lsb-release)' do
|
81
123
|
subject { backend.check_os }
|
82
124
|
it do
|
125
|
+
mock_success_response = double :run_command_response, :success? => true
|
126
|
+
mock_failure_response = double :run_command_response, :success? => false
|
83
127
|
backend.should_receive(:run_command).at_least(1).times do |args|
|
84
|
-
|
85
|
-
double :run_command_response, :success? => true
|
86
|
-
elsif args == 'uname -m'
|
87
|
-
double :run_command_response, :success? => true, :stdout => "x86_64\n"
|
88
|
-
else
|
89
|
-
double :run_command_response, :success? => false
|
90
|
-
end
|
128
|
+
args == 'ls /etc/debian_version' ? mock_success_response : mock_failure_response
|
91
129
|
end
|
92
|
-
should eq({:family => 'Debian', :release => nil
|
130
|
+
should eq({:family => 'Debian', :release => nil})
|
93
131
|
end
|
94
132
|
end
|
95
133
|
end
|
134
|
+
|