Hello community,

here is the log from the commit of package yast2-ntp-client for 
openSUSE:Factory checked in at 2020-03-14 09:54:38
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/yast2-ntp-client (Old)
 and      /work/SRC/openSUSE:Factory/.yast2-ntp-client.new.3160 (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Package is "yast2-ntp-client"

Sat Mar 14 09:54:38 2020 rev:119 rq:783568 version:4.2.9

Changes:
--------
--- /work/SRC/openSUSE:Factory/yast2-ntp-client/yast2-ntp-client.changes        
2020-03-01 21:27:00.228433350 +0100
+++ 
/work/SRC/openSUSE:Factory/.yast2-ntp-client.new.3160/yast2-ntp-client.changes  
    2020-03-14 09:54:41.587081629 +0100
@@ -1,0 +2,7 @@
+Tue Mar  3 16:38:54 CET 2020 - [email protected]
+
+- Supporting more than one ntp server in the time setting module.
+  (bsc#1164547)
+- 4.2.9
+
+-------------------------------------------------------------------

Old:
----
  yast2-ntp-client-4.2.8.tar.bz2

New:
----
  yast2-ntp-client-4.2.9.tar.bz2

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Other differences:
------------------
++++++ yast2-ntp-client.spec ++++++
--- /var/tmp/diff_new_pack.NiWpPl/_old  2020-03-14 09:54:43.195082809 +0100
+++ /var/tmp/diff_new_pack.NiWpPl/_new  2020-03-14 09:54:43.199082812 +0100
@@ -17,7 +17,7 @@
 
 
 Name:           yast2-ntp-client
-Version:        4.2.8
+Version:        4.2.9
 Release:        0
 Summary:        YaST2 - NTP Client Configuration
 License:        GPL-2.0-or-later

++++++ yast2-ntp-client-4.2.8.tar.bz2 -> yast2-ntp-client-4.2.9.tar.bz2 ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' 
old/yast2-ntp-client-4.2.8/package/yast2-ntp-client.changes 
new/yast2-ntp-client-4.2.9/package/yast2-ntp-client.changes
--- old/yast2-ntp-client-4.2.8/package/yast2-ntp-client.changes 2020-02-21 
00:15:07.000000000 +0100
+++ new/yast2-ntp-client-4.2.9/package/yast2-ntp-client.changes 2020-03-09 
17:00:02.000000000 +0100
@@ -1,4 +1,11 @@
 -------------------------------------------------------------------
+Tue Mar  3 16:38:54 CET 2020 - [email protected]
+
+- Supporting more than one ntp server in the time setting module.
+  (bsc#1164547)
+- 4.2.9
+
+-------------------------------------------------------------------
 Wed Feb 19 13:24:06 UTC 2020 - Imobach Gonzalez Sosa <[email protected]>
 
 - Rely on the new Y2Network::NtpServer class (jsc#SLE-7188).
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/yast2-ntp-client-4.2.8/package/yast2-ntp-client.spec 
new/yast2-ntp-client-4.2.9/package/yast2-ntp-client.spec
--- old/yast2-ntp-client-4.2.8/package/yast2-ntp-client.spec    2020-02-21 
00:15:07.000000000 +0100
+++ new/yast2-ntp-client-4.2.9/package/yast2-ntp-client.spec    2020-03-09 
17:00:02.000000000 +0100
@@ -17,7 +17,7 @@
 
 
 Name:           yast2-ntp-client
-Version:        4.2.8
+Version:        4.2.9
 Release:        0
 Summary:        YaST2 - NTP Client Configuration
 License:        GPL-2.0-or-later
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' 
old/yast2-ntp-client-4.2.8/src/clients/ntp-client_proposal.rb 
new/yast2-ntp-client-4.2.9/src/clients/ntp-client_proposal.rb
--- old/yast2-ntp-client-4.2.8/src/clients/ntp-client_proposal.rb       
2020-02-21 00:15:07.000000000 +0100
+++ new/yast2-ntp-client-4.2.9/src/clients/ntp-client_proposal.rb       
2020-03-09 17:00:02.000000000 +0100
@@ -126,7 +126,7 @@
     end
 
     def ui_enable_disable_widgets(enabled)
-      UI.ChangeWidget(Id(:ntp_address), :Enabled, enabled)
+      UI.ChangeWidget(Id(:ntp_address), :Enabled, enabled) if select_ntp_server
       UI.ChangeWidget(Id(:run_service), :Enabled, enabled)
       # FIXME: With chronyd, we cannot synchronize if the service is already
       # running, we could force a makestep in this case, but then the button
@@ -172,8 +172,6 @@
     end
 
     def MakeProposal
-      ntp_items = []
-
       # On the running system, read all the data, otherwise firewall and other
       # stuff outside ntp.conf may not be initialized correctly (#375877)
       if !Stage.initial
@@ -185,18 +183,14 @@
         NtpClient.ProcessNtpConf
       end
 
-      if NtpClient.config_has_been_read || NtpClient.ntp_selected
-        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 = configured_ntp_items
-      end
-
-      ntp_items = fallback_ntp_items if ntp_items.empty?
-      # Once read or proposed any config we consider it as read (bnc#427712)
-      NtpClient.config_has_been_read = true
+      if select_ntp_server
+        ntp_items = fallback_ntp_items
+        # Once read or proposed any config we consider it as read (bnc#427712)
+        NtpClient.config_has_been_read = true
 
-      log.info "ntp_items :#{ntp_items}"
-      UI.ChangeWidget(Id(:ntp_address), :Items, ntp_items)
+        log.info "ntp_items :#{ntp_items}"
+        UI.ChangeWidget(Id(:ntp_address), :Items, ntp_items)
+      end
 
       nil
     end
@@ -205,6 +199,29 @@
     # @param [Boolean] first_time when asking for first time, we check if 
service is running
     # @return should our radio button be selected
     def ui_init(replace_point, first_time)
+      if select_ntp_server
+        ntp_server_widget = ComboBox(
+          Id(:ntp_address),
+          Opt(:editable, :hstretch),
+          # TRANSLATORS: combo box label
+          _("&NTP Server Address")
+        )
+      else
+        # Only show all ntp servers
+        text = _("Synchronization Servers:\n").dup
+        counter = (NtpClient.GetUsedNtpServers.size > 3) ? 3 : 
NtpClient.GetUsedNtpServers.size
+        counter.times do |i|
+          text << NtpClient.GetUsedNtpServers[i]
+          text << "\n"
+        end
+        if NtpClient.GetUsedNtpServers.size > 3
+          # TRANSLATOR %{count} number of additional servers
+          text << format(_("... (%{count} more servers)"),
+            count: (NtpClient.GetUsedNtpServers.size - counter))
+        end
+        ntp_server_widget = Label(text)
+      end
+
       cont = VBox(
         VSpacing(0.5),
         HBox(
@@ -212,12 +229,7 @@
           HWeight(
             1,
             Left(
-              ComboBox(
-                Id(:ntp_address),
-                Opt(:editable, :hstretch),
-                # TRANSLATORS: combo box label
-                _("&NTP Server Address")
-              )
+              ntp_server_widget
             )
           ),
           HWeight(
@@ -286,16 +298,20 @@
 
     def AskUser
       ret = nil
-      ntp_server = Convert.to_string(UI.QueryWidget(Id(:ntp_address), :Value))
-      if !ValidateSingleServer(ntp_server)
-        ret = :invalid_hostname
-      else
+      if select_ntp_server
+        # The user can select ONE ntp server.
+        # So we Initialize the ntp client module with the selected ntp server.
+        ntp_server = Convert.to_string(UI.QueryWidget(Id(:ntp_address), 
:Value))
+        return :invalid_hostname unless ValidateSingleServer(ntp_server)
+
         NtpClient.ntp_conf.clear_pools
         NtpClient.ntp_conf.add_pool(ntp_server)
-        retval = Convert.to_boolean(WFM.CallFunction("ntp-client"))
-        ret = :next if retval
-        MakeProposal()
       end
+      # Calling ntp client module.
+      ret = :next if WFM.CallFunction("ntp-client")
+      # Initialize the rest
+      MakeProposal()
+
       ret
     end
 
@@ -353,13 +369,15 @@
       params.compact!
 
       ntp_server  = params.fetch("server", "")
-      ntp_servers = params.fetch("servers", [])
+      ntp_servers = params.fetch("servers", NtpClient.GetUsedNtpServers)
       run_service = params.fetch("run_service", NtpClient.run_service)
 
       # Get the ntp_server value from UI only if isn't present (probably 
wasn't given as parameter)
-      ntp_server = UI.QueryWidget(Id(:ntp_address), :Value) if 
ntp_server.strip.empty?
+      if ntp_server.strip.empty? && select_ntp_server
+        ntp_server = UI.QueryWidget(Id(:ntp_address), :Value) || ""
+      end
 
-      return :invalid_hostname unless ValidateSingleServer(ntp_server)
+      return :invalid_hostname if !ntp_server.empty? && 
!ValidateSingleServer(ntp_server)
 
       add_or_install_required_package unless params["write_only"]
 
@@ -367,11 +385,23 @@
 
       return :success if params["write_only"]
 
-      # Only if network is running try to synchronize the ntp server
+      # Only if network is running try to synchronize
+      # the ntp server.
       if NetworkService.isNetworkRunning && 
!Service.Active(NtpClient.service_name)
-        Popup.ShowFeedback("", _("Synchronizing with NTP server..."))
-        exit_code = NtpClient.sync_once(ntp_server)
-        Popup.ClearFeedback
+        ntp_servers = [ntp_server]
+        if !select_ntp_server
+          # Taking also the rest of the ntp servers, configured in the ntp 
client module.
+          ntp_servers += NtpClient.GetUsedNtpServers unless 
NtpClient.GetUsedNtpServers.nil?
+        end
+        ntp_servers.delete("")
+        ntp_servers.uniq
+        exit_code = 0
+        ntp_servers.each do |server|
+          Popup.ShowFeedback("", _("Synchronizing with NTP server...") + 
server)
+          exit_code = NtpClient.sync_once(server)
+          Popup.ClearFeedback
+          break if exit_code.zero?
+        end
 
         return :ntpdate_failed unless exit_code.zero?
       end
@@ -390,6 +420,8 @@
             UI.QueryWidget(Id(:ntp_address), :Value)
           )
         elsif rv == :next && !Stage.initial
+          # Updating UI for the changed ntp servers
+          ui_init(Id(:rp), false)
           # show the 'save' status after configuration
           UI.ChangeWidget(Id(:ntp_save), :Value, GetNTPEnabled())
         end
@@ -428,8 +460,11 @@
 
       rv = Write(argmap)
 
-      server = Convert.to_string(UI.QueryWidget(Id(:ntp_address), :Value))
+      # The user has not had the possibility to change the ntp server.
+      # So we are done here.
+      return true unless select_ntp_server
 
+      server = Convert.to_string(UI.QueryWidget(Id(:ntp_address), :Value))
       Builtins.y2milestone("ui_try_save argmap %1", argmap)
       if rv == :invalid_hostname
         handle_invalid_hostname(server)
@@ -478,13 +513,6 @@
       end
     end
 
-    # Configured ntp servers Yast::Term items with the ntp address ID and label
-    #
-    # @return [Yast::Term] ntp address table Item
-    def configured_ntp_items
-      NtpClient.GetUsedNtpServers.map { |s| Item(Id(s), s) }
-    end
-
     # Public list of ntp servers Yast::Term items with the ntp address ID and
     # label
     #
@@ -511,16 +539,35 @@
     #
     # @return [Array<Yast::Term>] ntp address table Item
     def fallback_ntp_items
-      dhcp_items = dhcp_ntp_items
+      return @cached_fallback_ntp_items if @cached_fallback_ntp_items
 
-      log.info("Nothing found in /etc/chrony.conf")
-      if dhcp_items.empty?
+      @cached_fallback_ntp_items = dhcp_ntp_items
+      if !@cached_fallback_ntp_items.empty?
+        log.info("Proposing NTP server list provided by DHCP")
+      else
         log.info("Proposing current timezone-based NTP server list")
-        return timezone_ntp_items
+        @cached_fallback_ntp_items = timezone_ntp_items
       end
+      @cached_fallback_ntp_items
+    end
 
-      log.info("Proposing NTP server list provided by DHCP")
-      dhcp_items
+    # Checking if the user can select one ntp server from the list
+    # of proposed servers.
+    # It does not make sense if there are more than one ntp server
+    # defined.
+    #
+    # @return [Boolean] true if the user should select a server
+    def select_ntp_server
+      ret = NtpClient.GetUsedNtpServers.nil? || 
NtpClient.GetUsedNtpServers.empty?
+      # It could be that the user has defined an own ntp server in the 
ntp-client
+      # module which is not defined in the combo box. In that case we do not 
offer
+      # a selection. The user should go back to ntp-client to change it.
+      if NtpClient.GetUsedNtpServers.size == 1
+        ret = fallback_ntp_items.any? do |item|
+          item.params[1] == NtpClient.GetUsedNtpServers.first
+        end
+      end
+      ret
     end
   end
 end
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' 
old/yast2-ntp-client-4.2.8/test/ntp_client_proposal_test.rb 
new/yast2-ntp-client-4.2.9/test/ntp_client_proposal_test.rb
--- old/yast2-ntp-client-4.2.8/test/ntp_client_proposal_test.rb 2020-02-21 
00:15:07.000000000 +0100
+++ new/yast2-ntp-client-4.2.9/test/ntp_client_proposal_test.rb 2020-03-09 
17:00:02.000000000 +0100
@@ -30,7 +30,8 @@
       allow(Yast::NtpClient).to 
receive(:config_has_been_read).and_return(config_was_read?)
       allow(Yast::NtpClient).to 
receive(:ntp_selected).and_return(ntp_was_selected?)
       allow(Yast::NtpClient).to receive(:GetUsedNtpServers)
-        .and_return(["2.opensuse.pool.ntp.org"])
+        .and_return(["de.pool.ntp.org"])
+      allow(subject).to receive(:select_ntp_server).and_return(true)
     end
 
     context "when NTP servers were found via DHCP" do
@@ -68,7 +69,7 @@
         expect(Yast::UI).to receive(:ChangeWidget) do |*args|
           items = args.last
           hostnames = items.map { |i| i[1] }
-          expect(hostnames).to eq(["2.opensuse.pool.ntp.org"])
+          expect(hostnames).to eq(["de.pool.ntp.org"])
         end
         subject.MakeProposal
       end
@@ -81,7 +82,7 @@
         expect(Yast::UI).to receive(:ChangeWidget) do |*args|
           items = args.last
           hostnames = items.map { |i| i[1] }
-          expect(hostnames).to eq(["2.opensuse.pool.ntp.org"])
+          expect(hostnames).to eq(["de.pool.ntp.org"])
         end
         subject.MakeProposal
       end
@@ -105,16 +106,17 @@
 
     before do
       allow(subject).to receive(:WriteNtpSettings)
-
       allow(Yast::Stage).to receive(:initial).and_return(initial_stage)
       allow(Yast::PackageSystem).to receive(:CheckAndInstallPackages)
       allow(Yast::Report).to receive(:Error)
       allow(Yast::NetworkService).to 
receive(:isNetworkRunning).and_return(network_running)
       allow(Yast::Service).to 
receive(:Active).with(ntp_client.service_name).and_return(false)
+      allow(Yast::NtpClient).to receive(:dhcp_ntp_servers).and_return([])
+      allow(Yast::Timezone).to receive(:GetCountryForTimezone).and_return("de")
     end
 
     context "with a not valid hostname" do
-      let(:ntp_server) { nil }
+      let(:ntp_server) { "not_valid" }
 
       it "does not write settings" do
         expect(subject).to_not receive(:WriteNtpSettings)
@@ -213,13 +215,13 @@
         let(:network_running) { true }
 
         it "returns :ntpdate_failed if synchronization fails" do
-          allow(Yast::NtpClient).to 
receive(:sync_once).with(ntp_server).and_return(1)
+          allow(Yast::NtpClient).to receive(:sync_once).and_return(1)
 
           expect(subject.Write(params)).to eq(:ntpdate_failed)
         end
 
         it "returns :success if synchronization was successfully" do
-          allow(Yast::NtpClient).to 
receive(:sync_once).with(ntp_server).and_return(0)
+          allow(Yast::NtpClient).to receive(:sync_once).and_return(0)
 
           expect(subject.Write(params)).to eq(:success)
         end
@@ -251,4 +253,48 @@
       end
     end
   end
+
+  describe "#select_ntp_server" do
+    before do
+      allow(Yast::Timezone).to receive(:GetCountryForTimezone).and_return("de")
+    end
+
+    context "there are already more than one ntp server defined" do
+      it "returns false" do
+        allow(Yast::NtpClient).to 
receive(:GetUsedNtpServers).and_return(["n1", "n2"])
+        expect(subject.send(:select_ntp_server)).to eq(false)
+      end
+    end
+
+    context "there is no ntp server defined" do
+      it "returns true" do
+        allow(Yast::NtpClient).to receive(:GetUsedNtpServers).and_return([])
+        expect(subject.send(:select_ntp_server)).to eq(true)
+      end
+    end
+
+    context "there is ONE ntp server defined" do
+      before do
+        allow(Yast::NtpClient).to receive(:dhcp_ntp_servers).and_return([])
+      end
+
+      context "and defined server is not in the selection list" do
+        it "returns false" do
+          allow(Yast::NtpClient).to 
receive(:GetUsedNtpServers).and_return(["not_found"])
+          expect(subject.send(:select_ntp_server)).to eq(false)
+        end
+      end
+
+      context "and defined server is in the selection list" do
+        it "returns true" do
+          allow(Yast::NtpClient).to 
receive(:GetNtpServersByCountry).and_return(
+            [Item(Id("de.pool.ntp.org"), "de.pool.ntp.org", true)]
+          )
+          allow(Yast::NtpClient).to 
receive(:GetUsedNtpServers).and_return(["de.pool.ntp.org"])
+          expect(subject.send(:select_ntp_server)).to eq(true)
+        end
+      end
+    end
+
+  end
 end


Reply via email to