diff --git a/lib/evm_database_ops.rb b/lib/evm_database_ops.rb index 0d73d12f667..c8261ce971c 100644 --- a/lib/evm_database_ops.rb +++ b/lib/evm_database_ops.rb @@ -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 @@ -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}]") @@ -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 diff --git a/spec/lib/evm_database_ops_spec.rb b/spec/lib/evm_database_ops_spec.rb index 8d34ff81e10..83c83bd2922 100644 --- a/spec/lib/evm_database_ops_spec.rb +++ b/spec/lib/evm_database_ops_spec.rb @@ -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) @@ -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) @@ -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) @@ -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 @@ -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)