Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added vlan support and added wireless write unit test
- Loading branch information
Showing
6 changed files
with
149 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/lib/y2network/network_manager/connection_config_writers/vlan.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Copyright (c) [2021] SUSE LLC | ||
# | ||
# All Rights Reserved. | ||
# | ||
# This program is free software; you can redistribute it and/or modify it | ||
# under the terms of version 2 of the GNU General Public License as published | ||
# by the Free Software Foundation. | ||
# | ||
# This program is distributed in the hope that it will be useful, but WITHOUT | ||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
# more details. | ||
# | ||
# You should have received a copy of the GNU General Public License along | ||
# with this program; if not, contact SUSE LLC. | ||
# | ||
# To contact SUSE LLC about this file by physical or electronic mail, you may | ||
# find current contact information at www.suse.com. | ||
|
||
require "y2network/network_manager/connection_config_writers/base" | ||
|
||
module Y2Network | ||
module NetworkManager | ||
module ConnectionConfigWriters | ||
# This class is responsible for writing the information from a ConnectionConfig::Vlan | ||
# object to the underlying system. | ||
class Vlan < Base | ||
# @see Y2Network::ConnectionConfigWriters::Base#update_file | ||
# @param conn [Y2Network::ConnectionConfig::Vlan] Configuration to write | ||
def update_file(conn) | ||
file.vlan["id"] = conn.vlan_id | ||
file.vlan["parent"] = conn.parent_device | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
test/y2network/network_manager/connection_config_writers/wireless_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# Copyright (c) [2019] SUSE LLC | ||
# | ||
# All Rights Reserved. | ||
# | ||
# This program is free software; you can redistribute it and/or modify it | ||
# under the terms of version 2 of the GNU General Public License as published | ||
# by the Free Software Foundation. | ||
# | ||
# This program is distributed in the hope that it will be useful, but WITHOUT | ||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
# more details. | ||
# | ||
# You should have received a copy of the GNU General Public License along | ||
# with this program; if not, contact SUSE LLC. | ||
# | ||
# To contact SUSE LLC about this file by physical or electronic mail, you may | ||
# find current contact information at www.suse.com. | ||
|
||
require_relative "../../../test_helper" | ||
require "y2network/network_manager/connection_config_writers/wireless" | ||
require "cfa/nm_connection" | ||
require "y2network/boot_protocol" | ||
require "y2network/startmode" | ||
require "y2network/connection_config/wireless" | ||
|
||
describe Y2Network::NetworkManager::ConnectionConfigWriters::Wireless do | ||
subject(:handler) { described_class.new(file) } | ||
let(:file) { CFA::NmConnection.new("wlan0.nm_connection") } | ||
|
||
let(:conn) do | ||
Y2Network::ConnectionConfig::Wireless.new.tap do |c| | ||
c.interface = "wlan0" | ||
c.description = "Wireless Card 0" | ||
c.startmode = Y2Network::Startmode.create("auto") | ||
c.bootproto = Y2Network::BootProtocol::DHCP | ||
c.mode = "managed" | ||
c.essid = "example_essid" | ||
c.auth_mode = :open | ||
c.ap = "00:11:22:33:44:55" | ||
c.ap_scanmode = "1" | ||
end | ||
end | ||
|
||
describe "#write" do | ||
it "sets relevant attributes" do | ||
handler.write(conn) | ||
expect(file.wifi["ssid"]).to eql(conn.essid) | ||
expect(file.wifi["mode"]).to eql("infrastructure") | ||
expect(file.ipv4["method"]).to eql("auto") | ||
expect(file.ipv6["method"]).to eql("auto") | ||
end | ||
|
||
context "WPA-PSK network configuration" do | ||
let(:conn) do | ||
Y2Network::ConnectionConfig::Wireless.new.tap do |c| | ||
c.startmode = Y2Network::Startmode.create("auto") | ||
c.bootproto = Y2Network::BootProtocol::DHCP | ||
c.mode = "managed" | ||
c.auth_mode = "psk" | ||
c.wpa_psk = "example_psk" | ||
end | ||
end | ||
|
||
it "sets specific WPA-PSK attributes" do | ||
handler.write(conn) | ||
expect(file.wifi_security["key-mgmt"]).to eql("wpa-psk") | ||
expect(file.wifi_security["psk"]).to eql("example_psk") | ||
end | ||
end | ||
end | ||
end |