Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions director/lib/director.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module Director
require "time"
require "zlib"

require "common/exec"
require "common/properties"

require "bcrypt"
Expand Down
2 changes: 2 additions & 0 deletions director/lib/director/api/api_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ def write_file(path, stream, chunk_size = READ_CHUNK_SIZE)
File.open(path, "w") do |file|
file.write(buffer) until stream.read(chunk_size, buffer).nil?
end
rescue SystemCallError => e
raise SystemError, e.message
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions director/lib/director/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,6 @@ def self.err(error_code, response_code = BAD_REQUEST)

RpcRemoteException = err(450001)
RpcTimeout = err(450002)

SystemError = err(500000, INTERNAL_SERVER_ERROR)
end
8 changes: 4 additions & 4 deletions director/lib/director/jobs/update_stemcell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ def perform
stemcell_dir = Dir.mktmpdir("stemcell")

track_and_log("Extracting stemcell archive") do
output = `tar -C #{stemcell_dir} -xzf #{@stemcell_file} 2>&1`
if $?.exitstatus != 0
result = Bosh::Exec.sh("tar -C #{stemcell_dir} -xzf #{@stemcell_file} 2>&1", :on_error => :return)
if result.failed?
raise StemcellInvalidArchive,
"Invalid stemcell archive, tar returned #{$?.exitstatus}, " +
"output: #{output}"
"Invalid stemcell archive, tar returned #{result.exit_status}, " +
"output: #{result.output}"
end
end

Expand Down
31 changes: 31 additions & 0 deletions director/spec/unit/api/api_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright (c) 2009-2012 VMware, Inc.

require File.expand_path("../../../spec_helper", __FILE__)

describe Bosh::Director::Api::ApiHelper do
include Bosh::Director::Api::ApiHelper

before(:each) do
@tmpdir = Dir.mktmpdir("base_dir")
end

describe :write_file do
it "should write a file" do
file_in = StringIO.new("contents")
file_out = File.join(@tmpdir, SecureRandom.uuid)

write_file(file_out, file_in)
File.read(file_out).should == "contents"
end

it "should raise an exception if there's any system error call" do
file_in = StringIO.new("contents")
file_out = File.join(@tmpdir, SecureRandom.uuid)
File.should_receive(:open).with(file_out, "w").and_raise(Errno::ENOSPC)

expect {
write_file(file_out, file_in)
}.to raise_exception(Bosh::Director::SystemError)
end
end
end
10 changes: 10 additions & 0 deletions director/spec/unit/jobs/update_stemcell_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,14 @@
lambda { update_stemcell_job.perform }.should raise_exception(Bosh::Director::StemcellAlreadyExists)
end

it "should fail if cannot extract stemcell" do
result = Bosh::Exec::Result.new("cmd", "output", 1)
Bosh::Exec.should_receive(:sh).and_return(result)

update_stemcell_job = Bosh::Director::Jobs::UpdateStemcell.new(@stemcell_file.path)

expect {
update_stemcell_job.perform
}.to raise_exception(Bosh::Director::StemcellInvalidArchive)
end
end