diff --git a/lib/helpers/gem_exec.rb b/lib/helpers/gem_exec.rb index fdff62859..5fdc77a61 100644 --- a/lib/helpers/gem_exec.rb +++ b/lib/helpers/gem_exec.rb @@ -37,12 +37,20 @@ class GemExec end Dir.chdir(working_dir) - output_hash = {:output => '', :status => 0} + output_hash = {:output => '', :status => 0, :exception => nil} begin - output_hash[:output] = ProcessHelper.process("#{gem_path} #{arguments}", {:timeout => (60*40)}) + output_hash[:output] = ProcessHelper.process("#{gem_path} #{arguments}", {:timeout => (30), + include_output_in_exception: true}) rescue Exception => ex - output_hash[:output] = ex.to_s.split('Command output: ')[1] output_hash[:status] = 1 + output_hash[:exception] = ex + if ex.type == ProcessHelper::UnexpectedExitStatusError + output_hash[:output] = ex.to_s.split('Command output: ')[1] + elsif ex.type == ProcessHelper::TimeoutError + output_hash[:output] = ex.to_s.split('Command output prior to timeout: ')[1] + else + output_hash[:output] = nil + end end output_hash end diff --git a/secgen.rb b/secgen.rb index 02914542a..f39470c86 100644 --- a/secgen.rb +++ b/secgen.rb @@ -149,7 +149,7 @@ def build_vms(project_dir, options) else if retry_count > 0 # Identify which VMs failed - if vagrant_output[:output] != nil + if vagrant_output[:exception].type == ProcessHelper::UnexpectedExitStatusError split = vagrant_output[:output].split('==>') failures = [] split.each do |line| @@ -177,7 +177,8 @@ def build_vms(project_dir, options) GemExec.exe('vagrant', project_dir, 'destroy') end else - Print.err 'Error creating VMs, exiting SecGen.' + Print.err 'Error provisioning VMs, destroying VMs and exiting SecGen.' + GemExec.exe('vagrant', project_dir, 'destroy') exit 1 end end