diff --git a/lib/evm_database_ops.rb b/lib/evm_database_ops.rb index a2ae54822c0..ee5391ce32b 100644 --- a/lib/evm_database_ops.rb +++ b/lib/evm_database_ops.rb @@ -111,7 +111,10 @@ def self.restore(db_opts, connect_opts = {}) if db_opts[:local_file].nil? if action == :restore uri = connect_opts[:uri] - connect_opts[:uri] = File.dirname(connect_opts[:uri]) + + connect_uri = URI::Generic.new(*URI.split(uri)) + connect_uri.path = File.dirname(connect_uri.path) + connect_opts[:uri] = connect_uri.to_s else connect_opts[:remote_file_name] ||= File.basename(backup_file_name(action)) # diff --git a/spec/lib/evm_database_ops_spec.rb b/spec/lib/evm_database_ops_spec.rb index 397a02b3612..8f93f16c8ed 100644 --- a/spec/lib/evm_database_ops_spec.rb +++ b/spec/lib/evm_database_ops_spec.rb @@ -291,10 +291,28 @@ def execute_with_file_storage(action = :backup) execute_with_file_storage(:restore) end + it "parses the dirname of the `uri` and passes that in `connect_opts`" do + expected_connect_opts = { :uri => "smb://tmp/" } + allow(file_storage).to receive(:download) + expect(MiqFileStorage).to receive(:with_interface_class).with(expected_connect_opts) + execute_with_file_storage(:restore) + end + it "returns calculated uri" do allow(file_storage).to receive(:download).and_yield(input_path) expect(execute_with_file_storage(:restore) { "block result" }).to eq("smb://tmp/foo") end + + context "with query_params in the URI" do + let(:connect_opts) { { :uri => "swift://container/foo.gz?2plus2=5" } } + + it "retains query_params when parsing dirname" do + expected_connect_opts = { :uri => "swift://container/?2plus2=5" } + allow(file_storage).to receive(:download) + expect(MiqFileStorage).to receive(:with_interface_class).with(expected_connect_opts) + execute_with_file_storage(:restore) + end + end end end end