-
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
Open
okynos
wants to merge
11
commits into
os-autoinst:master
Choose a base branch
from
okynos:175728-profile-generator
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
7269a65
Generate all Agama json profiles using jsonnet profiles
okynos f45ee12
Added PR revision
okynos 4c23734
Added PR comments
okynos 3dc42ea
Removed unused code
okynos f115136
Added feature to select partial JSONs
okynos 1bceffb
Added bootloader option
okynos bb08ffc
Fix trim import
okynos 59d0e5b
Import utils
okynos e2a9847
Added Mojo utils
okynos e958fe6
Changed command to which
okynos 02d7ef8
Added profile record
okynos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
||| | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
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 | ||
||| | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
local get_root_filesystem(filesystem) = { | ||
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'), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
local base_lib = import 'lib/base.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(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']: { | ||
[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 == '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'], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ 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; | ||
|
@@ -41,6 +42,7 @@ our @EXPORT = qw( | |
expand_variables | ||
adjust_user_password | ||
upload_profile | ||
generate_json_profile | ||
inject_registration | ||
init_autoyast_profile | ||
test_ayp_url | ||
|
@@ -783,6 +785,51 @@ sub expand_agama_profile { | |
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("which", "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"; | ||
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`; | ||
record_info("Profile", $profile_content); | ||
|
||
save_tmp_file($profile_name, $profile_content); | ||
|
||
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) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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.