Skip to content

Commit

Permalink
Merge pull request #18745 from NickLaMuro/fix_database_backup_diskspa…
Browse files Browse the repository at this point in the history
…ce_check

[EvmDatabaseOps] Fix .validate_free_space target

(cherry picked from commit 6642bf6)

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1717025
  • Loading branch information
carbonin authored and simaishi committed Jun 10, 2019
1 parent aa86709 commit c3c65b6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
16 changes: 10 additions & 6 deletions lib/evm_database_ops.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ def self.backup(db_opts, connect_opts = {})
# :remote_file_name => "backup_1", - Provide a base file name for the uploaded file

uri = with_file_storage(:backup, db_opts, connect_opts) do |database_opts|
validate_free_space(database_opts)
backup_result = PostgresAdmin.backup(database_opts)
backup_result
end
Expand All @@ -67,11 +66,6 @@ def self.dump(db_opts, connect_opts = {})
# db_opts and connect_opts similar to .backup

uri = with_file_storage(:dump, db_opts, connect_opts) do |database_opts|
# For database dumps, this isn't going to be as accurate (since the dump
# size will probably be larger than the calculated BD size), but it still
# won't hurt to do as a generic way to get a rough idea if we have enough
# disk space or the appliance for the task.
validate_free_space(database_opts)
PostgresAdmin.backup_pg_dump(database_opts)
end
_log.info("[#{merged_db_opts(db_opts)[:dbname]}] database has been dumped up to file: [#{uri}]")
Expand Down Expand Up @@ -168,6 +162,16 @@ def self.restore(db_opts, connect_opts = {})
if action == :restore
yield(db_opts, backup_type)
else
if file_storage.class <= MiqGenericMountSession
# Only check free space on "mountable" storages
#
# For database dumps, this isn't going to be as accurate (since the
# dump size will probably be larger than the calculated DB size), but
# it still won't hurt to do as a generic way to get a rough idea if
# we have enough disk space on the appliance for the task.
free_space_opts = db_opts.merge(:local_file => file_storage.uri_to_local_path(uri))
validate_free_space(free_space_opts)
end
yield(db_opts)
end
end
Expand Down
8 changes: 5 additions & 3 deletions spec/lib/evm_database_ops_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@

it "without enough free space" do
EvmSpecHelper.create_guid_miq_server_zone
allow(file_storage).to receive(:class).and_return(MiqSmbSession)
allow(EvmDatabaseOps).to receive(:backup_destination_free_space).and_return(100.megabytes)
allow(EvmDatabaseOps).to receive(:database_size).and_return(200.megabytes)
expect { EvmDatabaseOps.backup(@db_opts, @connect_opts) }.to raise_error(MiqException::MiqDatabaseBackupInsufficientSpace)
Expand Down Expand Up @@ -74,6 +75,8 @@
allow(described_class).to receive(:backup_file_name).and_return("miq_backup")
expect(PostgresAdmin).to receive(:backup).with(run_db_ops)

allow(file_storage).to receive(:class).and_return(MiqSmbSession)

log_stub = instance_double("_log")
expect(described_class).to receive(:_log).twice.and_return(log_stub)
expect(log_stub).to receive(:info).with(any_args)
Expand All @@ -88,8 +91,8 @@
before do
@connect_opts = {:username => 'blah', :password => 'blahblah', :uri => "smb://myserver.com/share"}
@db_opts = {:dbname => 'vmdb_production', :username => 'root'}
allow(MiqSmbSession).to receive(:runcmd)
allow(file_storage).to receive(:settings_mount_point).and_return(tmpdir)
allow(file_storage).to receive(:uri_to_local_path).and_return(tmpdir.join("share").to_s)
allow(file_storage).to receive(:add).and_yield(input_path)

allow(MiqUtil).to receive(:runcmd)
Expand Down Expand Up @@ -122,6 +125,7 @@

it "without enough free space" do
EvmSpecHelper.create_guid_miq_server_zone
allow(file_storage).to receive(:class).and_return(MiqSmbSession)
allow(EvmDatabaseOps).to receive(:backup_destination_free_space).and_return(100.megabytes)
allow(EvmDatabaseOps).to receive(:database_size).and_return(200.megabytes)
expect(PostgresAdmin).to receive(:backup_pg_dump).never
Expand Down Expand Up @@ -149,8 +153,6 @@
@connect_opts = {:username => 'blah', :password => 'blahblah'}
@db_opts = {:dbname => 'vmdb_production', :username => 'root'}

allow(MiqSmbSession).to receive(:runcmd)
allow(MiqSmbSession).to receive(:raw_disconnect)
allow(file_storage).to receive(:settings_mount_point).and_return(tmpdir)
allow(file_storage).to receive(:magic_number_for).and_return(:pgdump)
allow(file_storage).to receive(:download).and_yield(input_path)
Expand Down

0 comments on commit c3c65b6

Please sign in to comment.