Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
lslezak committed Nov 9, 2018
1 parent 96e5b6c commit 7b2a01b
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 23 deletions.
19 changes: 2 additions & 17 deletions src/clients/inst_kubic_kubeadm_role.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@

require "yast"

include Yast::I18n
textdomain "caasp"

# so far the Kubic dialog is the same as in CaaSP,
# just with different title and defaults
require "y2caasp/clients/admin_role_dialog"

dialog = Y2Caasp::AdminRoleDialog.new(
# TRANSLATORS: kubeadm is a tool for creating Kubernetes clusters,
# do not translate that name
title: _("kubeadm node configuration"),
# propose random pool server in range 0..3 if not set via DHCP
ntp_fallback: "#{rand(4)}.opensuse.pool.ntp.org"
)
dialog.run
require "y2caasp/clients/kubeadm_role_dialog"
Y2Caasp::KubeadmRoleDialog.new.run
31 changes: 25 additions & 6 deletions src/lib/y2caasp/clients/admin_role_dialog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,19 @@ module Y2Caasp
class AdminRoleDialog < CWM::Dialog
include DhcpNtpServers

attr_reader :title, :ntp_fallback

def initialize(title: nil, ntp_fallback: nil)
def initialize
textdomain "caasp"
super
end

#
# The dialog title
#
# @return [String ] the title
#
def title
# TRANSLATORS: dialog title
@title = title || _("Admin Node Configuration")
@ntp_fallback = ntp_fallback
super()
_("Admin Node Configuration")
end

def contents
Expand All @@ -51,6 +55,8 @@ def contents
)
end

private

#
# Propose the NTP servers
#
Expand All @@ -64,5 +70,18 @@ def ntp_servers

servers
end

protected

#
# The fallback servers for NTP configuration, used when there is no
# server specified in the DHCP response.
#
# @return [String,nil] the fallback servers (comma or space separated),
# nil for none
#
def ntp_fallback
nil
end
end
end
35 changes: 35 additions & 0 deletions src/lib/y2caasp/clients/kubeadm_role_dialog.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
require "yast"

# so far the Kubic dialog is the same as in CaaSP,
# just with different title and defaults
require "y2caasp/clients/admin_role_dialog"

module Y2Caasp
# This library provides a simple dialog for setting
# the kubeadm role specific settings:
# - the NTP server names
class KubeadmRoleDialog < AdminRoleDialog
def initialize
textdomain "caasp"

super
end

#
# The dialog title
#
# @return [String ] the title
#
def title
# TRANSLATORS: dialog title
_("kubeadm node configuration")
end

protected

def ntp_fallback
# propose random pool server in range 0..3 if not set via DHCP
"#{rand(4)}.opensuse.pool.ntp.org"
end
end
end
38 changes: 38 additions & 0 deletions test/lib/y2caasp/clients/kubeadm_role_dialog_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#! /usr/bin/env rspec

require_relative "../../../test_helper.rb"
require_relative "role_dialog_examples"
require "cwm/rspec"

require "y2caasp/clients/kubeadm_role_dialog.rb"

Yast.import "CWM"
Yast.import "Lan"
Yast.import "Wizard"

describe ::Y2Caasp::KubeadmRoleDialog do
describe "#run" do
let(:ntp_servers) { [] }

before do
allow(Yast::Wizard).to receive(:CreateDialog)
allow(Yast::Wizard).to receive(:CloseDialog)
allow(Yast::CWM).to receive(:show).and_return(:next)
allow(Yast::Lan).to receive(:ReadWithCacheNoGUI)
allow(Yast::LanItems).to receive(:dhcp_ntp_servers).and_return({})
end

include_examples "CWM::Dialog"
include_examples "NTP from DHCP"

context "when no NTP server is detected via DHCP" do
it "proposes to use a random openSUSE pool server" do
expect(Y2Caasp::Widgets::NtpServer).to receive(:new) do |s|
expect(s.first).to match(/\A[0-3]\.opensuse\.pool\.ntp\.org\z/)
end.and_call_original
subject.run
end
end

end
end

0 comments on commit 7b2a01b

Please sign in to comment.