Skip to content

Commit

Permalink
Update NTP configuration for the dashboard role
Browse files Browse the repository at this point in the history
  • Loading branch information
imobachgs committed Apr 17, 2017
1 parent 5643e19 commit e6e100d
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 12 deletions.
3 changes: 2 additions & 1 deletion src/Makefile.am
Expand Up @@ -217,7 +217,8 @@ ylibdialog_DATA = \
ylibwidgetdir = "${yast2dir}/lib/installation/widgets"
ylibwidget_DATA = \
lib/installation/widgets/overview.rb \
lib/installation/widgets/system_role.rb
lib/installation/widgets/system_role.rb \
lib/installation/widgets/ntp_server.rb

EXTRA_DIST = $(module_DATA) $(client_DATA) $(ynclude_DATA) $(scrconf_DATA) $(schemafiles_DATA) $(desktop_DATA) $(fillup_DATA) $(ylibdialog_DATA) $(ylib_DATA) $(ylibtransfer_DATA)

Expand Down
4 changes: 3 additions & 1 deletion src/lib/installation/clients/inst_casp_overview.rb
Expand Up @@ -147,6 +147,7 @@ def quadrant_layout(upper_left:, lower_left:, upper_right:, lower_right:)
# block installation
def content
controller_node = Installation::Widgets::ControllerNodePlace.new
ntp_server = Installation::Widgets::NtpServerPlace.new

kdump_overview = Installation::Widgets::Overview.new(client: "kdump_proposal")
bootloader_overview = Installation::Widgets::Overview.new(client: "bootloader_proposal", redraw: [kdump_overview])
Expand All @@ -159,8 +160,9 @@ def content
::Y2Country::Widgets::KeyboardSelectionCombo.new("english-us")
),
lower_left: VBox(
Installation::Widgets::SystemRole.new(controller_node),
Installation::Widgets::SystemRole.new(controller_node, ntp_server),
controller_node,
ntp_server,
Tune::Widgets::SystemInformation.new
),
upper_right: VBox(
Expand Down
55 changes: 55 additions & 0 deletions src/lib/installation/widgets/ntp_server.rb
@@ -0,0 +1,55 @@
require "yast"
Yast.import "CWM"

module Installation
module Widgets
# This widget is responsible of validating and storing the NTP server to use.
class NtpServer < CWM::InputField
# intentional no translation for CaaSP
def label
"NTP Server"
end

# Store the value of the input field if validates
def store
role["ntp_servers"] = value.split(" ")
end

# Validate input
def validate
return true if value.split(" ").all? do |v|
Yast::IP.Check(v) || Yast::Hostname.CheckFQ(value)
end

Yast::Popup.Error(
# TRANSLATORS: error message for invalid ntp server name/address
_("Not valid NTP server names, " \
"please enter a valid IP or Hostname")
)
false
end

private

def role
::Installation::SystemRole.find("dashboard_role")
end
end

class NtpServerPlace < CWM::ReplacePoint
def initialize
@ntp_server = NtpServer.new
@empty = CWM::Empty.new("no_ntp_server")
super(widget: @empty)
end

def show
replace(@ntp_server)
end

def hide
replace(@empty)
end
end
end
end
26 changes: 17 additions & 9 deletions src/lib/installation/widgets/system_role.rb
Expand Up @@ -23,6 +23,7 @@
require "cwm/widget"
require "installation/services"
require "installation/system_role"
require "installation/widgets/ntp_server"

Yast.import "ProductControl"
Yast.import "IP"
Expand Down Expand Up @@ -91,9 +92,19 @@ def hide
end

class SystemRole < CWM::ComboBox
def initialize(controller_node_widget)
ROLE_WIDGETS = {
"worker_role" => [:controller_node],
"dashboard_role" => [:ntp_server]
}.freeze

attr_reader :widgets

def initialize(controller_node_widget, ntp_server_widget)
textdomain "installation"
@controller_node_widget = controller_node_widget
@widgets = {
controller_node: controller_node_widget,
ntp_server: ntp_server_widget
}
end

def label
Expand All @@ -110,13 +121,10 @@ def init
end

def handle
if value == "worker_role"
@controller_node_widget.show
else
@controller_node_widget.hide
end

nil
to_show = ROLE_WIDGETS.fetch(value, [])
to_hide = widgets.keys - to_show
to_hide.each { |w| widgets[w].hide }
to_show.each { |w| widgets[w].show }
end

def items
Expand Down
3 changes: 2 additions & 1 deletion test/Makefile.am
Expand Up @@ -35,7 +35,8 @@ TESTS = \
updates_manager_test.rb \
widgets_overview_test.rb \
widgets_system_role_test.rb \
lib/system_role_handlers_runner_test.rb
lib/system_role_handlers_runner_test.rb \
lib/widgets/system_role_test.rb

TEST_EXTENSIONS = .rb
RB_LOG_COMPILER = rspec
Expand Down
61 changes: 61 additions & 0 deletions test/lib/widgets/system_role_test.rb
@@ -0,0 +1,61 @@
#!/usr/bin/env rspec

require_relative "../../test_helper"
require "installation/widgets/system_role"

describe ::Installation::Widgets::SystemRole do
subject(:widget) do
::Installation::Widgets::SystemRole.new(controller_node_widget, ntp_server_widget)
end

let(:controller_node_widget) { double("controller_node_widget") }
let(:ntp_server_widget) { double("ntp_server_widget") }
Yast::ProductControl.GetTranslatedText("roles_caption")

describe "#label" do
before do
allow(Yast::ProductControl).to receive(:GetTranslatedText)
.with("roles_caption").and_return("LABEL")
end

it "returns the label defined in the product's control file" do
expect(widget.label).to eq("LABEL")
end
end

describe "#handle" do
before do
allow(widget).to receive(:value).and_return(value)
end

context "when value is 'worker_role'" do
let(:value) { "worker_role" }

it "only shows the controller node widget" do
expect(ntp_server_widget).to receive(:hide)
expect(controller_node_widget).to receive(:show)
widget.handle
end
end

context "when value is 'dashboard_role'" do
let(:value) { "dashboard_role" }

it "only shows the NTP server widget" do
expect(ntp_server_widget).to receive(:show)
expect(controller_node_widget).to receive(:hide)
widget.handle
end
end

context "when value is not 'worker_role' nor 'dashboard_role'" do
let(:value) { "none_role" }

it "hides all widgets" do
expect(ntp_server_widget).to receive(:hide)
expect(controller_node_widget).to receive(:hide)
widget.handle
end
end
end
end

0 comments on commit e6e100d

Please sign in to comment.