Skip to content

Commit

Permalink
Merge pull request #694 from yast/dhcp_ntp_servers
Browse files Browse the repository at this point in the history
Expose the dhcp_ntp_servers method directly in Yast::Lan
  • Loading branch information
teclator committed Nov 12, 2018
2 parents 833c9c9 + 2f806be commit 9f0124e
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 1 deletion.
7 changes: 7 additions & 0 deletions package/yast2-network.changes
@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Sun Nov 11 16:29:30 UTC 2018 - knut.anderssen@suse.com

- Yast::Lan: Added method for obtaining the NTP servers offered by
DHCP (fate#323454)
- 4.0.44

-------------------------------------------------------------------
Wed Oct 24 08:26:24 UTC 2018 - mfilka@suse.com

Expand Down
2 changes: 1 addition & 1 deletion package/yast2-network.spec
Expand Up @@ -17,7 +17,7 @@


Name: yast2-network
Version: 4.0.43
Version: 4.0.44
Release: 0
BuildArch: noarch

Expand Down
14 changes: 14 additions & 0 deletions src/modules/Lan.rb
Expand Up @@ -1013,6 +1013,20 @@ def HaveXenBridge
have_br
end

# Provides a list with the NTP servers obtained via any of dhcp aware
# interfaces
#
# @note parsing dhcp ntp servers when NetworkManager is in use is not
# supported yet (bsc#798886)
#
# @return [Array<String>] list of ntp servers obtained byg DHCP
def dhcp_ntp_servers
return [] if !NetworkService.isNetworkRunning || Yast::NetworkService.is_network_manager

ReadWithCacheNoGUI()
Yast::LanItems.dhcp_ntp_servers.values.flatten.uniq
end

publish variable: :ipv6, type: "boolean"
publish variable: :AbortFunction, type: "block <boolean>"
publish variable: :bond_autoconf_slaves, type: "list <string>"
Expand Down
46 changes: 46 additions & 0 deletions test/lan_test.rb
Expand Up @@ -444,3 +444,49 @@ def expect_modification_succeedes(modname, method)
expect(actual["config"]).to eq(expected_config)
end
end

describe "Yast::LanClass#dhcp_ntp_servers" do
subject { Yast::Lan }
let(:running) { true }
let(:nm_enabled) { true }
let(:servers) do
{
"eth0" => ["0.pool.ntp.org", "1.pool.ntp.org"],
"eth1" => ["1.pool.ntp.org", "2.pool.ntp.org"]
}
end

before do
allow(Yast::NetworkService).to receive(:isNetworkRunning).and_return(running)
allow(Yast::NetworkService).to receive(:is_network_manager).and_return(nm_enabled)
allow(Yast::LanItems).to receive(:dhcp_ntp_servers).and_return(servers)
end

context "when the network is not running" do
let(:running) { false }
it "returns an empty array" do
expect(subject.dhcp_ntp_servers).to eq([])
end
end

context "when NetworkManager is in use" do
let(:nm_enabled) { true }
it "returns an empty array" do
expect(subject.dhcp_ntp_servers).to eq([])
end
end

context "when wicked is in use" do
let(:nm_enabled) { false }

it "reads the current network configuration" do
expect(Yast::Lan).to receive(:ReadWithCacheNoGUI)
subject.dhcp_ntp_servers
end

it "returns a list of the ntp_servers provided by dhcp " do
expect(subject.dhcp_ntp_servers.sort)
.to eql(["0.pool.ntp.org", "1.pool.ntp.org", "2.pool.ntp.org"])
end
end
end

0 comments on commit 9f0124e

Please sign in to comment.