Skip to content

Commit

Permalink
Merge pull request #1046 from yast/merge_SLE-15-SP1
Browse files Browse the repository at this point in the history
Merge 'SLE-15-SP1' into 'master'
  • Loading branch information
teclator committed Apr 13, 2020
2 parents 90d517f + 00dd4c6 commit fe1f0f8
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 6 deletions.
41 changes: 36 additions & 5 deletions library/network/src/modules/NetworkInterfaces.rb
Expand Up @@ -801,12 +801,11 @@ def Write(devregex)

# remove deleted devices
log.info("Deleted=#{@Deleted}")
Builtins.foreach(@Deleted) do |d|
# delete config file
p = Builtins.add(path(".network.section"), d)
log.debug("deleting: #{p}")
SCR.Write(p, nil)
@Deleted.each do |d|
iface, alias_num = d.split("#")
alias_num ? delete_alias(original_devs, iface, alias_num) : delete_device(iface)
end

@Deleted = []

# write all devices
Expand Down Expand Up @@ -1537,6 +1536,38 @@ def get_devices(devregex)
devices
end

# Convenience method to delete an interface config file from the system
#
# @param iface [String] interface name of the config file to be deleted
def delete_device(iface)
p = path(".network.section") + iface
log.debug("deleting: #{p}")
SCR.Write(p, nil)
end

# Convenience method to delete an specific ip alias from an interface
# config file
#
# @param devices [Hash<String, Hash<String, Object>>] hash with the devices
# to remove the aliases from
# @param iface [String] interface name of the alias which alias need to be
# removed
# @param alias_num [String] index num of the alias that needs to be removed
def delete_alias(devices, iface, alias_num)
dev_map = devices.values.find { |d| d.keys.include?(iface) } || {}
dev_aliases = dev_map.fetch(iface, {}).fetch("_aliases", {})

base = path(".network.value") + iface
# look in OriginalDevs because we need to catch all variables
# of the alias

dev_aliases.fetch(alias_num, {}).keys.each do |key|
p = base + "#{key}_#{alias_num}"
log.debug("deleting: #{p}")
SCR.Write(p, nil)
end
end

publish variable: :Name, type: "string"
publish variable: :Current, type: "map <string, any>"
publish variable: :CardRegex, type: "map <string, string>"
Expand Down
17 changes: 17 additions & 0 deletions library/network/test/network_interfaces_test.rb
Expand Up @@ -322,15 +322,20 @@ def mock_ppp
let(:network_path) { File.join(data_dir, "etc/sysconfig/network") }
let(:ifcfg_copy) { File.join(network_path, "ifcfg-copy") }
let(:ifcfg_file) { File.join(network_path, "ifcfg-eth1") }
let(:eth0_back) { File.join(network_path, "ifcfg-eth0.backup") }
let(:eth0) { File.join(network_path, "ifcfg-eth0") }

before do
subject.CleanCacheRead()
end

around do |example|
::FileUtils.cp(ifcfg_file, ifcfg_copy)
::FileUtils.cp(eth0, eth0_back)
change_scr_root(data_dir, &example)
::FileUtils.cp(eth0_back, eth0)
::FileUtils.rm(ifcfg_copy)
::FileUtils.rm(eth0_back)
end

context "when the configuration has changed" do
Expand Down Expand Up @@ -364,6 +369,18 @@ def mock_ppp
subject.Write("")
expect(subject.List("").size).to eq(size - 1)
end

it "deletes removed aliases" do
devmap = subject.devmap("eth0")
expect(devmap["_aliases"].size).to eq(1)
subject.Edit("eth0")
subject.Current["_aliases"] = {}
subject.Commit()
subject.DeleteAlias("eth0", "0")
subject.Write("")
devmap = subject.devmap("eth0")
expect(devmap["_aliases"]).to be(nil)
end
end
end
end
7 changes: 7 additions & 0 deletions package/yast2.changes
@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Mon Apr 13 12:36:58 UTC 2020 - Knut Anderssen <kanderssen@suse.com>

- Remove ip aliases that were marked to be deleted from the
interface configuration files (bsc#1146020)
- 4.2.82

-------------------------------------------------------------------
Tue Apr 7 08:33:55 UTC 2020 - Stefan Hundhammer <shundhammer@suse.com>

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


Name: yast2
Version: 4.2.81
Version: 4.2.82
Release: 0
Summary: YaST2 Main Package
License: GPL-2.0-only
Expand Down

0 comments on commit fe1f0f8

Please sign in to comment.