Skip to content

Commit

Permalink
Error handling -> fail fast
Browse files Browse the repository at this point in the history
  • Loading branch information
ggiamarchi committed Sep 15, 2014
1 parent ebb0fd8 commit c8a6128
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
8 changes: 5 additions & 3 deletions source/lib/vagrant-openstack-provider/action/create_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ def initialize(app, _env)
def call(env)
@logger.info 'Start create server action'

config = env[:machine].provider_config

fail Errors::MissingBootOption if config.image.nil? && config.volume_boot.nil?
fail Errors::ConflictBootOption unless config.image.nil? || config.volume_boot.nil?

nova = env[:openstack_client].nova

options = {
Expand All @@ -31,9 +36,6 @@ def call(env)
availability_zone: env[:machine].provider_config.availability_zone
}

fail Errors::MissingBootOption if options[:image].nil? && options[:volume_boot].nil?
fail Errors::ConflictBootOption unless options[:image].nil? || options[:volume_boot].nil?

server_id = create_server(env, options)

# Store the ID right away so we can track it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,23 @@
@action = CreateServer.new(nil, nil)
end

describe 'call' do
context 'with both image and volume_boot specified' do
it 'should raise an error' do
config.stub(:image) { 'linux-image' }
config.stub(:volume_boot) { 'linux-volume' }
expect { @action.call(env) }.to raise_error Errors::ConflictBootOption
end
end
context 'with neither image nor volume_boot specified' do
it 'should raise an error' do
config.stub(:image) { nil }
config.stub(:volume_boot) { nil }
expect { @action.call(env) }.to raise_error Errors::MissingBootOption
end
end
end

describe 'create_server' do
context 'with all options specified' do
it 'calls nova with all the options' do
Expand Down

0 comments on commit c8a6128

Please sign in to comment.