Skip to content
7 changes: 5 additions & 2 deletions service/lib/agama/autoyast/connections_reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ module AutoYaST
class ConnectionsReader
# @param section [Y2Network::AutoinstProfile::Interfaces] AutoYaST interfaces section.
# @param ipv6 [boolean] Whether IPv6 is wanted or not.
def initialize(section, ipv6: false)
# @param dns [Hash] Agama DNS settings.
def initialize(section, ipv6: false, dns: {})
@section = section
@ipv6 = ipv6
@dns = dns
end

# Returns a hash that contains the list of Agama connections
Expand All @@ -51,7 +53,7 @@ def read

private

attr_reader :section
attr_reader :section, :dns

def ipv6?
@ipv6
Expand All @@ -75,6 +77,7 @@ def read_connection(interface)
conn["wireless"] = wireless unless wireless.empty?
bond = Agama::AutoYaST::BondReader.new(interface).read
conn["bond"] = bond unless bond.empty?
conn.merge!(dns)

conn
end
Expand Down
49 changes: 49 additions & 0 deletions service/lib/agama/autoyast/hostname_reader.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# 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"

# :nodoc:
module Agama
module AutoYaST
# Builds the Agama "network.hostname" section from an AutoYaST profile.
class HostnameReader
# @param profile [ProfileHash] AutoYaST profile
def initialize(profile)
@profile = profile
end

# @return [Hash] Agama "hostname" section.
def read
networking = profile.fetch_as_hash("networking")
dns = networking.fetch_as_hash("dns")
hostname = dns["hostname"]
return {} if hostname.to_s.empty?

{ "hostname" => { "static" => hostname } }
end

private

attr_reader :profile
end
end
end
14 changes: 13 additions & 1 deletion service/lib/agama/autoyast/network_reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ def read
return {} if networking.empty?

section = Y2Network::AutoinstProfile::NetworkingSection.new_from_hashes(networking)
dns = read_dns_settings(section.dns)
connections_reader = Agama::AutoYaST::ConnectionsReader.new(
section.interfaces, ipv6: ipv6?
section.interfaces, ipv6: ipv6?, dns: dns
)
connections = connections_reader.read
return {} if connections.empty?
Expand All @@ -55,6 +56,17 @@ def read
def ipv6?
profile.fetch_as_hash("networking").fetch("ipv6", false)
end

# Reads an AutoYaST DNS section and builds its equivalent hash.
#
# @param dns_section [Y2Network::AutoinstProfile::DNSSection] DNS section.
# @return [Hash]
def read_dns_settings(dns_section)
dns = {}
dns["dns_searchlist"] = dns_section.searchlist unless dns_section.searchlist.empty?
dns["nameservers"] = dns_section.nameservers unless dns_section.nameservers.empty?
dns
end
end
end
end
21 changes: 18 additions & 3 deletions service/lib/tasks/autoyast.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,30 @@ module Tasks
class AutoYaSTCompatGenerator
attr_reader :description

INTRO = <<~INTRO
# AutoYaST compatibility reference

Let's describe which sections and elements from an AutoYaST profile are (or will be) supported in
Agama. In some cases, you might find a table with the following columns:

- AutoYaST: name of the AutoYaST element.
- Supported: whether it is (or will be) supported. The meaning of each value is:
- Yes: fully supported.
- Planned: not supported yet, but there are plans to support it.
- Undecided: no decision about whether it should be supported.
- No: there are no plans for supporting that element.
- Agama: name of the Agama element.
- Comment: any comment or reason about the element.

INTRO

def initialize
@description = Agama::AutoYaST::ProfileDescription.load
end

# Generates the document in Markdown format
def generate
lines = ["# AutoYaST compatibility reference"]
lines = [INTRO]

top_level = description.elements.select(&:top_level?)
.sort_by(&:short_key)
Expand All @@ -46,8 +63,6 @@ def generate
lines.concat(section(e))
end

lines.join("\n")

lines.concat(unsupported_elements(unsupported))
end

Expand Down
7 changes: 6 additions & 1 deletion service/package/rubygem-agama-yast.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
-------------------------------------------------------------------
Wed May 7 10:24:14 UTC 2025 - Imobach Gonzalez Sosa <[email protected]>

- Convert AutoYaST DNS section to JSON (gh#agama-project/agama#2335).

-------------------------------------------------------------------
Wed May 7 06:33:28 UTC 2025 - José Iván López González <[email protected]>

Expand Down Expand Up @@ -26,7 +31,7 @@ Fri Apr 25 13:36:13 UTC 2025 - Ancor Gonzalez Sosa <[email protected]>
Thu Apr 24 17:18:04 UTC 2025 - Knut Anderssen <[email protected]>

- Copy only the NetworkManager connnections from /etc and just
in case the copy has not been disabled
in case the copy has not been disabled
(gh#agama-project/agama#2291).

-------------------------------------------------------------------
Expand Down
66 changes: 58 additions & 8 deletions service/share/autoyast-compat.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
[
{ "key": "add-on", "support": "no" },
{ "key": "add-on", "support": "planned" },
{ "key": "audit-laf", "support": "no" },
{ "key": "auth-client", "support": "no" },
{ "key": "configuration_management", "support": "no" },
{ "key": "deploy_image", "support": "no" },
{ "key": "dhcp-server", "support": "no" },
{ "key": "dns-server", "support": "no" },
{ "key": "fcoe-client", "support": "no" },
{
{
"key": "files",
"children": [
{ "key": "file_path", "support": "yes", "agama": "files.destination", "notes": "Creating directories by using trailing slash is not yet supported."},
{
"key": "file_path",
"support": "yes",
"agama": "files.destination",
"notes": "Creating directories by using trailing slash is not yet supported."
},
{ "key": "file_contents", "support": "yes", "agama": "files.content" },
{ "key": "file_location", "support": "yes", "agama": "files.url" },
{ "key": "file_owner", "support": "yes", "notes": "In agama it is split to files.user and files.group" },
{
"key": "file_owner",
"support": "yes",
"notes": "In agama it is split to files.user and files.group"
},
{ "key": "file_permissions", "support": "yes" },
{ "key": "file_script", "support": "planned" }
]
Expand Down Expand Up @@ -54,7 +63,36 @@
"notes": "Only NetworkManager is supported."
},
{ "key": "dhcp_options", "support": "no" },
{ "key": "dns", "support": "no" },
{
"key": "dns",
"children": [
{
"key": "dhcp_hostname",
"support": "no"
},
{
"key": "hostname",
"support": "yes",
"agama": "hostname.static"
},
{
"key": "nameservers",
"support": "yes",
"agama": "network.connections[].nameservers",
"notes": "Copied to each connection."
},
{
"key": "resolv_conf_policy",
"support": "no"
},
{
"key": "searchlist",
"support": "yes",
"agama": "network.connections[].dns_searchlist",
"notes": "Copied to each connection."
}
]
},
{
"key": "ipv6",
"support": "yes",
Expand Down Expand Up @@ -262,7 +300,11 @@
"agama": "scripts.pre[].name"
},
{ "key": "location", "support": "yes", "agama": "scripts.pre[].url" },
{ "key": "source", "support": "yes", "agama": "scripts.pre[].content" },
{
"key": "source",
"support": "yes",
"agama": "scripts.pre[].content"
},
{
"key": "interpreter",
"support": "no",
Expand Down Expand Up @@ -353,7 +395,11 @@
"support": "yes",
"agama": "scripts.init[].url"
},
{ "key": "source", "support": "yes", "agama": "scripts.init[].content" },
{
"key": "source",
"support": "yes",
"agama": "scripts.init[].content"
},
{
"key": "interpreter",
"support": "no",
Expand Down Expand Up @@ -381,7 +427,11 @@
"support": "yes",
"agama": "scripts.init[].url"
},
{ "key": "source", "support": "yes", "agama": "scripts.init[].content" },
{
"key": "source",
"support": "yes",
"agama": "scripts.init[].content"
},
{ "key": "rerun", "support": "no" }
]
}
Expand Down
10 changes: 9 additions & 1 deletion service/test/agama/autoyast/connections_reader_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@
{ "bootproto" => eth0_bootproto, "name" => "eth0" }
end
let(:ipv6?) { true }
let(:dns) { { "nameservers" => ["1.1.1.1"], "dns_searchlist" => ["example.lan"] } }
let(:eth0_bootproto) { "dhcp" }

subject do
section = Y2Network::AutoinstProfile::InterfacesSection.new_from_hashes(
interfaces
)
described_class.new(section, ipv6: ipv6?)
described_class.new(section, ipv6: ipv6?, dns: dns)
end

describe "#read" do
Expand Down Expand Up @@ -196,5 +197,12 @@
expect(conn["bond"]).to be_a(Hash)
end
end

it "adds DNS settings to the connection" do
connections = subject.read["connections"]
connections.each do |conn|
expect(conn).to include(dns)
end
end
end
end
64 changes: 64 additions & 0 deletions service/test/agama/autoyast/hostname_reader_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# 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/hostname_reader"

Yast.import "Profile"

describe Agama::AutoYaST::HostnameReader do
let(:profile) do
{
"networking" => {
"dns" => {
"hostname" => "host.example.lan"
}
}
}
end

subject do
described_class.new(Yast::ProfileHash.new(profile))
end

describe "#read" do
context "when there is no 'networking' section" do
let(:profile) { {} }

it "returns an empty hash" do
expect(subject.read).to be_empty
end
end

context "when there is no 'hostname' property" do
let(:profile) { { "networking" => {} } }

it "returns an empty hash" do
expect(subject.read).to be_empty
end
end

it "returns a hash containing the hostname" do
expect(subject.read["hostname"]).to eq("static" => "host.example.lan")
end
end
end
11 changes: 10 additions & 1 deletion service/test/agama/autoyast/network_reader_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@
let(:profile) do
{
"networking" => {
"interfaces" => [{ "name" => "eth0" }]
"interfaces" => [{ "name" => "eth0" }],
"dns" => {
"nameservers" => ["1.1.1.1"],
"searchlist" => ["example.lan"]
}
}
}
end
Expand All @@ -51,6 +55,11 @@
it "returns a section with the 'connections' list" do
network = subject.read
expect(network["network"].keys).to include("connections")
network["network"]["connections"].each do |conn|
expect(conn).to include(
"nameservers" => ["1.1.1.1"], "dns_searchlist" => ["example.lan"]
)
end
end
end
end
Expand Down
Loading