Skip to content

Commit

Permalink
Allow to use spaces instead of ':' when importing chanids
Browse files Browse the repository at this point in the history
  • Loading branch information
imobachgs committed Apr 2, 2020
1 parent 47937c1 commit e716863
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
32 changes: 31 additions & 1 deletion src/lib/y2network/autoinst_profile/s390_device_section.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
#
Expand All @@ -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
16 changes: 16 additions & 0 deletions test/y2network/autoinst_profile/s390_device_section_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit e716863

Please sign in to comment.