Skip to content

Commit

Permalink
User sees an error if deployment does not exist on the director
Browse files Browse the repository at this point in the history
Note that the CLI side check was already implemented in a previous
commit.

[#97328938]
https://www.pivotaltracker.com/story/show/97328938

Signed-off-by: Jonathan Fuerth <jfuerth@pivotal.io>
  • Loading branch information
nader-ziada authored and Jonathan Fuerth committed Jun 25, 2015
1 parent 3f5c1a4 commit f7839a2
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 33 deletions.
4 changes: 4 additions & 0 deletions bosh-director/lib/bosh/director/jobs/export_release.rb
Expand Up @@ -25,6 +25,9 @@ def initialize(deployment_name, release_name, release_version, stemcell_os, stem
def perform
logger.info("Exporting release: #{@release_name}/#{@release_version} for #{@stemcell_os}/#{@stemcell_version}")

deployment_manager = Bosh::Director::Api::DeploymentManager.new()
deployment_manager.find_by_name(@deployment_name)

release_manager = Bosh::Director::Api::ReleaseManager.new
release = release_manager.find_by_name(@release_name)
release_manager.find_version(release, @release_version)
Expand All @@ -33,6 +36,7 @@ def perform
stemcell = stemcell_manager.find_by_os_and_version(@stemcell_os, @stemcell_version)

logger.info "Will compile with stemcell: #{stemcell.desc}"

end
end
end
Expand Down
76 changes: 43 additions & 33 deletions bosh-director/spec/unit/jobs/export_release_spec.rb
Expand Up @@ -3,64 +3,57 @@
module Bosh::Director
describe Jobs::ExportRelease do
let(:snapshots) { [Models::Snapshot.make(snapshot_cid: 'snap0'), Models::Snapshot.make(snapshot_cid: 'snap1')] }
let(:deployment_manager) { instance_double(Bosh::Director::Api::DeploymentManager) }

subject(:job) { described_class.new("deployment_name", "release_name", "release_version", "stemcell_os", "stemcell_version") }

context 'when the requested release does not exist' do
it 'fails with the expected error' do
expect {
job.perform
}.to raise_error(Bosh::Director::ReleaseNotFound)
end
it 'raises an error when the targeted deployment is not found' do
expect {
job.perform
}.to raise_error(Bosh::Director::DeploymentNotFound)
end

context 'when the requested release exists but release version does not exist' do
before { Bosh::Director::Models::Release.create(name: 'release_name') }
context 'with a valid deployment targeted' do
before {
allow(Bosh::Director::Api::DeploymentManager).to receive(:new).and_return(deployment_manager)
allow(deployment_manager).to receive(:find_by_name)
}

it 'fails with the expected error' do
it 'raises an error when the requested release does not exist' do
expect {
job.perform
}.to raise_error(Bosh::Director::ReleaseVersionNotFound)
}.to raise_error(Bosh::Director::ReleaseNotFound)
end
end

context 'when the requested release and version exist' do
before {
release = Bosh::Director::Models::Release.create(name: 'release_name')
release.add_version(:version => 'release_version')
}
context 'when the requested release exists but release version does not exist' do
before { Bosh::Director::Models::Release.create(name: 'release_name') }

context 'and the requested stemcell is not found' do
it 'fails with the expected error' do
expect {
job.perform
}.to raise_error(Bosh::Director::StemcellNotFound)
}.to raise_error(Bosh::Director::ReleaseVersionNotFound)
end
end

context 'and the requested stemcell is found' do
context 'when the requested release and version exist' do
before {
Bosh::Director::Models::Stemcell.create(
name: 'my-stemcell-with-a-name',
version: 'stemcell_version',
operating_system: 'stemcell_os',
cid: 'cloud-id-a',
)
release = Bosh::Director::Models::Release.create(name: 'release_name')
release.add_version(:version => 'release_version')
}

it 'succeeds' do
it 'raises an error if the requested stemcell is not found' do
expect {
job.perform
}.to_not raise_error
}.to raise_error(Bosh::Director::StemcellNotFound)
end

context 'and multiple stemcells match the requested stemcell' do
context 'and the requested stemcell is found' do
before {
Bosh::Director::Models::Stemcell.create(
name: 'my-stemcell-with-b-name',
name: 'my-stemcell-with-a-name',
version: 'stemcell_version',
operating_system: 'stemcell_os',
cid: 'cloud-id-b',
cid: 'cloud-id-a',
)
}

Expand All @@ -70,9 +63,26 @@ module Bosh::Director
}.to_not raise_error
end

it 'chooses the first stemcell alhpabetically by name' do
job.perform
expect(log_string).to match /Will compile with stemcell: my-stemcell-with-a-name/
context 'and multiple stemcells match the requested stemcell' do
before {
Bosh::Director::Models::Stemcell.create(
name: 'my-stemcell-with-b-name',
version: 'stemcell_version',
operating_system: 'stemcell_os',
cid: 'cloud-id-b',
)
}

it 'succeeds' do
expect {
job.perform
}.to_not raise_error
end

it 'chooses the first stemcell alhpabetically by name' do
job.perform
expect(log_string).to match /Will compile with stemcell: my-stemcell-with-a-name/
end
end
end
end
Expand Down

0 comments on commit f7839a2

Please sign in to comment.