Skip to content

Commit

Permalink
Merge pull request #653 from yast/ctc-type
Browse files Browse the repository at this point in the history
Recognize CTC devices named like slc600
  • Loading branch information
mvidner committed Dec 8, 2017
2 parents 5f31e6d + 179aa9d commit 020d1b1
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 165 deletions.
131 changes: 17 additions & 114 deletions library/network/src/modules/NetworkInterfaces.rb
Expand Up @@ -41,8 +41,6 @@ class NetworkInterfacesClass < Module
ID_REGEX = "([^#{ALIAS_SEPARATOR}]*)".freeze
ALIAS_REGEX = "(.*)".freeze
DEVNAME_REGEX = "#{TYPE_REGEX}-?#{ID_REGEX}".freeze
# Supported hotplug types
HOTPLUG_TYPES = ["pcmcia", "usb"].freeze

# @attribute Name
# @return [String]
Expand All @@ -68,7 +66,6 @@ def main
Yast.import "Map"
Yast.import "Mode"
Yast.import "Netmask"
Yast.import "TypeRepository"
Yast.import "FileUtils"
Yast.import "IP"

Expand Down Expand Up @@ -104,7 +101,7 @@ def main
@CardRegex =
# other: irlan|lo|plip|...
{
"netcard" => "arc|ath|bnep|ci|ctc|dummy|bond|escon|eth|fddi|ficon|hsi|qeth|lcs|iucv|myri|tr|usb|wlan|xp|vlan|br|tun|tap|ib|em|p|p[0-9]+p",
"netcard" => "arc|ath|bnep|ci|ctc|slc|dummy|bond|escon|eth|fddi|ficon|hsi|qeth|lcs|iucv|myri|tr|usb|wlan|xp|vlan|br|tun|tap|ib|em|p|p[0-9]+p",
"modem" => "ppp|modem",
"isdn" => "isdn|ippp",
"dsl" => "dsl"
Expand All @@ -113,39 +110,18 @@ def main
# Predefined network device regular expressions
@DeviceRegex = {
# device types
"netcard" => Ops.add(
Ops.add(
Ops.get(@CardRegex, "netcard", ""),
HotplugRegex(["ath", "eth", "tr", "wlan"])
),
"|usb-usb|usb-usb-"
),
"modem" => Ops.get(@CardRegex, "modem", ""),
"isdn" => Ops.add(
Ops.get(@CardRegex, "isdn", ""),
HotplugRegex(["isdn", "ippp"])
),
"dsl" => Ops.get(@CardRegex, "dsl", ""),
"netcard" => @CardRegex["netcard"],
"modem" => @CardRegex["modem"],
"isdn" => @CardRegex["isdn"],
"dsl" => @CardRegex["dsl"],
# device groups
"dialup" => Ops.add(
Ops.add(
Ops.add(
Ops.add(Ops.get(@CardRegex, "modem", ""), "|"),
Ops.get(@CardRegex, "dsl", "")
),
"|"
),
Ops.get(@CardRegex, "isdn", "")
)
"dialup" => @CardRegex["modem"] + "|" + @CardRegex["dsl"] + "|" + @CardRegex["isdn"]
}

# Types in order from fastest to slowest.
# @see #FastestRegexps
@FastestTypes = { 1 => "dsl", 2 => "isdn", 3 => "modem", 4 => "netcard" }

# @see #Push
@stack = {}

# -------------------- components of configuration names --------------------

# ifcfg name = type + id + alias_id
Expand Down Expand Up @@ -205,22 +181,8 @@ def main
]
end

# Create a list of hot-pluggable device names for the given devices
def HotplugRegex(devs)
return "" unless devs

ret = ""
devs.each do |dev|
HOTPLUG_TYPES.each do |hot|
ret += "|#{dev}-#{hot}|#{dev}-#{hot}-"
end
end
ret
end

def IsEmpty(value)
value = deep_copy(value)
TypeRepository.IsEmpty(value)
value.nil? ? true : value.empty?
end

def ifcfg_part(ifcfg, part)
Expand Down Expand Up @@ -509,12 +471,10 @@ def alias_name(typ, num, anum)
Builtins.sformat("%1#%2", device_name(typ, num), anum)
end

# Test hotplugability of a device
# @param [String] type device type
# @return true if hotpluggable
def IsHotplug(type)
return false if type == "" || type.nil?
HOTPLUG_TYPES.any? { |t| type.end_with?(t) }
# @deprecated Formerly hotpluggable devices required a special ifcfg name
# @return false
def IsHotplug(_type)
false
end

# Test whether device is connected (Link:up)
Expand All @@ -533,23 +493,18 @@ def IsConnected(dev)
Builtins.deletechars(Ops.get_string(ret, "stdout", ""), "\n") == "1"
end

# @deprecated hotpluggable devices no longer need a special type
# Return real type of the device (incl. PCMCIA, USB, ...)
# @param [String] type basic device type
# @param [String] hotplug hot plug type
# @return real type
# @example RealType("eth", "usb") -> "eth-usb"
def RealType(type, hotplug)
Builtins.y2debug("type=%1", type)
# @example RealType("eth", "usb") -> "eth"
def RealType(type, _hotplug)
if type == "" || type.nil?
Builtins.y2error("Wrong type: %1", type)
return "eth"
end

return type if hotplug == "" || hotplug.nil?

realtype = Ops.add(Ops.add(type, "-"), hotplug)
Builtins.y2debug("realtype=%1", realtype)
realtype
type
end

# ---------------------------------------------------------------------------
Expand Down Expand Up @@ -1391,13 +1346,6 @@ def GetFreeDevices(type, num)
count = 0
ret = []

# Hotpluggable devices
if IsHotplug(type) && !curdevs.include?("")
log.debug("Added simple hotplug device")
count += 1
ret << ""
end

# Remaining numbered devices
while count < num
if !curdevs.include?(i.to_s)
Expand Down Expand Up @@ -1678,29 +1626,9 @@ def LocateNOT(key, val)
ret
end

# Clean the hotplug devices compatibility symlink,
# usually ifcfg-eth-pcmcia -> ifcfg-eth-pcmcia-0.
# @return true if success
# @deprecated No longer needed
# @return true
def CleanHotplugSymlink
types = ["eth-pcmcia", "eth-usb", "tr-pcmcia", "tr-usb"]
Builtins.maplist(types) do |t|
link = Ops.add("/etc/sysconfig/network/ifcfg-", t)
Builtins.y2debug("link=%1", link)
lstat = Convert.to_map(SCR.Read(path(".target.lstat"), link))
if Ops.get_boolean(lstat, "islink", false) == true
file = Convert.to_string(SCR.Read(path(".target.symlink"), link))
file = Ops.add("/etc/sysconfig/network/", file)
Builtins.y2debug("file=%1", file)
if Ops.greater_than(SCR.Read(path(".target.size"), file), -1)
Builtins.y2milestone("Cleaning hotplug symlink")
Builtins.y2milestone("Devices[%1]=%2", t, Ops.get(@Devices, t, {}))
Ops.set(@Devices, t, Builtins.remove(Ops.get(@Devices, t, {}), ""))
Builtins.y2milestone("Devices[%1]=%2", t, Ops.get(@Devices, t, {}))
end
end
end

Builtins.y2debug("Devices=%1", @Devices)
true
end

Expand Down Expand Up @@ -1782,28 +1710,6 @@ def FastestType(name)
ret
end

# DSL needs to save its config while the underlying network card is
# being configured.
def Push
Builtins.y2error("Stack not empty: %1", @stack) if @stack != {}
Ops.set(@stack, "Name", @Name)
Ops.set(@stack, "Current", @Current)
Ops.set(@stack, "operation", @operation)
Builtins.y2milestone("PUSH: %1", @stack)

nil
end

def Pop
Builtins.y2milestone("POP: %1", @stack)
@Name = Ops.get_string(@stack, "Name", "")
@Current = Ops.get_map(@stack, "Current", {})
@operation = Ops.get_symbol(@stack, "operation")
@stack = {}

nil
end

# #46803: forbid "/" (filename), maybe also "-" (separator) "_" (escape)
def ValidCharsIfcfg
String.ValidCharsFilename
Expand Down Expand Up @@ -1854,13 +1760,10 @@ def ListDevicesExcept(dev)
publish function: :SetValue, type: "boolean (string, string, string)"
publish function: :GetIP, type: "list <string> (string)"
publish function: :Locate, type: "list <string> (string, string)"
publish function: :UpdateModemSymlink, type: "boolean ()"
publish function: :CleanHotplugSymlink, type: "boolean ()"
publish function: :List, type: "list <string> (string)"
publish function: :Fastest, type: "string ()"
publish function: :FastestType, type: "string (string)"
publish function: :Push, type: "void ()"
publish function: :Pop, type: "void ()"
publish function: :ValidCharsIfcfg, type: "string ()"
publish function: :ListDevicesExcept, type: "list <string> (string)"
end
Expand Down
19 changes: 0 additions & 19 deletions library/network/test/network_interfaces_test.rb
Expand Up @@ -185,21 +185,6 @@
end
end

describe "IsHotplug" do
it "returns true if given interfaces is a pcmcia interface" do
expect(subject.IsHotplug("eth-pcmcia")).to eql(true)
end
it "returns true if given interfaces is a usb interface" do
expect(subject.IsHotplug("eth-usb")).to eql(true)
end

it "return false otherwise" do
expect(subject.IsHotplug("eth")).to eql(false)
expect(subject.IsHotplug("qeth")).to eql(false)
expect(subject.IsHotplug("br")).to eql(false)
end
end

describe "#GetFreeDevices" do
it "returns an array with available device numbers" do
subject.instance_variable_set(:@Devices, "eth" => { "0" => {} })
Expand All @@ -208,10 +193,6 @@
expect(subject.GetFreeDevices("eth", 2)).to eql(["0", "2"])
subject.instance_variable_set(:@Devices, "eth" => { "2" => {} })
expect(subject.GetFreeDevices("eth", 2)).to eql(["0", "1"])
subject.instance_variable_set(:@Devices, "eth-pcmcia" => { "0" => {} })
expect(subject.GetFreeDevices("eth-pcmcia", 2)).to eql(["", "1"])
subject.instance_variable_set(:@Devices, "eth-pcmcia" => { "" => {} })
expect(subject.GetFreeDevices("eth-pcmcia", 2)).to eql(["0", "1"])
end
end

Expand Down
6 changes: 4 additions & 2 deletions library/types/test/Makefile.am
@@ -1,9 +1,11 @@
TESTS = \
hostname_test.rb \
ip_test.rb \
ipv4_netmask_test.rb \
hostname_test.rb \
string_test.rb \
type_repository_test.rb \
url_test.rb \
string_test.rb
urlrecode_test.rb

TEST_EXTENSIONS = .rb
RB_LOG_COMPILER = rspec
Expand Down
28 changes: 28 additions & 0 deletions library/types/test/type_repository_test.rb
@@ -0,0 +1,28 @@
#!/usr/bin/env rspec

require_relative "test_helper"

Yast.import "TypeRepository"

describe Yast::TypeRepository do
describe "#IsEmpty" do
it "returns true for nil and the empty String, Array, Hash, Term" do
expect(Yast::TypeRepository.IsEmpty(nil)).to eq(true)
expect(Yast::TypeRepository.IsEmpty("")).to eq(true)
expect(Yast::TypeRepository.IsEmpty([])).to eq(true)
expect(Yast::TypeRepository.IsEmpty({})).to eq(true)
expect(Yast::TypeRepository.IsEmpty(HBox())).to eq(true)
end

it "returns false otherwise" do
expect(Yast::TypeRepository.IsEmpty(0)).to eq(false)
expect(Yast::TypeRepository.IsEmpty(0.0)).to eq(false)
expect(Yast::TypeRepository.IsEmpty("item")).to eq(false)
expect(Yast::TypeRepository.IsEmpty(["item"])).to eq(false)
expect(Yast::TypeRepository.IsEmpty("dummy" => "item")).to eq(false)
expect(Yast::TypeRepository.IsEmpty(HBox(Label()))).to eq(false)
expect(Yast::TypeRepository.IsEmpty(false)).to eq(false)
expect(Yast::TypeRepository.IsEmpty(true)).to eq(false)
end
end
end
Empty file.
Empty file.
29 changes: 0 additions & 29 deletions library/types/testsuite/tests/isempty.rb

This file was deleted.

7 changes: 7 additions & 0 deletions package/yast2.changes
@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Fri Dec 8 14:05:59 UTC 2017 - mvidner@suse.com

- Recognize CTC devices named like slc600 (bsc#1058227).
- Stopped treating old-style hotplug devices specially.
- 4.0.25

-------------------------------------------------------------------
Fri Dec 8 11:24:46 UTC 2017 - lslezak@suse.cz

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

Name: yast2
Version: 4.0.24
Version: 4.0.25
Release: 0
Summary: YaST2 - Main Package
License: GPL-2.0
Expand Down

0 comments on commit 020d1b1

Please sign in to comment.