Skip to content

Commit

Permalink
Merge 41c0f64 into 92db853
Browse files Browse the repository at this point in the history
  • Loading branch information
teclator committed Oct 7, 2019
2 parents 92db853 + 41c0f64 commit cde5faa
Show file tree
Hide file tree
Showing 22 changed files with 571 additions and 24 deletions.
6 changes: 6 additions & 0 deletions package/yast2-network.changes
@@ -1,3 +1,9 @@
-------------------------------------------------------------------
Mon Oct 7 06:05:22 UTC 2019 - Knut Anderssen <kanderssen@suse.com>

- AutoYaST: Added back the activation of s390 devices during the
first stage as it was removed when switched to the new data model

-------------------------------------------------------------------
Fri Oct 4 13:51:42 UTC 2019 - Josef Reidinger <jreidinger@suse.com>

Expand Down
6 changes: 2 additions & 4 deletions src/clients/lan_auto.rb
Expand Up @@ -139,10 +139,8 @@ def ToAY(settings)
Builtins.y2milestone("net-udev: #{net_udev.inspect})")

# Modules
s390_devices = []
Builtins.foreach(Ops.get_map(settings, "s390-devices", {})) do |_device, mod|
s390_devices = Builtins.add(s390_devices, mod)
end
s390_devices = settings["s390-devices"] || []
Builtins.y2milestone("s390-devices: #{s390_devices.inspect})")

modules = []
Builtins.foreach(Ops.get_map(settings, "hwcfg", {})) do |device, mod|
Expand Down
9 changes: 6 additions & 3 deletions src/lib/network/clients/save_network.rb
Expand Up @@ -136,12 +136,13 @@ def copy_udev_rules
dest_root = String.Quote(Installation.destdir)

if Arch.s390
log.info("Copy S390 specific udev rule files (/etc/udev/rules/51*)")
# chzdev creates the rules starting with "41-"
log.info("Copy S390 specific udev rule files (/etc/udev/rules/41*)")

WFM.Execute(
path(".local.bash"),
Builtins.sformat(
"/bin/cp -p %1/51-* '%2%1'",
"/bin/cp -p %1/41-* '%2%1'",
"/etc/udev/rules.d",
dest_root.shellescape
)
Expand Down Expand Up @@ -201,7 +202,9 @@ def copy_from_instsys
# 2) original ifcfg file is copied otherwise too. It doesn't break things itself
# but definitely not looking well ;-)
# TODO: implement support for create udev rules if needed
# NetworkAutoYast.instance.create_udevs if Mode.autoinst

# The s390 devices activation was part of the rules handling.
NetworkAutoYast.instance.activate_s390_devices if Mode.autoinst && Arch.s390

copy_dhcp_info
copy_udev_rules
Expand Down
23 changes: 23 additions & 0 deletions src/lib/network/network_autoyast.rb
Expand Up @@ -18,6 +18,10 @@
# find current contact information at www.suse.com.

require "yast"
require "y2network/autoinst_profile/s390_devices_section"
require "y2network/autoinst/s390_devices_reader"
require "y2network/interface_config_builder"
require "y2network/s390_device_activator"

module Yast
# Provides functionality for network AutoYaST client(s)
Expand Down Expand Up @@ -113,6 +117,25 @@ def configure_lan(write: false)
configure_submodule(Lan, ay_configuration, write: write)
end

# Takes care of activate s390 devices from the profile declaration
def activate_s390_devices(section = nil)
profile_devices = section || ay_networking_section["s390-devices"] || {}
devices_section = Y2Network::AutoinstProfile::S390DevicesSection.new_from_hashes(profile_devices)
connections = Y2Network::Autoinst::S390DevicesReader.new(devices_section).config
connections.each do |conn|
begin
builder = Y2Network::InterfaceConfigBuilder.for(conn.type, config: conn)
activator = Y2Network::S390DeviceActivator.for(builder)
log.info "Created interface #{activator.configured_interface}" if activator.configure
rescue RuntimeError => e
log.error("An error ocurred when trying to activate the s390 device: #{conn.inspect}")
log.error("Error: #{e.sinpect}")
end
end

true
end

# Initializates /etc/hosts according AY profile
#
# If the installer is running in 1st stage mode only, then the configuration
Expand Down
82 changes: 82 additions & 0 deletions src/lib/y2network/autoinst/s390_devices_reader.rb
@@ -0,0 +1,82 @@
# Copyright (c) [2019] 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/connection_configs_collection"
require "y2network/connection_config"
require "y2network/interface_type"

module Y2Network
module Autoinst
# This class is responsible of importing the AutoYast S390 devices section
class S390DevicesReader
# @return [AutoinstProfile::S390DevicesSection]
attr_reader :section

# @param section [AutoinstProfile::S390DevicesSection]
def initialize(section)
@section = section
end

# @return [ConnectionConfigsCollection] the imported connections configs
def config
connections = ConnectionConfigsCollection.new([])

@section.devices.each do |device_section|
config = create_config(device_section)
next unless config

case config
when ConnectionConfig::Qeth
load_qeth(config, device_section)
when ConnectionConfig::Lcs
load_lcs(config, device_section)
when ConnectionConfig::Ctc
load_ctc(config, device_section)
end
connections << config
end

connections
end

private

def create_config(device_section)
type = InterfaceType.from_short_name(device_section.type)
return unless type
ConnectionConfig.const_get(type.class_name).new
end

def load_qeth(config, device_section)
config.read_channel, config.write_channel, config.data_channel = device_section.chanids.split(" ")
config.layer2 = device_section.layer2
end

def load_ctc(config, device_section)
config.read_channel, config.write_channel = device_section.chanids.split(" ")
config.protocol = device_section.protocol
end

def load_lcs(config, device_section)
config.read_channel, config.write_channel = device_section.chanids.split(" ")
end
end
end
end
14 changes: 10 additions & 4 deletions src/lib/y2network/autoinst_profile/networking_section.rb
Expand Up @@ -21,6 +21,7 @@
require "y2network/autoinst_profile/interfaces_section"
require "y2network/autoinst_profile/routing_section"
require "y2network/autoinst_profile/udev_rules_section"
require "y2network/autoinst_profile/s390_devices_section"

module Y2Network
module AutoinstProfile
Expand All @@ -42,6 +43,8 @@ class NetworkingSection
attr_accessor :interfaces
# @return [UdevRulesSection]
attr_accessor :udev_rules
# @return [S390DevicesSection]
attr_accessor :s390_devices

# Creates an instance based on the profile representation used by the AutoYaST modules
# (hash with nested hashes and arrays).
Expand All @@ -54,6 +57,7 @@ def self.new_from_hashes(hash)
result.dns = DNSSection.new_from_hashes(hash["dns"]) if hash["dns"]
result.interfaces = InterfacesSection.new_from_hashes(hash["interfaces"]) if hash["interfaces"]
result.udev_rules = UdevRulesSection.new_from_hashes(hash["net-udev"]) if hash["net-udev"]
result.s390_devices = S390DevicesSection.new_from_hashes(hash["s390-devices"]) if hash["s390-devices"]
result
end

Expand All @@ -68,6 +72,7 @@ def self.new_from_network(config)
result.dns = DNSSection.new_from_network(config.dns) if config.dns
result.interfaces = InterfacesSection.new_from_network(config.connections)
result.udev_rules = UdevRulesSection.new_from_network(config.interfaces)
result.s390_devices = S390DevicesSection.new_from_network(config.connections)
result
end

Expand All @@ -76,10 +81,11 @@ def self.new_from_network(config)
# @return [Hash]
def to_hashes
{
"routing" => routing.to_hashes,
"dns" => dns.to_hashes,
"interfaces" => interfaces.to_hashes,
"net-udev" => udev_rules.to_hashes
"routing" => routing.to_hashes,
"dns" => dns.to_hashes,
"interfaces" => interfaces.to_hashes,
"net-udev" => udev_rules.to_hashes,
"s390-devices" => s390_devices.to_hashes
}
end
end
Expand Down
96 changes: 96 additions & 0 deletions src/lib/y2network/autoinst_profile/s390_device_section.rb
@@ -0,0 +1,96 @@
# Copyright (c) [2019] 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 "y2network/autoinst_profile/section_with_attributes"
module Y2Network
module AutoinstProfile
# This class represents an AutoYaST <device> section under <s390-devices>
#
# <device>
# <chanids>0.0.0700 0.0.0701 0.0.0702</chanids>
# <layer2 config:type="boolean>true</layer2>
# <type>qeth</type>
# </device>
#
# @see S390DevicesSection
class S390DeviceSection < SectionWithAttributes
def self.attributes
[
{ name: :chanids },
{ name: :layer2 },
{ name: :type },
{ name: :portname }, # deprecated
{ name: :protocol },
{ name: :router }
]
end

define_attr_accessors

# @!attribute chanids
# @return [String] channel device id separated by spaces

# @!attribute layer2
# @return [Boolean] Whether layer2 is enabler or not

# @!attribute type
# @return [String] S390 device type (qeth, ctc, iucv)

# @!attribute portname
# @return [String] QETH portname (deprecated)

# @!attribute protocol
# @return [String]

# @!attribute router
# @return [String] IUCV router/user

# Clones a network s390 connection config into an AutoYaST s390 device section
#
# @param connection_config [Y2Network::ConnectionConfig] Network connection config
# @return [S390DeviceSection]
def self.new_from_network(connection_config)
result = new
result.init_from_config(connection_config)
result
end

# Method used by {.new_from_network} to populate the attributes when cloning a network s390
# device
#
# @param config [Y2Network::ConnectionConfig]
# @return [Boolean]
def init_from_config(config)
@type = config.type.short_name
case config
when ConnectionConfig::Qeth
@chanids = config.device_id
@layer2 = config.layer2
when ConnectionConfig::Ctc
@chanids = config.device_id
@protocol = config.protocol
when ConnectionConfig::Lcs
@chanids = config.device_id
end

true
end
end
end
end

0 comments on commit cde5faa

Please sign in to comment.