Skip to content

Commit

Permalink
Preprocess <partitioning/> section
Browse files Browse the repository at this point in the history
  • Loading branch information
imobachgs committed Nov 27, 2017
1 parent 0cf22bd commit 2b25ea4
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 13 deletions.
40 changes: 27 additions & 13 deletions src/modules/AutoinstStorage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -48,20 +49,11 @@ def main
# When called by inst_auto<module name> (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<Hash>] 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
Expand Down Expand Up @@ -266,6 +258,22 @@ def set_multipathing

private

# Build the storage proposal if possible
#
# @param settings [Array<Hash>] 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:
Expand Down Expand Up @@ -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<Hash>, 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
Expand Down
11 changes: 11 additions & 0 deletions test/autoinst_storage_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,17 @@
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)
.and_return(storage_proposal)
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|
Expand All @@ -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 }

Expand Down

0 comments on commit 2b25ea4

Please sign in to comment.