From 2b25ea413f949d0f5412b6f0ea999fa13164f757 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Imobach=20Gonz=C3=A1lez=20Sosa?= Date: Mon, 27 Nov 2017 14:52:28 +0000 Subject: [PATCH] Preprocess section --- src/modules/AutoinstStorage.rb | 40 +++++++++++++++++++++++----------- test/autoinst_storage_test.rb | 11 ++++++++++ 2 files changed, 38 insertions(+), 13 deletions(-) diff --git a/src/modules/AutoinstStorage.rb b/src/modules/AutoinstStorage.rb index 28bc2ae66..a9f1e3b65 100644 --- a/src/modules/AutoinstStorage.rb +++ b/src/modules/AutoinstStorage.rb @@ -10,6 +10,7 @@ require "autoinstall/storage_proposal" require "autoinstall/dialogs/question" require "autoinstall/storage_proposal_issues_presenter" +require "autoinstall/partitioning_preprocessor" module Yast class AutoinstStorageClass < Module @@ -48,20 +49,11 @@ def main # When called by inst_auto (preparing autoinstallation data) # the list may be empty. # - # @param settings [Hash] Profile settings (list of drives for custom partitioning) - # @return [Boolean] success + # @param settings [Array] Profile settings (list of drives for custom partitioning) + # @return [Boolean] success def Import(settings) log.info "entering Import with #{settings.inspect}" - proposal = Y2Autoinstallation::StorageProposal.new(settings) - if valid_proposal?(proposal) - log.info "Saving successful proposal: #{proposal.inspect}" - proposal.save - true - else # not needed - log.warn "Failed proposal: #{proposal.inspect}" - false - end - + build_proposal(preprocessed_settings(settings)) end # Import settings from the general/storage section @@ -266,6 +258,22 @@ def set_multipathing private + # Build the storage proposal if possible + # + # @param settings [Array] Profile settings (list of drives for custom partitioning) + # @return [Boolean] success + def build_proposal(settings) + proposal = Y2Autoinstallation::StorageProposal.new(settings) + if valid_proposal?(proposal) + log.info "Saving successful proposal: #{proposal.inspect}" + proposal.save + true + else # not needed + log.warn "Failed proposal: #{proposal.inspect}" + false + end + end + # Determine whether the proposal is valid and inform the user if not valid # # When proposal is not valid: @@ -313,10 +321,16 @@ def valid_proposal?(proposal) # @param level [Symbol] Message level (:error, :warn) # @param content [String] Text to log def log_proposal_issues(level, content) - settings_name = (level == :error) ? :error : :warning log.send(level, content) end + # Preprocess partitioning settings + # + # @param settings [Array, nil] Profile settings (list of drives for custom partitioning) + def preprocessed_settings(settings) + preprocessor = Y2Autoinstallation::PartitioningPreprocessor.new + preprocessor.run(settings) + end attr_accessor :general_settings end diff --git a/test/autoinst_storage_test.rb b/test/autoinst_storage_test.rb index 6f0b641af..4bd0379dd 100755 --- a/test/autoinst_storage_test.rb +++ b/test/autoinst_storage_test.rb @@ -20,6 +20,8 @@ let(:valid?) { true } let(:errors_settings) { { "show" => false, "timeout" => 10 } } let(:warnings_settings) { { "show" => true, "timeout" => 5 } } + let(:settings) { [{ "device" => "/dev/sda" }] } + let(:preprocessor) { instance_double(Y2Autoinstallation::PartitioningPreprocessor, run: settings) } before do allow(Y2Autoinstallation::StorageProposal).to receive(:new) @@ -27,6 +29,8 @@ allow(Y2Autoinstallation::Dialogs::Question).to receive(:new) .and_return(issues_dialog) allow(storage_proposal).to receive(:save) + allow(Y2Autoinstallation::PartitioningPreprocessor).to receive(:new) + .and_return(preprocessor) end around do |example| @@ -41,6 +45,13 @@ subject.Import({}) end + it "preprocess given settings" do + expect(Y2Autoinstallation::StorageProposal).to receive(:new) + .with(settings) + .and_return(storage_proposal) + subject.Import([{ "device" => "ask" }]) + end + context "when the proposal is valid" do let(:valid?) { true }