-
Notifications
You must be signed in to change notification settings - Fork 282
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
Generate all Agama json profiles using jsonnet profiles #21108
base: master
Are you sure you want to change the base?
Changes from 2 commits
7269a65
f45ee12
4c23734
3dc42ea
f115136
1bceffb
bb08ffc
59d0e5b
e2a9847
e958fe6
02d7ef8
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
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 | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
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: { | ||
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 case we do some more multipath actions, better "activate_multipath". |
||
name: 'activate multipath', | ||
body: ||| | ||
#!/bin/bash | ||
if ! systemctl status multpathd ; then | ||
echo 'Activating multipath' | ||
systemctl start multipathd.socket | ||
systemctl start multipathd | ||
fi | ||
||| | ||
}, | ||
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 | ||
||| | ||
}, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
local get_root_filesystem(filesystem='ext4') = { | ||
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. shouldn't be any default for this, looks to me like some external variable. |
||
drives: [ | ||
{ | ||
partitions: [ | ||
{ search: "*", delete: true }, | ||
{ generate: 'default' }, | ||
{ filesystem: { path: '/', type: filesystem } }, | ||
], | ||
}, | ||
], | ||
}; | ||
|
||
{ | ||
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: get_root_filesystem('ext4'), | ||
root_filesystem_xfs: get_root_filesystem('xfs'), | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
local base_lib = import 'lib/base.libsonnet'; | ||
local scripts = import 'lib/scripts.libsonnet'; | ||
local storage = import 'lib/storage.libsonnet'; | ||
|
||
function(storage_schema='', product='SLES', pre_scripts='', | ||
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. let's not invent words here, the only schema that we have is the one in the Agama repo against which the profile is validated, this should just be 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. for the same reason to make it flexible for openSUSE, |
||
post_scripts='', encrypted=false) { | ||
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. perhaps this could be |
||
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_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'], | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
=head1 autoyast | ||
|
||
Provide translations for autoyast XML file | ||
|
||
|
@@ -41,6 +41,7 @@ | |
expand_variables | ||
adjust_user_password | ||
upload_profile | ||
generate_json_profile | ||
inject_registration | ||
init_autoyast_profile | ||
test_ayp_url | ||
|
@@ -783,6 +784,73 @@ | |
return $profile_url; | ||
} | ||
|
||
=head2 workaround_install_jsonnet | ||
|
||
workaround_install_jsonnet(); | ||
|
||
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 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"); | ||
} | ||
|
||
if (system("command", "-v", "jsonnet") != 0) { | ||
system("sudo", "zypper", "-n", "install", "-f", "golang-github-google-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 | ||
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. try to avoid loops at all cost and use higher-order functions, Perl provides grep, map, the code is much more concise, something like this: |
||
} | ||
|
||
=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"; | ||
my $profile_options = parse_profile_options(get_var('AGAMA_PROFILE_OPTIONS')); | ||
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. the lines which contains some logic should go below, the casedir is just an assignation and should go here instead. |
||
my $casedir = get_required_var('CASEDIR'); | ||
|
||
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); | ||
|
||
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 extra line is not needed, the whole thing could be logic block, kind of blocks (1) preparation (2) execution (3) post-stuff and no need for comment in each block because it is obvious that is the structure. |
||
my $profile_url = autoinst_url . "/files/$profile_name"; | ||
upload_profile(path => $profile_name, profile => $profile_content); | ||
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 case of failure we might not have the uploaded json file, so I think we should also |
||
return $profile_url; | ||
} | ||
|
||
=head2 upload_profile | ||
|
||
upload_profile(profile => $profile, path => $path) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
||
|
@@ -58,6 +58,9 @@ 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\""); | ||
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 don't understand when we use it, I would expect something like:
otherwise existing change would run for interactive installation. |
||
} | ||
my @params = split ' ', trim(get_var('EXTRABOOTPARAMS', '')); | ||
|
||
|
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.
I find really unlikely that we use a pre script also as post script, wouldn't make more sent to separate them in different files, so the user of this feature can see clearly the catalog for each.