Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EvmDatabaseOps] Fix .validate_free_space target #18745

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
NickLaMuro marked this conversation as resolved.
Show resolved Hide resolved
# 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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reason this can't live in the definition of the double? For example, will it break other specs? It seems like a reasonable stub in any case.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since I am fixing the specs for this (without my patch):

Yes, this is necessary to be here. It causes a bunch of other specs to fail if you do it globally.


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