-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a class to preprocess <partitioning/> section
- Loading branch information
Showing
2 changed files
with
135 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# encoding: utf-8 | ||
|
||
# Copyright (c) [2017] SUSE LLC | ||
# | ||
# All Rights Reserved. | ||
# | ||
# This program is free software; you can redistribute it and/or modify it | ||
# under the terms of version 2 of the GNU General Public License as published | ||
# by the Free Software Foundation. | ||
# | ||
# This program is distributed in the hope that it will be useful, but WITHOUT | ||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
# more details. | ||
# | ||
# You should have received a copy of the GNU General Public License along | ||
# with this program; if not, contact SUSE LLC. | ||
# | ||
# To contact SUSE LLC about this file by physical or electronic mail, you may | ||
# find current contact information at www.suse.com. | ||
|
||
require "y2storage" | ||
require "autoinstall/dialogs/disk_selector" | ||
|
||
module Y2Autoinstallation | ||
# This class is responsible for preprocessing the +<partitioning/>+ section | ||
# of an AutoYaST profile. | ||
# | ||
# At this time, the only preprocessing is replacing +device=ask+ with a real | ||
# device name. | ||
class PartitioningPreprocessor | ||
include Yast | ||
|
||
# Preprocesses the partitioning section | ||
# | ||
# It returns a new object so the original section is not modified. | ||
# | ||
# @param original_drives [Array<Hash>] List of drives according to an AutoYaST | ||
# +partitioning+ section. | ||
def run(drives) | ||
return if drives.nil? | ||
replace_ask(deep_copy(drives)) | ||
end | ||
|
||
protected | ||
|
||
# Replaces +ask+ for user selected values | ||
# | ||
# When +device+ is set to +ask+, ask the user about which device to use. | ||
# | ||
# @param [Array<Hash>] Drives definition from an AutoYaST profile | ||
# @return [Array<Hash>] Drives definition replacing +ask+ for user selected values | ||
def replace_ask(drives) | ||
blacklist = [] | ||
drives.each do |drive| | ||
next unless drive["device"] == "ask" | ||
selection = select_disk(blacklist) | ||
return nil if selection == :abort | ||
drive["device"] = selection | ||
blacklist << drive["device"] | ||
end | ||
end | ||
|
||
# Asks the user about which device should be used | ||
# | ||
# @param blacklist [Array<String>] List of device names that were already used | ||
# @return [String,Symbol] Selected device name | ||
def select_disk(blacklist) | ||
Y2Autoinstallation::Dialogs::DiskSelector.new(blacklist: blacklist).run | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#!/usr/bin/env rspec | ||
# encoding: utf-8 | ||
|
||
# Copyright (c) [2017] SUSE LLC | ||
# | ||
# All Rights Reserved. | ||
# | ||
# This program is free software; you can redistribute it and/or modify it | ||
# under the terms of version 2 of the GNU General Public License as published | ||
# by the Free Software Foundation. | ||
# | ||
# This program is distributed in the hope that it will be useful, but WITHOUT | ||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
# more details. | ||
# | ||
# You should have received a copy of the GNU General Public License along | ||
# with this program; if not, contact SUSE LLC. | ||
# | ||
# To contact SUSE LLC about this file by physical or electronic mail, you may | ||
# find current contact information at www.suse.com. | ||
|
||
require_relative "../test_helper" | ||
require "autoinstall/partitioning_preprocessor" | ||
|
||
describe Y2Autoinstallation::PartitioningPreprocessor do | ||
subject(:preprocessor) { described_class.new } | ||
|
||
let(:profile) do | ||
[sda, undefined] | ||
end | ||
|
||
let(:sda) { { "device" => "/dev/sda" } } | ||
let(:selected) { "/dev/sdb" } | ||
let(:undefined) { { "device" => "ask" } } | ||
|
||
let(:disk_selector) do | ||
instance_double(Y2Autoinstallation::Dialogs::DiskSelector, run: selected) | ||
end | ||
|
||
before do | ||
allow(Y2Autoinstallation::Dialogs::DiskSelector).to receive(:new).and_return(disk_selector) | ||
end | ||
|
||
describe "#run" do | ||
it "sets disk devices when device=ask" do | ||
expect(preprocessor.run(profile)).to eq([sda, { "device" => selected }]) | ||
end | ||
|
||
it "asks the user about which device to use" do | ||
expect(disk_selector).to receive(:run).and_return(selected) | ||
preprocessor.run(profile) | ||
end | ||
|
||
context "when the user aborts" do | ||
let(:selected) { :abort } | ||
|
||
it "returns nil" do | ||
expect(preprocessor.run(profile)).to be_nil | ||
end | ||
end | ||
end | ||
end |