Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1186 from yast/nm_parent_devices
NM: add support to bridge and bonding configurations
- Loading branch information
Showing
12 changed files
with
219 additions
and
10 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
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
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
42 changes: 42 additions & 0 deletions
42
src/lib/y2network/network_manager/connection_config_writers/bonding.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,42 @@ | ||
# 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::Bonding | ||
# object to the underlying system. | ||
class Bonding < Base | ||
# @see Y2Network::ConnectionConfigWriters::Base#update_file | ||
# @param conn [Y2Network::ConnectionConfig::Bonding] Configuration to write | ||
def update_file(conn) | ||
file.connection["type"] = "bond" | ||
conn.options.to_s.split.each do |option| | ||
k, v = option.split("=") | ||
next if [k, v].any? { |o| o.to_s.empty? } | ||
|
||
file.bond[k] = v | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
38 changes: 38 additions & 0 deletions
38
src/lib/y2network/network_manager/connection_config_writers/bridge.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,38 @@ | ||
# 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::Bridge | ||
# object to the underlying system. | ||
class Bridge < Base | ||
# @see Y2Network::ConnectionConfigWriters::Base#update_file | ||
# @param conn [Y2Network::ConnectionConfig::Bonding] Configuration to write | ||
def update_file(conn) | ||
file.connection["type"] = "bridge" | ||
file.bridge["stp"] = conn.stp.to_s | ||
file.bridge["forward-delay"] = conn.forward_delay.to_s | ||
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
52 changes: 52 additions & 0 deletions
52
test/y2network/network_manager/connection_config_writers/bonding_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,52 @@ | ||
# 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_relative "../../../test_helper" | ||
require "y2network/network_manager/connection_config_writers/bonding" | ||
require "cfa/nm_connection" | ||
require "y2network/boot_protocol" | ||
require "y2network/startmode" | ||
require "y2network/connection_config/bonding" | ||
|
||
describe Y2Network::NetworkManager::ConnectionConfigWriters::Bonding do | ||
subject(:handler) { described_class.new(file) } | ||
let(:file) { CFA::NmConnection.new("bond0.nm_connection") } | ||
|
||
let(:conn) do | ||
Y2Network::ConnectionConfig::Bonding.new.tap do |c| | ||
c.interface = "bond0" | ||
c.description = "Bond 0" | ||
c.startmode = Y2Network::Startmode.create("auto") | ||
c.bootproto = Y2Network::BootProtocol::DHCP | ||
c.options = "mode=active-backup miimon=100" | ||
c.slaves = ["eth0"] | ||
end | ||
end | ||
|
||
describe "#write" do | ||
it "sets device and IP relevant attributes" do | ||
handler.write(conn) | ||
expect(file.connection["type"]).to eql("bond") | ||
expect(file.bond["mode"]).to eql("active-backup") | ||
expect(file.bond["miimon"]).to eql("100") | ||
expect(file.ipv4["method"]).to eql("auto") | ||
expect(file.ipv6["method"]).to eql("auto") | ||
end | ||
end | ||
end |
53 changes: 53 additions & 0 deletions
53
test/y2network/network_manager/connection_config_writers/bridge_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,53 @@ | ||
# 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_relative "../../../test_helper" | ||
require "y2network/network_manager/connection_config_writers/bridge" | ||
require "cfa/nm_connection" | ||
require "y2network/boot_protocol" | ||
require "y2network/startmode" | ||
require "y2network/connection_config/bridge" | ||
|
||
describe Y2Network::NetworkManager::ConnectionConfigWriters::Bridge do | ||
subject(:handler) { described_class.new(file) } | ||
let(:file) { CFA::NmConnection.new("br0.nm_connection") } | ||
|
||
let(:conn) do | ||
Y2Network::ConnectionConfig::Bridge.new.tap do |c| | ||
c.interface = "br0" | ||
c.description = "Bridge 0" | ||
c.startmode = Y2Network::Startmode.create("auto") | ||
c.bootproto = Y2Network::BootProtocol::DHCP | ||
c.stp = true | ||
c.forward_delay = 2 | ||
c.ports = ["eth0"] | ||
end | ||
end | ||
|
||
describe "#write" do | ||
it "sets device and IP relevant attributes" do | ||
handler.write(conn) | ||
expect(file.connection["type"]).to eql("bridge") | ||
expect(file.bridge["stp"]).to eql("true") | ||
expect(file.bridge["forward-delay"]).to eql("2") | ||
expect(file.ipv4["method"]).to eql("auto") | ||
expect(file.ipv6["method"]).to eql("auto") | ||
end | ||
end | ||
end |