From 2f084dab18cd017192e2263c49a0df76fee09713 Mon Sep 17 00:00:00 2001 From: Nick LaMuro Date: Fri, 20 Jul 2018 19:14:16 -0500 Subject: [PATCH 1/2] Adds DatabaseAdmin#ask_to_split_up_output Adds a set of questions to be queried for `:dump` and `:restore` actions in DatabaseAdmin. It asks: - If the wishes to split up the output of the dump/restore - If yes, how big should the split files be (default 500M) --- .../appliance_console/database_admin.rb | 12 +++ spec/database_admin_spec.rb | 91 +++++++++++++++++++ 2 files changed, 103 insertions(+) diff --git a/lib/manageiq/appliance_console/database_admin.rb b/lib/manageiq/appliance_console/database_admin.rb index dd046f550..7f6ad5dfb 100644 --- a/lib/manageiq/appliance_console/database_admin.rb +++ b/lib/manageiq/appliance_console/database_admin.rb @@ -147,6 +147,12 @@ def ask_for_tables_to_exclude_in_dump end || true end + def ask_to_split_up_output + if action == :dump && should_split_output? + @task_params.last[:byte_count] = ask_for_string("byte size to split by", "500M") + end || true + end + def confirm_and_execute if allowed_to_execute? processing_message @@ -182,6 +188,12 @@ def should_exclude_tables? end end + def should_split_output? + ask_yn?("Would you like to split the #{action} output into multiple parts") do |q| + q.readline = true + end + end + def filename_prompt_args default = action == :dump ? DB_DEFAULT_DUMP_FILE : DB_RESTORE_FILE validator = LOCAL_FILE_VALIDATOR if action == :restore && backup_type == LOCAL_FILE diff --git a/spec/database_admin_spec.rb b/spec/database_admin_spec.rb index ced8cc017..3ce796b5d 100644 --- a/spec/database_admin_spec.rb +++ b/spec/database_admin_spec.rb @@ -449,6 +449,27 @@ end end + describe "#ask_to_split_up_output" do + let(:uri) { "/tmp/my_db.dump" } + let(:yn_prompt) { "Would you like to split the restore output into multiple parts" } + let(:byte_count_prompt) { "byte size to split by" } + + before do + subject.instance_variable_set(:@task_params, ["--", { :uri => uri }]) + end + + it "no-ops" do + expect(subject).to receive(:ask_yn?).with(yn_prompt).never + expect(subject).to receive(:ask_for_string).with(byte_count_prompt, "500M").never + expect(subject.ask_to_split_up_output).to be_truthy + end + + it "does not modify the @task_params" do + expect(subject.ask_to_split_up_output).to be_truthy + expect(subject.task_params).to eq(["--", {:uri => uri}]) + end + end + describe "#confirm_and_execute" do let(:uri) { "/tmp/my_db.backup" } let(:agree) { "y" } @@ -1006,6 +1027,27 @@ def confirm_and_execute end end + describe "#ask_to_split_up_output" do + let(:uri) { "/tmp/my_db.dump" } + let(:yn_prompt) { "Would you like to split the restore output into multiple parts" } + let(:byte_count_prompt) { "byte size to split by" } + + before do + subject.instance_variable_set(:@task_params, ["--", { :uri => uri }]) + end + + it "no-ops" do + expect(subject).to receive(:ask_yn?).with(yn_prompt).never + expect(subject).to receive(:ask_for_string).with(byte_count_prompt, "500M").never + expect(subject.ask_to_split_up_output).to be_truthy + end + + it "does not modify the @task_params" do + expect(subject.ask_to_split_up_output).to be_truthy + expect(subject.task_params).to eq(["--", {:uri => uri}]) + end + end + describe "#confirm_and_execute" do let(:uri) { "/tmp/my_db.backup" } let(:agree) { "y" } @@ -1457,6 +1499,55 @@ def confirm_and_execute end end + describe "#ask_to_split_up_output" do + let(:uri) { "/tmp/my_db.dump" } + let(:yn_prompt) { "Would you like to split the dump output into multiple parts" } + let(:byte_count_prompt) { "byte size to split by" } + + before do + subject.instance_variable_set(:@task_params, ["--", { :uri => uri }]) + end + + context "when not splitting output" do + it "does not add :byte_count to @task_params" do + expect(subject).to receive(:ask_yn?).with(yn_prompt).once.and_call_original + expect(subject).to receive(:ask_for_string).with(byte_count_prompt, "500M").never + + say "n" + expect(subject.ask_to_split_up_output).to be_truthy + + expect(subject.task_params).to eq(["--", {:uri => uri}]) + end + end + + context "when splitting output" do + it "prompts the user" do + say ["y", "750M"] + expect(subject.ask_to_split_up_output).to be_truthy + expect_readline_question_asked <<-PROMPT.strip_heredoc.chomp + Would you like to split the dump output into multiple parts? (Y/N): y + Enter the byte size to split by: |500M| 750M + PROMPT + end + + it "adds `:byte_count => '250M'` to @task_params" do + expect(subject).to receive(:ask_yn?).with(yn_prompt).once.and_call_original + expect(subject).to receive(:ask_for_string).with(byte_count_prompt, "500M").once.and_call_original + say ["y", "250M"] + + expect(subject.ask_to_split_up_output).to be_truthy + expect(subject.task_params).to eq(["--", {:uri => uri, :byte_count => "250M"}]) + end + + it "defaults to '500M'" do + say ["y", ""] + + expect(subject.ask_to_split_up_output).to be_truthy + expect(subject.task_params).to eq(["--", {:uri => uri, :byte_count => "500M"}]) + end + end + end + describe "#confirm_and_execute" do let(:uri) { "/tmp/my_db.dump" } let(:agree) { "y" } From b7ab9cb044d2881a197723ed291bf07360a1bed0 Mon Sep 17 00:00:00 2001 From: Nick LaMuro Date: Fri, 20 Jul 2018 19:16:20 -0500 Subject: [PATCH 2/2] Ask for table excludes in DatabaseAdmin#ask_questions --- lib/manageiq/appliance_console/database_admin.rb | 1 + spec/database_admin_spec.rb | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/lib/manageiq/appliance_console/database_admin.rb b/lib/manageiq/appliance_console/database_admin.rb index 7f6ad5dfb..903c78bb8 100644 --- a/lib/manageiq/appliance_console/database_admin.rb +++ b/lib/manageiq/appliance_console/database_admin.rb @@ -42,6 +42,7 @@ def ask_questions say(DB_DUMP_WARNING) if action == :dump ask_file_location ask_for_tables_to_exclude_in_dump + ask_to_split_up_output end def activate diff --git a/spec/database_admin_spec.rb b/spec/database_admin_spec.rb index 3ce796b5d..01e0a4879 100644 --- a/spec/database_admin_spec.rb +++ b/spec/database_admin_spec.rb @@ -27,6 +27,7 @@ expect(subject).to receive(:say).with("Restore Database From Backup\n\n") expect(subject).to receive(:ask_file_location) expect(subject).to receive(:ask_for_tables_to_exclude_in_dump) + expect(subject).to receive(:ask_to_split_up_output) subject.ask_questions end @@ -613,6 +614,7 @@ def confirm_and_execute expect(subject).to receive(:say).with("Create Database Backup\n\n") expect(subject).to receive(:ask_file_location) expect(subject).to receive(:ask_for_tables_to_exclude_in_dump) + expect(subject).to receive(:ask_to_split_up_output) subject.ask_questions end @@ -1172,6 +1174,7 @@ def confirm_and_execute expect(subject).to receive(:say).with(pg_dump_warning) expect(subject).to receive(:ask_file_location) expect(subject).to receive(:ask_for_tables_to_exclude_in_dump) + expect(subject).to receive(:ask_to_split_up_output) subject.ask_questions end @@ -1179,6 +1182,7 @@ def confirm_and_execute it "has proper formatting for the pg_dump warning" do allow(subject).to receive(:ask_file_location) allow(subject).to receive(:ask_for_tables_to_exclude_in_dump) + allow(subject).to receive(:ask_to_split_up_output) subject.ask_questions expect_output <<-PROMPT.strip_heredoc