-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Sle15] AY setup written in first stage #520
Changes from 21 commits
9c25d6a
ef87aa3
4bcc266
be868cb
dc0e9cc
d1a3ff5
d7b3d77
40bdff0
77ee946
4ffc055
8423096
dad7efe
dd69fbb
1fc8484
588c2a4
7a481a5
5b11294
77bfcd8
766076d
f7eb359
a8d5ee9
58bb702
b9c5e1a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ | |
|
||
|
||
Name: yast2-network | ||
Version: 3.3.2 | ||
Version: 3.3.3 | ||
Release: 0 | ||
BuildArch: noarch | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -259,16 +259,36 @@ def configure_dns | |
DNS.create_hostname_link | ||
end | ||
|
||
# Creates target's /etc/hosts configuration | ||
# | ||
# It uses hosts' configuration as defined in AY profile (if any) or | ||
# proceedes according the proposal | ||
def configure_hosts | ||
configured = false | ||
configured = NetworkAutoYast.instance.configure_hosts if Mode.autoinst | ||
NetworkAutoconfiguration.instance.configure_hosts if !configured | ||
end | ||
|
||
# Invokes configuration of parts which are in charge of Lan module | ||
# | ||
# Currently it handles just AutoYaST installation. It just exits in case | ||
# of common installation as there currently is nothing to do. | ||
def configure_lan | ||
return if !Mode.autoinst | ||
|
||
NetworkAutoYast.instance.configure_lan | ||
end | ||
|
||
# It does an automatic configuration of installed system | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AFAIK formerly this was not associated with AutoYaST. So we should explicitly point this out:
BTW, what about autoupgrade? http://www.rubydoc.info/github/yast/yast-yast2/Yast/ModeClass There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. upgrade scenario ignores network setup ... but i'm not sure about autoupgrade - will check |
||
# | ||
# Basically, it runs several proposals. | ||
def configure_target | ||
NetworkAutoconfiguration.instance.configure_virtuals | ||
|
||
configure_dns | ||
configure_lan | ||
|
||
# this depends on DNS configuration | ||
NetworkAutoconfiguration.instance.configure_hosts | ||
configure_hosts | ||
|
||
set_network_service | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,8 @@ def initialize | |
Yast.import "Lan" | ||
Yast.import "LanItems" | ||
Yast.import "Linuxrc" | ||
Yast.import "Host" | ||
Yast.import "Routing" | ||
end | ||
|
||
# Merges existing config from system into given configuration map | ||
|
@@ -104,26 +106,39 @@ def set_network_service | |
NetworkService.EnableDisableNow | ||
end | ||
|
||
# Initializates DNS setup according AY profile | ||
# Initializates NICs 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. | ||
# If the installer is running in 1st stage mode only, then the configuration | ||
# is also written | ||
# | ||
# @param [Boolean] write forces instant writing of the configuration | ||
# @return [Boolean] true when configuration was present and loaded from the profile | ||
def configure_dns | ||
ay_dns_config = ay_networking_section["dns"] | ||
def configure_lan(write: false) | ||
log.info("NetworkAutoYast: Lan configuration") | ||
|
||
return false if !ay_dns_config | ||
ay_configuration = Lan.FromAY(ay_networking_section) | ||
ay_configuration = NetworkAutoYast.instance.merge_configs(ay_configuration) if keep_net_config? | ||
|
||
DNS.Import(ay_dns_config) | ||
configure_submodule(Lan, ay_configuration, write: write) | ||
end | ||
|
||
log.info("NetworkAutoYast: DNS / Hostname configuration") | ||
log.info("dhcp hostname: #{DNS.dhcp_hostname}") | ||
log.info("write hostname: #{DNS.write_hostname}") | ||
# Initializates /etc/hosts according AY profile | ||
# | ||
# If the installer is running in 1st stage mode only, then the configuration | ||
# is also written | ||
# | ||
# @param [Boolean] write forces instant writing of the configuration | ||
# @return [Boolean] true when configuration was present and loaded from the profile | ||
def configure_hosts(write: false) | ||
log.info("NetworkAutoYast: Hosts configuration") | ||
|
||
true | ||
hosts_config = (ay_host_section["hosts"] || {}).map do |host| | ||
# we need to guarantee order of the items here | ||
[host["host_address"] || "", host["names"] || []] | ||
end | ||
hosts_config = hosts_config.to_h.delete_if { |k, v| k.empty? || v.empty? } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This non-trivial FromAY-like section should go into its own method (class?) and be covered with tests. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. well this is almost everything what There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, now that the other configure_* methods are gone it makes less sense to split it off. Still, with all the "or empty" logic in here, tests are needed. Also, how does this code relate to Import in host_auto? Do we need to "guarantee item order" also there? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Item order is most probably bad description here. I refer to "host_address" and "names". Each of these hash keys refer to a xml node. And this nodes can be ordered differently in the profile. We must guarantee that "host_address" is at first place. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that this duplicates There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, sorry, |
||
|
||
configure_submodule(Host, "hosts" => hosts_config, write: write) | ||
end | ||
|
||
# Checks if the profile asks for keeping installation network configuration | ||
|
@@ -206,16 +221,53 @@ def merge_routing(instsys_routing, ay_routing) | |
instsys_routing.merge(ay_routing) | ||
end | ||
|
||
# Returns networking section of current AY profile | ||
def ay_networking_section | ||
# Returns current AY profile in the internal representation | ||
# | ||
# @return [Hash] hash representing current profile or empty hash | ||
def ay_current_profile | ||
Yast.import "Profile" | ||
|
||
ay_profile = Profile.current | ||
|
||
return {} if ay_profile.nil? || ay_profile.empty? | ||
return {} if ay_profile["networking"].nil? | ||
ay_profile | ||
end | ||
|
||
# Returns networking section of current AY profile | ||
def ay_networking_section | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMHO it would be more clear to replace this method by inlining There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. regarding There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in my POV "networking" section is used quite often so it deserved own method as a shortcut. |
||
return {} if ay_current_profile["networking"].nil? | ||
|
||
ay_current_profile["networking"] | ||
end | ||
|
||
# Returns global section of current AY profile | ||
def ay_general_section | ||
return {} if ay_current_profile["general"].nil? | ||
|
||
ay_profile["networking"] | ||
ay_current_profile["general"] | ||
end | ||
|
||
# Returns host section of the current AY profile | ||
# | ||
# Note that autoyast transforms the host's subsection | ||
# into: | ||
# { | ||
# hosts => [ | ||
# # first <host_entry> | ||
# { | ||
# "host_address" => <ip>, | ||
# "names" => [list, of, names] | ||
# } | ||
# # second <host_entry> | ||
# ... | ||
# ] | ||
# } | ||
# | ||
# return <Hash> with hosts configuration | ||
def ay_host_section | ||
return {} if ay_current_profile["host"].nil? | ||
|
||
ay_current_profile["host"] | ||
end | ||
|
||
# Checks if the udev rule is valid for renaming a NIC | ||
|
@@ -265,5 +317,26 @@ def assign_udevs_to_devs(udev_rules) | |
LanItems.rename(name_to) | ||
end | ||
end | ||
|
||
# Configures given yast submodule according AY configuration | ||
# | ||
# It takes data from AY profile transformed into a format expected by the YaST | ||
# sub module's Import method. | ||
# | ||
# It imports the profile, configures the module and writes the configuration. | ||
# Writing the configuration is optional when second stage is available and mandatory | ||
# when running autoyast installation with first stage only. | ||
def configure_submodule(yast_module, ay_config, write: false) | ||
return false if !ay_config | ||
|
||
yast_module.Import(ay_config) | ||
|
||
write ||= !ay_general_section.fetch("mode", "second_stage" => true)["second_stage"] | ||
log.info("Write configuration instantly: #{write}") | ||
|
||
yast_module.Write(gui: false) if write | ||
|
||
true | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As this is a major thing we should have a public bug for this. I could not find one in https://trello.com/c/dxyLJ9c8/956-8-sle-15-%E2%9A%A1-autoyast-configure-the-whole-network-in-the-first-stage so should I create one?
Also, /etc/hosts should be mentioned.