Skip to content

Commit

Permalink
Merge pull request os-autoinst#20949 from pdostal/LTSSregistercloudguest
Browse files Browse the repository at this point in the history
PC: Register LTSS via proper binary
  • Loading branch information
asmorodskyi authored Jan 14, 2025
2 parents 5142174 + 8d6d6b2 commit 682d637
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 47 deletions.
55 changes: 48 additions & 7 deletions lib/publiccloud/utils.pm
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use testapi;
use utils;
use version_utils qw(is_sle is_public_cloud get_version_id is_transactional is_openstack is_sle_micro check_version);
use transactional qw(reboot_on_changes trup_call process_reboot);
use registration;
use registration 'get_addon_fullname';
use maintenance_smelt qw(is_embargo_update);

# Indicating if the openQA port has been already allowed via SELinux policies
Expand Down Expand Up @@ -60,40 +60,81 @@ sub utc_timestamp {
return sprintf("%04d/%02d/%02d %02d:%02d:%02d", $year, $mon, $day, $hour, $min, $sec);
}


=head2 ssh_add_suseconnect_product
ssh_add_suseconnect_product($remote, $name, [program => $program, [version => $version, [arch => $arch, [params => $params, [timeout => $timeout, [retries => $retries, [delay => $delay]]]]]]]);
Register addon in the SUT
=cut

sub ssh_add_suseconnect_product {
my ($remote, $name, %args) = @_;
if ($args{program} eq 'registercloudguest') {
script_retry(sprintf("ssh %s sudo %s %s", $remote, $args{program}, $args{params}), delay => $args{delay}, retry => $args{retries}, timeout => $args{timeout});
} else {
script_retry(sprintf("ssh %s sudo %s -p %s/%s/%s %s", $remote, $args{program}, $name, $args{version}, $args{arch}, $args{params}), delay => $args{delay}, retry => $args{retries}, timeout => $args{timeout});
}
}

sub register_addon {
my ($remote, $addon) = @_;

my $arch = get_var('PUBLIC_CLOUD_ARCH') // "x86_64";
$arch = "aarch64" if ($arch eq "arm64");
my $timestamp = utc_timestamp();
record_info($addon, "Going to register '$addon' addon\nUTC: $timestamp");
my $cmd_time = time();
# ssh_add_suseconnect_product($remote, $name, $version, $arch, $params, $timeout, $retries, $delay)
my ($timeout, $retries, $delay) = (300, 3, 120);
my $program = get_var("PUBLIC_CLOUD_SCC_ENDPOINT", "registercloudguest");

assert_script_run "sftp $remote:/etc/os-release /tmp/os-release";
assert_script_run 'source /tmp/os-release';

if ($addon =~ /ltss/) {
ssh_add_suseconnect_product($remote, get_addon_fullname($addon), '${VERSION_ID}', $arch, "-r " . get_required_var('SCC_REGCODE_LTSS'), $timeout, $retries, $delay);
ssh_add_suseconnect_product($remote, get_addon_fullname($addon), program => $program, version => '${VERSION_ID}', arch => $arch, params => "-r " . get_required_var('SCC_REGCODE_LTSS'), timeout => $timeout, retries => $retries, delay => $delay);
} elsif (is_sle('<15') && $addon =~ /tcm|wsm|contm|asmm|pcm/) {
ssh_add_suseconnect_product($remote, get_addon_fullname($addon), '`echo ${VERSION} | cut -d- -f1`', $arch, '', $timeout, $retries, $delay);
ssh_add_suseconnect_product($remote, get_addon_fullname($addon), program => 'SUSEConnect', version => '`echo ${VERSION} | cut -d- -f1`', arch => $arch, params => '', timeout => $timeout, retries => $retries, delay => $delay);
} elsif (is_sle('<15') && $addon =~ /sdk|we/) {
ssh_add_suseconnect_product($remote, get_addon_fullname($addon), '${VERSION_ID}', $arch, '', $timeout, $retries, $delay);
ssh_add_suseconnect_product($remote, get_addon_fullname($addon), program => 'SUSEConnect', version => '${VERSION_ID}', arch => $arch, params => '', timeout => $timeout, retries => $retries, delay => $delay);
} else {
if ($addon =~ /nvidia/i) {
(my $version = get_version_id(dst_machine => $remote)) =~ s/^(\d+).*/$1/m;
ssh_add_suseconnect_product($remote, get_addon_fullname($addon), $version, $arch, '', $timeout, $retries, $delay);
ssh_add_suseconnect_product($remote, get_addon_fullname($addon), program => 'SUSEConnect', version => $version, arch => $arch, params => '', timeout => $timeout, retries => $retries, delay => $delay);
} else {
ssh_add_suseconnect_product($remote, get_addon_fullname($addon), undef, $arch, '', $timeout, $retries, $delay);
ssh_add_suseconnect_product($remote, get_addon_fullname($addon), program => 'SUSEConnect', version => '${VERSION_ID}', arch => $arch, params => '', timeout => $timeout, retries => $retries, delay => $delay);
}
}
record_info('SUSEConnect time', 'The command SUSEConnect -r ' . get_addon_fullname($addon) . ' took ' . (time() - $cmd_time) . ' seconds.');
}

=head2 ssh_remove_suseconnect_product
ssh_remove_suseconnect_product($name, [$version, [$arch, [$params]]]);
Deregister addon in SUT
=cut

sub ssh_remove_suseconnect_product {
my ($remote, $name, $version, $arch, $params) = @_;
assert_script_run "sftp $remote:/etc/os-release /tmp/os-release";
assert_script_run 'source /tmp/os-release';
script_retry(sprintf("ssh $remote sudo SUSEConnect -d -p $name/$version/$arch $params", $remote, $name, $version, $arch, $params), retry => 5, delay => 60, timeout => 180);
}

sub deregister_addon {
my ($remote, $addon) = @_;

my $arch = get_var('PUBLIC_CLOUD_ARCH', 'x86_64');
$arch = "aarch64" if ($arch eq "arm64");
my $timestamp = utc_timestamp();
record_info($addon, "Going to deregister '$addon' addon\nUTC: $timestamp");
my $cmd_time = time();
my ($timeout, $retries, $delay) = (300, 3, 120);

assert_script_run "sftp $remote:/etc/os-release /tmp/os-release";
assert_script_run 'source /tmp/os-release';

if ($addon =~ /ltss/) {
# ssh_remove_suseconnect_product($remote, $name, $version, $arch, $params, $timeout, $retries, $delay)
ssh_remove_suseconnect_product($remote, get_addon_fullname($addon), '${VERSION_ID}', $arch, "-r " . get_required_var('SCC_REGCODE_LTSS'), $timeout, $retries, $delay);
Expand Down
40 changes: 0 additions & 40 deletions lib/registration.pm
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ use transactional;

our @EXPORT = qw(
add_suseconnect_product
ssh_add_suseconnect_product
remove_suseconnect_product
ssh_remove_suseconnect_product
cleanup_registration
register_product
assert_registration_screen_present
Expand Down Expand Up @@ -221,27 +219,6 @@ sub add_suseconnect_product {
die "SUSEConnect failed activating module $name after $retry retries.";
}

=head2 ssh_add_suseconnect_product
ssh_add_suseconnect_product($remote, $name, [$version, [$arch, [$params, [$timeout, [$retries, [$delay]]]]]]);
Wrapper for SUSEConnect -p $name over ssh.
=cut

sub ssh_add_suseconnect_product {
my ($remote, $name, $version, $arch, $params, $timeout, $retries, $delay) = @_;
assert_script_run "sftp $remote:/etc/os-release /tmp/os-release";
assert_script_run 'source /tmp/os-release';
$version //= '${VERSION_ID}';
$arch //= '${CPU}';
$params //= '';
$timeout //= 300;
$retries //= 3;
$delay //= 10;

script_retry("ssh $remote sudo SUSEConnect $debug_flag -p $name/$version/$arch $params", delay => $delay, retry => $retries, timeout => $timeout);
}

=head2 remove_suseconnect_product
remove_suseconnect_product($name, [$version, [$arch, [$params]]]);
Expand All @@ -257,23 +234,6 @@ sub remove_suseconnect_product {
script_retry("SUSEConnect $debug_flag -d -p $name/$version/$arch $params", retry => 5, delay => 60, timeout => 180);
}

=head2 ssh_remove_suseconnect_product
ssh_remove_suseconnect_product($name, [$version, [$arch, [$params]]]);
Wrapper for SUSEConnect -d $name over ssh.
=cut

sub ssh_remove_suseconnect_product {
my ($remote, $name, $version, $arch, $params) = @_;
assert_script_run "sftp $remote:/etc/os-release /tmp/os-release";
assert_script_run 'source /tmp/os-release';
$version //= scc_version();
$arch //= get_required_var('arch');
$params //= '';
script_retry("ssh $remote sudo SUSEConnect $debug_flag -d -p $name/$version/$arch $params", retry => 5, delay => 60, timeout => 180);
}

=head2 cleanup_registration
cleanup_registration();
Expand Down

0 comments on commit 682d637

Please sign in to comment.