boxgrinder-core 0.0.21 → 0.0.22

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,4 +1,8 @@
1
1
 
2
+ v0.0.22
3
+
4
+ * [BGBUILD-44] ExecHelper should raise exception if execution fails
5
+
2
6
  v0.0.21
3
7
 
4
8
  * Return nil if key is not found in OpenHash
data/Rakefile CHANGED
@@ -6,4 +6,5 @@ Echoe.new("boxgrinder-core") do |p|
6
6
  p.summary = "Core files for BoxGrinder."
7
7
  p.url = "http://www.jboss.org/stormgrind/projects/boxgrinder.html"
8
8
  p.email = "info@boxgrinder.org"
9
- end
9
+ p.runtime_dependencies = ['open4 >=1.0.0']
10
+ end
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{boxgrinder-core}
5
- s.version = "0.0.21"
5
+ s.version = "0.0.22"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Marek Goldmann"]
9
- s.date = %q{2010-08-08}
9
+ s.date = %q{2010-08-23}
10
10
  s.description = %q{Core files for BoxGrinder.}
11
11
  s.email = %q{info@boxgrinder.org}
12
12
  s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "README", "lib/boxgrinder-core.rb", "lib/boxgrinder-core/defaults.rb", "lib/boxgrinder-core/helpers/appliance-config-helper.rb", "lib/boxgrinder-core/helpers/appliance-helper.rb", "lib/boxgrinder-core/helpers/exec-helper.rb", "lib/boxgrinder-core/helpers/log-helper.rb", "lib/boxgrinder-core/helpers/queue-helper.rb", "lib/boxgrinder-core/models/appliance-config.rb", "lib/boxgrinder-core/models/config.rb", "lib/boxgrinder-core/models/task.rb", "lib/boxgrinder-core/validators/appliance-config-validator.rb", "lib/boxgrinder-core/validators/errors.rb", "lib/openhash/openhash.rb"]
@@ -23,8 +23,11 @@ Gem::Specification.new do |s|
23
23
  s.specification_version = 3
24
24
 
25
25
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
26
+ s.add_runtime_dependency(%q<open4>, [">= 1.0.0"])
26
27
  else
28
+ s.add_dependency(%q<open4>, [">= 1.0.0"])
27
29
  end
28
30
  else
31
+ s.add_dependency(%q<open4>, [">= 1.0.0"])
29
32
  end
30
33
  end
@@ -19,7 +19,8 @@
19
19
  # 02110-1301 USA, or see the FSF site: http://www.fsf.org.
20
20
 
21
21
  require 'logger'
22
- require 'open3'
22
+ require 'rubygems'
23
+ require 'open4'
23
24
 
24
25
  module BoxGrinder
25
26
  class ExecHelper
@@ -32,28 +33,40 @@ module BoxGrinder
32
33
 
33
34
  output = ""
34
35
 
35
- Open3.popen3( command ) do |stdin, stdout, stderr|
36
- threads = []
36
+ begin
37
+ status = Open4::popen4( command ) do |pid, stdin, stdout, stderr|
38
+ threads = []
37
39
 
38
- threads << Thread.new(stdout) do |input_str|
39
- input_str.each do |l|
40
- output << l
41
- @log.debug l.chomp.strip
40
+ threads << Thread.new(stdout) do |input_str|
41
+ input_str.each do |l|
42
+ l.chomp!
43
+ l.strip!
44
+
45
+ output << "\n#{l}"
46
+ @log.debug l
47
+ end
42
48
  end
43
- end
44
-
45
- threads << Thread.new(stderr) do |input_str|
46
- input_str.each do |l|
47
- output << l
48
- @log.debug l.chomp.strip
49
+
50
+ threads << Thread.new(stderr) do |input_str|
51
+ input_str.each do |l|
52
+ l.chomp!
53
+ l.strip!
54
+
55
+ output << "\n#{l}"
56
+ @log.debug l
57
+ end
49
58
  end
59
+ threads.each{|t|t.join}
50
60
  end
51
- threads.each{|t|t.join}
52
- end
53
61
 
54
- raise "An error occurred executing command: '#{command}'" if $?.to_i != 0
62
+ raise "process exited with wrong exit status: #{status.exitstatus}" if status.exitstatus != 0
55
63
 
56
- output
64
+ return output.strip
65
+ rescue => e
66
+ @log.error e.backtrace.join($/)
67
+ @log.error "An error occurred while executing command: '#{command}', #{e.message}"
68
+ raise "An error occurred while executing command: '#{command}', #{e.message}"
69
+ end
57
70
  end
58
71
  end
59
- end
72
+ end
data/spec/Rakefile CHANGED
@@ -3,7 +3,8 @@ require 'spec/rake/spectask'
3
3
 
4
4
  desc "Run all examples"
5
5
  Spec::Rake::SpecTask.new('examples') do |t|
6
- t.spec_files = FileList['../**/spec/**/*-spec.rb']
6
+ t.spec_files = FileList['**/*-spec.rb']
7
7
  t.rcov = true
8
+ t.spec_opts = ['--colour', '--format', 'nested']
8
9
  t.rcov_opts = ['--exclude', 'spec']
9
10
  end
@@ -2,5 +2,40 @@ require 'boxgrinder-core/helpers/exec-helper'
2
2
 
3
3
  module BoxGrinder
4
4
  describe ExecHelper do
5
+ before(:each) do
6
+ @helper = ExecHelper.new( :log => Logger.new('/dev/null') )
7
+ end
8
+
9
+ it "should fail when command doesn't exists" do
10
+ Open4.should_receive( :popen4 ).with('thisdoesntexists').and_raise('abc')
11
+
12
+ proc { @helper.execute("thisdoesntexists") }.should raise_error("An error occurred while executing command: 'thisdoesntexists', abc")
13
+ end
14
+
15
+ it "should fail when command exit status != 0" do
16
+ open4 = mock(Open4)
17
+ open4.stub!(:exitstatus).and_return(1)
18
+
19
+ Open4.should_receive( :popen4 ).with('abc').and_return(open4)
20
+
21
+ proc { @helper.execute("abc") }.should raise_error("An error occurred while executing command: 'abc', process exited with wrong exit status: 1")
22
+ end
23
+
24
+ it "should execute the command" do
25
+ open4 = mock(Open4)
26
+ open4.stub!(:exitstatus).and_return(0)
27
+
28
+ Open4.should_receive( :popen4 ).with('abc').and_return(open4)
29
+
30
+ proc { @helper.execute("abc") }.should_not raise_error
31
+ end
32
+
33
+ it "should execute the command and return output" do
34
+ @helper.execute("ls rspec/ls | wc -l").should == "2"
35
+ end
36
+
37
+ it "should execute the command and return multi line output" do
38
+ @helper.execute("ls -1 rspec/ls").should == "one\ntwo"
39
+ end
5
40
  end
6
41
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 21
9
- version: 0.0.21
8
+ - 22
9
+ version: 0.0.22
10
10
  platform: ruby
11
11
  authors:
12
12
  - Marek Goldmann
@@ -14,10 +14,23 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-08-08 00:00:00 +02:00
17
+ date: 2010-08-23 00:00:00 +02:00
18
18
  default_executable:
19
- dependencies: []
20
-
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: open4
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 1
29
+ - 0
30
+ - 0
31
+ version: 1.0.0
32
+ type: :runtime
33
+ version_requirements: *id001
21
34
  description: Core files for BoxGrinder.
22
35
  email: info@boxgrinder.org
23
36
  executables: []