Skip to content

Commit

Permalink
Merge pull request #1311 from yast/merge_SLE-15-SP4
Browse files Browse the repository at this point in the history
NM: Do not write gateway config when it is not there (master)
  • Loading branch information
teclator committed Sep 29, 2022
2 parents 443f40c + 0383cd5 commit 2035272
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 15 deletions.
7 changes: 7 additions & 0 deletions package/yast2-network.changes
@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Thu Sep 29 09:15:47 UTC 2022 - Knut Anderssen <kanderssen@suse.com>

- Fixed issue when writing the NetworkManager config without a
gateway (bsc#1203866)
- 4.5.8

-------------------------------------------------------------------
Fri Sep 16 08:23:21 UTC 2022 - Knut Anderssen <kanderssen@suse.com>

Expand Down
2 changes: 1 addition & 1 deletion package/yast2-network.spec
Expand Up @@ -17,7 +17,7 @@


Name: yast2-network
Version: 4.5.7
Version: 4.5.8
Release: 0
Summary: YaST2 - Network Configuration
License: GPL-2.0-only
Expand Down
Expand Up @@ -64,7 +64,7 @@ def write(conn, opts = {})
#
# @param routes [<Array<Y2Network::Route>] routes associated with the connection
def configure_routes(routes)
routes.select(&:default?).each { |r| configure_gateway(r) }
routes.select { |r| r.default? && r.gateway }.each { |r| configure_gateway(r) }
end

# @param route [Y2Network::Route] route to be written
Expand Down
67 changes: 54 additions & 13 deletions test/y2network/network_manager/config_writer_test.rb
Expand Up @@ -25,6 +25,9 @@
require "y2network/interface"
require "y2network/interfaces_collection"
require "y2network/boot_protocol"
require "y2network/route"
require "y2network/routing"
require "y2network/routing_table"
require "cfa/nm_connection"

describe Y2Network::NetworkManager::ConfigWriter do
Expand All @@ -45,6 +48,7 @@
old_config.copy.tap do |cfg|
cfg.add_or_update_connection_config(eth0_conn)
cfg.dns = dns
cfg.routing = routing
end
end

Expand All @@ -57,6 +61,22 @@
end
end

let(:routes) { [] }

let(:route) do
Y2Network::Route.new(
to: :default,
interface: eth0,
gateway: IPAddr.new("192.168.122.1")
)
end

let(:routing) do
Y2Network::Routing.new(
tables: [Y2Network::RoutingTable.new(routes)]
)
end

let(:nameserver1) { IPAddr.new("192.168.1.1") }
let(:nameserver2) { IPAddr.new("10.0.0.1") }
let(:nameserver3) { IPAddr.new("2000:e1dd:f002:0120:0000:0000:0000:0001") }
Expand All @@ -73,23 +93,54 @@
let(:ip) { Y2Network::ConnectionConfig::IPConfig.new(IPAddr.new("192.168.122.2")) }
let(:eth0) { Y2Network::Interface.new("eth0") }

let(:conn_config_writer) do
instance_double(Y2Network::NetworkManager::ConnectionConfigWriter, write: nil)
let(:conn_config_writer) { Y2Network::NetworkManager::ConnectionConfigWriter.new }

let(:file) do
CFA::NmConnection.new(File.join(DATA_PATH, "some_wifi.nmconnection"))
end

before do
allow(CFA::NmConnection).to receive(:for).and_return(file)
allow(file).to receive(:save)
end

before do
allow(Y2Network::NetworkManager::ConnectionConfigWriter).to receive(:new)
.and_return(conn_config_writer)
allow(writer).to receive(:write_drivers)
allow(writer).to receive(:write_hostname)
allow(writer).to receive(:write_routing)
end

it "writes connections configuration" do
expect(conn_config_writer).to receive(:write).with(eth0_conn, nil, routes: [], parent: nil)
writer.write(config)
end

context "when there is some route to be configured" do
let(:routes) { [route] }

context "and it contains a gateway" do
it "writes the connection gateway" do
writer.write(config)
expect(file.ipv4["gateway"]).to eq("192.168.122.1")
end
end

context "and it does not contain a gateway" do
let(:route) do
Y2Network::Route.new(
to: :default,
interface: eth0
)
end

it "does not write any gateway" do
writer.write(config)
expect(file.ipv4["gateway"]).to be_nil
end
end
end

context "writes DNS configuration" do
context "when a connection has static configuration" do
let(:eth0_conn) do
Expand All @@ -101,22 +152,12 @@
end
end

let(:file) do
CFA::NmConnection.new(File.join(DATA_PATH, "some_wifi.nmconnection"))
end

before do
allow(CFA::NmConnection).to receive(:for).and_return(file)
allow(file).to receive(:save)
end

it "includes DNS configuration in the configuration file" do
writer.write(config)
expect(file.ipv4["dns"]).to eq("#{nameserver1};#{nameserver2}")
expect(file.ipv6["dns"]).to eq("#{nameserver3};#{nameserver4}")
end
end
end

end
end

0 comments on commit 2035272

Please sign in to comment.