Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
225 additions
and
1 deletion.
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
49 changes: 49 additions & 0 deletions
49
src/lib/y2network/sysconfig/connection_config_readers/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,49 @@ | ||
# 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 "y2network/sysconfig/connection_config_readers/base" | ||
|
||
module Y2Network | ||
module Sysconfig | ||
module ConnectionConfigReaders | ||
# This class is able to build a ConnectionConfig::Bonding object given a | ||
# SysconfigInterfaceFile object. | ||
class Bonding < Base | ||
private | ||
|
||
# @see Y2Network::Sysconfig::ConnectionConfigReaders::Base#update_connection_config | ||
def update_connection_config(conn) | ||
conn.slaves = slaves | ||
conn.options = file.bonding_module_opts | ||
end | ||
|
||
# Convenience method to obtain the bonding slaves defined in the file | ||
# | ||
# @return [Array<String>] bonding slaves defined in the file | ||
def slaves | ||
return [] unless file.bonding_slaves | ||
|
||
file.bonding_slaves.map do |_id, name| | ||
name | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
49 changes: 49 additions & 0 deletions
49
src/lib/y2network/sysconfig/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,49 @@ | ||
# 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 "y2network/sysconfig/connection_config_writers/base" | ||
|
||
module Y2Network | ||
module Sysconfig | ||
module ConnectionConfigWriters | ||
# This class is responsible for writing the information from a ConnectionConfig::Bonding | ||
# object to the underlying system. | ||
class Bonding < Base | ||
private | ||
|
||
# @see Y2Network::ConnectionConfigWriters::Base#update_file | ||
# @param conn [Y2Network::ConnectionConfig::Bonding] Configuration to write | ||
def update_file(conn) | ||
file.bonding_slaves = file_slaves(conn) | ||
file.bonding_module_opts = conn.options | ||
end | ||
|
||
# Convenience method to obtain the map of bonding slaves in the file | ||
# format | ||
# | ||
# @return [Hash<Integer, String>] indexed bonding slaves | ||
def file_slaves(conn) | ||
{}.tap do |h| | ||
conn.slaves.each_with_index { |name, i| h[i] = name } | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
STARTMODE=auto | ||
BOOTPROTO=static | ||
IPADDR=192.168.20.100/24 | ||
BONDING_SLAVE1=eth0 | ||
BONDING_SLAVE2=eth1 | ||
BONDING_MODULE_OPTS='mode=active-backup miimon=100' |
46 changes: 46 additions & 0 deletions
46
test/y2network/sysconfig/connection_config_readers/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,46 @@ | ||
# 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/sysconfig/connection_config_readers/bonding" | ||
require "y2network/sysconfig/interface_file" | ||
|
||
describe Y2Network::Sysconfig::ConnectionConfigReaders::Bonding do | ||
subject(:handler) { described_class.new(file) } | ||
|
||
let(:scr_root) { File.join(DATA_PATH, "scr_read") } | ||
|
||
around do |example| | ||
change_scr_root(scr_root, &example) | ||
end | ||
|
||
let(:interface_name) { "bond0" } | ||
let(:file) do | ||
Y2Network::Sysconfig::InterfaceFile.find(interface_name).tap(&:load) | ||
end | ||
|
||
describe "#connection_config" do | ||
it "returns a bonding connection config object" do | ||
bonding_conn = handler.connection_config | ||
expect(bonding_conn.interface).to eq("bond0") | ||
expect(bonding_conn.slaves).to eq(["eth0", "eth1"]) | ||
expect(bonding_conn.options).to eq("mode=active-backup miimon=100") | ||
end | ||
end | ||
end |
63 changes: 63 additions & 0 deletions
63
test/y2network/sysconfig/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,63 @@ | ||
# 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/sysconfig/connection_config_writers/bonding" | ||
require "y2network/sysconfig/interface_file" | ||
require "y2network/startmode" | ||
require "y2network/connection_config/bonding" | ||
|
||
describe Y2Network::Sysconfig::ConnectionConfigWriters::Bonding do | ||
subject(:handler) { described_class.new(file) } | ||
|
||
let(:conn) do | ||
instance_double( | ||
Y2Network::ConnectionConfig::Bonding, | ||
name: "bond0", | ||
interface: "bond0", | ||
description: "", | ||
ip_configs: [], | ||
startmode: Y2Network::Startmode.create("auto"), | ||
bootproto: Y2Network::BootProtocol::DHCP, | ||
slaves: ["eth0", "eth1"], | ||
options: "mode=active-backup miimon=100" | ||
) | ||
end | ||
|
||
let(:file) { Y2Network::Sysconfig::InterfaceFile.new(conn.name) } | ||
|
||
describe "#write" do | ||
it "writes common properties" do | ||
handler.write(conn) | ||
expect(file).to have_attributes( | ||
startmode: "auto", | ||
bootproto: "dhcp" | ||
) | ||
end | ||
|
||
it "writes bonding properties" do | ||
handler.write(conn) | ||
expect(file).to have_attributes( | ||
bonding_slaves: { 0 => "eth0", 1 => "eth1" }, | ||
bonding_module_opts: "mode=active-backup miimon=100" | ||
) | ||
end | ||
end | ||
end |