Skip to content

Commit

Permalink
Merge pull request #1076 from yast/merge_SLE-15-SP2
Browse files Browse the repository at this point in the history
Merge SLE-15-SP2 into master
  • Loading branch information
teclator committed Jun 11, 2020
2 parents 8c0ff46 + b4f0773 commit 6f4990e
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 8 deletions.
7 changes: 7 additions & 0 deletions package/yast2-network.changes
@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Thu Jun 11 08:24:34 UTC 2020 - Knut Anderssen <kanderssen@suse.com>

- Try to install the wireless-tools package when the package is
not installed and the wifi networks are scanned (bsc#1168479)
- 4.3.5

-------------------------------------------------------------------
Wed Jun 10 11:10:29 UTC 2020 - José Iván López González <jlopez@suse.com>

Expand Down
2 changes: 1 addition & 1 deletion package/yast2-network.spec
Expand Up @@ -17,7 +17,7 @@


Name: yast2-network
Version: 4.3.4
Version: 4.3.5
Release: 0
Summary: YaST2 - Network Configuration
License: GPL-2.0-only
Expand Down
42 changes: 35 additions & 7 deletions src/lib/y2network/widgets/wireless_essid.rb
Expand Up @@ -22,6 +22,8 @@
require "yast2/feedback"

Yast.import "String"
Yast.import "Package"
Yast.import "Stage"

module Y2Network
module Widgets
Expand Down Expand Up @@ -110,21 +112,47 @@ def label
end

def handle
networks = essid_list
return unless scan_supported?

@update_widget&.update_essid_list(fetch_essid_list)
nil
end

private

IWLIST_PKG = "wireless-tools".freeze

def scan_supported?
return true if install_needed_packages

Yast::Popup.Error(
_("The package %s was not installed. It is needed in order to " \
"be able to scan the network") % IWLIST_PKG
)
false
end

# Require wireless-tools installation in order to be able to scan the
# wlan network (bsc#1112952, bsc#1168479)
#
# TODO: drop it when supported by wicked directly
def install_needed_packages
Yast::Stage.initial ||
Yast::Package.Installed(IWLIST_PKG) ||
Yast::Package.Install(IWLIST_PKG)
end

def fetch_essid_list
networks = []

Yast2::Feedback.show("Obtaining essid list", headline: "Scanning network") do |_f|
networks = essid_list
log.info("Found networks: #{networks}")
end

return unless @update_widget

@update_widget.update_essid_list(networks)
nil
networks
end

private

# TODO: own class and do not call directly in widget.
def essid_list
command = "#{link_up} && #{scan} | #{grep_and_cut_essid} | #{sort}"
Expand Down
53 changes: 53 additions & 0 deletions test/y2network/widgets/wireless_essid_test.rb
Expand Up @@ -29,3 +29,56 @@

include_examples "CWM::CustomWidget"
end

describe Y2Network::Widgets::WirelessScan do
let(:builder) { Y2Network::InterfaceConfigBuilder.for("wlan") }
let(:essid) { Y2Network::Widgets::WirelessEssidName.new(builder) }
let(:installed) { true }
let(:initial_stage) { false }
let(:available_networks) { ["YaST", "Guests"] }
subject { described_class.new(builder, update: essid) }

before do
allow(subject).to receive(:scan_supported?).and_return(installed)
allow(Yast::Package).to receive(:Installed).and_return(installed)
allow(Yast::Stage).to receive(:initial).and_return(initial_stage)
allow(subject).to receive(:fetch_essid_list).and_return(available_networks)
allow(essid).to receive(:update_essid_list)
end

describe "#handle" do
context "when the package for scanning wireless networks is not installed" do
let(:installed) { false }
before do
allow(subject).to receive(:scan_supported?).and_call_original
end

it "tries to install it" do
expect(Yast::Package).to receive(:Install).and_return(true)
subject.handle
end

context "and failed installing the missing package" do
it "returns without scanning the available network" do
allow(Yast::Package).to receive(:Install).and_return(false)
expect(Yast::Popup).to receive(:Error).with(/was not installed/)
expect(subject).to_not receive(:fetch_essid_list)

expect(subject.handle).to eql(nil)
end
end
end

context "when the package for scanning wireless networks is installed" do
it "scans the list of available essids" do
expect(subject).to receive(:fetch_essid_list).and_return(available_networks)
subject.handle
end

it "updates the widget with the list of the available essids with the obtained one" do
expect(essid).to receive(:update_essid_list).with(available_networks)
subject.handle
end
end
end
end

0 comments on commit 6f4990e

Please sign in to comment.