Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update NTP configuration for the dashboard role
- Loading branch information
Showing
6 changed files
with
140 additions
and
12 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
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
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,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 |
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
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
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,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 |