Skip to content

Commit

Permalink
Merge pull request #18166 from NickLaMuro/fix_uri_for_database_restor…
Browse files Browse the repository at this point in the history
…e_mount_point

Fix uri dirname parsing for swift restore

(cherry picked from commit 3d2a9b6)
  • Loading branch information
kbrock authored and simaishi committed Nov 7, 2018
1 parent 3c2d5cb commit bdaaea6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/evm_database_ops.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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))
#
Expand Down
18 changes: 18 additions & 0 deletions spec/lib/evm_database_ops_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit bdaaea6

Please sign in to comment.