Skip to content

Commit

Permalink
Fixed sync issue and bring bach 'Select from'
Browse files Browse the repository at this point in the history
  • Loading branch information
teclator committed Nov 8, 2018
1 parent fcde62d commit ea495aa
Show file tree
Hide file tree
Showing 12 changed files with 468 additions and 42 deletions.
10 changes: 10 additions & 0 deletions package/yast2-ntp-client.changes
@@ -1,3 +1,13 @@
-------------------------------------------------------------------
Sun Nov 4 18:16:03 UTC 2018 - knut.anderssen@suse.com

- Bring back the menu button for choosing a ntp address from a
public ntp servers list or from the ones returned by dhcp.
(fate#323454)
- Do not save changes when we are only synchronizing the date.
(bsc#1102982)
4.1.4

-------------------------------------------------------------------
Tue Oct 16 10:28:35 CEST 2018 - schubi@suse.de

Expand Down
3 changes: 2 additions & 1 deletion package/yast2-ntp-client.spec
Expand Up @@ -17,7 +17,7 @@


Name: yast2-ntp-client
Version: 4.1.3
Version: 4.1.4
Release: 0
Summary: YaST2 - NTP Client Configuration
License: GPL-2.0-or-later
Expand All @@ -31,6 +31,7 @@ BuildRequires: update-desktop-files
BuildRequires: yast2 >= 3.2.21
BuildRequires: yast2-country-data
BuildRequires: yast2-devtools >= 3.1.10
BuildRequires: yast2-network
BuildRequires: rubygem(%rb_default_ruby_abi:cfa) >= 0.6.0
BuildRequires: rubygem(%rb_default_ruby_abi:rspec)
BuildRequires: rubygem(%rb_default_ruby_abi:yast-rake)
Expand Down
52 changes: 36 additions & 16 deletions src/clients/ntp-client_proposal.rb
Expand Up @@ -128,7 +128,7 @@ def ui_help_text
def ui_enable_disable_widgets(enabled)
UI.ChangeWidget(Id(:ntp_address), :Enabled, enabled)
UI.ChangeWidget(Id(:run_service), :Enabled, enabled)
if !NetworkService.isNetworkRunning
if !NetworkService.isNetworkRunning || Service.Active(NtpClient.service_name)
UI.ChangeWidget(Id(:ntp_now), :Enabled, false)
else
UI.ChangeWidget(Id(:ntp_now), :Enabled, enabled)
Expand Down Expand Up @@ -184,20 +184,18 @@ def MakeProposal
end

if NtpClient.config_has_been_read || NtpClient.ntp_selected
Builtins.y2milestone("ntp_items will be filled from /etc/chrony.conf")
log.info("ntp_items will be filled from /etc/chrony.conf")
# grr, GUNS means all of them are used and here we just pick one
ntp_items = Builtins.maplist(NtpClient.GetUsedNtpServers) do |server|
Item(Id(server), server)
end
ntp_items = configured_ntp_items

# avoid calling Read again (bnc #427712)
NtpClient.config_has_been_read = true
end
if ntp_items == []
Builtins.y2milestone(
"Nothing found in /etc/chrony.conf, proposing current timezone-based NTP server list"
)
time_zone_country = Timezone.GetCountryForTimezone(Timezone.timezone)
ntp_items = NtpClient.GetNtpServersByCountry(time_zone_country, true)

if ntp_items.empty?
log.info("Nothing found in /etc/chrony.conf, " \
"proposing current timezone-based NTP server list")
ntp_items = dhcp_ntp_items.empty? ? timezone_ntp_items : dhcp_ntp_items
NtpClient.config_has_been_read = true
end
ntp_items = Builtins.add(ntp_items, "")
Expand Down Expand Up @@ -356,24 +354,21 @@ def Write(params)

return :invalid_hostname unless ValidateSingleServer(ntp_server)

WriteNtpSettings(ntp_servers, ntp_server, run_service)
WriteNtpSettings(ntp_servers, ntp_server, run_service) unless params["ntpdate_only"]

return :success if params["write_only"]

add_or_install_required_package

# Only if network is running try to synchronize the ntp server
if NetworkService.isNetworkRunning
if NetworkService.isNetworkRunning && !Service.Active(NtpClient.service_name)
Popup.ShowFeedback("", _("Synchronizing with NTP server..."))
exit_code = NtpClient.sync_once(ntp_server)
Popup.ClearFeedback

return :ntpdate_failed unless exit_code.zero?
end

# User wants more than running one time sync (synchronize on boot)
WriteNtpSettings(ntp_servers, ntp_server, run_service) unless params["ntpdate_only"]

:success
end

Expand Down Expand Up @@ -480,6 +475,31 @@ def add_or_install_required_package
)
end
end

# Configured ntp servers Yast::Term items with the ntp address as the ID
# and label
#
# @return [Yast::Term] ntp address table Item
def configured_ntp_items
NtpClient.GetUsedNtpServers
end

# Public list of ntp servers Yast::Term items with the ntp address as the
# ID and label
#
# @return [Array<Yast::Term>] ntp address Item
def timezone_ntp_items
timezone_country = Timezone.GetCountryForTimezone(Timezone.timezone)
NtpClient.GetNtpServersByCountry(timezone_country, true)
end

# List of ntp servers Yast::Term items with the ntp address as the ID and
# label
#
# @return [Array<Yast::Term>] ntp address table Item
def dhcp_ntp_items
NtpClient.dhcp_ntp_servers
end
end
end

Expand Down
88 changes: 88 additions & 0 deletions src/lib/y2ntp_client/dialog/add_pool.rb
@@ -0,0 +1,88 @@
require "yast"

require "cwm/popup"

Yast.import "Label"
Yast.import "NtpClient"
Yast.import "Stage"
Yast.import "Popup"

# Work around YARD inability to link across repos/gems:

# @!macro [new] seeAbstractWidget
# @see http://www.rubydoc.info/github/yast/yast-yast2/CWM/AbstractWidget:${0}
# @!macro [new] seeCustomWidget
# @see http://www.rubydoc.info/github/yast/yast-yast2/CWM/CustomWidget:${0}
# @!macro [new] seeItemsSelection
# @see http://www.rubydoc.info/github/yast/yast-yast2/CWM/ItemsSelection:${0}
# @!macro [new] seeDialog
# @see http://www.rubydoc.info/github/yast/yast-yast2/CWM/Dialog:${0}
# @!macro [new] seePopup
# @see http://www.rubydoc.info/github/yast/yast-yast2/CWM/Popup:${0}

module Y2NtpClient
module Dialog
# Dialog to add/edit ntp pool server
class AddPool < ::CWM::Popup
# Constructor
#
# @param address_widget [CWM::InputField]
# @param pool_type [Symbol]
def initialize(address_widget, pool_type)
textdomain "ntp-client"
@address_widget = address_widget
@address = @address_widget.value
@pool_chooser = pool_for(pool_type)
end

# @macro seeDialog
def title
_("Local ntp servers discovered")
end

# @macro seeDialog
def contents
VBox(
@pool_chooser
)
end

def next_handler
return :cancel if @pool_chooser.value.to_s.empty?
@address = @pool_chooser.value

:next
end

# @macro seeDialog
def next_button
ok_button_label
end

# @macro seeDialog
def run
result = super
@address_widget.value = @address if result == :next

result
end

private

# @macro seeDialog
def ok_button
PushButton(Id(:next), Opt(:default), ok_button_label)
end

def pool_for(type)
{ local: Widgets::LocalList,
public: Widgets::PublicList }.fetch(type, Widgets::LocalList).new(@address_widget.value)
end

# @macro see
def min_height
8
end
end
end
end
11 changes: 10 additions & 1 deletion src/lib/y2ntp_client/dialog/pool.rb
Expand Up @@ -32,10 +32,19 @@ def contents
HBox(
@address_widget,
HSpacing(),
Widgets::TestButton.new(@address_widget)
VBox(
VSpacing(1),
Widgets::SelectFrom.new(@address_widget)
),
HSpacing(),
VBox(
VSpacing(1),
Widgets::TestButton.new(@address_widget)
)
),
VSpacing(),
HBox(
HSpacing(),
Widgets::Iburst.new(@options),
HSpacing(),
Widgets::Offline.new(@options)
Expand Down
22 changes: 22 additions & 0 deletions src/lib/y2ntp_client/dynamic_servers.rb
@@ -0,0 +1,22 @@
require "yast"

module Y2NtpClient
# Bunch of methods for retrieving ntp servers dinamically, i.e. by dhcp or
# slp.
module DynamicServers
def dhcp_ntp_servers
Yast.import "Lan"
Yast.import "LanItems"
Yast.import "NetworkService"

# When proposing NTP servers we need to know
# 1) list of (dhcp) interfaces
# 2) network service in use
# We can either use networking submodule for network service handling and get list of
# interfaces e.g. using a bash command or initialize whole networking module.
Yast::Lan.ReadWithCacheNoGUI

Yast::LanItems.dhcp_ntp_servers.values.reduce(&:concat) || []
end
end
end
6 changes: 3 additions & 3 deletions src/lib/y2ntp_client/widgets/main_widgets.rb
Expand Up @@ -26,10 +26,10 @@ def label
def help
# TRANSLATORS: 'man 8 netconfig' is a command, do not translate that
_(
"The NTP configuration may be provided by the local network over DHCP. " \
"<p>The NTP configuration may be provided by the local network over DHCP. " \
"<b>Configuration Source</b> can simply enable or disable using that configuration. " \
"In cases where there may be multiple DHCP sources, it can prioritize them: " \
"see 'man 8 netconfig'."
"see 'man 8 netconfig'.</p>"
)
end

Expand Down Expand Up @@ -127,7 +127,7 @@ def help
"Select whether to start the NTP daemon now and on every system boot. \n" \
"Selecting <b>Synchronize without Daemon</b> the NTP daemon will not be activated\n" \
"and the system time will be set periodically by a <i>cron</i> script. \n" \
"The interval is configurable, by default it is %d minutes."
"The interval is configurable, by default it is %d minutes.</p>"
) % Yast::NtpClientClass::DEFAULT_SYNC_INTERVAL
end

Expand Down

0 comments on commit ea495aa

Please sign in to comment.