Skip to content

Commit

Permalink
Enhance provider's paramters validation
Browse files Browse the repository at this point in the history
Fix #186
  • Loading branch information
ggiamarchi committed Jan 18, 2015
1 parent 9d90a8f commit d320b70
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
5 changes: 3 additions & 2 deletions source/lib/vagrant-openstack-provider/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,9 @@ def rsync_include(inc)
def validate(machine)
errors = _detected_errors

errors << I18n.t('vagrant_openstack.config.password_required') unless @password
errors << I18n.t('vagrant_openstack.config.username_required') unless @username
errors << I18n.t('vagrant_openstack.config.password_required') if @password.nil? || @password.empty?
errors << I18n.t('vagrant_openstack.config.username_required') if @username.nil? || @username.empty?
errors << I18n.t('vagrant_openstack.config.tenant_name_required') if @tenant_name.nil? || @tenant_name.empty?
errors << I18n.t('vagrant_openstack.config.invalid_endpoint_type') unless %w(publicURL adminURL internalURL).include?(@endpoint_type)

validate_ssh_username(machine, errors)
Expand Down
2 changes: 2 additions & 0 deletions source/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ en:
A password is required.
username_required: |-
A username is required.
tenant_name_required: |-
A tenant name is required.
invalid_uri: |-
The value for %{key} is not a valid URI: %{uri}
invalid_stack: |-
Expand Down
11 changes: 10 additions & 1 deletion source/spec/vagrant-openstack-provider/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@
machine.stub(:config) { config }
subject.username = 'foo'
subject.password = 'bar'
subject.tenant_name = 'tenant'
subject.keypair_name = 'keypair'
end

Expand Down Expand Up @@ -299,7 +300,7 @@
end
end

context 'the API key' do
context 'the password' do
it 'should error if not given' do
subject.password = nil
I18n.should_receive(:t).with('vagrant_openstack.config.password_required').and_return error_message
Expand All @@ -315,6 +316,14 @@
end
end

context 'the tenant name' do
it 'should error if not given' do
subject.tenant_name = nil
I18n.should_receive(:t).with('vagrant_openstack.config.tenant_name_required').and_return error_message
validation_errors.first.should == error_message
end
end

context 'the ssh_timeout' do
it 'should error if do not represent an integer' do
subject.ssh_timeout = 'timeout'
Expand Down

0 comments on commit d320b70

Please sign in to comment.