diff --git a/package/yast2-nfs-client.changes b/package/yast2-nfs-client.changes index af98014..7963269 100644 --- a/package/yast2-nfs-client.changes +++ b/package/yast2-nfs-client.changes @@ -1,3 +1,8 @@ +------------------------------------------------------------------- +Fri Feb 4 13:54:00 UTC 2022 - José Iván López González + +- Recover hosts caching (related to fate#318196). + ------------------------------------------------------------------- Wed Feb 2 17:06:10 UTC 2022 - José Iván López González diff --git a/src/include/nfs/ui.rb b/src/include/nfs/ui.rb index c03cc28..64a3629 100644 --- a/src/include/nfs/ui.rb +++ b/src/include/nfs/ui.rb @@ -47,7 +47,6 @@ def initialize_nfs_ui(include_target) Yast.include include_target, "nfs/routines.rb" # Caches names of nfs servers for GetFstabEntry - @hosts = nil # List of already defined nfs mount points @@ -124,7 +123,7 @@ def GetFstabEntry(fstab_ent, existing) nfs.fstopt = "defaults" end - form = Y2NfsClient::Widgets::NfsForm.new(nfs, nfs_entries) + form = Y2NfsClient::Widgets::NfsForm.new(nfs, nfs_entries, hosts: @hosts) return nil unless form.run? UI.OpenDialog( @@ -167,6 +166,8 @@ def GetFstabEntry(fstab_ent, existing) break if [:ok, :cancel].include?(ret) end + @hosts = form.hosts + UI.CloseDialog Wizard.RestoreScreenShotName diff --git a/src/lib/y2nfs_client/widgets/nfs_form.rb b/src/lib/y2nfs_client/widgets/nfs_form.rb index 5b39b99..ddca8c1 100644 --- a/src/lib/y2nfs_client/widgets/nfs_form.rb +++ b/src/lib/y2nfs_client/widgets/nfs_form.rb @@ -32,12 +32,19 @@ module Widgets class NfsForm < CWM::CustomWidget Yast.import "NfsOptions" + # List of cached hosts + # + # @return [Array, nil] + attr_reader :hosts + # Constructor # # @param nfs [Y2Storage::Filesystems::LegacyNfs] Object representing a nfs entry. This object is # modified in #store method. # @param nfs_entries [Array] The rest of entries - def initialize(nfs, nfs_entries) + # @param hosts [Array, nil] List of cached hosts. Passing a list avoids to perform a new + # search. + def initialize(nfs, nfs_entries, hosts: nil) super() Yast.import "Nfs" @@ -56,6 +63,7 @@ def initialize(nfs, nfs_entries) @mount_options = nfs.fstopt || "" @nfs_entries = nfs_entries + @hosts = hosts end # NFS being created or edited @@ -305,8 +313,8 @@ def mount_options_from_widget Yast::UI.QueryWidget(Id(:optionsent), :Value).strip end + # FIXME: Hosts are not correctly found, see bsc#1167589 def handle_choose - # FIXME: @hosts is supposed to be a cache for the whole module execution if @hosts.nil? # label message Yast::UI.OpenDialog(Label(_("Scanning for hosts on this LAN..."))) diff --git a/test/y2nfs_client/widgets/nfs_form_test.rb b/test/y2nfs_client/widgets/nfs_form_test.rb index bd8fb76..558f8b2 100755 --- a/test/y2nfs_client/widgets/nfs_form_test.rb +++ b/test/y2nfs_client/widgets/nfs_form_test.rb @@ -29,7 +29,7 @@ Yast.import "Nfs" describe Y2NfsClient::Widgets::NfsForm do - subject { described_class.new(nfs, nfs_entries) } + subject { described_class.new(nfs, nfs_entries, hosts: hosts) } let(:entry) do { @@ -40,6 +40,7 @@ let(:nfs) { Y2Storage::Filesystems::LegacyNfs.new_from_hash(entry) } let(:nfs_entries) { [] } + let(:hosts) { nil } before do allow(Yast::UI).to receive(:QueryWidget).and_return("") @@ -133,49 +134,64 @@ let(:servers) { ["nfs.example.com"] } - it "scans servers" do - expect(Yast::Nfs).to receive(:ProbeServers) + context "if the list of hosts is unknown" do + let(:hosts) { nil } - subject.handle(event) - end + it "scans servers" do + expect(Yast::Nfs).to receive(:ProbeServers) - context "when scan succeeds" do - let(:servers) { ["nfs1.example.com", "nfs2.example.com"] } + subject.handle(event) + end - context "and the user selects a server" do - let(:input) { :ok } + context "when scan succeeds" do + let(:servers) { ["nfs1.example.com", "nfs2.example.com"] } - let(:server) { servers.first } + context "and the user selects a server" do + let(:input) { :ok } - before do - allow(Yast::UI).to receive(:QueryWidget).with(Id(:items), :CurrentItem).and_return(server) + let(:server) { servers.first } + + before do + allow(Yast::UI).to receive(:QueryWidget).with(Id(:items), :CurrentItem).and_return(server) + end + + it "sets the server selected by the user" do + expect(Yast::UI).to receive(:ChangeWidget).with(Id(:serverent), :Value, server) + + subject.handle(event) + end end - it "sets the server selected by the user" do - expect(Yast::UI).to receive(:ChangeWidget).with(Id(:serverent), :Value, server) + context "and the user cancels the selection" do + let(:input) { :cancel } - subject.handle(event) + it "does not change server" do + expect(Yast::UI).to_not receive(:ChangeWidget).with(Id(:serverent), any_args) + + subject.handle(event) + end end end - context "and the user cancels the selection" do - let(:input) { :cancel } + context "when scan fails" do + let(:servers) { [] } - it "does not change server" do - expect(Yast::UI).to_not receive(:ChangeWidget).with(Id(:serverent), any_args) + it "reports an error" do + expect(Yast::Report).to receive(:Error).with(/No NFS server/) subject.handle(event) end end - end - context "when scan fails" do - let(:servers) { [] } + context "if the list of hosts is already known" do + let(:hosts) { ["nfs.example.com"] } - it "reports an error" do - expect(Yast::Report).to receive(:Error).with(/No NFS server/) + it "does not scan servers" do + expect(Yast::Nfs).to_not receive(:ProbeServers) + + subject.handle(event) + end - subject.handle(event) end end end