Skip to content

Commit

Permalink
Refactoring: dropped LanItems#UnsetModified function
Browse files Browse the repository at this point in the history
  • Loading branch information
mchf committed Sep 23, 2015
1 parent 4435239 commit d9b5900
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
1 change: 0 additions & 1 deletion src/clients/lan_auto.rb
Expand Up @@ -83,7 +83,6 @@ def main
@ret = Ops.get_string(Lan.Summary("summary"), 0, "")
elsif @func == "Reset"
Lan.Import({})
LanItems.UnsetModified
@ret = {}
elsif @func == "Change"
@ret = LanAutoSequence("")
Expand Down
30 changes: 18 additions & 12 deletions src/modules/LanItems.rb
Expand Up @@ -59,9 +59,10 @@ def main
Yast.include self, "network/lan/udev.rb"
Yast.include self, "network/lan/bridge.rb"

reset_cache

# Hardware information
# @see #ReadHardware
@Items = {}
@Hardware = []
@udev_net_rules = {}
@driver_options = {}
Expand All @@ -70,7 +71,6 @@ def main
@autoinstall_settings = {}

# Data was modified?
@modified = false
# current selected HW
@hw = {}

Expand Down Expand Up @@ -731,13 +731,6 @@ def SetModified

nil
end
# Function sets internal variable, which indicates, that any
# settings were modified, to "false"
def UnsetModified
@modified = false

nil
end

def AddNew
@current = @Items.to_h.size
Expand Down Expand Up @@ -1088,6 +1081,19 @@ def Read
nil
end

# Clears internal cache of the module to default values
#
# TODO: LanItems consists of several sets of internal variables.
# 1) cache of items describing network interface
# 2) variables used as a kind of iterator in the cache
# 3) variables which keeps (some of) attributes of the current item (= item
# which is being pointed by the iterator)
def reset_cache
LanItems.Items = {}

@modified = false
end

# Imports data from AY profile
#
# As network related configuration is spread over the whole AY profile
Expand All @@ -1096,7 +1102,7 @@ def Read
# @param [Hash] AY profile converted into hash
# @return [Boolean] on success
def Import(settings)
LanItems.Items = {}
reset_cache

NetworkInterfaces.Import("netcard", settings["devices"] || {})
NetworkInterfaces.List("netcard").each do |device|
Expand All @@ -1108,7 +1114,8 @@ def Import(settings)
autoinstall_settings["strict_IP_check_timeout"] = settings["strict_IP_check_timeout"] || -1
autoinstall_settings["keep_install_network"] = settings["keep_install_network"] || false

SetModified()
# settings == {} has special meaning 'Reset' used by AY
SetModified() if !settings.empty?

true
end
Expand Down Expand Up @@ -2648,7 +2655,6 @@ def s390_correct_lladdr(lladdr)
publish :function => :WriteUdevRules, :type => "void ()"
publish :function => :GetModified, :type => "boolean ()"
publish :function => :SetModified, :type => "void ()"
publish :function => :UnsetModified, :type => "void ()"
publish :function => :AddNew, :type => "void ()"
publish :function => :GetItemModules, :type => "list <string> (string)"
publish :function => :GetSlaveCandidates, :type => "list <integer> (string, boolean (string, integer))"
Expand Down
4 changes: 4 additions & 0 deletions test/lan_test.rb
Expand Up @@ -155,7 +155,11 @@
}

expect(Yast::Lan.Import(AY_PROFILE)).to be true
expect(Yast::LanItems.GetModified).to be true
expect(Yast::LanItems.Items).not_to be_empty

expect(Yast::Lan.Import({})).to be true
expect(Yast::LanItems.GetModified).to be false
expect(Yast::LanItems.Items).to be_empty
end
end

0 comments on commit d9b5900

Please sign in to comment.