specinfra 2.0.0.beta32 → 2.0.0.beta33

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6bdf29071ca5229cf86e2c3652d9e5aff5a95adf
4
- data.tar.gz: 3316f09764ff4c1bdf3e77ca77d1e1b50473fbbe
3
+ metadata.gz: 0db001bb80acc21063e836cfcc9f38085f321b5c
4
+ data.tar.gz: c8798ab23084ea41e8b9f24dd682658c9f11dff5
5
5
  SHA512:
6
- metadata.gz: d47a9c0b81348438f99b5d9f8074c6442b0d7e35ce86e802b24c7a5350ef93c1994dba0b4d66d71b99c7fd52febdc580de8b9dddc2c0daa23421ec17b67de137
7
- data.tar.gz: cf65c9ea30eb98dd69890127ecdfc1ce1649eaa02787db878a95ac6156ca61b9fee07c422602f0cfa2382e735b72f4b2fc628357d42acc90ee010b6d35c2e8e2
6
+ metadata.gz: 5470153f45e9c0ea4cd866b6d2f3dfb8a1e0d99372bf6a8082b51539dbb397c67d3db0bda2401a52aed9a14a3cf0e37da6deab27d1a77d8f62beb80ebacd559e
7
+ data.tar.gz: f60a57128d79bef16301c1c97b3f700e7e4391d59369046b575255dd189585f7b115d3c247108180a73524a4fdc2dd31d045a07274de3285061440081959bbe4
@@ -6,6 +6,7 @@ module Specinfra
6
6
  include PowerShell::ScriptHelper
7
7
 
8
8
  def run_command(cmd, opts={})
9
+ set :os, :family => 'windows'
9
10
  script = create_script(cmd)
10
11
  result = execute_script %Q{#{powershell} -encodedCommand #{encode_script(script)}}
11
12
 
@@ -4,7 +4,6 @@ require 'shellwords'
4
4
 
5
5
  module Specinfra::Backend
6
6
  class Exec < Base
7
-
8
7
  def run_command(cmd, opts={})
9
8
  cmd = build_command(cmd)
10
9
  cmd = add_pre_command(cmd)
@@ -22,6 +21,11 @@ module Specinfra::Backend
22
21
  CommandResult.new :stdout => stdout, :exit_status => $?.exitstatus
23
22
  end
24
23
 
24
+ def copy_file(from, to)
25
+ FileUtils.cp(from, to)
26
+ end
27
+
28
+ private
25
29
  def with_env
26
30
  keys = %w[BUNDLER_EDITOR BUNDLE_BIN_PATH BUNDLE_GEMFILE
27
31
  RUBYOPT GEM_HOME GEM_PATH GEM_CACHE]
@@ -67,9 +71,5 @@ module Specinfra::Backend
67
71
  cmd
68
72
  end
69
73
  end
70
-
71
- def copy_file(from, to)
72
- FileUtils.cp(from, to)
73
- end
74
74
  end
75
75
  end
@@ -1,13 +1,10 @@
1
+ # -*- coding: utf-8 -*-
1
2
  require 'specinfra/backend/exec'
2
3
  require 'net/ssh'
3
4
  require 'net/scp'
4
5
 
5
6
  module Specinfra::Backend
6
7
  class Ssh < Exec
7
- def prompt
8
- 'Password: '
9
- end
10
-
11
8
  def run_command(cmd, opt={})
12
9
  cmd = build_command(cmd)
13
10
  cmd = add_pre_command(cmd)
@@ -25,6 +22,30 @@ module Specinfra::Backend
25
22
  CommandResult.new ret
26
23
  end
27
24
 
25
+ def copy_file(from, to)
26
+ if Specinfra.configuration.scp.nil?
27
+ Specinfra.configuration.scp = create_scp
28
+ end
29
+
30
+ scp = Specinfra.configuration.scp
31
+ scp.upload!(from, to)
32
+ end
33
+
34
+ private
35
+ def prompt
36
+ 'Password: '
37
+ end
38
+
39
+ def build_command(cmd)
40
+ cmd = super(cmd)
41
+ user = Specinfra.configuration.ssh_options[:user]
42
+ disable_sudo = Specinfra.configuration.disable_sudo
43
+ if user != 'root' && !disable_sudo
44
+ cmd = "#{sudo} -p '#{prompt}' #{cmd}"
45
+ end
46
+ cmd
47
+ end
48
+
28
49
  def with_env
29
50
  env = Specinfra.configuration.env || {}
30
51
  env[:LANG] ||= 'C'
@@ -47,26 +68,6 @@ module Specinfra::Backend
47
68
  end
48
69
  end
49
70
 
50
- def build_command(cmd)
51
- cmd = super(cmd)
52
- user = Specinfra.configuration.ssh_options[:user]
53
- disable_sudo = Specinfra.configuration.disable_sudo
54
- if user != 'root' && !disable_sudo
55
- cmd = "#{sudo} -p '#{prompt}' #{cmd}"
56
- end
57
- cmd
58
- end
59
-
60
- def copy_file(from, to)
61
- if Specinfra.configuration.scp.nil?
62
- Specinfra.configuration.scp = create_scp
63
- end
64
-
65
- scp = Specinfra.configuration.scp
66
- scp.upload!(from, to)
67
- end
68
-
69
- private
70
71
  def create_ssh
71
72
  Net::SSH.start(
72
73
  Specinfra.configuration.host,
@@ -116,7 +117,7 @@ module Specinfra::Backend
116
117
  end
117
118
 
118
119
  if data.match /^sudo: no tty present and no askpass program specified/
119
- abort "Please set sudo password by using SUDO_PASSWORD or ASK_SUDO_PASSWORD environment variable"
120
+ abort 'Please set sudo password to Specinfra.configuration.sudo_password.'
120
121
  else
121
122
  stderr_data += data
122
123
  end
@@ -1,8 +1,9 @@
1
1
  module Specinfra::Backend
2
- class WinRM < Base
2
+ class Winrm < Base
3
3
  include PowerShell::ScriptHelper
4
4
 
5
5
  def run_command(cmd, opts={})
6
+ set :os, :family => 'windows'
6
7
  script = create_script(cmd)
7
8
  winrm = Specinfra.configuration.winrm
8
9
 
@@ -35,9 +35,10 @@ class Specinfra::Command::Base::File < Specinfra::Command::Base
35
35
  from ||= '1'
36
36
  to ||= '$'
37
37
  sed = "sed -n #{escape(from)},#{escape(to)}p #{escape(file)}"
38
+ sed_end = "sed -n 1,#{escape(to)}p"
38
39
  checker_with_regexp = check_contains_with_regexp("-", expected_pattern)
39
40
  checker_with_fixed = check_contains_with_fixed_strings("-", expected_pattern)
40
- "#{sed} | #{checker_with_regexp} || #{sed} | #{checker_with_fixed}"
41
+ "#{sed} | #{sed_end} | #{checker_with_regexp} || #{sed} | #{sed_end} | #{checker_with_fixed}"
41
42
  end
42
43
 
43
44
  def check_contains_lines(file, expected_lines, from=nil, to=nil)
@@ -52,11 +53,11 @@ class Specinfra::Command::Base::File < Specinfra::Command::Base
52
53
  end
53
54
 
54
55
  def check_contains_with_regexp(file, expected_pattern)
55
- "grep -q -- #{escape(expected_pattern)} #{escape(file)}"
56
+ "grep -qs -- #{escape(expected_pattern)} #{escape(file)}"
56
57
  end
57
58
 
58
59
  def check_contains_with_fixed_strings(file, expected_pattern)
59
- "grep -qF -- #{escape(expected_pattern)} #{escape(file)}"
60
+ "grep -qFs -- #{escape(expected_pattern)} #{escape(file)}"
60
61
  end
61
62
 
62
63
  def get_md5sum(file)
@@ -4,10 +4,6 @@ class Specinfra::Command::Base::Service < Specinfra::Command::Base
4
4
  "service #{escape(service)} status"
5
5
  end
6
6
 
7
- def check_is_installed(service, level=3)
8
- raise NotImplementedError.new
9
- end
10
-
11
7
  def check_is_running_under_supervisor(service)
12
8
  "supervisorctl status #{escape(service)} | grep RUNNING"
13
9
  end
@@ -1,8 +1,6 @@
1
1
  require 'shellwords'
2
2
  class Specinfra::Command::Base
3
3
  class << self
4
- @@types = nil
5
-
6
4
  class NotImplementedError < Exception; end
7
5
 
8
6
  def create
@@ -19,78 +17,5 @@ class Specinfra::Command::Base
19
17
 
20
18
  Shellwords.shellescape(str)
21
19
  end
22
-
23
- def get(meth, *args)
24
- action, resource_type, subaction = breakdown(meth)
25
- method = action
26
- method += "_#{subaction}" if subaction
27
- command_class = create_command_class(resource_type)
28
- if command_class.respond_to?(method)
29
- command_class.send(method, *args)
30
- else
31
- raise NotImplementedError.new("#{method} is not implemented in #{command_class}")
32
- end
33
- end
34
-
35
- def create_command_class(resource_type)
36
- family = os[:family]
37
- version = os[:release] ? "V#{os[:release].to_i}" : nil
38
-
39
- common_class = Specinfra::Command
40
- base_class = common_class.const_get('Base')
41
- os_class = family.nil? ? base_class : common_class.const_get(family.capitalize)
42
-
43
- if family && version
44
- begin
45
- version_class = os_class.const_get(version)
46
- rescue
47
- version_class = os_class.const_get('Base')
48
- end
49
- elsif family.nil?
50
- version_class = os_class
51
- elsif family != 'base' && version.nil?
52
- version_class = os_class.const_get('Base')
53
- end
54
-
55
- begin
56
- command_class = version_class.const_get(resource_type.to_camel_case)
57
- rescue
58
- end
59
-
60
- if command_class.nil? ||( (command_class < Specinfra::Command::Base).nil? && (command_class < Specinfra::Command::Windows::Base).nil? )
61
- command_class = base_class.const_get(resource_type.to_camel_case)
62
- end
63
-
64
- command_class.create
65
- end
66
-
67
- private
68
- def breakdown(meth)
69
- types = resource_types.map {|t| t.to_snake_case }.join('|')
70
- md = meth.to_s.match(/^([^_]+)_(#{types})_?(.+)?$/)
71
- if md.nil?
72
- message = "Could not break down `#{meth}' to appropriate type and method.\n"
73
- message += "The method name shoud be in the form of `action_type_subaction'."
74
- raise message
75
- end
76
- return md[1], md[2], md[3]
77
- end
78
-
79
- def resource_types
80
- if @@types.nil?
81
- @@types = []
82
- Specinfra::Command::Base.subclasses.each do |s|
83
- @@types << s.to_s.split(':')[-1]
84
- end
85
- Specinfra::Command::Windows::Base.subclasses.each do |s|
86
- @@types << s.to_s.split(':')[-1]
87
- end
88
- @@types.uniq!
89
- end
90
- @@types
91
- end
92
20
  end
93
21
  end
94
-
95
-
96
-
@@ -10,5 +10,3 @@ class Specinfra::Command::Linux::Base::Selinux < Specinfra::Command::Base::Selin
10
10
  end
11
11
  end
12
12
  end
13
-
14
-
@@ -9,10 +9,3 @@ class Specinfra::Command::Openbsd::Base::User < Specinfra::Command::Base::User
9
9
  end
10
10
  end
11
11
  end
12
-
13
-
14
-
15
-
16
-
17
-
18
-
@@ -4,9 +4,10 @@ class Specinfra::Command::Solaris::Base::File < Specinfra::Command::Base::File
4
4
  from ||= '1'
5
5
  to ||= '$'
6
6
  sed = "sed -n #{escape(from)},#{escape(to)}p #{escape(file)}"
7
+ sed_end = "sed -n 1,#{escape(to)}p"
7
8
  checker_with_regexp = check_contains_with_regexp("/dev/stdin", expected_pattern)
8
9
  checker_with_fixed = check_contains_with_fixed_strings("/dev/stdin", expected_pattern)
9
- "#{sed} | #{checker_with_regexp} || #{sed} | #{checker_with_fixed}"
10
+ "#{sed} | #{sed_end} | #{checker_with_regexp}|| #{sed} | #{sed_end} | #{checker_with_fixed}"
10
11
  end
11
12
 
12
13
  def check_is_accessible_by_user(file, user, access)
@@ -1,10 +1,10 @@
1
1
  class Specinfra::Command::Windows::Base::Feature < Specinfra::Command::Windows::Base
2
2
  class << self
3
- def check_is_enabled(name,provider)
3
+ def check_is_enabled(name, provider)
4
4
  if provider.nil?
5
5
  cmd = "@(ListWindowsFeatures -feature #{name}).count -gt 0"
6
6
  else
7
- cmd = "@(ListWindowsFeatures -feature #{name} -provider #{provider}).count -gt 0"
7
+ cmd = "@(ListWindowsFeatures -feature #{name} -provider #{provider.to_s}).count -gt 0"
8
8
  end
9
9
 
10
10
  Backend::PowerShell::Command.new do
@@ -93,7 +93,7 @@ class Specinfra::Command::Windows::Base::File < Specinfra::Command::Windows::Bas
93
93
 
94
94
  private
95
95
  def item_has_attribute item, attribute
96
- "((Get-Item -Path '#{item}' -Force).attributes.ToString() -Split ', ') -contains '#{attribute}'"
96
+ %Q!((Get-Item -Path "#{item}" -Force).attributes.ToString() -Split ', ') -contains '#{attribute}'!
97
97
  end
98
98
  end
99
99
  end
@@ -64,6 +64,3 @@ class Specinfra::Command::Windows::Base::IisAppPool < Specinfra::Command::Window
64
64
  end
65
65
  end
66
66
  end
67
-
68
-
69
-
@@ -0,0 +1,75 @@
1
+ class Specinfra::CommandFactory
2
+ class << self
3
+ @@types = nil
4
+
5
+ def get(meth, *args)
6
+ action, resource_type, subaction = breakdown(meth)
7
+ method = action
8
+ method += "_#{subaction}" if subaction
9
+ command_class = create_command_class(resource_type)
10
+ if command_class.respond_to?(method)
11
+ command_class.send(method, *args)
12
+ else
13
+ raise NotImplementedError.new("#{method} is not implemented in #{command_class}")
14
+ end
15
+ end
16
+
17
+ private
18
+ def create_command_class(resource_type)
19
+ family = os[:family]
20
+ version = os[:release] ? "V#{os[:release].to_i}" : nil
21
+
22
+ common_class = Specinfra::Command
23
+ base_class = common_class.const_get('Base')
24
+ os_class = family.nil? ? base_class : common_class.const_get(family.capitalize)
25
+
26
+ if family && version
27
+ begin
28
+ version_class = os_class.const_get(version)
29
+ rescue
30
+ version_class = os_class.const_get('Base')
31
+ end
32
+ elsif family.nil?
33
+ version_class = os_class
34
+ elsif family != 'base' && version.nil?
35
+ version_class = os_class.const_get('Base')
36
+ end
37
+
38
+ begin
39
+ command_class = version_class.const_get(resource_type.to_camel_case)
40
+ rescue
41
+ end
42
+
43
+ if command_class.nil? ||( (command_class < Specinfra::Command::Base).nil? && (command_class < Specinfra::Command::Windows::Base).nil? )
44
+ command_class = base_class.const_get(resource_type.to_camel_case)
45
+ end
46
+
47
+ command_class.create
48
+ end
49
+
50
+ def breakdown(meth)
51
+ types = resource_types.map {|t| t.to_snake_case }.join('|')
52
+ md = meth.to_s.match(/^([^_]+)_(#{types})_?(.+)?$/)
53
+ if md.nil?
54
+ message = "Could not break down `#{meth}' to appropriate type and method.\n"
55
+ message += "The method name shoud be in the form of `action_type_subaction'."
56
+ raise message
57
+ end
58
+ return md[1], md[2], md[3]
59
+ end
60
+
61
+ def resource_types
62
+ if @@types.nil?
63
+ @@types = []
64
+ Specinfra::Command::Base.subclasses.each do |s|
65
+ @@types << s.to_s.split(':')[-1]
66
+ end
67
+ Specinfra::Command::Windows::Base.subclasses.each do |s|
68
+ @@types << s.to_s.split(':')[-1]
69
+ end
70
+ @@types.uniq!
71
+ end
72
+ @@types
73
+ end
74
+ end
75
+ end
@@ -35,8 +35,8 @@ module Specinfra
35
35
  mode = sprintf('%04s',Specinfra.backend.run_command(cmd).stdout.strip)
36
36
  mode = mode.split('')
37
37
  mode_octal = mode[0].to_i * 512 + mode[1].to_i * 64 + mode[2].to_i * 8 + mode[3].to_i * 1
38
- case by_whom
39
- when nil
38
+ case by_whom.to_s
39
+ when ''
40
40
  mode_octal & 0444 != 0
41
41
  when 'owner'
42
42
  mode_octal & 0400 != 0
@@ -52,8 +52,8 @@ module Specinfra
52
52
  mode = sprintf('%04s',Specinfra.backend.run_command(cmd).stdout.strip)
53
53
  mode = mode.split('')
54
54
  mode_octal = mode[0].to_i * 512 + mode[1].to_i * 64 + mode[2].to_i * 8 + mode[3].to_i * 1
55
- case by_whom
56
- when nil
55
+ case by_whom.to_s
56
+ when ''
57
57
  mode_octal & 0222 != 0
58
58
  when 'owner'
59
59
  mode_octal & 0200 != 0
@@ -69,8 +69,8 @@ module Specinfra
69
69
  mode = sprintf('%04s',Specinfra.backend.run_command(cmd).stdout.strip)
70
70
  mode = mode.split('')
71
71
  mode_octal = mode[0].to_i * 512 + mode[1].to_i * 64 + mode[2].to_i * 8 + mode[3].to_i * 1
72
- case by_whom
73
- when nil
72
+ case by_whom.to_s
73
+ when ''
74
74
  mode_octal & 0111 != 0
75
75
  when 'owner'
76
76
  mode_octal & 0100 != 0
@@ -1,11 +1,16 @@
1
1
  module Specinfra
2
2
  class Runner
3
3
  def self.method_missing(meth, *args)
4
+ backend = Specinfra.backend
5
+ processor = Specinfra::Processor
6
+
4
7
  if os.include?(:family) && os[:family] == 'windows'
5
- run(meth, *args)
8
+ if backend.respond_to?(meth)
9
+ backend.send(meth, *args)
10
+ else
11
+ run(meth, *args)
12
+ end
6
13
  else
7
- processor = Specinfra::Processor
8
- backend = Specinfra.backend
9
14
  if processor.respond_to?(meth)
10
15
  processor.send(meth, *args)
11
16
  elsif backend.respond_to?(meth)
@@ -16,19 +21,15 @@ module Specinfra
16
21
  end
17
22
  end
18
23
 
19
- def self.run_command(cmd)
20
- Specinfra.backend.run_command(cmd)
21
- end
22
-
23
24
  private
24
25
  def self.run(meth, *args)
25
26
  cmd = Specinfra.command.get(meth, *args)
27
+ ret = Specinfra.backend.run_command(cmd)
26
28
  if meth.to_s =~ /^check/
27
- Specinfra.backend.run_command(cmd).success?
29
+ ret.success?
28
30
  else
29
- Specinfra.backend.run_command(cmd)
31
+ ret
30
32
  end
31
33
  end
32
-
33
34
  end
34
35
  end
@@ -1,3 +1,3 @@
1
1
  module Specinfra
2
- VERSION = "2.0.0.beta32"
2
+ VERSION = "2.0.0.beta33"
3
3
  end
data/lib/specinfra.rb CHANGED
@@ -2,6 +2,7 @@ require 'specinfra/version'
2
2
  require 'specinfra/helper'
3
3
  require 'specinfra/backend'
4
4
  require 'specinfra/command'
5
+ require 'specinfra/command_factory'
5
6
  require 'specinfra/command_result'
6
7
  require 'specinfra/configuration'
7
8
  require 'specinfra/runner'
@@ -16,7 +17,7 @@ module Specinfra
16
17
  end
17
18
 
18
19
  def command
19
- Specinfra::Command::Base
20
+ Specinfra::CommandFactory
20
21
  end
21
22
 
22
23
  def backend
@@ -4,13 +4,13 @@ describe Specinfra::Backend::Exec do
4
4
  describe '#build_command' do
5
5
  context 'with simple command' do
6
6
  it 'should escape spaces' do
7
- expect(Specinfra.backend.build_command('test -f /etc/passwd')).to eq '/bin/sh -c test\ -f\ /etc/passwd'
7
+ expect(Specinfra.backend.send(:build_command, 'test -f /etc/passwd')).to eq '/bin/sh -c test\ -f\ /etc/passwd'
8
8
  end
9
9
  end
10
10
 
11
11
  context 'with complex command' do
12
12
  it 'should escape special chars' do
13
- expect(Specinfra.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\)'
13
+ expect(Specinfra.backend.send(: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\)'
14
14
  end
15
15
  end
16
16
 
@@ -24,7 +24,7 @@ describe Specinfra::Backend::Exec do
24
24
  end
25
25
 
26
26
  it 'should use custom shell' do
27
- expect(Specinfra.backend.build_command('test -f /etc/passwd')).to eq '/usr/local/bin/tcsh -c test\ -f\ /etc/passwd'
27
+ expect(Specinfra.backend.send(:build_command, 'test -f /etc/passwd')).to eq '/usr/local/bin/tcsh -c test\ -f\ /etc/passwd'
28
28
  end
29
29
  end
30
30
 
@@ -38,7 +38,7 @@ describe Specinfra::Backend::Exec do
38
38
  end
39
39
 
40
40
  it 'should use custom shell' do
41
- expect(Specinfra.backend.build_command('test -f /etc/passwd')).to eq '/usr/test\ \&\ spec/bin/sh -c test\ -f\ /etc/passwd'
41
+ expect(Specinfra.backend.send(:build_command, 'test -f /etc/passwd')).to eq '/usr/test\ \&\ spec/bin/sh -c test\ -f\ /etc/passwd'
42
42
  end
43
43
  end
44
44
 
@@ -52,7 +52,7 @@ describe Specinfra::Backend::Exec do
52
52
  end
53
53
 
54
54
  it 'should use custom path' do
55
- expect(Specinfra.backend.build_command('test -f /etc/passwd')).to eq 'env PATH="/opt/bin:/opt/foo/bin:$PATH" /bin/sh -c test\ -f\ /etc/passwd'
55
+ expect(Specinfra.backend.send(:build_command, 'test -f /etc/passwd')).to eq 'env PATH="/opt/bin:/opt/foo/bin:$PATH" /bin/sh -c test\ -f\ /etc/passwd'
56
56
  end
57
57
  end
58
58
 
@@ -66,7 +66,7 @@ describe Specinfra::Backend::Exec do
66
66
  end
67
67
 
68
68
  it 'should use custom path' do
69
- expect(Specinfra.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'
69
+ expect(Specinfra.backend.send(:build_command, 'test -f /etc/passwd')).to eq 'env PATH="/opt/bin:/opt/test & spec/bin:$PATH" /bin/sh -c test\ -f\ /etc/passwd'
70
70
  end
71
71
  end
72
72
  end
@@ -13,11 +13,11 @@ describe Specinfra::Backend::Ssh do
13
13
  end
14
14
 
15
15
  it 'should not prepend sudo' do
16
- expect(Specinfra.backend.build_command('test -f /etc/passwd')).to eq '/bin/sh -c test\ -f\ /etc/passwd'
16
+ expect(Specinfra.backend.send(:build_command, 'test -f /etc/passwd')).to eq '/bin/sh -c test\ -f\ /etc/passwd'
17
17
  end
18
18
 
19
19
  it 'should escape special characters' do
20
- expect(Specinfra.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\)'
20
+ expect(Specinfra.backend.send(: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\)'
21
21
  end
22
22
  end
23
23
 
@@ -30,11 +30,11 @@ describe Specinfra::Backend::Ssh do
30
30
  end
31
31
 
32
32
  it 'should prepend sudo' do
33
- expect(Specinfra.backend.build_command('test -f /etc/passwd')).to eq %q{sudo -p 'Password: ' /bin/sh -c test\ -f\ /etc/passwd}
33
+ expect(Specinfra.backend.send(:build_command, 'test -f /etc/passwd')).to eq %q{sudo -p 'Password: ' /bin/sh -c test\ -f\ /etc/passwd}
34
34
  end
35
35
 
36
36
  it 'should escape special characters' do
37
- expect(Specinfra.backend.build_command('test ! -f /etc/selinux/config || (getenforce | grep -i -- disabled && grep -i -- ^SELINUX=disabled$ /etc/selinux/config)')).to eq %q{sudo -p 'Password: ' /bin/sh -c test\ \!\ -f\ /etc/selinux/config\ \|\|\ \(getenforce\ \|\ grep\ -i\ --\ disabled\ \&\&\ grep\ -i\ --\ \^SELINUX\=disabled\$\ /etc/selinux/config\)}
37
+ expect(Specinfra.backend.send(:build_command, 'test ! -f /etc/selinux/config || (getenforce | grep -i -- disabled && grep -i -- ^SELINUX=disabled$ /etc/selinux/config)')).to eq %q{sudo -p 'Password: ' /bin/sh -c test\ \!\ -f\ /etc/selinux/config\ \|\|\ \(getenforce\ \|\ grep\ -i\ --\ disabled\ \&\&\ grep\ -i\ --\ \^SELINUX\=disabled\$\ /etc/selinux/config\)}
38
38
  end
39
39
  end
40
40
 
@@ -54,11 +54,11 @@ describe Specinfra::Backend::Ssh do
54
54
  end
55
55
 
56
56
  it 'command pattern 1a' do
57
- expect(Specinfra.backend.build_command('test -f /etc/passwd')).to eq %q{/usr/local/bin/sudo -p 'Password: ' /bin/sh -c test\ -f\ /etc/passwd}
57
+ expect(Specinfra.backend.send(:build_command, 'test -f /etc/passwd')).to eq %q{/usr/local/bin/sudo -p 'Password: ' /bin/sh -c test\ -f\ /etc/passwd}
58
58
  end
59
59
 
60
60
  it 'command pattern 2a' do
61
- expect(Specinfra.backend.build_command('test ! -f /etc/selinux/config || (getenforce | grep -i -- disabled && grep -i -- ^SELINUX=disabled$ /etc/selinux/config)')).to eq %q{/usr/local/bin/sudo -p 'Password: ' /bin/sh -c test\ \!\ -f\ /etc/selinux/config\ \|\|\ \(getenforce\ \|\ grep\ -i\ --\ disabled\ \&\&\ grep\ -i\ --\ \^SELINUX\=disabled\$\ /etc/selinux/config\)}
61
+ expect(Specinfra.backend.send(:build_command, 'test ! -f /etc/selinux/config || (getenforce | grep -i -- disabled && grep -i -- ^SELINUX=disabled$ /etc/selinux/config)')).to eq %q{/usr/local/bin/sudo -p 'Password: ' /bin/sh -c test\ \!\ -f\ /etc/selinux/config\ \|\|\ \(getenforce\ \|\ grep\ -i\ --\ disabled\ \&\&\ grep\ -i\ --\ \^SELINUX\=disabled\$\ /etc/selinux/config\)}
62
62
  end
63
63
  end
64
64
 
@@ -78,11 +78,11 @@ describe Specinfra::Backend::Ssh do
78
78
  end
79
79
 
80
80
  it 'command pattern 1b' do
81
- expect(Specinfra.backend.build_command('test -f /etc/passwd')).to eq '/bin/sh -c test\ -f\ /etc/passwd'
81
+ expect(Specinfra.backend.send(:build_command, 'test -f /etc/passwd')).to eq '/bin/sh -c test\ -f\ /etc/passwd'
82
82
  end
83
83
 
84
84
  it 'command pattern 2b' do
85
- expect(Specinfra.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\)'
85
+ expect(Specinfra.backend.send(: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\)'
86
86
  end
87
87
 
88
88
  end
@@ -104,12 +104,12 @@ describe Specinfra::Backend::Ssh do
104
104
  end
105
105
 
106
106
  context 'command pattern 1a' do
107
- subject { Specinfra.backend.build_command('test -f /etc/passwd') }
107
+ subject { Specinfra.backend.send(:build_command, 'test -f /etc/passwd') }
108
108
  it { should eq %q{sudo -p 'Password: ' /bin/sh -c test\ -f\ /etc/passwd} }
109
109
  end
110
110
 
111
111
  context 'command pattern 2a' do
112
- subject { Specinfra.backend.build_command('test ! -f /etc/selinux/config || (getenforce | grep -i -- disabled && grep -i -- ^SELINUX=disabled$ /etc/selinux/config)') }
112
+ subject { Specinfra.backend.send(:build_command, 'test ! -f /etc/selinux/config || (getenforce | grep -i -- disabled && grep -i -- ^SELINUX=disabled$ /etc/selinux/config)') }
113
113
  it { should eq %q{sudo -p 'Password: ' /bin/sh -c test\ \!\ -f\ /etc/selinux/config\ \|\|\ \(getenforce\ \|\ grep\ -i\ --\ disabled\ \&\&\ grep\ -i\ --\ \^SELINUX\=disabled\$\ /etc/selinux/config\)} }
114
114
  end
115
115
  end
@@ -9,21 +9,21 @@ describe 'create_command_class work correctly' do
9
9
  before do
10
10
  set :os, :family => 'base'
11
11
  end
12
- it { expect(Specinfra::Command::Base.create_command_class('file')).to eq Specinfra::Command::Base::File }
12
+ it { expect(Specinfra.command.send(:create_command_class, 'file')).to eq Specinfra::Command::Base::File }
13
13
  end
14
14
 
15
15
  context 'family: redhat, release: nil' do
16
16
  before do
17
17
  set :os, :family => 'redhat'
18
18
  end
19
- it { expect(Specinfra::Command::Base.create_command_class('file')).to eq Specinfra::Command::Redhat::Base::File }
19
+ it { expect(Specinfra.command.send(:create_command_class, 'file')).to eq Specinfra::Command::Redhat::Base::File }
20
20
  end
21
21
 
22
22
  context 'family: redhat, release: 7' do
23
23
  before do
24
24
  set :os, :family => 'redhat', :release => 7
25
25
  end
26
- it { expect(Specinfra::Command::Base.create_command_class('file')).to eq Specinfra::Command::Redhat::V7::File }
26
+ it { expect(Specinfra.command.send(:create_command_class, 'file')).to eq Specinfra::Command::Redhat::V7::File }
27
27
  end
28
28
  end
29
29
 
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  property[:os] = nil
4
4
  set :os, { :family => 'redhat', :release => 7 }
5
5
 
6
- describe Specinfra.command.create_command_class('interface') do
6
+ describe Specinfra.command.send(:create_command_class, 'interface') do
7
7
  it { should be_an_instance_of(Specinfra::Command::Linux::Base::Interface) }
8
8
  end
9
9
 
data/wercker.yml CHANGED
@@ -36,7 +36,7 @@ build:
36
36
  cwd: $WORKING_DIR
37
37
  - script:
38
38
  name: Run rake spec:centos65
39
- code: rake spec:centos65
39
+ code: DIGITALOCEAN=true rake spec:centos65
40
40
  cwd: $WORKING_DIR
41
41
  - script:
42
42
  name: Run vagrant up centos70
@@ -52,7 +52,7 @@ build:
52
52
  cwd: $WORKING_DIR
53
53
  - script:
54
54
  name: Run rake spec:centos70
55
- code: rake spec:centos70
55
+ code: DIGITALOCEAN=true rake spec:centos70
56
56
  cwd: $WORKING_DIR
57
57
  - script:
58
58
  name: Run vagrant up ubuntu1404
@@ -68,7 +68,7 @@ build:
68
68
  cwd: $WORKING_DIR
69
69
  - script:
70
70
  name: Run rake spec:ubuntu1404
71
- code: rake spec:ubuntu1404
71
+ code: DIGITALOCEAN=true rake spec:ubuntu1404
72
72
  cwd: $WORKING_DIR
73
73
 
74
74
  after-steps:
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: specinfra
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.beta32
4
+ version: 2.0.0.beta33
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gosuke Miyashita
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-11 00:00:00.000000000 Z
11
+ date: 2014-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-ssh
@@ -292,6 +292,7 @@ files:
292
292
  - lib/specinfra/command/windows/base/scheduled_task.rb
293
293
  - lib/specinfra/command/windows/base/service.rb
294
294
  - lib/specinfra/command/windows/base/user.rb
295
+ - lib/specinfra/command_factory.rb
295
296
  - lib/specinfra/command_result.rb
296
297
  - lib/specinfra/configuration.rb
297
298
  - lib/specinfra/helper.rb
@@ -322,7 +323,7 @@ files:
322
323
  - spec/backend/exec/env_spec.rb
323
324
  - spec/backend/ssh/build_command_spec.rb
324
325
  - spec/command/base/file_spec.rb
325
- - spec/command/base_spec.rb
326
+ - spec/command/factory_spec.rb
326
327
  - spec/command/module/systemd_spec.rb
327
328
  - spec/command/redhat/interface_spec.rb
328
329
  - spec/command/redhat/package_spec.rb
@@ -362,7 +363,7 @@ test_files:
362
363
  - spec/backend/exec/env_spec.rb
363
364
  - spec/backend/ssh/build_command_spec.rb
364
365
  - spec/command/base/file_spec.rb
365
- - spec/command/base_spec.rb
366
+ - spec/command/factory_spec.rb
366
367
  - spec/command/module/systemd_spec.rb
367
368
  - spec/command/redhat/interface_spec.rb
368
369
  - spec/command/redhat/package_spec.rb