Hello community, here is the log from the commit of package yast2-network for openSUSE:Factory checked in at 2020-10-18 16:20:23 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/yast2-network (Old) and /work/SRC/openSUSE:Factory/.yast2-network.new.3486 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "yast2-network" Sun Oct 18 16:20:23 2020 rev:434 rq:840404 version:4.3.26 Changes: -------- --- /work/SRC/openSUSE:Factory/yast2-network/yast2-network.changes 2020-09-24 16:13:58.140882115 +0200 +++ /work/SRC/openSUSE:Factory/.yast2-network.new.3486/yast2-network.changes 2020-10-18 16:20:28.760465669 +0200 @@ -1,0 +2,28 @@ +Wed Oct 7 11:45:04 UTC 2020 - Knut Anderssen <kanders...@suse.com> + +- Write hostname changes when modified through the 'dns' client + (bsc#1177191). +- 4.3.26 + +------------------------------------------------------------------- +Mon Oct 5 11:28:46 UTC 2020 - Knut Anderssen <kanders...@suse.com> + +- Modified the way the current hostnames are (static & transient) + read and write (bsc#1173915) +- 4.3.25 + +------------------------------------------------------------------- +Mon Sep 28 13:44:08 UTC 2020 - Knut Anderssen <kanders...@suse.com> + +- Write the virtualization network configuration properly during an + autoinstallation (bsc#1177025) +- 4.3.24 + +------------------------------------------------------------------- +Thu Sep 24 15:20:15 UTC 2020 - Knut Anderssen <kanders...@suse.com> + +- Fixed initialization of the bridge STP configuration + (bsc#1176820) +- 4.3.23 + +------------------------------------------------------------------- Old: ---- yast2-network-4.3.22.tar.bz2 New: ---- yast2-network-4.3.26.tar.bz2 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ yast2-network.spec ++++++ --- /var/tmp/diff_new_pack.XigcCo/_old 2020-10-18 16:20:30.384466392 +0200 +++ /var/tmp/diff_new_pack.XigcCo/_new 2020-10-18 16:20:30.384466392 +0200 @@ -17,7 +17,7 @@ Name: yast2-network -Version: 4.3.22 +Version: 4.3.26 Release: 0 Summary: YaST2 - Network Configuration License: GPL-2.0-only ++++++ yast2-network-4.3.22.tar.bz2 -> yast2-network-4.3.26.tar.bz2 ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yast2-network-4.3.22/package/yast2-network.changes new/yast2-network-4.3.26/package/yast2-network.changes --- old/yast2-network-4.3.22/package/yast2-network.changes 2020-09-21 15:34:06.000000000 +0200 +++ new/yast2-network-4.3.26/package/yast2-network.changes 2020-10-08 16:19:16.000000000 +0200 @@ -1,4 +1,32 @@ ------------------------------------------------------------------- +Wed Oct 7 11:45:04 UTC 2020 - Knut Anderssen <kanders...@suse.com> + +- Write hostname changes when modified through the 'dns' client + (bsc#1177191). +- 4.3.26 + +------------------------------------------------------------------- +Mon Oct 5 11:28:46 UTC 2020 - Knut Anderssen <kanders...@suse.com> + +- Modified the way the current hostnames are (static & transient) + read and write (bsc#1173915) +- 4.3.25 + +------------------------------------------------------------------- +Mon Sep 28 13:44:08 UTC 2020 - Knut Anderssen <kanders...@suse.com> + +- Write the virtualization network configuration properly during an + autoinstallation (bsc#1177025) +- 4.3.24 + +------------------------------------------------------------------- +Thu Sep 24 15:20:15 UTC 2020 - Knut Anderssen <kanders...@suse.com> + +- Fixed initialization of the bridge STP configuration + (bsc#1176820) +- 4.3.23 + +------------------------------------------------------------------- Mon Sep 21 13:15:39 UTC 2020 - Ladislav Slezák <lsle...@suse.cz> - Fixed false error in the y2log (bsc#1176653) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yast2-network-4.3.22/package/yast2-network.spec new/yast2-network-4.3.26/package/yast2-network.spec --- old/yast2-network-4.3.22/package/yast2-network.spec 2020-09-21 15:34:06.000000000 +0200 +++ new/yast2-network-4.3.26/package/yast2-network.spec 2020-10-08 16:19:16.000000000 +0200 @@ -17,7 +17,7 @@ Name: yast2-network -Version: 4.3.22 +Version: 4.3.26 Release: 0 Summary: YaST2 - Network Configuration License: GPL-2.0-only diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yast2-network-4.3.22/src/clients/dns.rb new/yast2-network-4.3.26/src/clients/dns.rb --- old/yast2-network-4.3.22/src/clients/dns.rb 2020-09-21 15:34:06.000000000 +0200 +++ new/yast2-network-4.3.26/src/clients/dns.rb 2020-10-08 16:19:16.000000000 +0200 @@ -1,284 +1,3 @@ -# *************************************************************************** -# -# Copyright (c) 2012 Novell, Inc. -# All Rights Reserved. -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of version 2 of the GNU General Public License as -# published by the Free Software Foundation. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, contact Novell, Inc. -# -# To contact Novell about this file by physical or electronic mail, -# you may find current contact information at www.novell.com -# -# ************************************************************************** -# File: clients/dns.ycp -# Package: Network configuration -# Summary: Hostname and DNS client -# Authors: Michal Svec <ms...@suse.cz> -# -# -# Main file for hostname and DNS configuration. -# Uses all other files. -module Yast - class DnsClient < Client - def main - Yast.import "UI" +require "y2network/clients/dns" - textdomain "network" - - # The main () - Builtins.y2milestone("----------------------------------------") - Builtins.y2milestone("DNS module started") - - Yast.import "DNS" - Yast.import "Label" - Yast.import "Lan" - Yast.import "NetworkService" - Yast.import "Wizard" - - Yast.import "CommandLine" - Yast.import "RichText" - - Yast.include self, "network/services/dns.rb" - - @hostname = "hostname" - @nameserver1 = "nameserver1" - @nameserver2 = "nameserver2" - @nameserver3 = "nameserver3" - - # Command line definition - @cmdline = { - # Commandline help title - "help" => _("DNS Configuration"), - "id" => "dns", - "guihandler" => fun_ref(method(:DNSGUI), "any ()"), - "initialize" => fun_ref(method(:InitHandler), "boolean ()"), - "finish" => fun_ref(method(:FinishHandler), "boolean ()"), - "actions" => { - "list" => { - # Commandline command help - "help" => _( - "Display configuration summary" - ), - "handler" => fun_ref( - method(:ListHandler), - "boolean (map <string, string>)" - ) - }, - "edit" => { - "help" => _("Edit current settings"), - "handler" => fun_ref( - method(:EditHandler), - "boolean (map <string, string>)" - ) - } - }, - "options" => { - @hostname => { - "help" => _("Used machine hostname"), - "type" => "string", - "example" => "dns edit hostname=SUSE-host" - }, - @nameserver1 => { - "help" => _("IP address of first nameserver."), - "type" => "string", - "example" => "dns edit nameserver1=192.168.0.1" - }, - @nameserver2 => { - "help" => _("IP address of second nameserver."), - "type" => "string", - "example" => "dns edit nameserver2=192.168.0.1" - }, - @nameserver3 => { - "help" => _("IP address of third nameserver."), - "type" => "string", - "example" => "dns edit nameserver3=192.168.0.1" - } - }, - "mappings" => { - "edit" => [@hostname, @nameserver1, @nameserver2, @nameserver3] - } - } - - @ret = CommandLine.Run(@cmdline) - Builtins.y2debug("ret=%1", @ret) - - # Finish - Builtins.y2milestone("DNS module finished") - Builtins.y2milestone("----------------------------------------") - deep_copy(@ret) - - # EOF - end - - # Return a modification status - # @return true if data was modified - def Modified - DNS.modified - end - - # Main DNS GUI - def DNSGUI - Wizard.CreateDialog - Wizard.SetDesktopTitleAndIcon("dns") - DNS.Read - Lan.Read(:cache) - - Wizard.SetNextButton(:next, Label.FinishButton) - - # main ui function - ret = DNSMainDialog(true) - Builtins.y2debug("ret == %1", ret) - - if ret == :next && DNS.modified - DNS.Write - # no more workarounds with dhcp-clients - # do a full network restart (bnc#528937) - NetworkService.StartStop - end - - UI.CloseDialog - deep_copy(ret) - end - - # Handler for action "list" - # @param _options [Hash{String => String}] action options - def ListHandler(_options) - # Command line output Headline - summary = Ops.add( - Ops.add( - "\n" + _("DNS Configuration Summary:") + "\n\n", - RichText.Rich2Plain(DNS.Summary) - ), - "\n" - ) - - Builtins.y2debug("%1", summary) - CommandLine.Print(summary) - true - end - - # Handler for action "edit" - # @param [Hash{String => String}] options action options - # @return [Boolean] if successful - def EditHandler(options) - options = deep_copy(options) - Builtins.y2milestone("Edit handler, options: %1", options) - - # validator: a reference to boolean( string) is expected - # setter: a reference to void( any) is expected - # fail message: a string is expected - option_handlers = { - @hostname => { - "validator" => fun_ref(Hostname.method(:Check), "boolean (string)"), - "setter" => fun_ref(method(:SetHostname), "void (any)"), - "fail_message" => Ops.add(_("InvalidHostname. "), Hostname.ValidHost) - }, - @nameserver1 => { - "validator" => fun_ref(IP.method(:Check), "boolean (string)"), - "setter" => fun_ref(method(:SetNameserver1), "void (any)"), - "fail_message" => Ops.add( - Ops.add(Ops.add(_("Invalid IP. "), IP.Valid4), "\n"), - IP.Valid6 - ) - }, - @nameserver2 => { - "validator" => fun_ref(IP.method(:Check), "boolean (string)"), - "setter" => fun_ref(method(:SetNameserver2), "void (any)"), - "fail_message" => Ops.add( - Ops.add(Ops.add(_("Invalid IP. "), IP.Valid4), "\n"), - IP.Valid6 - ) - }, - @nameserver3 => { - "validator" => fun_ref(IP.method(:Check), "boolean (string)"), - "setter" => fun_ref(method(:SetNameserver3), "void (any)"), - "fail_message" => Ops.add( - Ops.add(Ops.add(_("Invalid IP. "), IP.Valid4), "\n"), - IP.Valid6 - ) - } - } - - unmanaged_only_options = [@nameserver1, @nameserver2, @nameserver3] - - ret = true - - Builtins.foreach(options) do |option, value| - if Builtins.contains(unmanaged_only_options, option) && - NetworkService.is_network_manager - CommandLine.Print( - Ops.add( - Ops.add(_("Cannot set "), option), - _(". Network is managed by NetworkManager.") - ) - ) - - ret = false - end - option_validator = Convert.convert( - Ops.get(option_handlers, [option, "validator"]), - from: "any", - to: "boolean (string)" - ) - option_setter = Convert.convert( - Ops.get(option_handlers, [option, "setter"]), - from: "any", - to: "void (any)" - ) - fail_message = Ops.get_locale( - option_handlers, - [option, "fail_message"], - _("Invalid option value.") - ) - if option_validator.nil? || option_setter.nil? - Builtins.y2internal( - "Edit handler: unknown option (%1=%2) or unknown option handlers", - option, - value - ) - - CommandLine.Print(_("Internal error")) - - ret = false - end - if option_validator.call(value) - option_setter.call(value) - else - CommandLine.Print(fail_message) - ret = false - end - end - - ret - end - - # CLI mode initialization handler - # @return [Boolean] if successful - def InitHandler - return false if !DNS.Read || !Lan.Read(:cache) - - InitHnSettings() - - true - end - - # CLI mode finish handler - # @return [Boolean] if successful - def FinishHandler - StoreHnSettings() - - DNS.Write - end - end -end - -Yast::DnsClient.new.main +Y2Network::Clients::DNS.new.main diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yast2-network-4.3.22/src/lib/network/clients/inst_setup_dhcp.rb new/yast2-network-4.3.26/src/lib/network/clients/inst_setup_dhcp.rb --- old/yast2-network-4.3.22/src/lib/network/clients/inst_setup_dhcp.rb 2020-09-21 15:34:06.000000000 +0200 +++ new/yast2-network-4.3.26/src/lib/network/clients/inst_setup_dhcp.rb 2020-10-08 16:19:16.000000000 +0200 @@ -43,8 +43,6 @@ log.info("Network is not managed by wicked, skipping DHCP setup") end - # if this is not wrapped in a def, ruby -cw says - # warning: possibly useless use of a literal in void context :next end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yast2-network-4.3.22/src/lib/network/network_autoconfiguration.rb new/yast2-network-4.3.26/src/lib/network/network_autoconfiguration.rb --- old/yast2-network-4.3.22/src/lib/network/network_autoconfiguration.rb 2020-09-21 15:34:06.000000000 +0200 +++ new/yast2-network-4.3.26/src/lib/network/network_autoconfiguration.rb 2020-10-08 16:19:16.000000000 +0200 @@ -91,6 +91,10 @@ end activate_changes(dhcp_cards.map(&:name)) + + # Force a read of the configuration just for reading the transient + # hostname as it could be modified through dhcp since previous read. + Lan.read_config end # Propose configuration for virtual devices @@ -109,7 +113,7 @@ # wait for rebooting into just installed target return if Lan.yast_config == Lan.system_config - Lan.yast_config.write + Lan.write_config end # Propose DNS and Hostname setup @@ -152,16 +156,12 @@ config.delete_interface(interface.name) end - def write_configuration - config.write - end - # Writes and activates changes in devices configurations # # @param devnames [Array] list of device names # @return true when changes were successfully applied def activate_changes(devnames) - write_configuration + Lan.write_config reload_config(devnames) end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yast2-network-4.3.22/src/lib/network/wicked.rb new/yast2-network-4.3.26/src/lib/network/wicked.rb --- old/yast2-network-4.3.22/src/lib/network/wicked.rb 2020-09-21 15:34:06.000000000 +0200 +++ new/yast2-network-4.3.26/src/lib/network/wicked.rb 2020-10-08 16:19:16.000000000 +0200 @@ -50,9 +50,7 @@ # @return [String] hostname def parse_hostname(iface) result = query_wicked(iface, "//hostname") - - raise "Malformed wicked runtime configuration" if result.count > 1 - + # If there is more than one just pick the first one result.first end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yast2-network-4.3.22/src/lib/y2network/clients/dns.rb new/yast2-network-4.3.26/src/lib/y2network/clients/dns.rb --- old/yast2-network-4.3.22/src/lib/y2network/clients/dns.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/yast2-network-4.3.26/src/lib/y2network/clients/dns.rb 2020-10-08 16:19:16.000000000 +0200 @@ -0,0 +1,283 @@ +# Copyright (c) [2020] SUSE LLC +# +# All Rights Reserved. +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of version 2 of the GNU General Public License as published +# by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, contact SUSE LLC. +# +# To contact SUSE LLC about this file by physical or electronic mail, you may +# find current contact information at www.suse.com. + +require "yast" +require "y2network/config" + +Yast.import "DNS" +Yast.import "Label" +Yast.import "Lan" +Yast.import "NetworkService" +Yast.import "Wizard" + +Yast.import "CommandLine" +Yast.import "RichText" + +module Y2Network + module Clients + # DNS client for configuring DNS and hostname settings + class DNS < Yast::Client + include Yast::Logger + + attr_reader :hostname, :nameserver1, :nameserver2, :nameserver3 + + # Constructor + def initialize + textdomain "network" + Yast.include self, "network/services/dns.rb" + + @hostname = "hostname" + @nameserver1 = "nameserver1" + @nameserver2 = "nameserver2" + @nameserver3 = "nameserver3" + end + + def main + log_and_return { CommandLine.Run(cmdline_definition) } + end + + private + + # Main DNS GUI + def DNSGUI + Wizard.CreateDialog + Wizard.SetDesktopTitleAndIcon("dns") + read_config + + Wizard.SetNextButton(:next, Label.FinishButton) + + # main ui function + ret = DNSMainDialog(true) + log.debug("ret == #{ret}") + + if (ret == :next) && modified? + write_config + + # no more workarounds with dhcp-clients + # do a full network restart (bnc#528937) + Yast::NetworkService.StartStop + end + + UI.CloseDialog + ret + end + + def modified? + Yast::Lan.system_config != Yast::Lan.yast_config + end + + def valid_hostname?(value) + value.empty? || Yast::Hostname.Check(value.tr(".", "")) + end + + def config + Yast::Lan.yast_config + end + + def log_and_return(&block) + # The main () + log.info("----------------------------------------") + log.info("Dns module started") + ret = block.call + # Finish + log.info("Dns module finished with ret=#{ret.inspect}") + log.info("----------------------------------------") + ret + end + + def cmdline_definition + { + # Commandline help title + "help" => _("DNS Configuration"), + "id" => "dns", + "guihandler" => fun_ref(method(:DNSGUI), "any ()"), + "initialize" => fun_ref(method(:InitHandler), "boolean ()"), + "finish" => fun_ref(method(:FinishHandler), "boolean ()"), + "actions" => { + "list" => { + # Commandline command help + "help" => _( + "Display configuration summary" + ), + "handler" => fun_ref( + method(:ListHandler), + "boolean (map <string, string>)" + ) + }, + "edit" => { + "help" => _("Edit current settings"), + "handler" => fun_ref( + method(:EditHandler), + "boolean (map <string, string>)" + ) + } + }, + "options" => { + hostname => { + "help" => _("Used machine hostname"), + "type" => "string", + "example" => "dns edit hostname=SUSE-host" + }, + nameserver1 => { + "help" => _("IP address of first nameserver."), + "type" => "string", + "example" => "dns edit nameserver1=192.168.0.1" + }, + nameserver2 => { + "help" => _("IP address of second nameserver."), + "type" => "string", + "example" => "dns edit nameserver2=192.168.0.1" + }, + nameserver3 => { + "help" => _("IP address of third nameserver."), + "type" => "string", + "example" => "dns edit nameserver3=192.168.0.1" + } + }, + "mappings" => { + "edit" => [hostname, nameserver1, nameserver2, nameserver3] + } + } + end + + def option_handlers + { + hostname => { + "validator" => fun_ref(method(:valid_hostname?), "boolean (string)"), + "setter" => fun_ref(method(:SetHostname), "void (any)"), + "fail_message" => Ops.add(_("InvalidHostname. "), Yast::Hostname.ValidHost) + }, + nameserver1 => { + "validator" => fun_ref(Yast::IP.method(:Check), "boolean (string)"), + "setter" => fun_ref(method(:SetNameserver1), "void (any)"), + "fail_message" => Ops.add( + Ops.add(Ops.add(_("Invalid IP. "), Yast::IP.Valid4), "\n"), + Yast::IP.Valid6 + ) + }, + nameserver2 => { + "validator" => fun_ref(Yast::IP.method(:Check), "boolean (string)"), + "setter" => fun_ref(method(:SetNameserver2), "void (any)"), + "fail_message" => Ops.add( + Ops.add(Ops.add(_("Invalid IP. "), Yast::IP.Valid4), "\n"), + Yast::IP.Valid6 + ) + }, + nameserver3 => { + "validator" => fun_ref(IP.method(:Check), "boolean (string)"), + "setter" => fun_ref(method(:SetNameserver3), "void (any)"), + "fail_message" => Ops.add( + Ops.add(Ops.add(_("Invalid IP. "), IP.Valid4), "\n"), + IP.Valid6 + ) + } + } + end + + # Handler for action "list" + # @param _options [Hash{String => String}] action options + def ListHandler(_options) + dns_summary = + Yast::RichText.Rich2Plain(Y2Network::Presenters::Summary.for(config, "dns").text) + summary = "\n" + _("DNS Configuration Summary:") + "\n" + dns_summary + "\n" + + log.debug(summary) + Yast::CommandLine.Print(summary) + + true + end + + # Handler for action "edit" + # @param [Hash{String => String}] options action options + # @return [Boolean] if successful + def EditHandler(options) + log.info("Edit handler, options: #{options.inspect}") + + # validator: a reference to boolean( string) is expected + # setter: a reference to void( any) is expected + # fail message: a string is expected + + unmanaged_only_options = [nameserver1, nameserver2, nameserver3] + + ret = true + + options.each do |option, value| + if unmanaged_only_options.include?(option) && Yast::NetworkService.is_network_manager + error_message = _("Cannot set ") + option + _(". Network is managed by NetworkManager.") + Yast::CommandLine.Print(error_message) + + ret = false + end + option_validator = option_handlers.fetch(option, {}).fetch("validator") + option_setter = option_handlers.fetch(option, {}).fetch("setter") + fail_message = Ops.get_locale( + option_handlers, + [option, "fail_message"], + _("Invalid option value.") + ) + + if option_validator.nil? || option_setter.nil? + log.info("Edit handler: unknown option or handler for (#{option}=#{value})") + + Yast::CommandLine.Print(_("Internal error")) + + ret = false + end + + if option_validator.call(value) + option_setter.call(value) + else + Yast::CommandLine.Print(fail_message) + ret = false + end + end + + ret + end + + # CLI mode initialization handler + # @return [Boolean] if successful + def InitHandler + return false if !read_config + + InitHnSettings() + + true + end + + # CLI mode finish handler + # @return [Boolean] if successful + def FinishHandler + StoreHnSettings() + + write_config if modified? + + true + end + + def read_config + Yast::Lan.Read(:cache) + end + + def write_config + Yast::Lan.write_config(only: [:dns, :hostname]) + end + end + end +end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yast2-network-4.3.22/src/lib/y2network/config.rb new/yast2-network-4.3.26/src/lib/y2network/config.rb --- old/yast2-network-4.3.22/src/lib/y2network/config.rb 2020-09-21 15:34:06.000000000 +0200 +++ new/yast2-network-4.3.26/src/lib/y2network/config.rb 2020-10-08 16:19:16.000000000 +0200 @@ -132,11 +132,13 @@ # # @param original [Y2Network::Config] configuration used for detecting changes # @param target [Symbol] Target to write the configuration to (:sysconfig) + # @param only [Array<symbol>, nil] explicit sections to be written, by default if no + # parameter is given then all changes will be written. # # @see Y2Network::ConfigWriter - def write(original: nil, target: nil) + def write(original: nil, target: nil, only: nil) target ||= source - Y2Network::ConfigWriter.for(target).write(self, original) + Y2Network::ConfigWriter.for(target).write(self, original, only: only) end # Determines whether two configurations are equal diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yast2-network-4.3.22/src/lib/y2network/config_writer.rb new/yast2-network-4.3.26/src/lib/y2network/config_writer.rb --- old/yast2-network-4.3.22/src/lib/y2network/config_writer.rb 2020-09-21 15:34:06.000000000 +0200 +++ new/yast2-network-4.3.26/src/lib/y2network/config_writer.rb 2020-10-08 16:19:16.000000000 +0200 @@ -22,6 +22,8 @@ # # @param source [Symbol] Source name (e.g., :sysconfig) # @return [Y2Network::Sysconfig::ConfigWriter] + # + # @see Y2Network::Sysconfig::ConfigWriter def self.for(source) require "y2network/#{source}/config_writer" modname = source.to_s.split("_").map(&:capitalize).join diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yast2-network-4.3.22/src/lib/y2network/hostname.rb new/yast2-network-4.3.26/src/lib/y2network/hostname.rb --- old/yast2-network-4.3.22/src/lib/y2network/hostname.rb 2020-09-21 15:34:06.000000000 +0200 +++ new/yast2-network-4.3.26/src/lib/y2network/hostname.rb 2020-10-08 16:19:16.000000000 +0200 @@ -46,7 +46,7 @@ # @option opts [String] :static # @option opts [String] :transient # @option opts [String] :installer - # @option opts [Boolean] :dhcp_hostname + # @option opts [String, Symbol] :dhcp_hostname def initialize(opts = {}) @static = opts[:static] @transient = opts[:transient] || @static @@ -68,16 +68,6 @@ alias_method :hostname, :proposal - # Checks whether the hostname should be stored when writing configuration - # - # Currently this is relevant only in installer when only explicitly set hostname - # via hostname linuxrc option should be stored - # - # @return [Boolean] - def save_hostname? - !Yast::Stage.initial || !@installer.nil? - end - # @return [Array<Symbol>] Methods to check when comparing two instances ATTRS = [ :dhcp_hostname, :static, :transient, :installer @@ -92,6 +82,21 @@ ATTRS.all? { |a| public_send(a) == other.public_send(a) } end + # Reads the static hostname from /etc/hostname + # + # @return [String, nil] + def current_static + name = Yast::SCR.Read(Yast::Path.new(".target.string"), "/etc/hostname").to_s.strip + name.empty? ? nil : name + end + + # Returns whether the static hostname is different than the current one + # + # #@return [Boolean] + def static_modified? + @static != current_static.to_s + end + private # @return [Array<String>] Valid chars to be used in the random part of a hostname diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yast2-network-4.3.22/src/lib/y2network/sysconfig/config_writer.rb new/yast2-network-4.3.26/src/lib/y2network/sysconfig/config_writer.rb --- old/yast2-network-4.3.22/src/lib/y2network/sysconfig/config_writer.rb 2020-09-21 15:34:06.000000000 +0200 +++ new/yast2-network-4.3.26/src/lib/y2network/sysconfig/config_writer.rb 2020-10-08 16:19:16.000000000 +0200 @@ -18,6 +18,7 @@ # find current contact information at www.suse.com. require "yast" +require "y2network/config" require "y2network/sysconfig/routes_file" require "y2network/sysconfig/dns_writer" require "y2network/sysconfig/hostname_writer" @@ -36,26 +37,25 @@ class ConfigWriter include Yast::Logger + # @return [Array<Symbol>] The different sections handled by the writer + SECTIONS = [:routing, :drivers, :interfaces, :connections, :dns, :hostname].freeze + # Writes the configuration into YaST network related modules # # @param config [Y2Network::Config] Configuration to write # @param old_config [Y2Network::Config] Old configuration - def write(config, old_config = nil) - log.info "Writing configuration: #{config.inspect}" - log.info "Old configuration: #{old_config.inspect}" - write_ip_forwarding(config.routing) if config.routing - write_interface_changes(config, old_config) + # @param only [Array<symbol>, nil] explicit sections to be written, by default if no + # parameter is given then all changes will be written + def write(config, old_config = nil, only: nil) + sections = only || SECTIONS + + # TODO: Improve the loging using better format + log.info "Writing configuration: #{config.inspect}\n" + log.info "Old configuration: #{old_config.inspect}\n" - # update /etc/sysconfig/network/routes file - file = routes_file_for(nil) - file.routes = find_routes_for(nil, config.routing.routes) - file.save + log.info("Writing sections: #{sections.inspect}") if only - write_drivers(config.drivers) - write_interfaces(config.interfaces) - write_connections(config.connections, old_config) - write_dns_settings(config, old_config) - write_hostname_settings(config, old_config) + SECTIONS.each { |s| send(:"write_#{s}", config, old_config) if sections.include?(s) } # NOTE: This code might be moved outside of the Sysconfig namespace, as it is generic. Yast::Host.Write(gui: false) @@ -63,13 +63,30 @@ private - # Writes changes per interface + # Updates the ip forwarding config and the routing config which does not + # belongs to a particular interface + # + # @param config [Y2Network::Config] Current config object + # @param old_config [Y2Network::Config,nil] Config object with original configuration + def write_routing(config, old_config) + write_ip_forwarding(config.routing) + + # update /etc/sysconfig/network/routes file + file = routes_file_for(nil) + file.routes = find_routes_for(nil, config.routing.routes) + file.save + + write_interface_routes(config, old_config) + end + + # Writes the routes for the configured interfaces removing the ones not + # configured # # @param config [Y2Network::Config] current configuration for writing # @param old_config [Y2Network::Config, nil] original configuration used # for detecting changes. When nil, no actions related to # configuration changes are processed. - def write_interface_changes(config, old_config) + def write_interface_routes(config, old_config) # Write ifroute files config.interfaces.each do |dev| # S390 devices that have not been activated yet will be part of the @@ -92,7 +109,6 @@ file = routes_file_for(iface) file.remove end - nil end @@ -165,9 +181,9 @@ # Updates the DNS configuration # - # @param config [Y2Network::Config] Current DNS configuration - # @param old_config [Y2Network::Config,nil] Old DNS configuration; nil if it is unknown - def write_dns_settings(config, old_config) + # @param config [Y2Network::Config] Current config object + # @param old_config [Y2Network::Config,nil] Config object with original configuration + def write_dns(config, old_config) old_dns = old_config.dns if old_config writer = Y2Network::Sysconfig::DNSWriter.new writer.write(config.dns, old_dns) @@ -177,42 +193,44 @@ # # @param config [Y2Network::Config] Current config object # @param old_config [Y2Network::Config,nil] Config object with original configuration - def write_hostname_settings(config, old_config) + def write_hostname(config, old_config) old_hostname = old_config.hostname if old_config writer = Y2Network::Sysconfig::HostnameWriter.new writer.write(config.hostname, old_hostname) end - # Updates the interfaces configuration + # Updates the interfaces configuration and the routes associated with + # them # - # @param interfaces [Y2Network::InterfacesCollection] - # @see Y2Network::Sysconfig::InterfacesWriter - def write_interfaces(interfaces) + # @param config [Y2Network::Config] Current config object + # @param _old_config [Y2Network::Config,nil] Config object with original configuration + def write_interfaces(config, _old_config) writer = Y2Network::Sysconfig::InterfacesWriter.new(reload: !Yast::Lan.write_only) - writer.write(interfaces) + writer.write(config.interfaces) end # Writes connections configuration # # @todo Handle old connections (removing those that are not needed, etc.) # - # @param conns [Array<Y2Network::ConnectionConfig::Base>] Connections to write - # @param old_config [Y2Network::Config,nil] Old configuration; nil if it is unknown - def write_connections(conns, old_config) + # @param config [Y2Network::Config] Current config object + # @param old_config [Y2Network::Config,nil] Config object with original configuration + def write_connections(config, old_config) # FIXME: this code might live in its own class writer = Y2Network::Sysconfig::ConnectionConfigWriter.new - remove_old_connections(conns, old_config.connections, writer) if old_config - conns.each do |conn| - old_conn = old_config ? old_config.connections.by_ids(conn.id).first : nil + remove_old_connections(config.connections, old_config.connections, writer) if old_config + config.connections.each do |conn| + old_conn = old_config ? old_config.connections.by_ids(conn.id).first : nil writer.write(conn, old_conn) end end # Writes drivers options # - # @param drivers [Array<Y2Network::Driver>] Drivers to write options - def write_drivers(drivers) - Y2Network::Driver.write_options(drivers) + # @param config [Y2Network::Config] Current config object + # @param _old_config [Y2Network::Config,nil] Config object with original configuration + def write_drivers(config, _old_config) + Y2Network::Driver.write_options(config.drivers) end # Removes old connections files diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yast2-network-4.3.22/src/lib/y2network/sysconfig/connection_config_readers/bridge.rb new/yast2-network-4.3.26/src/lib/y2network/sysconfig/connection_config_readers/bridge.rb --- old/yast2-network-4.3.22/src/lib/y2network/sysconfig/connection_config_readers/bridge.rb 2020-09-21 15:34:06.000000000 +0200 +++ new/yast2-network-4.3.26/src/lib/y2network/sysconfig/connection_config_readers/bridge.rb 2020-10-08 16:19:16.000000000 +0200 @@ -28,7 +28,7 @@ # @see Y2Network::Sysconfig::ConnectionConfigReaders::Base#update_connection_config def update_connection_config(conn) conn.ports = file.bridge_ports ? file.bridge_ports.split(" ") : [] - conn.stp = file.bridge_stp + conn.stp = file.bridge_stp == "on" conn.forward_delay = file.bridge_forwarddelay end end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yast2-network-4.3.22/src/lib/y2network/sysconfig/hostname_reader.rb new/yast2-network-4.3.26/src/lib/y2network/sysconfig/hostname_reader.rb --- old/yast2-network-4.3.22/src/lib/y2network/sysconfig/hostname_reader.rb 2020-09-21 15:34:06.000000000 +0200 +++ new/yast2-network-4.3.26/src/lib/y2network/sysconfig/hostname_reader.rb 2020-10-08 16:19:16.000000000 +0200 @@ -44,16 +44,10 @@ # # @return [Y2Network::Hostname] Hostname configuration def config - transient_hostname = if Yast::Stage.initial - hostname_from_dhcp - else - hostname_from_resolver - end - Y2Network::Hostname.new( installer: hostname_from_install_inf, - static: hostname_from_system, - transient: transient_hostname, + static: static_hostname, + transient: hostname_from_system, dhcp_hostname: dhcp_hostname ) end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yast2-network-4.3.22/src/lib/y2network/sysconfig/hostname_writer.rb new/yast2-network-4.3.26/src/lib/y2network/sysconfig/hostname_writer.rb --- old/yast2-network-4.3.22/src/lib/y2network/sysconfig/hostname_writer.rb 2020-09-21 15:34:06.000000000 +0200 +++ new/yast2-network-4.3.26/src/lib/y2network/sysconfig/hostname_writer.rb 2020-10-08 16:19:16.000000000 +0200 @@ -34,7 +34,7 @@ return if old_hostname && hostname == old_hostname update_sysconfig_dhcp(hostname, old_hostname) - update_hostname(hostname) if hostname.save_hostname? + update_hostname(hostname) if update_needed?(hostname, old_hostname) end private @@ -69,18 +69,29 @@ end end + def update_needed?(hostname, old_hostname) + # If we disable the set of the hostname through dhcp, then we should + # modify the current hostname to the static one + if old_hostname && old_hostname.dhcp_hostname != hostname.dhcp_hostname + return true if hostname.dhcp_hostname == :none + end + + hostname.static_modified? + end + # Sets the hostname # # @param hostname [Y2Network::Hostname] Hostname configuration def update_hostname(hostname) - hostname = hostname.static.to_s + static_hostname = hostname.static.to_s + # 1) when user asked for erasing hostname from /etc/hostname, we keep runtime as it is # 2) we will write whatever user wants even FQDN - no changes under the hood - Yast::Execute.locally!("/usr/bin/hostname", hostname) if !hostname.empty? + Yast::Execute.locally!("/usr/bin/hostname", static_hostname) if !static_hostname.empty? Yast::SCR.Write( Yast::Path.new(".target.string"), HOSTNAME_PATH, - hostname.empty? ? "" : hostname + "\n" + static_hostname.empty? ? "" : static_hostname + "\n" ) end end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yast2-network-4.3.22/src/lib/y2network/widgets/boot_protocol.rb new/yast2-network-4.3.26/src/lib/y2network/widgets/boot_protocol.rb --- old/yast2-network-4.3.22/src/lib/y2network/widgets/boot_protocol.rb 2020-09-21 15:34:06.000000000 +0200 +++ new/yast2-network-4.3.26/src/lib/y2network/widgets/boot_protocol.rb 2020-10-08 16:19:16.000000000 +0200 @@ -173,12 +173,11 @@ none_enabled(false) one_ip = Yast::UI.QueryWidget(Id(:bootproto_ipaddr), :Value) if one_ip.empty? - log.info "Presetting global hostname" - Yast::UI.ChangeWidget( - Id(:bootproto_hostname), - :Value, - Yast::Hostname.MergeFQ(Yast::DNS.hostname, Yast::DNS.domain) - ) + current_hostname = Yast::Hostname.MergeFQ(Yast::DNS.hostname, Yast::DNS.domain) + unless current_hostname.empty? || (current_hostname == "localhost") + log.info "Presetting global hostname" + Yast::UI.ChangeWidget(Id(:bootproto_hostname), :Value, current_hostname) + end end when :bootproto_dynamic static_enabled(false) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yast2-network-4.3.22/src/modules/Lan.rb new/yast2-network-4.3.26/src/modules/Lan.rb --- old/yast2-network-4.3.22/src/modules/Lan.rb 2020-09-21 15:34:06.000000000 +0200 +++ new/yast2-network-4.3.26/src/modules/Lan.rb 2020-10-08 16:19:16.000000000 +0200 @@ -755,9 +755,14 @@ end # Writes current yast config and replaces the system config with it - def write_config + # + # @param only [Array<Symbol>, nil] explicit sections to be written, by default if no + # parameter is given then all changes will be written + # + # @see Y2Network::ConfigWriter + def write_config(only: nil) target = :sysconfig if Mode.auto - yast_config.write(original: system_config, target: target) + yast_config.write(original: system_config, target: target, only: only) # Force a refresh of the system_config bsc#1162987 add_config(:system, yast_config.copy) end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yast2-network-4.3.22/test/data/scr_read/etc/hostname new/yast2-network-4.3.26/test/data/scr_read/etc/hostname --- old/yast2-network-4.3.22/test/data/scr_read/etc/hostname 1970-01-01 01:00:00.000000000 +0100 +++ new/yast2-network-4.3.26/test/data/scr_read/etc/hostname 2020-10-08 16:19:16.000000000 +0200 @@ -0,0 +1 @@ +test diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yast2-network-4.3.22/test/lan_test.rb new/yast2-network-4.3.26/test/lan_test.rb --- old/yast2-network-4.3.22/test/lan_test.rb 2020-09-21 15:34:06.000000000 +0200 +++ new/yast2-network-4.3.26/test/lan_test.rb 2020-10-08 16:19:16.000000000 +0200 @@ -539,7 +539,8 @@ end it "writes the current yast_config passing the system config as the original" do - expect(Yast::Lan.yast_config).to receive(:write).with(original: system_config, target: nil) + expect(Yast::Lan.yast_config).to receive(:write) + .with(original: system_config, target: nil, only: nil) subject.write_config end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yast2-network-4.3.22/test/network_autoconfiguration_test.rb new/yast2-network-4.3.26/test/network_autoconfiguration_test.rb --- old/yast2-network-4.3.22/test/network_autoconfiguration_test.rb 2020-09-21 15:34:06.000000000 +0200 +++ new/yast2-network-4.3.26/test/network_autoconfiguration_test.rb 2020-10-08 16:19:16.000000000 +0200 @@ -72,8 +72,8 @@ before do Y2Network::Config.add(:yast, yast_config) Y2Network::Config.add(:system, system_config) - allow(yast_config).to receive(:write) allow(Yast::Lan).to receive(:Read) + allow(Yast::Lan).to receive(:write_config) end describe "it sets DHCLIENT_SET_DEFAULT_ROUTE properly" do @@ -203,7 +203,7 @@ allow(Y2Network::Config).to receive(:find).with(:yast).and_return(yast_config) allow(Y2Network::Config).to receive(:find).with(:system).and_return(system_config) allow(instance).to receive(:virtual_proposal_required?).and_return(proposal) - allow(yast_config).to receive(:write) + allow(Yast::Lan).to receive(:write_config) allow_any_instance_of(Y2Network::VirtualizationConfig) .to receive(:connected_and_bridgeable?).and_return(true) allow(Yast::PackageSystem).to receive(:Installed).and_return(true) @@ -231,7 +231,7 @@ end it "writes the configuration of the interfaces" do - expect(Yast::Lan.yast_config).to receive(:write) + expect(Yast::Lan).to receive(:write_config) instance.configure_virtuals end @@ -241,7 +241,7 @@ end it "writes the routing config" do - expect(yast_config).to receive(:write) + expect(Yast::Lan).to receive(:write_config) instance.configure_virtuals end end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yast2-network-4.3.22/test/y2network/clients/dns_test.rb new/yast2-network-4.3.26/test/y2network/clients/dns_test.rb --- old/yast2-network-4.3.22/test/y2network/clients/dns_test.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/yast2-network-4.3.26/test/y2network/clients/dns_test.rb 2020-10-08 16:19:16.000000000 +0200 @@ -0,0 +1,159 @@ +#!/usr/bin/env rspec +# Copyright (c) [2020] SUSE LLC +# +# All Rights Reserved. +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of version 2 of the GNU General Public License as published +# by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, contact SUSE LLC. +# +# To contact SUSE LLC about this file by physical or electronic mail, you may +# find current contact information at www.suse.com. + +require_relative "../../test_helper" +require "y2network/clients/dns" +require "y2network/dns" + +describe Y2Network::Clients::DNS do + let(:args) { [] } + + let(:table) { Y2Network::RoutingTable.new([route]) } + let(:config) do + Y2Network::Config.new(interfaces: [], dns: dns, hostname: hostname, source: :sysconfig) + end + let(:dns) { Y2Network::DNS.new(resolv_conf_policy: "auto") } + let(:hostname) do + Y2Network::Hostname.new(static: "test", transient: "transient", dhcp_hostname: :any) + end + + before do + allow(Yast::WFM).to receive(:Args).and_return(args) + allow(subject).to receive(:write_config).and_return(true) + allow(subject).to receive(:read_config).and_return(true) + allow(subject).to receive(:config).and_return(config) + allow(Yast::Lan).to receive(:Read) + allow(Yast::CommandLine).to receive(:Print) + end + + describe "#main" do + before do + allow(subject).to receive(:DNSMainDialog).and_return(:abort) + end + + it "runs the dns cmdline client" do + expect(subject).to receive(:cmdline_definition) + subject.main + end + + context "when calling with no ARGS" do + it "reads the current config" do + expect(subject).to receive(:read_config) + subject.main + end + + it "runs the GUI dialog" do + expect(subject).to receive(:DNSMainDialog).and_return(:abort) + subject.main + end + + context "and returned from the dns dialog without changes" do + it "does not write anything" do + allow(subject).to receive(:DNSMainDialog).and_return(:next) + allow(subject).to receive(:modified?).and_return(false) + + expect(subject).to_not receive(:write_config) + subject.main + end + end + + context "and applied some modification in the dns dialog" do + before do + allow(subject).to receive(:modified?).and_return(true) + allow(subject).to receive(:DNSMainDialog).and_return(:next) + allow(Yast::NetworkService).to receive(:StartStop) + end + + it "writes the changes" do + allow(subject).to receive(:write_config).and_call_original + expect(Yast::Lan).to receive(:write_config).with(only: [:dns, :hostname]) + subject.main + end + + it "restarts the network service" do + expect(Yast::NetworkService).to receive(:StartStop) + subject.main + end + end + end + + context "when calling with 'list'" do + let(:args) { ["list"] } + + before do + allow(subject).to receive(:InitHandler).and_return(true) + allow(subject).to receive(:FinishHandler).and_return(true) + end + + it "prints the DNS and hostname summary" do + expect(Yast::CommandLine).to receive(:Print).with(/DNS Configuration Summary/) + subject.main + end + end + + context "when calling with 'edit'" do + let(:network_manager) { true } + + before do + allow(subject).to receive(:read_config).and_return(true) + allow(subject).to receive(:write_config).and_return(true) + allow(Yast::NetworkService).to receive(:is_network_manager).and_return(network_manager) + Yast::Lan.clear_configs + Yast::Lan.add_config(:system, config.copy) + Yast::Lan.add_config(:yast, config) + end + + context "and the hostname is modified" do + let(:args) { ["edit", "hostname=changedhostname"] } + + it "modifies the static hostname" do + expect { subject.main } + .to change { config.hostname.static } + .from("test").to("changedhostname") + end + end + + context "and the network backend is NetworkManager" do + let(:args) { ["edit", "nameserver1=named1.suse.com"] } + + context "when the options to edit are some of the nameservers" do + it "prints that the options cannot be set because is managed by Networkmanager" do + expect(Yast::CommandLine).to receive(:Print).with(/Cannot set nameserver1/) + + subject.main + end + end + end + + context "and the network backend is wicked" do + let(:args) { ["edit", "nameserver1=8.8.8.8"] } + let(:network_manager) { false } + + context "when some of the options to edit are some of the nameservers" do + it "sets them" do + expect { subject.main } + .to change { config.dns.nameservers.map(&:to_s) } + .from([]).to(["8.8.8.8"]) + end + end + end + end + end +end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yast2-network-4.3.22/test/y2network/config_test.rb new/yast2-network-4.3.26/test/y2network/config_test.rb --- old/yast2-network-4.3.22/test/y2network/config_test.rb 2020-09-21 15:34:06.000000000 +0200 +++ new/yast2-network-4.3.26/test/y2network/config_test.rb 2020-10-08 16:19:16.000000000 +0200 @@ -116,7 +116,7 @@ end it "writes the config using the required writer" do - expect(writer).to receive(:write).with(config, nil) + expect(writer).to receive(:write).with(config, nil, only: nil) config.write end end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yast2-network-4.3.22/test/y2network/hostname_test.rb new/yast2-network-4.3.26/test/y2network/hostname_test.rb --- old/yast2-network-4.3.22/test/y2network/hostname_test.rb 2020-09-21 15:34:06.000000000 +0200 +++ new/yast2-network-4.3.26/test/y2network/hostname_test.rb 2020-10-08 16:19:16.000000000 +0200 @@ -98,40 +98,4 @@ end end end - - describe "#save_hostname?" do - context "When used in installer" do - before(:each) do - allow(Yast::Stage).to receive(:initial).and_return(true) - end - - context "without explicitly set hostname" do - let(:installer_hostname) { nil } - - it "do not propose the hostname to be stored" do - expect(hostname.save_hostname?).to be false - end - end - - context "with explicitly set hostname" do - let(:installer_hostname) { "install_inf_hostname" } - - it "proposese the hostname to be saved" do - expect(hostname.save_hostname?).to be true - end - end - end - - context "When used in running system" do - before(:each) do - allow(Yast::Stage).to receive(:initial).and_return(false) - end - - let(:installer_hostname) { nil } - - it "always proposes the hostname to be saved" do - expect(hostname.save_hostname?).to be true - end - end - end end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yast2-network-4.3.22/test/y2network/hostname_writer_test.rb new/yast2-network-4.3.26/test/y2network/hostname_writer_test.rb --- old/yast2-network-4.3.22/test/y2network/hostname_writer_test.rb 2020-09-21 15:34:06.000000000 +0200 +++ new/yast2-network-4.3.26/test/y2network/hostname_writer_test.rb 2020-10-08 16:19:16.000000000 +0200 @@ -22,34 +22,32 @@ describe Y2Network::Sysconfig::HostnameWriter do subject { Y2Network::Sysconfig::HostnameWriter.new } + let(:static_hostname) { "test" } + let(:transient_hostname) { "dhcp_test" } + let(:installer_hostname) { "test" } + let(:dhcp_hostname) { :any } + + let(:hostname_container) do + Y2Network::Hostname.new(static: static_hostname, + transient: transient_hostname, + dhcp_hostname: dhcp_hostname) + end - describe ".write" do - let(:hostname_container) do - instance_double( - Y2Network::Hostname, - static: hostname, - dhcp_hostname: false, - save_hostname?: true - ) - end - - let(:old_hostname_container) do - instance_double( - Y2Network::Hostname, - static: "old#{hostname}", - dhcp_hostname: false, - save_hostname?: true - ) - end + let(:new_hostname) { hostname_container.dup } + describe ".write" do before(:each) do allow(subject).to receive(:update_sysconfig_dhcp).and_return(nil) end - context "when updating hostname" do - let(:hostname) { "hostname" } + around { |e| change_scr_root(File.join(DATA_PATH, "scr_read"), &e) } + + context "when the static hostname has been modified" do + let(:hostname) { "new_hostname" } it "updates system with the new hostname" do + new_hostname.static = hostname + expect(Yast::Execute) .to receive(:locally!) .with("/usr/bin/hostname", hostname) @@ -57,7 +55,7 @@ .to receive(:Write) .with(anything, anything, /#{hostname}/) - subject.write(hostname_container, old_hostname_container) + subject.write(new_hostname, hostname_container) end end @@ -65,27 +63,49 @@ let(:hostname) { "" } it "updates system with the new hostname" do + new_hostname.static = hostname + expect(Yast::Execute) .not_to receive(:on_target!) expect(Yast::SCR) .to receive(:Write) .with(anything, anything, /#{hostname}/) - subject.write(hostname_container, old_hostname_container) + subject.write(new_hostname, hostname_container) end end context "when no change in hostname" do - let(:hostname) { "hostname" } + let(:hostname) { static_hostname } - it "does not try to update anything" do - expect(Yast::Execute) - .not_to receive(:on_target!) - expect(Yast::SCR) - .not_to receive(:Write) + context "and dhcp hostname is set by dhcp" do + it "does not try to update anything" do + new_hostname.static = hostname + + expect(Yast::Execute) + .not_to receive(:on_target!) + expect(Yast::SCR) + .not_to receive(:Write) - subject.write(hostname_container, hostname_container) + subject.write(new_hostname, hostname_container) + end end + + context "and the hostname is not set by dhcp" do + it "writes the hostname if the dhcp hostname was previously set by dhcp" do + new_hostname.dhcp_hostname = :none + + expect(Yast::Execute) + .to receive(:locally!) + .with("/usr/bin/hostname", hostname) + expect(Yast::SCR) + .to receive(:Write) + .with(anything, anything, /#{hostname}/) + + subject.write(new_hostname, hostname_container) + end + end + end end end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yast2-network-4.3.22/test/y2network/sysconfig/connection_config_readers/bridge_test.rb new/yast2-network-4.3.26/test/y2network/sysconfig/connection_config_readers/bridge_test.rb --- old/yast2-network-4.3.22/test/y2network/sysconfig/connection_config_readers/bridge_test.rb 2020-09-21 15:34:06.000000000 +0200 +++ new/yast2-network-4.3.26/test/y2network/sysconfig/connection_config_readers/bridge_test.rb 2020-10-08 16:19:16.000000000 +0200 @@ -40,7 +40,7 @@ bridge_conn = handler.connection_config expect(bridge_conn.interface).to eq("br0") expect(bridge_conn.ports).to eq(["eth0", "eth1"]) - expect(bridge_conn.stp).to eq("on") + expect(bridge_conn.stp).to eq(true) expect(bridge_conn.forward_delay).to eq(5) end end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yast2-network-4.3.22/test/y2network/sysconfig/hostname_reader_test.rb new/yast2-network-4.3.26/test/y2network/sysconfig/hostname_reader_test.rb --- old/yast2-network-4.3.22/test/y2network/sysconfig/hostname_reader_test.rb 2020-09-21 15:34:06.000000000 +0200 +++ new/yast2-network-4.3.26/test/y2network/sysconfig/hostname_reader_test.rb 2020-10-08 16:19:16.000000000 +0200 @@ -23,6 +23,8 @@ describe Y2Network::Sysconfig::HostnameReader do subject(:reader) { described_class.new } + around { |e| change_scr_root(File.join(DATA_PATH, "scr_read"), &e) } + describe "#config" do let(:install_inf_hostname) { "linuxrc" } let(:dhcp_hostname) { "dhcp" } @@ -34,38 +36,18 @@ allow(reader).to receive(:hostname_from_dhcp).and_return(dhcp_hostname) allow(reader).to receive(:hostname_from_system).and_return(system_hostname) allow(reader).to receive(:hostname_from_resolver).and_return(resolver_hostname) - - allow(Yast::Stage).to receive(:initial).and_return(installation) end - RSpec.shared_examples "installer and static" do - it "reads the installer hostname from /etc/install.conf" do - expect(reader.config.installer).to eq("linuxrc") - end - - it "reads the static hostname from the system" do - expect(reader.config.static).to eq("system") - end + it "reads the installer hostname from /etc/install.conf" do + expect(reader.config.installer).to eq("linuxrc") end - context "during installation" do - let(:installation) { true } - - include_examples "installer and static" - - it "reads the transient hostname from DHCP" do - expect(reader.config.transient).to eq("dhcp") - end + it "reads the static hostname from /etc_hostname" do + expect(reader.config.static).to eq("test") end - context "in an installed system" do - let(:installation) { false } - - include_examples "installer and static" - - it "reads the transient hostname from the resolver" do - expect(reader.config.transient).to eq("system.suse.de") - end + it "reads the current hostname from the system" do + expect(reader.config.transient).to eq("system") end end @@ -150,8 +132,6 @@ allow(File).to receive(:file?).and_return(false) end - around { |e| change_scr_root(File.join(DATA_PATH, "scr_read"), &e) } - it "returns name provided as part of dhcp configuration when available on any interface" do allow(File) .to receive(:file?)