Skip to content

Commit

Permalink
Merge pull request #106 from joseivanlopez/cache-hosts
Browse files Browse the repository at this point in the history
Cache hosts
  • Loading branch information
joseivanlopez committed Feb 7, 2022
2 parents ad416de + bfcbaaf commit a50bdc9
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 29 deletions.
5 changes: 5 additions & 0 deletions package/yast2-nfs-client.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
-------------------------------------------------------------------
Fri Feb 4 13:54:00 UTC 2022 - José Iván López González <jlopez@suse.com>

- Recover hosts caching (related to fate#318196).

-------------------------------------------------------------------
Wed Feb 2 17:06:10 UTC 2022 - José Iván López González <jlopez@suse.com>

Expand Down
5 changes: 3 additions & 2 deletions src/include/nfs/ui.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -167,6 +166,8 @@ def GetFstabEntry(fstab_ent, existing)
break if [:ok, :cancel].include?(ret)
end

@hosts = form.hosts

UI.CloseDialog
Wizard.RestoreScreenShotName

Expand Down
12 changes: 10 additions & 2 deletions src/lib/y2nfs_client/widgets/nfs_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,19 @@ module Widgets
class NfsForm < CWM::CustomWidget
Yast.import "NfsOptions"

# List of cached hosts
#
# @return [Array<String>, 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<Y2Storage::Filesystems::LegacyNfs>] The rest of entries
def initialize(nfs, nfs_entries)
# @param hosts [Array<String>, 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"
Expand All @@ -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
Expand Down Expand Up @@ -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...")))
Expand Down
66 changes: 41 additions & 25 deletions test/y2nfs_client/widgets/nfs_form_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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("")
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a50bdc9

Please sign in to comment.