From 8d6fd9e78fbbffe9d6ede33e063968cedb3b0663 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Knut=20Alejandro=20Anderssen=20Gonz=C3=A1lez?= Date: Thu, 1 Aug 2019 06:49:24 +0100 Subject: [PATCH] Add qeth connection config --- src/lib/y2network/connection_config/base.rb | 2 + src/lib/y2network/connection_config/qeth.rb | 28 ++++++++++ .../connection_config_readers/base.rb | 1 + .../connection_config_readers/qeth.rb | 31 +++++++++++ .../connection_config_writers/base.rb | 1 + .../connection_config_writers/qeth.rb | 31 +++++++++++ src/lib/y2network/sysconfig/interface_file.rb | 4 ++ .../scr_read/etc/sysconfig/network/ifcfg-eth5 | 4 ++ test/y2network/connection_config/qeth_test.rb | 30 +++++++++++ .../connection_config_readers/qeth_test.rb | 49 +++++++++++++++++ .../connection_config_writers/qeth_test.rb | 53 +++++++++++++++++++ 11 files changed, 234 insertions(+) create mode 100644 src/lib/y2network/connection_config/qeth.rb create mode 100644 src/lib/y2network/sysconfig/connection_config_readers/qeth.rb create mode 100644 src/lib/y2network/sysconfig/connection_config_writers/qeth.rb create mode 100644 test/data/scr_read/etc/sysconfig/network/ifcfg-eth5 create mode 100644 test/y2network/connection_config/qeth_test.rb create mode 100644 test/y2network/sysconfig/connection_config_readers/qeth_test.rb create mode 100644 test/y2network/sysconfig/connection_config_writers/qeth_test.rb diff --git a/src/lib/y2network/connection_config/base.rb b/src/lib/y2network/connection_config/base.rb index 7a017e8c9..d1d8d0721 100644 --- a/src/lib/y2network/connection_config/base.rb +++ b/src/lib/y2network/connection_config/base.rb @@ -53,6 +53,8 @@ class Base attr_accessor :startmode # @return [String] Connection's description (e.g., "Ethernet Card 0") attr_accessor :description + # @return [String] Link layer address + attr_accessor :lladdress # Constructor def initialize diff --git a/src/lib/y2network/connection_config/qeth.rb b/src/lib/y2network/connection_config/qeth.rb new file mode 100644 index 000000000..767963da7 --- /dev/null +++ b/src/lib/y2network/connection_config/qeth.rb @@ -0,0 +1,28 @@ +# 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/connection_config/base" + +module Y2Network + module ConnectionConfig + # Configuration for qeth connections + class Qeth < Base + end + end +end diff --git a/src/lib/y2network/sysconfig/connection_config_readers/base.rb b/src/lib/y2network/sysconfig/connection_config_readers/base.rb index 1df6b3208..efb25e78b 100644 --- a/src/lib/y2network/sysconfig/connection_config_readers/base.rb +++ b/src/lib/y2network/sysconfig/connection_config_readers/base.rb @@ -51,6 +51,7 @@ def connection_config conn.ip = all_ips.find { |i| i.id.empty? } conn.ip_aliases = all_ips.reject { |i| i.id.empty? } conn.name = file.interface + conn.lladdress = file.lladdr conn.startmode = Startmode.create(file.startmode || "manual") conn.startmode.priority = file.ifplugd_priority if conn.startmode.name == "ifplugd" update_connection_config(conn) diff --git a/src/lib/y2network/sysconfig/connection_config_readers/qeth.rb b/src/lib/y2network/sysconfig/connection_config_readers/qeth.rb new file mode 100644 index 000000000..9dc140a82 --- /dev/null +++ b/src/lib/y2network/sysconfig/connection_config_readers/qeth.rb @@ -0,0 +1,31 @@ +# 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/ethernet" + +module Y2Network + module Sysconfig + module ConnectionConfigReaders + # This class is able to build a ConnectionConfig::Qeth object given a + # Sysconfig::InterfaceFile object. + class Qeth < Ethernet + end + end + end +end diff --git a/src/lib/y2network/sysconfig/connection_config_writers/base.rb b/src/lib/y2network/sysconfig/connection_config_writers/base.rb index 0e2252d65..f1dffb075 100644 --- a/src/lib/y2network/sysconfig/connection_config_writers/base.rb +++ b/src/lib/y2network/sysconfig/connection_config_writers/base.rb @@ -42,6 +42,7 @@ def initialize(file) def write(conn) file.bootproto = conn.bootproto.name file.name = conn.description + file.lladdr = conn.lladdress file.startmode = conn.startmode.to_s file.ifplugd_priority = conn.startmode.priority if conn.startmode.name == "ifplugd" add_ips(conn) diff --git a/src/lib/y2network/sysconfig/connection_config_writers/qeth.rb b/src/lib/y2network/sysconfig/connection_config_writers/qeth.rb new file mode 100644 index 000000000..2841fad46 --- /dev/null +++ b/src/lib/y2network/sysconfig/connection_config_writers/qeth.rb @@ -0,0 +1,31 @@ +# 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/ethernet" + +module Y2Network + module Sysconfig + module ConnectionConfigWriters + # This class is responsible for writing the information from a ConnectionConfig::Qeth + # object to the underlying system. + class Qeth < Ethernet + end + end + end +end diff --git a/src/lib/y2network/sysconfig/interface_file.rb b/src/lib/y2network/sysconfig/interface_file.rb index 684eb22c7..2736fb0d2 100644 --- a/src/lib/y2network/sysconfig/interface_file.rb +++ b/src/lib/y2network/sysconfig/interface_file.rb @@ -177,6 +177,10 @@ def variable_name(param_name) # @return [Hash] Netmasks define_collection_variable(:netmask) + # !@attribute [r] lladdr + # @return [String] Link layer address + define_variable(:lladdr) + # !@attribute [r] wireless_key_length # @return [Integer] Length in bits for all keys used define_variable(:wireless_key_length, :integer) diff --git a/test/data/scr_read/etc/sysconfig/network/ifcfg-eth5 b/test/data/scr_read/etc/sysconfig/network/ifcfg-eth5 new file mode 100644 index 000000000..2f9e6e88b --- /dev/null +++ b/test/data/scr_read/etc/sysconfig/network/ifcfg-eth5 @@ -0,0 +1,4 @@ +STARTMODE='auto' +BOOTPROTO='static' +IPADDR='192.168.50.1/24' +LLADDR='00:06:29:55:2A:01' diff --git a/test/y2network/connection_config/qeth_test.rb b/test/y2network/connection_config/qeth_test.rb new file mode 100644 index 000000000..ff60b2572 --- /dev/null +++ b/test/y2network/connection_config/qeth_test.rb @@ -0,0 +1,30 @@ +# 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/connection_config/qeth" +require "y2network/interface_type" + +describe Y2Network::ConnectionConfig::Qeth do + describe "#type" do + it "returns 'qeth'" do + expect(subject.type).to eq(Y2Network::InterfaceType::QETH) + end + end +end diff --git a/test/y2network/sysconfig/connection_config_readers/qeth_test.rb b/test/y2network/sysconfig/connection_config_readers/qeth_test.rb new file mode 100644 index 000000000..85d7f20c6 --- /dev/null +++ b/test/y2network/sysconfig/connection_config_readers/qeth_test.rb @@ -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_relative "../../../test_helper" +require "y2network/sysconfig/connection_config_readers/qeth" +require "y2network/sysconfig/interface_file" +require "y2network/boot_protocol" + +describe Y2Network::Sysconfig::ConnectionConfigReaders::Qeth 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) { "eth5" } + + let(:file) do + Y2Network::Sysconfig::InterfaceFile.find(interface_name).tap(&:load) + end + + describe "#connection_config" do + it "returns a qeth connection config object" do + qeth = handler.connection_config + expect(qeth.type).to eql(Y2Network::InterfaceType::QETH) + expect(qeth.interface).to eq("eth5") + expect(qeth.ip.address).to eq(Y2Network::IPAddress.from_string("192.168.50.1/24")) + expect(qeth.bootproto).to eq(Y2Network::BootProtocol::STATIC) + end + end +end diff --git a/test/y2network/sysconfig/connection_config_writers/qeth_test.rb b/test/y2network/sysconfig/connection_config_writers/qeth_test.rb new file mode 100644 index 000000000..4a2c5f431 --- /dev/null +++ b/test/y2network/sysconfig/connection_config_writers/qeth_test.rb @@ -0,0 +1,53 @@ +# 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/qeth" +require "y2network/startmode" +require "y2network/boot_protocol" +require "y2network/connection_config/qeth" +require "y2network/connection_config/ip_config" + +describe Y2Network::Sysconfig::ConnectionConfigWriters::Qeth do + subject(:handler) { described_class.new(file) } + + let(:conn) do + Y2Network::ConnectionConfig::Qeth.new.tap do |c| + c.name = "eth6" + c.interface = "eth6" + c.bootproto = Y2Network::BootProtocol::STATIC + c.lladdress = "00:06:29:55:2A:04" + c.startmode = Y2Network::Startmode.create("auto") + end + 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( + bootproto: "static", + startmode: "auto", + lladdr: "00:06:29:55:2A:04" + ) + end + end +end