From fa3ac8110da236cccb0744fbe69be3afd445d52b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Imobach=20Gonz=C3=A1lez=20Sosa?= Date: Fri, 9 May 2025 16:03:14 +0100 Subject: [PATCH 1/8] feat(ruby): convert AutoYaST bootloader options --- .../lib/agama/autoyast/bootloader_reader.rb | 55 +++++++++++++++ service/lib/agama/autoyast/converter.rb | 1 + .../agama/autoyast/bootloader_reader_test.rb | 69 +++++++++++++++++++ 3 files changed, 125 insertions(+) create mode 100644 service/lib/agama/autoyast/bootloader_reader.rb mode change 100755 => 100644 service/lib/agama/autoyast/converter.rb create mode 100644 service/test/agama/autoyast/bootloader_reader_test.rb diff --git a/service/lib/agama/autoyast/bootloader_reader.rb b/service/lib/agama/autoyast/bootloader_reader.rb new file mode 100644 index 0000000000..2e277abb97 --- /dev/null +++ b/service/lib/agama/autoyast/bootloader_reader.rb @@ -0,0 +1,55 @@ +# frozen_string_literal: true + +# Copyright (c) [2025] 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 "y2users/config" +require "y2users/autoinst/reader" + +# :nodoc: +module Agama + module AutoYaST + # Builds the Agama "root" section from an AutoYaST profile. + class BootloaderReader + # @param profile [ProfileHash] AutoYaST profile + def initialize(profile) + @profile = profile + end + + # Returns a hash that corresponds to Agama "root" section. + # + # @return [Hash] Agama "root" section + def read + global = profile.fetch_as_hash("bootloader") + .fetch_as_hash("global") + return {} if global.empty? + + bootloader = {} + bootloader["timeout"] = global["timeout"] if global["timeout"].is_a?(Integer) + bootloader["extraKernelParams"] = global["append"] unless global["append"].to_s.empty? + { "bootloader" => bootloader } + end + + private + + attr_reader :profile + end + end +end diff --git a/service/lib/agama/autoyast/converter.rb b/service/lib/agama/autoyast/converter.rb old mode 100755 new mode 100644 index d719df4e97..c739baedf7 --- a/service/lib/agama/autoyast/converter.rb +++ b/service/lib/agama/autoyast/converter.rb @@ -53,6 +53,7 @@ class Converter # Sections which have a corresponding reader. The reader is expected to be # named in Pascal case and adding "Reader" as suffix (e.g., "L10nReader"). SECTIONS = [ + "bootloader", "files", "localization", "product", diff --git a/service/test/agama/autoyast/bootloader_reader_test.rb b/service/test/agama/autoyast/bootloader_reader_test.rb new file mode 100644 index 0000000000..038a42d3d9 --- /dev/null +++ b/service/test/agama/autoyast/bootloader_reader_test.rb @@ -0,0 +1,69 @@ +# frozen_string_literal: true + +# Copyright (c) [2025] 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 "yast" +require "agama/autoyast/bootloader_reader" + +Yast.import "Profile" + +describe Agama::AutoYaST::BootloaderReader do + let(:profile) do + { "bootloader" => { "global" => global } } + end + let(:global) { {} } + + subject do + described_class.new(Yast::ProfileHash.new(profile)) + end + + describe "#read" do + context "when there is no 'bootloader' section" do + it "returns an empty hash" do + expect(subject.read).to be_empty + end + end + + context "when kernel parameters are defined" do + let(:global) do + { "append" => "param0 param1" } + end + + it "returns a hash including the 'extraKernelParams'" do + expect(subject.read["bootloader"]).to include( + "extraKernelParams" => "param0 param1" + ) + end + end + + context "when a timeout is given" do + let(:global) do + { "timeout" => 5 } + end + + it "returns a hash containing the 'timeout' " do + expect(subject.read["bootloader"]).to include( + "timeout" => 5 + ) + end + end + end +end From e41393e02d5c329efd177bdc003be60726e7be11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Imobach=20Gonz=C3=A1lez=20Sosa?= Date: Fri, 9 May 2025 16:05:13 +0100 Subject: [PATCH 2/8] fix(ruby): enable import of hostname and network AutoYaST settings --- service/lib/agama/autoyast/converter.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/service/lib/agama/autoyast/converter.rb b/service/lib/agama/autoyast/converter.rb index c739baedf7..0b7e62ae30 100644 --- a/service/lib/agama/autoyast/converter.rb +++ b/service/lib/agama/autoyast/converter.rb @@ -55,7 +55,9 @@ class Converter SECTIONS = [ "bootloader", "files", + "hostname", "localization", + "network", "product", "root", "scripts", From ac3f712197fb0a4b47e292eba2236cb4192b7798 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Imobach=20Gonz=C3=A1lez=20Sosa?= Date: Fri, 9 May 2025 16:28:24 +0100 Subject: [PATCH 3/8] docs(ruby): add the bootloader to the AutoYaST compat document --- service/share/autoyast-compat.json | 38 ++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/service/share/autoyast-compat.json b/service/share/autoyast-compat.json index 685df07fb7..aad711a5aa 100644 --- a/service/share/autoyast-compat.json +++ b/service/share/autoyast-compat.json @@ -2,6 +2,44 @@ { "key": "add-on", "support": "planned" }, { "key": "audit-laf", "support": "no" }, { "key": "auth-client", "support": "no" }, + { + "key": "bootloader", + "children": [ + { "key": "device_map", "support": "no" }, + { + "key": "global", + "children": [ + { "key": "activate", "support": "no" }, + { + "key": "append", + "support": "yes", + "agama": "bootloader.extraKernelParams" + }, + { "key": "boot_boot", "support": "no" }, + { "key": "boot_custom", "support": "no" }, + { "key": "boot_extended", "support": "no" }, + { "key": "boot_mbr", "support": "no" }, + { "key": "boot_root", "support": "no" }, + { "key": "cpu_mitigations", "support": "no" }, + { "key": "generic_mbr", "support": "no" }, + { "key": "gfxmode", "support": "no" }, + { "key": "os_prober", "support": "no" }, + { "key": "password", "support": "no" }, + { "key": "suse_btrfs", "support": "no" }, + { "key": "serial", "support": "no" }, + { "key": "secure_boot", "support": "no" }, + { "key": "terminal", "support": "no" }, + { "key": "timeout", "support": "yes", "agama": "bootloader.timeout" }, + { "key": "trusted_boot", "support": "no" }, + { "key": "update_nvram", "support": "no" }, + { "key": "vgamode", "support": "no" }, + { "key": "xen_append", "support": "no" }, + { "key": "xen_kernel_append", "support": "no" } + ] + }, + { "key": "loader_type", "support": "no" } + ] + }, { "key": "configuration_management", "support": "no" }, { "key": "deploy_image", "support": "no" }, { "key": "dhcp-server", "support": "no" }, From 3b97e8be8d7953ead2f54166bf745c5d6d2a01e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Imobach=20Gonz=C3=A1lez=20Sosa?= Date: Fri, 9 May 2025 16:38:21 +0100 Subject: [PATCH 4/8] docs(ruby): update the changes file --- service/package/rubygem-agama-yast.changes | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/service/package/rubygem-agama-yast.changes b/service/package/rubygem-agama-yast.changes index b9f482db32..6d6d08544e 100644 --- a/service/package/rubygem-agama-yast.changes +++ b/service/package/rubygem-agama-yast.changes @@ -1,3 +1,10 @@ +------------------------------------------------------------------- +Fri May 9 15:37:04 UTC 2025 - Imobach Gonzalez Sosa + +- Convert the bootloader section to JSON (gh#agama-project/agama#2349). +- Fix the conversion of the hostname and the networking sections to JSON + (gh#agama-project/agama#2349). + ------------------------------------------------------------------- Wed May 7 10:24:14 UTC 2025 - Imobach Gonzalez Sosa From ab5783fd9228c33b880a9e9beedec9bcd0184f72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Imobach=20Gonz=C3=A1lez=20Sosa?= Date: Fri, 9 May 2025 16:48:15 +0100 Subject: [PATCH 5/8] fix(ruby): fix AutoYaST networking conversion --- .../lib/agama/autoyast/connections_reader.rb | 4 ++-- service/lib/agama/autoyast/network_reader.rb | 20 ++++++++++++++----- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/service/lib/agama/autoyast/connections_reader.rb b/service/lib/agama/autoyast/connections_reader.rb index 6223906229..5bda54b535 100755 --- a/service/lib/agama/autoyast/connections_reader.rb +++ b/service/lib/agama/autoyast/connections_reader.rb @@ -65,7 +65,7 @@ def ipv6? # @return [Hash] def read_connection(interface) conn = {} - conn["device"] = interface.device if interface.device + conn["interface"] = interface.device if interface.device conn["id"] = interface.name if interface.name addresses = read_addresses(interface) @@ -74,7 +74,7 @@ def read_connection(interface) conn["method6"] = method6 conn["addresses"] = addresses wireless = Agama::AutoYaST::WirelessReader.new(interface).read - conn["wireless"] = wireless unless wireless.empty? + conn.merge!(wireless) unless wireless.empty? bond = Agama::AutoYaST::BondReader.new(interface).read conn["bond"] = bond unless bond.empty? conn.merge!(dns) diff --git a/service/lib/agama/autoyast/network_reader.rb b/service/lib/agama/autoyast/network_reader.rb index 117479822c..1e52709c25 100755 --- a/service/lib/agama/autoyast/network_reader.rb +++ b/service/lib/agama/autoyast/network_reader.rb @@ -40,10 +40,7 @@ def read section = Y2Network::AutoinstProfile::NetworkingSection.new_from_hashes(networking) dns = read_dns_settings(section.dns) - connections_reader = Agama::AutoYaST::ConnectionsReader.new( - section.interfaces, ipv6: ipv6?, dns: dns - ) - connections = connections_reader.read + connections = read_connections(section.interfaces, dns) return {} if connections.empty? { "network" => connections } @@ -57,12 +54,25 @@ def ipv6? profile.fetch_as_hash("networking").fetch("ipv6", false) end + # @param section [Y2Network::AutoinstProfile::Interfaces, nil] AutoYaST interfaces section. + # @param dns [Hash] Agama DNS settings. + def read_connections(interfaces, dns) + return [] if interfaces.nil? + + connections_reader = Agama::AutoYaST::ConnectionsReader.new( + interfaces, ipv6: ipv6?, dns: dns + ) + connections_reader.read + end + # Reads an AutoYaST DNS section and builds its equivalent hash. # - # @param dns_section [Y2Network::AutoinstProfile::DNSSection] DNS section. + # @param dns_section [Y2Network::AutoinstProfile::DNSSection, nil] DNS section. # @return [Hash] def read_dns_settings(dns_section) dns = {} + return dns if dns_section.nil? + dns["dns_searchlist"] = dns_section.searchlist unless dns_section.searchlist.empty? dns["nameservers"] = dns_section.nameservers unless dns_section.nameservers.empty? dns From 134dcf43f267b6cdf6380a0946cde1bc59a3e594 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Imobach=20Gonz=C3=A1lez=20Sosa?= Date: Fri, 9 May 2025 17:16:08 +0100 Subject: [PATCH 6/8] fix(ruby): do not import empty wireless/device settings --- service/lib/agama/autoyast/connections_reader.rb | 2 +- service/lib/agama/autoyast/wireless_reader.rb | 7 +++++-- service/test/agama/autoyast/connections_reader_test.rb | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/service/lib/agama/autoyast/connections_reader.rb b/service/lib/agama/autoyast/connections_reader.rb index 5bda54b535..f0c2a2a520 100755 --- a/service/lib/agama/autoyast/connections_reader.rb +++ b/service/lib/agama/autoyast/connections_reader.rb @@ -65,7 +65,7 @@ def ipv6? # @return [Hash] def read_connection(interface) conn = {} - conn["interface"] = interface.device if interface.device + conn["interface"] = interface.device unless interface.device.to_s.empty? conn["id"] = interface.name if interface.name addresses = read_addresses(interface) diff --git a/service/lib/agama/autoyast/wireless_reader.rb b/service/lib/agama/autoyast/wireless_reader.rb index 9c4bb5f3e5..d4806a3eb2 100755 --- a/service/lib/agama/autoyast/wireless_reader.rb +++ b/service/lib/agama/autoyast/wireless_reader.rb @@ -39,12 +39,15 @@ def initialize(section) # # @return [Hash] def read - wireless = {} + wireless = { + "ssid" => section.wireless_essid.to_s + } + return {} if wireless["ssid"].empty? + security = security_from(section.wireless_auth_mode) wireless["security"] = security if security mode = mode_from(section.wireless_mode) wireless["mode"] = mode if mode - wireless["ssid"] = section.wireless_essid.to_s case security when "wpa-psk" diff --git a/service/test/agama/autoyast/connections_reader_test.rb b/service/test/agama/autoyast/connections_reader_test.rb index c271ee3a63..f08af237c2 100644 --- a/service/test/agama/autoyast/connections_reader_test.rb +++ b/service/test/agama/autoyast/connections_reader_test.rb @@ -176,7 +176,7 @@ context "when there are wireless settings" do let(:eth0) do - { "name" => "eth0", "wireless_mode" => "wpa-psk" } + { "name" => "eth0", "wireless_essid" => "mywifi" } end it "includes a 'wireless' key containing those settings" do From 934766a55cfca2be1319cfe682b583cce7caba6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Imobach=20Gonz=C3=A1lez=20Sosa?= Date: Fri, 9 May 2025 17:17:49 +0100 Subject: [PATCH 7/8] fix(ruby): fix wrong comments --- service/lib/agama/autoyast/bootloader_reader.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/service/lib/agama/autoyast/bootloader_reader.rb b/service/lib/agama/autoyast/bootloader_reader.rb index 2e277abb97..d1ddf8d143 100644 --- a/service/lib/agama/autoyast/bootloader_reader.rb +++ b/service/lib/agama/autoyast/bootloader_reader.rb @@ -26,16 +26,16 @@ # :nodoc: module Agama module AutoYaST - # Builds the Agama "root" section from an AutoYaST profile. + # Builds the Agama "bootloader" section from an AutoYaST profile. class BootloaderReader # @param profile [ProfileHash] AutoYaST profile def initialize(profile) @profile = profile end - # Returns a hash that corresponds to Agama "root" section. + # Returns a hash that corresponds to Agama "bootloader" section. # - # @return [Hash] Agama "root" section + # @return [Hash] Agama "bootloader" section def read global = profile.fetch_as_hash("bootloader") .fetch_as_hash("global") From 68885d05f5d72ab1e598be39df007b5bcdecd24a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Imobach=20Gonz=C3=A1lez=20Sosa?= Date: Fri, 9 May 2025 17:32:34 +0100 Subject: [PATCH 8/8] fix(ruby): fix calculation of unsupported AutoYaST elements --- service/lib/agama/autoyast/profile_checker.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/service/lib/agama/autoyast/profile_checker.rb b/service/lib/agama/autoyast/profile_checker.rb index a4d87324a8..867f5e4950 100644 --- a/service/lib/agama/autoyast/profile_checker.rb +++ b/service/lib/agama/autoyast/profile_checker.rb @@ -58,7 +58,7 @@ def elements_from(profile, parent = "") elements_from(e, "#{parent}#{ProfileDescription::SEPARATOR}#{k}[#{i}]") end else - elements_from(v, k) + elements_from(v, current) end [current, *children]