Skip to content

Commit

Permalink
Merge pull request #543 from mchf/backported
Browse files Browse the repository at this point in the history
Backported code from the current master
  • Loading branch information
mchf committed Mar 9, 2017
2 parents b807edb + c15998c commit 8dfd1fc
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ before_install:
# disable rvm, use system Ruby
- rvm reset
- wget https://raw.githubusercontent.com/yast/yast-devtools/master/travis-tools/travis_setup.sh
- sh ./travis_setup.sh -p "rake yast2-core yast2-devtools yast2-testsuite yast2-ruby-bindings yast2 yast2-pkg-bindings" -g "rspec:3.3.0 yast-rake gettext simplecov coveralls rubocop:0.29.1"
- sh ./travis_setup.sh -p "rake yast2-core yast2-devtools yast2-testsuite yast2-ruby-bindings yast2 yast2-pkg-bindings" -g "rspec:3.3.0 yast-rake gettext coveralls rubocop:0.29.1"
script:
- rake check:pot
- rubocop
Expand Down
23 changes: 17 additions & 6 deletions library/network/src/modules/NetworkInterfaces.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ module Yast
# Categorizes the configurations according to type.
# Presents them one ifcfg at a time through the {#Current} hash.
class NetworkInterfacesClass < Module
include Logger

Yast.import "String"

# A single character used to separate alias id
Expand Down Expand Up @@ -681,6 +683,20 @@ def ConcealSecrets(devs)
deep_copy(out)
end

# Get current sysconfig configured interfaces
#
# @param devregex [String] regex to filter by
# @return [Array] of ifcfg names
def get_devices(devregex = "[~]")
devices = SCR.Dir(path(".network.section")) || []

devices.select! { |file| file !~ /#{devregex}/ } unless devregex.nil? && devregex.empty?
devices.delete_if(&:empty?)

log.debug "devices=#{devices}"
devices
end

# Variables which could be suffixed and thus duplicated
LOCALS = [
"IPADDR",
Expand All @@ -701,12 +717,7 @@ def Read
@Devices = {}

# preparation
allfiles = SCR.Dir(path(".network.section"))
allfiles = [] if allfiles.nil?
devices = Builtins.filter(allfiles) do |file|
!Builtins.regexpmatch(file, "[~]")
end
Builtins.y2debug("devices=%1", devices)
devices = get_devices

# Read devices
Builtins.maplist(devices) do |d|
Expand Down
2 changes: 2 additions & 0 deletions library/network/test/data/etc/sysconfig/network/ifcfg-
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
STARTMODE="auto"
BOOTPROTO="dhcp"
42 changes: 42 additions & 0 deletions library/network/test/network_interfaces_helpers_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,47 @@ module Yast
expect(NetworkInterfaces.filter_interfacetype("INTERFACETYPE" => "dummy")).to include "INTERFACETYPE"
end
end

describe "#get_devices" do
let(:data_dir) { File.join(File.dirname(__FILE__), "data") }
# MOCKED IN test/data/etc/sysconfig/ifcfg*
let(:devices) do
["arc5", "bond0", "br1", "em1", "eth0", "eth1", "ppp0", "tr~", "vlan3"]
end

around do |example|
change_scr_root(data_dir, &example)
end

before do
subject.main
allow(subject).to receive(:Read).and_return(true)
allow(Yast::SCR).to receive(:Dir).with(Yast::Path.new(".network.section")).and_return(devices)
end

it "returns an array of configured interfaces filtered by regexp" do
expect(subject.get_devices("1")).not_to include "em1", "eth1", "br1"
end

it "filters with <[~]> by default" do
expect(subject.get_devices).not_to include "tr~"
end

it "returns an empty array with <.> argument" do
expect(subject.get_devices(".")).to eql []
end

it "returns all devices filtering with <''>" do
expect(subject.get_devices("")).to eql devices
end

it "does not crash with exception" do
expect { subject.get_devices }.not_to raise_error
end

it "doesn't carry empty strings" do
expect(subject.get_devices).not_to include ""
end
end
end
end
1 change: 0 additions & 1 deletion library/types/test/url_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
end
end


context "given a Samba device and a path" do
let(:samba_url) { "smb://username:passwd@servername/share/path/on/the/share?mountoptions=ro&workgroup=group" }
it "returns samba host" do
Expand Down
10 changes: 10 additions & 0 deletions package/yast2.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
-------------------------------------------------------------------
Thu Jan 5 11:35:23 UTC 2017 - mfilka@suse.com

- bnc#1017716
- do not cache ifcfg files with empty device name part (ifcfg-).
Such file cannot be mapped to any existing device and providing
empty device name could lead to unexpected crashes in other
parts of yast.
- 3.1.155.6

-------------------------------------------------------------------
Tue Oct 18 16:43:25 CEST 2016 - schubi@suse.de

Expand Down
2 changes: 1 addition & 1 deletion package/yast2.spec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


Name: yast2
Version: 3.1.155.5
Version: 3.1.155.6
Release: 0
Url: https://github.com/yast/yast-yast2

Expand Down

0 comments on commit 8dfd1fc

Please sign in to comment.