Skip to content

Commit

Permalink
Keep connection configs when keep_install_network
Browse files Browse the repository at this point in the history
  • Loading branch information
teclator committed Jun 7, 2020
1 parent 14db752 commit 8138955
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 71 deletions.
31 changes: 0 additions & 31 deletions src/lib/network/network_autoyast.rb
Expand Up @@ -62,16 +62,12 @@ def merge_configs(conf)

dns = from_system["dns"] || {}
routing = from_system["routing"] || {}
devices = from_system["interfaces"] || []

# copy the keys/values that are not existing in the XML
# so we merge the inst-sys settings with the XML while XML
# has higher priority
conf["dns"] = merge_dns(dns, conf["dns"])
conf["routing"] = merge_routing(routing, conf["routing"])
# merge devices definitions obtained from inst-sys
# and those which were read from AY profile. bnc#874259
conf["interfaces"] = merge_devices(devices, conf["interfaces"])

conf
end
Expand Down Expand Up @@ -175,33 +171,6 @@ def keep_net_config?

private

# Merges two devices map into one.
#
# Maps are expected in NetworkInterfaces format. That is
# {
# type1:
# {
# dev_name_1: { ... },
# ...
# },
# ...
# }
#
# If a device definition is present in both maps, then the one from devices2
# wins.
#
# @param [Hash, nil] in_devs1 first map of devices in NetworkInterfaces format
# @param [Hash, nil] in_devs2 second map of devices in NetworkInterfaces format
#
# @return merged device map in NetworkInterfaces format or empty map
def merge_devices(in_devs1, in_devs2)
return in_devs2 if in_devs1.nil? && !in_devs2.nil?
return in_devs1 if in_devs2.nil? && !in_devs1.nil?
return [] if in_devs1.nil? && in_devs2.nil?

(in_devs1 + in_devs2).group_by {|i| i["name"] }.values.map {|a| a.last }
end

# Merges two maps with dns related values.
#
# Value in second map has precendence over the value in first one in
Expand Down
3 changes: 3 additions & 0 deletions src/lib/y2network/autoinst/config_reader.rb
Expand Up @@ -52,6 +52,9 @@ def config
# We need the current interfaces in order to rewrite the config
# properly but the rest should be imported from the profile
config.interfaces = @original_config.interfaces.copy
# merge devices definitions obtained from inst-sys
# and those which were read from AY profile. bnc#874259
config.connections = @original_config.connections.copy if section.keep_install_network

# apply at first udev rules, so interfaces names are correct
UdevRulesReader.new(section.udev_rules).apply(config) if section.udev_rules
Expand Down
2 changes: 2 additions & 0 deletions src/lib/y2network/connection_configs_collection.rb
Expand Up @@ -18,6 +18,7 @@
# find current contact information at www.suse.com.

require "yast"
require "y2network/can_be_copied"
require "forwardable"

module Y2Network
Expand All @@ -32,6 +33,7 @@ module Y2Network
class ConnectionConfigsCollection
extend Forwardable
include Yast::Logger
include CanBeCopied

attr_reader :connection_configs
alias_method :to_a, :connection_configs
Expand Down
40 changes: 0 additions & 40 deletions test/network_autoyast_test.rb
Expand Up @@ -46,45 +46,6 @@
Yast::Lan.add_config(:yast, config)
end

describe "#merge_devices" do
let(:eth0_dhcp) { { "name" => "eth0", "bootproto" => "dhcp" } }
let(:eth1_dhcp) { { "name" => "eth1", "bootproto" => "dhcp" } }
let(:eth1_static) { { "name" => "eth1", "bootproto" => "static", "ipaddr"=>"192.168.1.5" } }
let(:eth2_dhcp) { { "name" => "eth2", "bootproto" => "dhcp" } }
let(:netconfig_linuxrc) { [eth0_dhcp, eth1_static] }
let(:netconfig_ay) { [eth2_dhcp] }
let(:netconfig_ay_colliding) { [eth1_dhcp, eth2_dhcp] }

context "when given interfaces list are nil or empty" do
it "returns an empty array" do
expect(network_autoyast.send(:merge_devices, [], [])).to eql([])
expect(network_autoyast.send(:merge_devices, nil, [])).to eql([])
expect(network_autoyast.send(:merge_devices, [], nil)).to eql([])
expect(network_autoyast.send(:merge_devices, nil, nil)).to eql([])
end
end

context "when only one of the given interfaces list is empty" do
it "returns the other list" do
expect(network_autoyast.send(:merge_devices, netconfig_linuxrc, [])).to eql netconfig_linuxrc
expect(network_autoyast.send(:merge_devices, [], netconfig_ay)).to eql netconfig_ay
end
end

it "combines the two lists ommiting duplicates using the name as the group value" do
devices = network_autoyast.send(:merge_devices, netconfig_linuxrc, netconfig_ay)
expect(devices.size).to eq(3)
end

context "when there is a duplicate interface definition" do
it "updates the system config with the defined by AutoYaST" do
devices = network_autoyast.send(:merge_devices, netconfig_linuxrc, netconfig_ay_colliding)
expect(devices.size).to eq(3)
expect(devices.find {|d| d["name"] == "eth1"}).to eq(eth1_dhcp)
end
end
end

describe "#merge_dns" do
let(:instsys_dns_setup) do
{
Expand Down Expand Up @@ -156,7 +117,6 @@
stub_const("Yast::UI", double.as_null_object)
expect(network_autoyast).to receive(:merge_dns)
expect(network_autoyast).to receive(:merge_routing)
expect(network_autoyast).to receive(:merge_devices)

network_autoyast.merge_configs("dns" => {}, "routing" => {}, "interfaces" => [])
end
Expand Down

0 comments on commit 8138955

Please sign in to comment.