diff --git a/app/models/file_depot_swift.rb b/app/models/file_depot_swift.rb index 3d845020653a..f7be3fe5cbfa 100644 --- a/app/models/file_depot_swift.rb +++ b/app/models/file_depot_swift.rb @@ -54,6 +54,7 @@ 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? @@ -61,6 +62,6 @@ def merged_uri(uri, api_port) 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 diff --git a/app/models/miq_schedule.rb b/app/models/miq_schedule.rb index b89b7f40ca85..09b0d4149b5f 100644 --- a/app/models/miq_schedule.rb +++ b/app/models/miq_schedule.rb @@ -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? diff --git a/spec/models/file_depot_swift_spec.rb b/spec/models/file_depot_swift_spec.rb index 06a31e51fc8e..7a0970bcbba1 100644 --- a/spec/models/file_depot_swift_spec.rb +++ b/spec/models/file_depot_swift_spec.rb @@ -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