Skip to content

Commit

Permalink
Merge pull request #1192 from yast/better-nm-wireless-naming
Browse files Browse the repository at this point in the history
Use the ESSID to name the NM config file
  • Loading branch information
imobachgs committed Mar 30, 2021
2 parents 9a96a0b + 3aeaf6e commit 618c9d5
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 3 deletions.
7 changes: 7 additions & 0 deletions package/yast2-network.changes
@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Mon Mar 29 11:52:08 UTC 2021 - Imobach Gonzalez Sosa <igonzalezsosa@suse.com>

- Use the ESSID to name the NetworkManager configuration files
for wireless networks (bsc#1183733).
- 4.3.63

-------------------------------------------------------------------
Thu Mar 18 12:59:31 UTC 2021 - 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.3.62
Version: 4.3.63
Release: 0
Summary: YaST2 - Network Configuration
License: GPL-2.0-only
Expand Down
12 changes: 11 additions & 1 deletion src/lib/y2network/network_manager/connection_config_writer.rb
Expand Up @@ -39,7 +39,7 @@ class ConnectionConfigWriter
def write(conn, old_conn = nil, opts = {})
return if conn == old_conn

path = SYSTEM_CONNECTIONS_PATH.join(conn.name).sub_ext(FILE_EXT)
path = SYSTEM_CONNECTIONS_PATH.join(file_basename_for(conn)).sub_ext(FILE_EXT)
file = CFA::NmConnection.new(path)
handler_class = find_handler_class(conn.type)
return nil if handler_class.nil?
Expand Down Expand Up @@ -74,6 +74,16 @@ def find_handler_class(type)
"Connection handler could not be loaded: #{e.message}"
nil
end

# Returns the file base name for the given connection
#
# @param conn [ConnectionConfig::Base]
# @return [String]
def file_basename_for(conn)
return conn.essid.to_s if conn.is_a?(ConnectionConfig::Wireless)

conn.name
end
end
end
end
39 changes: 38 additions & 1 deletion test/y2network/network_manager/connection_config_writer_test.rb
Expand Up @@ -21,6 +21,7 @@

require "y2network/network_manager/connection_config_writer"
require "y2network/network_manager/connection_config_writers/ethernet"
require "y2network/network_manager/connection_config_writers/wireless"
require "y2network/connection_config/ethernet"
require "y2network/interface_type"
require "cfa/nm_connection"
Expand Down Expand Up @@ -71,10 +72,10 @@
allow(CFA::NmConnection).to receive(:new).and_return(file)
allow(writer).to receive(:ensure_permissions)
allow(::File).to receive(:exist?).with(Pathname.new(path)).and_return(true)
allow(::File).to receive(:exist?).and_call_original
end

it "uses the appropiate handler" do
expect(writer).to receive(:require).and_return(handler)
expect(handler).to receive(:write).with(conn, {})
writer.write(conn)
end
Expand All @@ -90,6 +91,42 @@
end
end

it "uses the connection name as base file name" do
expect(CFA::NmConnection).to receive(:new) do |path|
expect(path.basename).to eq(Pathname.new("eth0.nmconnection"))
end.and_return(file)
writer.write(conn)
end

context "when writing a wireless connection" do
let(:conn) do
Y2Network::ConnectionConfig::Wireless.new.tap do |wlo1|
wlo1.name = "wlo1"
wlo1.interface = "wlo1"
wlo1.ip = ip_config
wlo1.essid = "MY_WIRELESS"
end
end

let(:handler) do
instance_double(
Y2Network::NetworkManager::ConnectionConfigWriters::Wireless, write: nil
)
end

before do
allow(Y2Network::NetworkManager::ConnectionConfigWriters::Wireless).to receive(:new)
.and_return(handler)
end

it "uses the ESSID as the base file name" do
expect(CFA::NmConnection).to receive(:new) do |path|
expect(path.basename).to eq(Pathname.new("MY_WIRELESS.nmconnection"))
end.and_return(file)
writer.write(conn)
end
end

it "does nothing if the connection has not changed"
end
end

0 comments on commit 618c9d5

Please sign in to comment.