Skip to content

Commit

Permalink
Merge pull request #398 from mchf/bnc971175-ay-dns-linuxrc
Browse files Browse the repository at this point in the history
Setup DNS according AY profile correctly when a static net configuration is provided to linuxrc
  • Loading branch information
mchf committed May 17, 2016
2 parents 7d6c492 + 7c1e716 commit c7218fd
Show file tree
Hide file tree
Showing 15 changed files with 114 additions and 19 deletions.
9 changes: 9 additions & 0 deletions package/yast2-network.changes
@@ -1,3 +1,12 @@
-------------------------------------------------------------------
Tue Apr 26 20:19:12 UTC 2016 - mfilka@suse.com

- bnc#971175
- /etc/hosts is correctly updated with static address, hostname
when static net configuration is done via linuxrc and hostname
is provided by AY profile
- 3.1.140.4

-------------------------------------------------------------------
Mon Feb 22 11:52:09 UTC 2016 - mfilka@suse.com

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


Name: yast2-network
Version: 3.1.140.3
Version: 3.1.140.4
Release: 0

BuildRoot: %{_tmppath}/%{name}-%{version}-build
Expand Down
2 changes: 1 addition & 1 deletion src/clients/firewall_stage1_proposal.rb
Expand Up @@ -277,7 +277,7 @@ def FirewallDialogSimple
Convert.to_symbol(dialog_ret)
end

private
private

def preformatted_proposal
firewall_proposal = if SuSEFirewall4Network.Enabled1stStage
Expand Down
23 changes: 18 additions & 5 deletions src/clients/save_network.rb
Expand Up @@ -36,8 +36,6 @@ class SaveNetworkClient < Client
include Logger

def main
Yast.import "UI"

textdomain "network"

Yast.import "DNS"
Expand Down Expand Up @@ -86,6 +84,8 @@ def adjust_for_network_disks(file)
SYSCONFIG = "/etc/sysconfig/network/"

def CopyConfiguredNetworkFiles
return if Mode.autoinst && !NetworkAutoYast.instance.keep_net_config?

log.info(
"Copy network configuration files from 1st stage into installed system"
)
Expand Down Expand Up @@ -247,15 +247,28 @@ def copy_from_instsys
nil
end

# Creates target's default DNS configuration
#
# It uses DNS configuration as defined in AY profile (if any) or
# proposes a predefined default values.
def configure_dns
configured = false
configured = NetworkAutoYast.instance.configure_dns if Mode.autoinst
NetworkAutoconfiguration.instance.configure_dns if !configured

DNS.create_hostname_link
end

# It does an automatic configuration of installed system
#
# Basically, it runs several proposals.
def configure_target
NetworkAutoconfiguration.instance.configure_virtuals
NetworkAutoconfiguration.instance.configure_dns
NetworkAutoconfiguration.instance.configure_hosts

DNS.create_hostname_link
configure_dns

# this depends on DNS configuration
NetworkAutoconfiguration.instance.configure_hosts

set_network_service

Expand Down
2 changes: 1 addition & 1 deletion src/include/network/lan/complex.rb
Expand Up @@ -567,7 +567,7 @@ def MainDialog(init_tab)
ret
end

private
private

def overview_buttons
ret = {}
Expand Down
2 changes: 1 addition & 1 deletion src/include/network/routines.rb
Expand Up @@ -1014,7 +1014,7 @@ def disable_unconfigureable_items(items, show_popup)
true
end

private
private

# Checks if the device should be filtered out in ReadHardware
def filter_out(device_info, driver)
Expand Down
2 changes: 1 addition & 1 deletion src/lib/network/edit_nic_name.rb
Expand Up @@ -82,7 +82,7 @@ def run
new_name || @old_name
end

private
private

# Opens dialog for editing NIC name
def open
Expand Down
2 changes: 1 addition & 1 deletion src/lib/network/install_inf_convertor.rb
Expand Up @@ -44,7 +44,7 @@ def write_netconfig
write_global_netconfig
end

private
private

def create_ifcfg
ifcfg = ""
Expand Down
2 changes: 1 addition & 1 deletion src/lib/network/network_autoconfiguration.rb
Expand Up @@ -107,7 +107,7 @@ def configure_hosts
Host.Write
end

private
private

def network_cards
LanItems.Read
Expand Down
34 changes: 33 additions & 1 deletion src/lib/network/network_autoyast.rb
Expand Up @@ -15,6 +15,7 @@ class NetworkAutoYast
include Singleton
include Logger

Yast.import "DNS"
Yast.import "Lan"
Yast.import "LanItems"
Yast.import "Linuxrc"
Expand Down Expand Up @@ -120,7 +121,38 @@ def set_network_service
NetworkService.EnableDisableNow
end

private
# Initializates DNS setup according AY profile
#
# FIXME: it currently doesn't write DNS configuration. It is used for initialization
# of DNS setup according AY profile in 1st stage as part of network setup was moved
# here already and some parts of network configuration needs to know it. DNS write
# is still done in 2nd stage.
#
# @return [Boolean] true when configuration was present and loaded from the profile
def configure_dns
ay_dns_config = ay_networking_section["dns"]

return false if !ay_dns_config

DNS.Import(ay_dns_config)

log.info("NetworkAutoYast: DNS / Hostname configuration")
log.info("dhcp hostname: #{DNS.dhcp_hostname}")
log.info("write hostname: #{DNS.write_hostname}")

true
end

# Checks if the profile asks for keeping installation network configuration
def keep_net_config?
ret = ay_networking_section.fetch("keep_install_network", false)

log.info("NetworkAutoYast: keep installation network: #{ret}")

ret
end

private

# Merges two devices map into one.
#
Expand Down
2 changes: 1 addition & 1 deletion src/modules/DNS.rb
Expand Up @@ -670,7 +670,7 @@ def create_hostname_link
nil
end

private
private

def read_hostname_from_install_inf
install_inf_hostname = SCR.Read(path(".etc.install_inf.Hostname")) || ""
Expand Down
2 changes: 1 addition & 1 deletion src/modules/Lan.rb
Expand Up @@ -1111,7 +1111,7 @@ def HaveXenBridge
publish function: :AutoPackages, type: "map ()"
publish function: :HaveXenBridge, type: "boolean ()"

private
private

def activate_network_service
if LanItems.force_restart
Expand Down
6 changes: 3 additions & 3 deletions src/modules/LanItems.rb
Expand Up @@ -2500,7 +2500,7 @@ def createS390Device
SCR.Execute(path(".target.bash_output"), command1),
from: "any",
to: "map <string, any>"
)
)
if Ops.get_integer(output1, "exit", -1) == 0 &&
Builtins.size(Ops.get_string(output1, "stderr", "")) == 0
Builtins.y2milestone("Success : %1", output1)
Expand Down Expand Up @@ -2543,7 +2543,7 @@ def createS390Device
result
end

private
private

# This helper allows YARD to extract DSL-defined attributes.
# Unfortunately YARD has problems with the Capitalized ones,
Expand Down Expand Up @@ -2575,7 +2575,7 @@ def drop_hosts(ip)
Host.set_names(ip, [])
end

public
public

# @attribute Items
# @return [Hash<Integer, Hash<String, Object> >]
Expand Down
2 changes: 1 addition & 1 deletion src/modules/Routing.rb
Expand Up @@ -481,7 +481,7 @@ def Summary
publish function: :SetDevices, type: "boolean (list)"
publish function: :Summary, type: "string ()"

private
private

def ifroute_term(device)
raise ArgumentError if device.nil? || device.empty?
Expand Down
41 changes: 41 additions & 0 deletions test/network_autoyast_test.rb
Expand Up @@ -210,4 +210,45 @@ def nm_installed(installed)
end
end
end

describe "#configure_dns" do
let(:network_autoyast) { Yast::NetworkAutoYast.instance }

it "imports DNS configuration when available in profile" do
Yast.import "DNS"

allow(network_autoyast)
.to receive(:ay_networking_section)
.and_return("dns" => { "dhcp_hostname" => false })

expect(Yast::DNS).to receive(:Import)

network_autoyast.configure_dns
end
end

describe "#keep_net_config?" do
let(:network_autoyast) { Yast::NetworkAutoYast.instance }

def keep_install_network_value(value)
allow(network_autoyast)
.to receive(:ay_networking_section)
.and_return(value)
end

it "succeedes when keep_install_network is set in AY profile" do
keep_install_network_value("keep_install_network" => true)
expect(network_autoyast.keep_net_config?).to be true
end

it "fails when keep_install_network is not set in AY profile" do
keep_install_network_value("keep_install_network" => false)
expect(network_autoyast.keep_net_config?).to be false
end

it "fails when keep_install_network is not present in AY profile" do
keep_install_network_value({})
expect(network_autoyast.keep_net_config?).to be false
end
end
end

0 comments on commit c7218fd

Please sign in to comment.