specinfra 2.0.0.beta9 → 2.0.0.beta10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/specinfra/backend/exec.rb +15 -3
- data/lib/specinfra/backend/ssh.rb +23 -1
- data/lib/specinfra/command/linux/base/lxc_container.rb +1 -1
- data/lib/specinfra/configuration.rb +1 -0
- data/lib/specinfra/version.rb +1 -1
- data/spec/backend/exec/build_command_spec.rb +4 -4
- data/spec/backend/exec/env_spec.rb +16 -0
- data/spec/spec_helper.rb +1 -0
- data/specinfra.gemspec +1 -0
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e1aff7042917b171b5d17ebf844a2d999aa6618e
|
4
|
+
data.tar.gz: 0b40b2253e90d2b396488e23760ba55ddbbe00d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 726743abc9b1a8e572e6919900d4caf7e1426e020b316ac6c2533032b7da7b8e335dbd79a9082ba3561358ff524beb6c0486fffa6f692512c2c98ab082717430
|
7
|
+
data.tar.gz: 95ceed7ebc6efbc6bb2a2ea6d37d991bf71145996d834521fbf7b62cbeed7d0ecebc5b53b21e4cd8aea0a72b0dfa73dbaec114698453bb39d2f0baec8e7badb3
|
@@ -9,7 +9,7 @@ module Specinfra
|
|
9
9
|
def run_command(cmd, opts={})
|
10
10
|
cmd = build_command(cmd)
|
11
11
|
cmd = add_pre_command(cmd)
|
12
|
-
stdout =
|
12
|
+
stdout = with_env do
|
13
13
|
`#{build_command(cmd)} 2>&1`
|
14
14
|
end
|
15
15
|
# In ruby 1.9, it is possible to use Open3.capture3, but not in 1.8
|
@@ -23,14 +23,26 @@ module Specinfra
|
|
23
23
|
CommandResult.new :stdout => stdout, :exit_status => $?.exitstatus
|
24
24
|
end
|
25
25
|
|
26
|
-
def
|
26
|
+
def with_env
|
27
27
|
keys = %w[BUNDLER_EDITOR BUNDLE_BIN_PATH BUNDLE_GEMFILE
|
28
28
|
RUBYOPT GEM_HOME GEM_PATH GEM_CACHE]
|
29
29
|
|
30
30
|
keys.each { |key| ENV["_SPECINFRA_#{key}"] = ENV[key] ; ENV.delete(key) }
|
31
|
+
|
32
|
+
env = Specinfra.configuration.env || {}
|
33
|
+
env['LANG'] ||= 'C'
|
34
|
+
|
35
|
+
env.each do |key, value|
|
36
|
+
ENV["_SPECINFRA_#{key}"] = ENV[key];
|
37
|
+
ENV[key] = value
|
38
|
+
end
|
39
|
+
|
31
40
|
yield
|
32
41
|
ensure
|
33
42
|
keys.each { |key| ENV[key] = ENV.delete("_SPECINFRA_#{key}") }
|
43
|
+
env.each do |key, value|
|
44
|
+
ENV[key] = ENV.delete("_SPECINFRA_#{key}");
|
45
|
+
end
|
34
46
|
end
|
35
47
|
|
36
48
|
def build_command(cmd)
|
@@ -40,7 +52,7 @@ module Specinfra
|
|
40
52
|
|
41
53
|
path = Specinfra.configuration.path
|
42
54
|
if path
|
43
|
-
cmd =
|
55
|
+
cmd = %Q{env PATH="#{path}" #{cmd}}
|
44
56
|
end
|
45
57
|
|
46
58
|
cmd
|
@@ -11,7 +11,9 @@ module Specinfra
|
|
11
11
|
def run_command(cmd, opt={})
|
12
12
|
cmd = build_command(cmd)
|
13
13
|
cmd = add_pre_command(cmd)
|
14
|
-
ret =
|
14
|
+
ret = with_env do
|
15
|
+
ssh_exec!(cmd)
|
16
|
+
end
|
15
17
|
|
16
18
|
ret[:stdout].gsub!(/\r\n/, "\n")
|
17
19
|
|
@@ -23,6 +25,26 @@ module Specinfra
|
|
23
25
|
CommandResult.new ret
|
24
26
|
end
|
25
27
|
|
28
|
+
def with_env
|
29
|
+
env = Specinfra.configuration.env || {}
|
30
|
+
env['LANG'] ||= 'C'
|
31
|
+
|
32
|
+
ssh_options = Specinfra.configuration.ssh_options || {}
|
33
|
+
ssh_options[:send_env] ||= []
|
34
|
+
|
35
|
+
env.each do |key, value|
|
36
|
+
ENV["_SPECINFRA_#{key}"] = ENV[key];
|
37
|
+
ENV[key] = value
|
38
|
+
ssh_options[:send_env] << key
|
39
|
+
end
|
40
|
+
|
41
|
+
yield
|
42
|
+
ensure
|
43
|
+
env.each do |key, value|
|
44
|
+
ENV[key] = ENV.delete("_SPECINFRA_#{key}");
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
26
48
|
def build_command(cmd)
|
27
49
|
cmd = super(cmd)
|
28
50
|
user = Specinfra.configuration.ssh_options[:user]
|
data/lib/specinfra/version.rb
CHANGED
@@ -46,7 +46,7 @@ describe Specinfra::Backend::Exec do
|
|
46
46
|
|
47
47
|
context 'with custom path' do
|
48
48
|
before do
|
49
|
-
RSpec.configure {|c| c.path = '/opt/bin:/opt/foo/bin' }
|
49
|
+
RSpec.configure {|c| c.path = '/opt/bin:/opt/foo/bin:$PATH' }
|
50
50
|
end
|
51
51
|
|
52
52
|
after do
|
@@ -54,13 +54,13 @@ describe Specinfra::Backend::Exec do
|
|
54
54
|
end
|
55
55
|
|
56
56
|
it 'should use custom path' do
|
57
|
-
expect(backend.build_command('test -f /etc/passwd')).to eq 'env PATH
|
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
58
|
end
|
59
59
|
end
|
60
60
|
|
61
61
|
context 'with custom path that needs escaping' do
|
62
62
|
before do
|
63
|
-
RSpec.configure {|c| c.path = '/opt/bin:/opt/test & spec/bin' }
|
63
|
+
RSpec.configure {|c| c.path = '/opt/bin:/opt/test & spec/bin:$PATH' }
|
64
64
|
end
|
65
65
|
|
66
66
|
after do
|
@@ -68,7 +68,7 @@ describe Specinfra::Backend::Exec do
|
|
68
68
|
end
|
69
69
|
|
70
70
|
it 'should use custom path' do
|
71
|
-
expect(backend.build_command('test -f /etc/passwd')).to eq 'env PATH
|
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
72
|
end
|
73
73
|
end
|
74
74
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe backend.run_command('echo $LANG').stdout.strip do
|
4
|
+
it { should eq 'C' }
|
5
|
+
end
|
6
|
+
|
7
|
+
describe do
|
8
|
+
before do
|
9
|
+
ENV['LANG'] = 'C'
|
10
|
+
set :env, 'LANG' => 'ja_JP.UTF-8'
|
11
|
+
end
|
12
|
+
let(:lang) { backend.run_command('echo $LANG').stdout.strip }
|
13
|
+
it { expect(lang).to eq 'ja_JP.UTF-8' }
|
14
|
+
it { expect(ENV['LANG']).to eq 'C' }
|
15
|
+
end
|
16
|
+
|
data/spec/spec_helper.rb
CHANGED
data/specinfra.gemspec
CHANGED
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.
|
4
|
+
version: 2.0.0.beta10
|
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-07-
|
11
|
+
date: 2014-07-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: net-ssh
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec-its
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
description: Common layer for serverspec and configspec
|
70
84
|
email:
|
71
85
|
- gosukenator@gmail.com
|
@@ -293,6 +307,7 @@ files:
|
|
293
307
|
- lib/specinfra/runner.rb
|
294
308
|
- lib/specinfra/version.rb
|
295
309
|
- spec/backend/exec/build_command_spec.rb
|
310
|
+
- spec/backend/exec/env_spec.rb
|
296
311
|
- spec/backend/ssh/build_command_spec.rb
|
297
312
|
- spec/command/base/file_spec.rb
|
298
313
|
- spec/command/base_spec.rb
|
@@ -333,6 +348,7 @@ specification_version: 4
|
|
333
348
|
summary: Common layer for serverspec and configspec
|
334
349
|
test_files:
|
335
350
|
- spec/backend/exec/build_command_spec.rb
|
351
|
+
- spec/backend/exec/env_spec.rb
|
336
352
|
- spec/backend/ssh/build_command_spec.rb
|
337
353
|
- spec/command/base/file_spec.rb
|
338
354
|
- spec/command/base_spec.rb
|