Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PoC] Add objects to read configuration from the system
- Loading branch information
Showing
4 changed files
with
146 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# 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. | ||
module Y2Network | ||
# This module contains a set of classes to read the network configuration from the system | ||
# | ||
# For the time being, only the wicked reader ({Y2Network::ConfigReader::Wicked}) reader is | ||
# available. | ||
module ConfigReader | ||
def self.for(source = :wicked) | ||
require "y2network/config_reader/#{source}" | ||
name = source.to_s.split("_").map(&:capitalize).join | ||
klass = self.const_get(name) | ||
klass.new | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# 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/config" | ||
|
||
Yast.import "LanItems" | ||
|
||
module Y2Network | ||
module ConfigReader | ||
# This class reads the current configuration from the system | ||
class Wicked | ||
# @return [Y2Network::Config] Network configuration | ||
def config | ||
Yast::LanItems.Read | ||
Config.new(interfaces: interfaces) | ||
end | ||
|
||
def interfaces | ||
# TODO: for the time being, we are just relying in the underlying stuff. | ||
Yast::LanItems.current_device_names.map do |name| | ||
Y2Network::Interface.new(name) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# 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/config_reader/wicked" | ||
|
||
describe Y2Network::ConfigReader::Wicked do | ||
subject(:reader) { described_class.new } | ||
|
||
let(:lan_items) do | ||
instance_double( | ||
Yast::LanItemsClass, | ||
Read: nil, | ||
current_device_names: ["lo", "eth0", "wlan0"] | ||
) | ||
end | ||
|
||
describe "" do | ||
before do | ||
allow(Yast).to receive(:import).with("LanItems") | ||
stub_const("Yast::LanItems", lan_items) | ||
end | ||
|
||
it "returns a configuration including network devices" do | ||
config = reader.config | ||
expect(config.interfaces.map(&:name)).to eq(["lo", "eth0", "wlan0"]) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# 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/config_reader" | ||
|
||
describe Y2Network::ConfigReader do | ||
describe ".for" do | ||
it "returns the reader for the given source" do | ||
reader = Y2Network::ConfigReader.for(:wicked) | ||
expect(reader).to be_a(Y2Network::ConfigReader::Wicked) | ||
end | ||
end | ||
end |