From 7269a65f880fc02001fee7eba8f8bccd173d9c97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Luis=20Fern=C3=A1ndez=20Aguilera?= Date: Tue, 4 Feb 2025 09:46:54 +0100 Subject: [PATCH 01/11] Generate all Agama json profiles using jsonnet profiles MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Squashed commit of the following: commit 1abca877e602e25fa2418fe222149bb5d599ca7d Author: José Luis Fernández Aguilera Date: Mon Feb 3 16:24:54 2025 +0100 Improved the way to install jsonnet commit b014cdb4f4d873658391e45eb0124d009e44dfc9 Author: José Luis Fernández Aguilera Date: Mon Feb 3 12:26:27 2025 +0100 Renamed encrypted variable commit 0578b9cfff8c7b5bdb96196c17a90ff578a92b09 Author: José Luis Fernández Aguilera Date: Mon Feb 3 12:06:29 2025 +0100 Added wipefs script commit 5c9961b2e751df50d4d8099d783f0be21ebd4714 Author: José Luis Fernández Aguilera Date: Mon Feb 3 11:19:46 2025 +0100 Fixed encryption definition commit a4d3c6f55247a27256f55d868f5627fc267073a4 Author: José Luis Fernández Aguilera Date: Mon Feb 3 11:01:35 2025 +0100 Squashed commit of the following: commit 59b65d82d88edfcce470bccaee1f0304884056ed Author: José Luis Fernández Aguilera Date: Mon Feb 3 10:40:56 2025 +0100 Added encryption to template commit e79bc06884eaf68f96f905e161645d190f1c9cd4 Author: José Luis Fernández Aguilera Date: Fri Jan 31 17:05:42 2025 +0100 Applied template modifications commit 815a68b5becad63346a7d1b33472834fd5f1f674 Author: José Luis Fernández Aguilera Date: Fri Jan 31 13:21:51 2025 +0100 Removed profile_generator reference commit d2f121c1a0f18a0c4537ba0f4881b7991ef836ce Author: José Luis Fernández Aguilera Date: Fri Jan 31 13:16:29 2025 +0100 Fix export function autoyast commit 224f792b8b91702df1e86a440522ba7c49974be0 Author: José Luis Fernández Aguilera Date: Fri Jan 31 13:14:02 2025 +0100 Applied design changes commit 8a0947255bebb92c88bf62706888a346c5ae4a64 Author: José Luis Fernández Aguilera Date: Fri Jan 31 11:16:36 2025 +0100 Clean the code commit 2257c1272ffbc320332910dd6a3dd793f80582cb Author: José Luis Fernández Aguilera Date: Fri Jan 31 09:59:48 2025 +0100 Added parameters commit dae3ca32b1d6a6466fa5c47a6b3ffd01aa0f9e80 Author: José Luis Fernández Aguilera Date: Thu Jan 30 17:47:49 2025 +0100 Fix product definition commit 451ca41e52b42b6e3522cb6eee6f553936dad66a Author: José Luis Fernández Aguilera Date: Thu Jan 30 17:29:31 2025 +0100 Added agama.auto parameter commit 0213b41b1a1ce9b3f9fcc8247435a03bb2a175e1 Author: José Luis Fernández Aguilera Date: Thu Jan 30 17:00:23 2025 +0100 Moved profile generation to boot Agama step commit 860343f20c5f2fff549a3624ccad31b4775eb0d5 Author: José Luis Fernández Aguilera Date: Thu Jan 30 16:38:28 2025 +0100 Added import commit 319eca22ddff1d64b2810ecf69320f880e712643 Author: José Luis Fernández Aguilera Date: Thu Jan 30 16:20:57 2025 +0100 Fix typo commit 58b2bbd67d335bed97c8e774145e5797d2ae2f36 Author: José Luis Fernández Aguilera Date: Thu Jan 30 16:18:06 2025 +0100 Added casedir variable commit 9d010e8d1067d70f3b272fcc2729f83aac6a9b3d Author: José Luis Fernández Aguilera Date: Thu Jan 30 09:54:38 2025 +0100 Minor fixes commit b92df71a4863a57e38b65a1a8cd359498bd67b33 Author: José Luis Fernández Aguilera Date: Wed Jan 29 17:59:29 2025 +0100 Added profile generation and upload commit 8d82a9337ef20ccb68eb8b30a0dec82023129b35 Author: José Luis Fernández Aguilera Date: Wed Jan 29 17:50:11 2025 +0100 Moved flags commit 9f0b3768772e76f10b52f6acc5c59aed2056b254 Author: José Luis Fernández Aguilera Date: Wed Jan 29 16:51:13 2025 +0100 Changed GPG check commit 342698c083b7dbf7292efccb8de92bd1e068fa5d Author: José Luis Fernández Aguilera Date: Wed Jan 29 16:39:47 2025 +0100 Remove previously added repo commit dae109f8834db68d58712e50c271a4d4e2a59f1f Author: José Luis Fernández Aguilera Date: Wed Jan 29 16:27:53 2025 +0100 Fixed repository URL commit 699a246cc9fa6e268d42457c9363b9716a3ca65b Author: José Luis Fernández Aguilera Date: Wed Jan 29 16:19:31 2025 +0100 Fixed parameters commit ae431a4b3129dac0eafdfcd3e3de193beb16b2d6 Author: José Luis Fernández Aguilera Date: Wed Jan 29 16:09:58 2025 +0100 Replace options order commit f766a078ea9cc4fb8a19d95fd6871c400cf089d9 Author: José Luis Fernández Aguilera Date: Wed Jan 29 16:01:44 2025 +0100 Added non-interactive in zypper commit 5ff245effb11c948f28e27cdf94f645a44edbeed Author: José Luis Fernández Aguilera Date: Wed Jan 29 15:54:18 2025 +0100 Added sudo to the commands commit 4264a4edaed5f7ff91a9d2f031df9c5520768e87 Author: José Luis Fernández Aguilera Date: Wed Jan 29 13:22:31 2025 +0100 Moved to system calls commit bd708c5682e5102edacbb6511b496d3559f8325a Author: José Luis Fernández Aguilera Date: Wed Jan 29 11:34:38 2025 +0100 Select console before test commit 307c6f015703e221c4fec11272b26ba899a5cc65 Author: José Luis Fernández Aguilera Date: Wed Jan 29 11:05:40 2025 +0100 Moved generate agama profile and test jsonnet package in worker commit 157f99374d603cde81d2e52cc637cbbfd06bf70d Author: José Luis Fernández Aguilera Date: Tue Jan 28 17:48:43 2025 +0100 Fix variable definition commit 99610a3ecff1611ee6cbbe8adf5a35ccc3bf032e Author: José Luis Fernández Aguilera Date: Tue Jan 28 17:44:57 2025 +0100 Fix default profile import commit c36f92da86c22e4a8b27282f1424278106fe636f Author: José Luis Fernández Aguilera Date: Tue Jan 28 17:40:54 2025 +0100 First approach to generate Agama profile Removed install jsonnet function Fix syntax error Restore install_jsonnet function Restore deleted templates Removed Pom model file --- data/yam/agama/auto/lib/base.libsonnet | 20 +++++++++ data/yam/agama/auto/lib/scripts.libsonnet | 43 ++++++++++++++++++ data/yam/agama/auto/lib/storage.libsonnet | 53 +++++++++++++++++++++++ data/yam/agama/auto/template.jsonnet | 12 +++++ lib/autoyast.pm | 43 ++++++++++++++++++ tests/yam/agama/boot_agama.pm | 6 ++- 6 files changed, 176 insertions(+), 1 deletion(-) create mode 100644 data/yam/agama/auto/lib/base.libsonnet create mode 100644 data/yam/agama/auto/lib/scripts.libsonnet create mode 100644 data/yam/agama/auto/lib/storage.libsonnet create mode 100644 data/yam/agama/auto/template.jsonnet diff --git a/data/yam/agama/auto/lib/base.libsonnet b/data/yam/agama/auto/lib/base.libsonnet new file mode 100644 index 000000000000..695a828b3ecc --- /dev/null +++ b/data/yam/agama/auto/lib/base.libsonnet @@ -0,0 +1,20 @@ +{ + storage: import 'storage.libsonnet', + scripts: import 'scripts.libsonnet', + getProduct(product_id='SLES'):: { + id: product_id + }, + bootloader: { + stopOnBootMenu: true + }, + user: { + fullName: 'Bernhard M. Wiedemann', + password: '$6$vYbbuJ9WMriFxGHY$gQ7shLw9ZBsRcPgo6/8KmfDvQ/lCqxW8/WnMoLCoWGdHO6Touush1nhegYfdBbXRpsQuy/FTZZeg7gQL50IbA/', + hashedPassword: true, + userName: 'bernhard' + }, + root: { + password: '$6$vYbbuJ9WMriFxGHY$gQ7shLw9ZBsRcPgo6/8KmfDvQ/lCqxW8/WnMoLCoWGdHO6Touush1nhegYfdBbXRpsQuy/FTZZeg7gQL50IbA/', + hashedPassword: true + } +} diff --git a/data/yam/agama/auto/lib/scripts.libsonnet b/data/yam/agama/auto/lib/scripts.libsonnet new file mode 100644 index 000000000000..f490384beaa7 --- /dev/null +++ b/data/yam/agama/auto/lib/scripts.libsonnet @@ -0,0 +1,43 @@ +local enable_root_login = { + name: 'enable root login', + chroot: true, + body: ||| + #!/usr/bin/env bash + echo 'PermitRootLogin yes' > /etc/ssh/sshd_config.d/root.conf + ||| +}; + +{ + default: { + post: [ enable_root_login ] + }, + multipath: { + pre: [{ + name: 'activate multipath', + body: ||| + #!/bin/bash + if ! systemctl status multpathd ; then + echo 'Activating multipath' + systemctl start multipathd.socket + systemctl start multipathd + fi + |||, + }] + }, + wipefs: { + pre: [ + { + name: 'wipefs', + body: ||| + #!/usr/bin/env bash + for i in `lsblk -n -l -o NAME -d -e 7,11,254` + do wipefs -af /dev/$i + sleep 1 + sync + done + ||| + } + ], + post: [ enable_root_login ], + }, +} diff --git a/data/yam/agama/auto/lib/storage.libsonnet b/data/yam/agama/auto/lib/storage.libsonnet new file mode 100644 index 000000000000..d619838c23cd --- /dev/null +++ b/data/yam/agama/auto/lib/storage.libsonnet @@ -0,0 +1,53 @@ +{ + lvm(encrypted=false): { + drives: [ + { + alias: 'pvs-disk', + partitions: [ + { search: "*", delete: true } + ] + }, + ], + volumeGroups: [ + { + name: 'system', + physicalVolumes: [ + { + [if encrypted == true then 'generate']: { + targetDevices: ['pvs-disk'], + encryption: { + luks2: { password: "nots3cr3t" } + } + }, + [if encrypted == false then 'generate']: ['pvs-disk'], + }, + ], + logicalVolumes: [ + { generate: 'default' }, + ], + }, + ] + }, + root_filesystem_ext4: { + drives: [ + { + partitions: [ + { search: "*", delete: true }, + { generate: 'default' }, + { filesystem: { path: '/', type: 'ext4' } }, + ], + }, + ], + }, + root_filesystem_xfs: { + drives: [ + { + partitions: [ + { search: "*", delete: true }, + { generate: 'default' }, + { filesystem: { path: '/', type: 'xfs' } }, + ], + }, + ], + }, +} diff --git a/data/yam/agama/auto/template.jsonnet b/data/yam/agama/auto/template.jsonnet new file mode 100644 index 000000000000..5776a029ad5a --- /dev/null +++ b/data/yam/agama/auto/template.jsonnet @@ -0,0 +1,12 @@ +local lib = import 'lib/base.libsonnet'; + +function(storage='default', product='SLES', scripts='default', encrypted=false) { + product: lib.getProduct(product), + user: lib['user'], + root: lib['root'], + [if scripts != '' then 'scripts']: lib.scripts[scripts], + + [if storage == 'lvm' then 'storage']: lib.storage.lvm(encrypted), + [if storage == 'root_filesystem_ext4' then 'storage']: lib.storage['root_filesystem_ext4'], + [if storage == 'root_filesystem_xfs' then 'storage']: lib.storage['root_filesystem_xfs'], +} diff --git a/lib/autoyast.pm b/lib/autoyast.pm index 3e31450c8856..3c5431332601 100644 --- a/lib/autoyast.pm +++ b/lib/autoyast.pm @@ -41,6 +41,7 @@ our @EXPORT = qw( expand_variables adjust_user_password upload_profile + generate_json_profile inject_registration init_autoyast_profile test_ayp_url @@ -783,6 +784,48 @@ sub expand_agama_profile { return $profile_url; } +=head2 install_jsonnet + + install_jsonnet(); + + Install via zypper golang-github-google-jsonnet package in the worker. + +=cut + +sub install_jsonnet { + if (system("sudo", "zypper", "-n", "repos", "systemsmanagement_Agama_Devel") != 0) { + system("sudo", "zypper", "-n", "addrepo", "-f", "-G", + "https://download.opensuse.org/repositories/systemsmanagement:Agama:Devel/15.6/systemsmanagement:Agama:Devel.repo"); + } + + if (system("command", "-v", "jsonnet") != 0) { + system("sudo", "zypper", "-n", "install", "-f", "golang-github-google-jsonnet"); + } +} + +=head2 generate_json_profile + + generate_json_profile(); + + Return the URL of generated JSON profile + +=cut + +sub generate_json_profile { + my $profile_name = "generated_profile.json"; + + install_jsonnet(); + my $profile_parameters = get_var('AGAMA_PROFILE_PARAMETERS'); + my $casedir = get_required_var('CASEDIR'); + my $profile_content = `jsonnet $profile_parameters $casedir/data/yam/agama/auto/template.jsonnet`; + + save_tmp_file($profile_name, $profile_content); + + my $profile_url = autoinst_url . "/files/$profile_name"; + upload_profile(path => $profile_name, profile => $profile_content); + return $profile_url; +} + =head2 upload_profile upload_profile(profile => $profile, path => $path) diff --git a/tests/yam/agama/boot_agama.pm b/tests/yam/agama/boot_agama.pm index d24d47e95018..a8dff079e964 100644 --- a/tests/yam/agama/boot_agama.pm +++ b/tests/yam/agama/boot_agama.pm @@ -10,7 +10,7 @@ use strict; use warnings; use testapi; -use autoyast qw(expand_agama_profile); +use autoyast qw(expand_agama_profile generate_json_profile); use Utils::Architectures; use Utils::Backends; @@ -63,6 +63,10 @@ sub run { $grub_menu->expect_is_shown(); $grub_menu->edit_current_entry(); + unless (get_var('AGAMA_AUTO')) { + my $profile_url = generate_json_profile(); + push(@params, "agama.auto=\"$profile_url\""); + } $grub_entry_edition->move_cursor_to_end_of_kernel_line(); $grub_entry_edition->type(\@params); $grub_entry_edition->boot(); From f45ee129822f5054d9410f304b5218835a586409 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Luis=20Fern=C3=A1ndez=20Aguilera?= Date: Tue, 4 Feb 2025 17:50:24 +0100 Subject: [PATCH 02/11] Added PR revision --- data/yam/agama/auto/lib/base.libsonnet | 5 -- data/yam/agama/auto/lib/scripts.libsonnet | 63 ++++++++++------------- data/yam/agama/auto/lib/storage.libsonnet | 36 +++++-------- data/yam/agama/auto/template.jsonnet | 26 ++++++---- lib/autoyast.pm | 41 ++++++++++++--- tests/yam/agama/boot_agama.pm | 7 ++- 6 files changed, 93 insertions(+), 85 deletions(-) diff --git a/data/yam/agama/auto/lib/base.libsonnet b/data/yam/agama/auto/lib/base.libsonnet index 695a828b3ecc..6c7048490ae3 100644 --- a/data/yam/agama/auto/lib/base.libsonnet +++ b/data/yam/agama/auto/lib/base.libsonnet @@ -1,9 +1,4 @@ { - storage: import 'storage.libsonnet', - scripts: import 'scripts.libsonnet', - getProduct(product_id='SLES'):: { - id: product_id - }, bootloader: { stopOnBootMenu: true }, diff --git a/data/yam/agama/auto/lib/scripts.libsonnet b/data/yam/agama/auto/lib/scripts.libsonnet index f490384beaa7..2a1716f4fe9f 100644 --- a/data/yam/agama/auto/lib/scripts.libsonnet +++ b/data/yam/agama/auto/lib/scripts.libsonnet @@ -1,43 +1,32 @@ -local enable_root_login = { - name: 'enable root login', - chroot: true, - body: ||| - #!/usr/bin/env bash - echo 'PermitRootLogin yes' > /etc/ssh/sshd_config.d/root.conf - ||| -}; - { - default: { - post: [ enable_root_login ] + enable_root_login: { + name: 'enable root login', + chroot: true, + body: ||| + #!/usr/bin/env bash + echo 'PermitRootLogin yes' > /etc/ssh/sshd_config.d/root.conf + ||| }, multipath: { - pre: [{ - name: 'activate multipath', - body: ||| - #!/bin/bash - if ! systemctl status multpathd ; then - echo 'Activating multipath' - systemctl start multipathd.socket - systemctl start multipathd - fi - |||, - }] + name: 'activate multipath', + body: ||| + #!/bin/bash + if ! systemctl status multpathd ; then + echo 'Activating multipath' + systemctl start multipathd.socket + systemctl start multipathd + fi + ||| }, - wipefs: { - pre: [ - { - name: 'wipefs', - body: ||| - #!/usr/bin/env bash - for i in `lsblk -n -l -o NAME -d -e 7,11,254` - do wipefs -af /dev/$i - sleep 1 - sync - done - ||| - } - ], - post: [ enable_root_login ], + wipe_filesystem: { + name: 'wipefs', + body: ||| + #!/usr/bin/env bash + for i in `lsblk -n -l -o NAME -d -e 7,11,254` + do wipefs -af /dev/$i + sleep 1 + sync + done + ||| }, } diff --git a/data/yam/agama/auto/lib/storage.libsonnet b/data/yam/agama/auto/lib/storage.libsonnet index d619838c23cd..80b6a9e2c313 100644 --- a/data/yam/agama/auto/lib/storage.libsonnet +++ b/data/yam/agama/auto/lib/storage.libsonnet @@ -1,3 +1,15 @@ +local get_root_filesystem(filesystem='ext4') = { + drives: [ + { + partitions: [ + { search: "*", delete: true }, + { generate: 'default' }, + { filesystem: { path: '/', type: filesystem } }, + ], + }, + ], +}; + { lvm(encrypted=false): { drives: [ @@ -28,26 +40,6 @@ }, ] }, - root_filesystem_ext4: { - drives: [ - { - partitions: [ - { search: "*", delete: true }, - { generate: 'default' }, - { filesystem: { path: '/', type: 'ext4' } }, - ], - }, - ], - }, - root_filesystem_xfs: { - drives: [ - { - partitions: [ - { search: "*", delete: true }, - { generate: 'default' }, - { filesystem: { path: '/', type: 'xfs' } }, - ], - }, - ], - }, + root_filesystem_ext4: get_root_filesystem('ext4'), + root_filesystem_xfs: get_root_filesystem('xfs'), } diff --git a/data/yam/agama/auto/template.jsonnet b/data/yam/agama/auto/template.jsonnet index 5776a029ad5a..341c3349eac3 100644 --- a/data/yam/agama/auto/template.jsonnet +++ b/data/yam/agama/auto/template.jsonnet @@ -1,12 +1,20 @@ -local lib = import 'lib/base.libsonnet'; +local base_lib = import 'lib/base.libsonnet'; +local scripts = import 'lib/scripts.libsonnet'; +local storage = import 'lib/storage.libsonnet'; -function(storage='default', product='SLES', scripts='default', encrypted=false) { - product: lib.getProduct(product), - user: lib['user'], - root: lib['root'], - [if scripts != '' then 'scripts']: lib.scripts[scripts], +function(storage_schema='', product='SLES', pre_scripts='', + post_scripts='', encrypted=false) { + product: { + id: product + }, + user: base_lib['user'], + root: base_lib['root'], + [if pre_scripts != '' || post_scripts != '' then 'scripts']: { + [if pre_scripts != '' then 'pre']: [ scripts[x] for x in std.split(pre_scripts, ',') ], + [if post_scripts != '' then 'post']: [ scripts[x] for x in std.split(post_scripts, ',') ], + }, - [if storage == 'lvm' then 'storage']: lib.storage.lvm(encrypted), - [if storage == 'root_filesystem_ext4' then 'storage']: lib.storage['root_filesystem_ext4'], - [if storage == 'root_filesystem_xfs' then 'storage']: lib.storage['root_filesystem_xfs'], + [if storage_schema == 'lvm' then 'storage']: storage.lvm(encrypted), + [if storage_schema == 'root_filesystem_ext4' then 'storage']: storage['root_filesystem_ext4'], + [if storage_schema == 'root_filesystem_xfs' then 'storage']: storage['root_filesystem_xfs'], } diff --git a/lib/autoyast.pm b/lib/autoyast.pm index 3c5431332601..42b7c0b23fe2 100644 --- a/lib/autoyast.pm +++ b/lib/autoyast.pm @@ -784,15 +784,17 @@ sub expand_agama_profile { return $profile_url; } -=head2 install_jsonnet +=head2 workaround_install_jsonnet - install_jsonnet(); + workaround_install_jsonnet(); - Install via zypper golang-github-google-jsonnet package in the worker. + Workaround Install via zypper golang-github-google-jsonnet package in the worker. + We need this meanwhile the package is built for all other architectures (s390x/aarch64/ppc64le). + After that it should be in the Salt repository. =cut -sub install_jsonnet { +sub workaround_install_jsonnet { if (system("sudo", "zypper", "-n", "repos", "systemsmanagement_Agama_Devel") != 0) { system("sudo", "zypper", "-n", "addrepo", "-f", "-G", "https://download.opensuse.org/repositories/systemsmanagement:Agama:Devel/15.6/systemsmanagement:Agama:Devel.repo"); @@ -803,6 +805,28 @@ sub install_jsonnet { } } +=head2 parse_profile_options + + parse_profile_options(options => $options); + + Parse given options to match required parameters syntax of jsonnet. + +=cut + +sub parse_profile_options { + my ($options) = @_; + + my @params = split(' ', trim($options)); + for my $element (@params) { + if ($element =~ /true/ || $element =~/false/) { + $element = " --tla-code " . $element + } else { + $element = " --tla-str " . $element + } + } + return @params +} + =head2 generate_json_profile generate_json_profile(); @@ -813,11 +837,12 @@ sub install_jsonnet { sub generate_json_profile { my $profile_name = "generated_profile.json"; - - install_jsonnet(); - my $profile_parameters = get_var('AGAMA_PROFILE_PARAMETERS'); + my $profile_options = parse_profile_options(get_var('AGAMA_PROFILE_OPTIONS')); my $casedir = get_required_var('CASEDIR'); - my $profile_content = `jsonnet $profile_parameters $casedir/data/yam/agama/auto/template.jsonnet`; + + workaround_install_jsonnet(); + my $profile_content = `jsonnet $profile_options $casedir/data/yam/agama/auto/template.jsonnet`; + die $profile_content; save_tmp_file($profile_name, $profile_content); diff --git a/tests/yam/agama/boot_agama.pm b/tests/yam/agama/boot_agama.pm index a8dff079e964..7ff6069bfc59 100644 --- a/tests/yam/agama/boot_agama.pm +++ b/tests/yam/agama/boot_agama.pm @@ -58,15 +58,14 @@ sub run { my $path = expand_agama_profile($agama_auto); set_var('AGAMA_AUTO', $path); set_var('EXTRABOOTPARAMS', get_var('EXTRABOOTPARAMS', '') . " agama.auto=\"$path\""); + } else { + my $profile_url = generate_json_profile(); + set_var('EXTRABOOTPARAMS', get_var('EXTRABOOTPARAMS', '') . " agama.auto=\"$profile_url\""); } my @params = split ' ', trim(get_var('EXTRABOOTPARAMS', '')); $grub_menu->expect_is_shown(); $grub_menu->edit_current_entry(); - unless (get_var('AGAMA_AUTO')) { - my $profile_url = generate_json_profile(); - push(@params, "agama.auto=\"$profile_url\""); - } $grub_entry_edition->move_cursor_to_end_of_kernel_line(); $grub_entry_edition->type(\@params); $grub_entry_edition->boot(); From 4c23734cb2bb64b7cf40ad7b8533e9de5bcf6b31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Luis=20Fern=C3=A1ndez=20Aguilera?= Date: Wed, 5 Feb 2025 09:48:41 +0100 Subject: [PATCH 03/11] Added PR comments --- .../yam/agama/auto/lib/scripts_post.libsonnet | 10 +++++++++ ...cripts.libsonnet => scripts_pre.libsonnet} | 10 +-------- data/yam/agama/auto/lib/storage.libsonnet | 2 +- data/yam/agama/auto/template.jsonnet | 21 ++++++++++--------- lib/autoyast.pm | 2 +- tests/yam/agama/boot_agama.pm | 14 +++++++------ 6 files changed, 32 insertions(+), 27 deletions(-) create mode 100644 data/yam/agama/auto/lib/scripts_post.libsonnet rename data/yam/agama/auto/lib/{scripts.libsonnet => scripts_pre.libsonnet} (69%) diff --git a/data/yam/agama/auto/lib/scripts_post.libsonnet b/data/yam/agama/auto/lib/scripts_post.libsonnet new file mode 100644 index 000000000000..3e12ec9ab951 --- /dev/null +++ b/data/yam/agama/auto/lib/scripts_post.libsonnet @@ -0,0 +1,10 @@ +{ + enable_root_login: { + name: 'enable root login', + chroot: true, + body: ||| + #!/usr/bin/env bash + echo 'PermitRootLogin yes' > /etc/ssh/sshd_config.d/root.conf + ||| + } +} diff --git a/data/yam/agama/auto/lib/scripts.libsonnet b/data/yam/agama/auto/lib/scripts_pre.libsonnet similarity index 69% rename from data/yam/agama/auto/lib/scripts.libsonnet rename to data/yam/agama/auto/lib/scripts_pre.libsonnet index 2a1716f4fe9f..e06db862c8c5 100644 --- a/data/yam/agama/auto/lib/scripts.libsonnet +++ b/data/yam/agama/auto/lib/scripts_pre.libsonnet @@ -1,13 +1,5 @@ { - enable_root_login: { - name: 'enable root login', - chroot: true, - body: ||| - #!/usr/bin/env bash - echo 'PermitRootLogin yes' > /etc/ssh/sshd_config.d/root.conf - ||| - }, - multipath: { + activate_multipath: { name: 'activate multipath', body: ||| #!/bin/bash diff --git a/data/yam/agama/auto/lib/storage.libsonnet b/data/yam/agama/auto/lib/storage.libsonnet index 80b6a9e2c313..15aa9cf2e158 100644 --- a/data/yam/agama/auto/lib/storage.libsonnet +++ b/data/yam/agama/auto/lib/storage.libsonnet @@ -1,4 +1,4 @@ -local get_root_filesystem(filesystem='ext4') = { +local get_root_filesystem(filesystem) = { drives: [ { partitions: [ diff --git a/data/yam/agama/auto/template.jsonnet b/data/yam/agama/auto/template.jsonnet index 341c3349eac3..42f64bbdf72c 100644 --- a/data/yam/agama/auto/template.jsonnet +++ b/data/yam/agama/auto/template.jsonnet @@ -1,20 +1,21 @@ local base_lib = import 'lib/base.libsonnet'; -local scripts = import 'lib/scripts.libsonnet'; -local storage = import 'lib/storage.libsonnet'; +local scripts_pre_lib = import 'lib/scripts_pre.libsonnet'; +local scripts_post_lib = import 'lib/scripts_post.libsonnet'; +local storage_lib = import 'lib/storage.libsonnet'; -function(storage_schema='', product='SLES', pre_scripts='', - post_scripts='', encrypted=false) { +function(storage='', product='', scripts_pre='', + scripts_post='', encrypted=false) { product: { id: product }, user: base_lib['user'], root: base_lib['root'], - [if pre_scripts != '' || post_scripts != '' then 'scripts']: { - [if pre_scripts != '' then 'pre']: [ scripts[x] for x in std.split(pre_scripts, ',') ], - [if post_scripts != '' then 'post']: [ scripts[x] for x in std.split(post_scripts, ',') ], + [if scripts_pre != '' || scripts_post != '' then 'scripts']: { + [if scripts_pre != '' then 'pre']: [ scripts_pre_lib[x] for x in std.split(scripts_pre, ',') ], + [if scripts_post != '' then 'post']: [ scripts_post_lib[x] for x in std.split(scripts_post, ',') ], }, - [if storage_schema == 'lvm' then 'storage']: storage.lvm(encrypted), - [if storage_schema == 'root_filesystem_ext4' then 'storage']: storage['root_filesystem_ext4'], - [if storage_schema == 'root_filesystem_xfs' then 'storage']: storage['root_filesystem_xfs'], + [if storage == 'lvm' then 'storage']: storage_lib.lvm(encrypted), + [if storage == 'root_filesystem_ext4' then 'storage']: storage_lib['root_filesystem_ext4'], + [if storage == 'root_filesystem_xfs' then 'storage']: storage_lib['root_filesystem_xfs'], } diff --git a/lib/autoyast.pm b/lib/autoyast.pm index 42b7c0b23fe2..6dcfa568298a 100644 --- a/lib/autoyast.pm +++ b/lib/autoyast.pm @@ -837,10 +837,10 @@ sub parse_profile_options { sub generate_json_profile { my $profile_name = "generated_profile.json"; - my $profile_options = parse_profile_options(get_var('AGAMA_PROFILE_OPTIONS')); my $casedir = get_required_var('CASEDIR'); workaround_install_jsonnet(); + my $profile_options = map { " --tla-" . (/true|false/ ? "code" : "str") . " $_" } split(' ', trim(get_var('AGAMA_PROFILE_OPTIONS'))); my $profile_content = `jsonnet $profile_options $casedir/data/yam/agama/auto/template.jsonnet`; die $profile_content; diff --git a/tests/yam/agama/boot_agama.pm b/tests/yam/agama/boot_agama.pm index 7ff6069bfc59..6f6d13359ffc 100644 --- a/tests/yam/agama/boot_agama.pm +++ b/tests/yam/agama/boot_agama.pm @@ -55,12 +55,14 @@ sub run { # prepare kernel parameters if (my $agama_auto = get_var('AGAMA_AUTO')) { - my $path = expand_agama_profile($agama_auto); - set_var('AGAMA_AUTO', $path); - set_var('EXTRABOOTPARAMS', get_var('EXTRABOOTPARAMS', '') . " agama.auto=\"$path\""); - } else { - my $profile_url = generate_json_profile(); - set_var('EXTRABOOTPARAMS', get_var('EXTRABOOTPARAMS', '') . " agama.auto=\"$profile_url\""); + if (is_x86_64()) { + my $profile_url = generate_json_profile(); + set_var('EXTRABOOTPARAMS', get_var('EXTRABOOTPARAMS', '') . " agama.auto=\"$profile_url\""); + } else { + my $path = expand_agama_profile($agama_auto); + set_var('AGAMA_AUTO', $path); + set_var('EXTRABOOTPARAMS', get_var('EXTRABOOTPARAMS', '') . " agama.auto=\"$path\""); + } } my @params = split ' ', trim(get_var('EXTRABOOTPARAMS', '')); From 3dc42ea210b73e89bff2d63101d63db288c4ca51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Luis=20Fern=C3=A1ndez=20Aguilera?= Date: Wed, 5 Feb 2025 09:53:56 +0100 Subject: [PATCH 04/11] Removed unused code --- lib/autoyast.pm | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/lib/autoyast.pm b/lib/autoyast.pm index 6dcfa568298a..5f23a6f60b9f 100644 --- a/lib/autoyast.pm +++ b/lib/autoyast.pm @@ -805,28 +805,6 @@ sub workaround_install_jsonnet { } } -=head2 parse_profile_options - - parse_profile_options(options => $options); - - Parse given options to match required parameters syntax of jsonnet. - -=cut - -sub parse_profile_options { - my ($options) = @_; - - my @params = split(' ', trim($options)); - for my $element (@params) { - if ($element =~ /true/ || $element =~/false/) { - $element = " --tla-code " . $element - } else { - $element = " --tla-str " . $element - } - } - return @params -} - =head2 generate_json_profile generate_json_profile(); From f115136a2d23af960f42436dae14050f5efc2ce6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Luis=20Fern=C3=A1ndez=20Aguilera?= Date: Thu, 6 Feb 2025 12:36:12 +0100 Subject: [PATCH 05/11] Added feature to select partial JSONs --- data/yam/agama/auto/template.jsonnet | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/data/yam/agama/auto/template.jsonnet b/data/yam/agama/auto/template.jsonnet index 42f64bbdf72c..d583bef262ec 100644 --- a/data/yam/agama/auto/template.jsonnet +++ b/data/yam/agama/auto/template.jsonnet @@ -3,13 +3,11 @@ local scripts_pre_lib = import 'lib/scripts_pre.libsonnet'; local scripts_post_lib = import 'lib/scripts_post.libsonnet'; local storage_lib = import 'lib/storage.libsonnet'; -function(storage='', product='', scripts_pre='', +function(user=true, root=true, storage='', product='', scripts_pre='', scripts_post='', encrypted=false) { - product: { - id: product - }, - user: base_lib['user'], - root: base_lib['root'], + [if product != '' then 'product']: { id: product }, + [if user == true then 'user']: base_lib['user'], + [if root == true then 'root']: base_lib['root'], [if scripts_pre != '' || scripts_post != '' then 'scripts']: { [if scripts_pre != '' then 'pre']: [ scripts_pre_lib[x] for x in std.split(scripts_pre, ',') ], [if scripts_post != '' then 'post']: [ scripts_post_lib[x] for x in std.split(scripts_post, ',') ], From 1bceffb368dac6fafecc1a7895c0e8be38c25001 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Luis=20Fern=C3=A1ndez=20Aguilera?= Date: Thu, 6 Feb 2025 12:49:45 +0100 Subject: [PATCH 06/11] Added bootloader option --- data/yam/agama/auto/template.jsonnet | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/data/yam/agama/auto/template.jsonnet b/data/yam/agama/auto/template.jsonnet index d583bef262ec..5af7f9d510f5 100644 --- a/data/yam/agama/auto/template.jsonnet +++ b/data/yam/agama/auto/template.jsonnet @@ -3,9 +3,10 @@ local scripts_pre_lib = import 'lib/scripts_pre.libsonnet'; local scripts_post_lib = import 'lib/scripts_post.libsonnet'; local storage_lib = import 'lib/storage.libsonnet'; -function(user=true, root=true, storage='', product='', scripts_pre='', +function(bootloader=true, user=true, root=true, storage='', product='', scripts_pre='', scripts_post='', encrypted=false) { [if product != '' then 'product']: { id: product }, + [if bootloader == true then 'bootloader']: base_lib['bootloader'], [if user == true then 'user']: base_lib['user'], [if root == true then 'root']: base_lib['root'], [if scripts_pre != '' || scripts_post != '' then 'scripts']: { From bb08ffc013ad16f2ed2fa7521ba75e5c5202425d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Luis=20Fern=C3=A1ndez=20Aguilera?= Date: Thu, 6 Feb 2025 17:00:19 +0100 Subject: [PATCH 07/11] Fix trim import --- lib/autoyast.pm | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/autoyast.pm b/lib/autoyast.pm index 5f23a6f60b9f..bd04ed275fa3 100644 --- a/lib/autoyast.pm +++ b/lib/autoyast.pm @@ -21,6 +21,7 @@ use warnings; use testapi; use Utils::Backends; use Utils::Architectures; +use Utils qw(trim); use version_utils qw(is_sle is_opensuse); use registration qw(scc_version get_addon_fullname); use File::Copy 'copy'; From 59d0e5baefeea3976679a6e1f0840ffe9de654a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Luis=20Fern=C3=A1ndez=20Aguilera?= Date: Thu, 6 Feb 2025 17:02:42 +0100 Subject: [PATCH 08/11] Import utils --- lib/autoyast.pm | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/autoyast.pm b/lib/autoyast.pm index bd04ed275fa3..4179a06212a8 100644 --- a/lib/autoyast.pm +++ b/lib/autoyast.pm @@ -19,9 +19,7 @@ use Exporter; use strict; use warnings; use testapi; -use Utils::Backends; -use Utils::Architectures; -use Utils qw(trim); +use Utils; use version_utils qw(is_sle is_opensuse); use registration qw(scc_version get_addon_fullname); use File::Copy 'copy'; From e2a9847d91eba54c0d1c12f6a760417974a81602 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Luis=20Fern=C3=A1ndez=20Aguilera?= Date: Thu, 6 Feb 2025 17:07:49 +0100 Subject: [PATCH 09/11] Added Mojo utils --- lib/autoyast.pm | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/autoyast.pm b/lib/autoyast.pm index 4179a06212a8..9b5d427e99f4 100644 --- a/lib/autoyast.pm +++ b/lib/autoyast.pm @@ -19,13 +19,15 @@ use Exporter; use strict; use warnings; use testapi; -use Utils; +use Utils::Backends; +use Utils::Architectures; use version_utils qw(is_sle is_opensuse); use registration qw(scc_version get_addon_fullname); use File::Copy 'copy'; use File::Find qw(finddepth); use File::Path 'make_path'; use LWP::Simple 'head'; +use Mojo::Util 'trim'; use Socket; use xml_utils; From e958fe6e110871bef8cc0abfe2b06da8d9b5dd3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Luis=20Fern=C3=A1ndez=20Aguilera?= Date: Thu, 6 Feb 2025 17:17:09 +0100 Subject: [PATCH 10/11] Changed command to which --- lib/autoyast.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/autoyast.pm b/lib/autoyast.pm index 9b5d427e99f4..06b9db6ce4f6 100644 --- a/lib/autoyast.pm +++ b/lib/autoyast.pm @@ -801,7 +801,7 @@ sub workaround_install_jsonnet { "https://download.opensuse.org/repositories/systemsmanagement:Agama:Devel/15.6/systemsmanagement:Agama:Devel.repo"); } - if (system("command", "-v", "jsonnet") != 0) { + if (system("which", "jsonnet") != 0) { system("sudo", "zypper", "-n", "install", "-f", "golang-github-google-jsonnet"); } } From 02d7ef8952c450be9bb31fe143981ee470f7f11a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Luis=20Fern=C3=A1ndez=20Aguilera?= Date: Thu, 6 Feb 2025 17:21:54 +0100 Subject: [PATCH 11/11] Added profile record --- lib/autoyast.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/autoyast.pm b/lib/autoyast.pm index 06b9db6ce4f6..b5da2ef487ab 100644 --- a/lib/autoyast.pm +++ b/lib/autoyast.pm @@ -821,7 +821,7 @@ sub generate_json_profile { workaround_install_jsonnet(); my $profile_options = map { " --tla-" . (/true|false/ ? "code" : "str") . " $_" } split(' ', trim(get_var('AGAMA_PROFILE_OPTIONS'))); my $profile_content = `jsonnet $profile_options $casedir/data/yam/agama/auto/template.jsonnet`; - die $profile_content; + record_info("Profile", $profile_content); save_tmp_file($profile_name, $profile_content);