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 90cf948 commit 436ab2d
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 12 deletions.
41 changes: 29 additions & 12 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,14 @@ 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
partitioning = preprocessed_settings(settings)
return false unless partitioning

build_proposal(partitioning)
end

# Import settings from the general/storage section
Expand Down Expand Up @@ -266,6 +261,22 @@ def set_multipathing

private

# Build the storage proposal if possible
#
# @param partitioning [Array<Hash>] Profile settings (list of drives for custom partitioning)
# @return [Boolean] success
def build_proposal(partitioning)
proposal = Y2Autoinstallation::StorageProposal.new(partitioning)
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 +324,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
21 changes: 21 additions & 0 deletions test/autoinst_storage_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,18 @@
let(:valid?) { true }
let(:errors_settings) { { "show" => false, "timeout" => 10 } }
let(:warnings_settings) { { "show" => true, "timeout" => 5 } }
let(:settings) { [{ "device" => "/dev/sda" }] }
let(:ask_settings) { [{ "device" => "ask" }] }
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 +46,22 @@
subject.Import({})
end

it "preprocess given settings" do
expect(preprocessor).to receive(:run).with(ask_settings)
expect(Y2Autoinstallation::StorageProposal).to receive(:new)
.with(settings)
.and_return(storage_proposal)
subject.Import([{ "device" => "ask" }])
end

context "when settings are not preprocessed successfully" do
let(:settings) { nil }

it "returns false" do
expect(subject.Import({})).to eq(false)
end
end

context "when the proposal is valid" do
let(:valid?) { true }

Expand Down

0 comments on commit 436ab2d

Please sign in to comment.