Skip to content

Commit

Permalink
Fix Failing Test and Merged URI Handling
Browse files Browse the repository at this point in the history
The merged_uri method was working incorrectly - coded to let the
spec tests succeed but the validation of the Swift connection to fail.
  • Loading branch information
jerryk55 committed Oct 10, 2018
1 parent 2f008f9 commit c25ac99
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
3 changes: 2 additions & 1 deletion app/models/file_depot_swift.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,14 @@ def verify_credentials(auth_type = 'default', options = {})
end

def merged_uri(uri, api_port)
uri = URI(uri)
uri.port = api_port.presence || 5000
query_elements = []
query_elements << "region=#{openstack_region}" if openstack_region.present?
query_elements << "api_version=#{keystone_api_version}" if keystone_api_version.present?
query_elements << "domain_id=#{v3_domain_ident}" if v3_domain_ident.present?
query_elements << "security_protocol=#{security_protocol}" if security_protocol.present?
uri.query = query_elements.join('&').presence
uri
uri.to_s
end
end
2 changes: 1 addition & 1 deletion app/models/miq_schedule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ def verify_file_depot(params) # TODO: This logic belongs in the UI, not sure wh
depot.keystone_api_version = params[:keystone_api_version]
depot.v3_domain_ident = params[:v3_domain_ident]
depot.security_protocol = params[:security_protocol]
depot.uri = api_port.blank? ? uri : depot.merged_uri(uri, api_port)
depot.uri = api_port.blank? ? uri : depot.merged_uri(URI(uri), api_port)
if params[:save]
file_depot.save!
file_depot.update_authentication(:default => {:userid => params[:username], :password => params[:password]}) if (params[:username] || params[:password]) && depot.class.requires_credentials?
Expand Down
6 changes: 3 additions & 3 deletions spec/models/file_depot_swift_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
describe FileDepotSwift do
let(:uri) { URI("swift://server.example.com/bucket") }
let(:merged_uri) { URI("swift://server.example.com:5678/bucket?region=test_openstack_region&api_version=v3&domain_id=default") }
let(:merged_default_uri) { URI("swift://server.example.com:5000/bucket?region=test_openstack_region&api_version=v3&domain_id=default") }
let(:uri) { "swift://server.example.com/bucket" }
let(:merged_uri) { "swift://server.example.com:5678/bucket?region=test_openstack_region&api_version=v3&domain_id=default" }
let(:merged_default_uri) { "swift://server.example.com:5000/bucket?region=test_openstack_region&api_version=v3&domain_id=default" }
let(:file_depot_swift) { FileDepotSwift.new(:uri => uri) }
it "should require credentials" do
expect(FileDepotSwift.requires_credentials?).to eq true
Expand Down

0 comments on commit c25ac99

Please sign in to comment.