diff --git a/src/lib/y2network/autoinst_profile/s390_device_section.rb b/src/lib/y2network/autoinst_profile/s390_device_section.rb index aaf3735fc..c8ace31a5 100644 --- a/src/lib/y2network/autoinst_profile/s390_device_section.rb +++ b/src/lib/y2network/autoinst_profile/s390_device_section.rb @@ -44,7 +44,7 @@ def self.attributes define_attr_accessors # @!attribute chanids - # @return [String] channel device id separated by spaces + # @return [String] channel device id separated by spaces or colons # @!attribute layer2 # @return [Boolean] Whether layer2 is enabler or not @@ -71,6 +71,17 @@ def self.new_from_network(connection_config) result end + # Creates an instance based on the profile representation used by the AutoYaST modules + # (array of hashes objects). + # + # @param hashes [Hash] Networking section from an AutoYaST profile + # @return [S390DeviceSection] + def self.new_from_hashes(hash) + result = new + result.init_from_hashes(hash) + result + end + # Method used by {.new_from_network} to populate the attributes when cloning a network s390 # device # @@ -91,6 +102,25 @@ def init_from_config(config) true end + + # Method used by {.new_from_hashes} to populate the attributes when importing a profile + # + # @param hash [Hash] see {.new_from_hashes} + def init_from_hashes(hash) + super + self.chanids = normalized_chanids(hash["chanids"]) if hash["chanids"] + end + + private + + # Normalizes the list of channel IDs + # + # It replaces spaces with colons. + # + # @return [String] + def normalized_chanids(ids) + ids.gsub(/\ +/, ":") + end end end end diff --git a/test/y2network/autoinst_profile/s390_device_section_test.rb b/test/y2network/autoinst_profile/s390_device_section_test.rb index 745a00106..5428b67d7 100644 --- a/test/y2network/autoinst_profile/s390_device_section_test.rb +++ b/test/y2network/autoinst_profile/s390_device_section_test.rb @@ -62,7 +62,23 @@ it "loads properly boot protocol" do section = described_class.new_from_hashes(hash) expect(section.type).to eq "ctc" + expect(section.chanids).to eq("0.0.0800:0.0.0801") expect(section.protocol).to eq "1" end + + context "using the old syntax for chanids" do + let(:hash) do + { + "type" => "ctc", + "chanids" => "0.0.0800 0.0.0801", + "protocol" => "1" + } + end + + it "loads properly boot protocol" do + section = described_class.new_from_hashes(hash) + expect(section.chanids).to eq("0.0.0800:0.0.0801") + end + end end end