Skip to content

Commit

Permalink
Unregister from SCC after job is stopped
Browse files Browse the repository at this point in the history
We need to consider canceled & failed jobs, so de-registration must be
performed from worker. It needs username & password that are generated
during registration.

Worker unregister from scc using by calling SCC url with:
DELETE /connect/systems
  • Loading branch information
kravciak committed Oct 10, 2016
1 parent 6673936 commit 701e761
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 4 deletions.
29 changes: 27 additions & 2 deletions lib/registration.pm
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,33 @@ use base Exporter;
use Exporter;

use strict;

use testapi;
use utils qw /addon_decline_license/;

our @EXPORT = qw/fill_in_registration_data registration_bootloader_params yast_scc_registration/;
our @EXPORT = qw/fill_in_registration_data registration_bootloader_params yast_scc_registration setup_unregister_hook/;

sub setup_unregister_hook {
# Run from multiple places to setup variables ASAP
return if get_var("SCC_DEREGISTER");

# Defaults - switch to log-console if root-console is in use
my ($pre, $post) = ("log-console", "root-console");
if (check_var('SCC_REGISTER', 'installation')) {
# Register during installation
($pre, $post) = ("install-shell", "installation");
}
elsif (get_var('SCC_REGISTER', '') =~ /addon|network/) {
# SLERT - register in X11
($pre, $post) = ("root-console", "x11");
}

# Save SCCcredentials information into variable
select_console $pre;
my $credentials = script_output("cut -d= -f2 /etc/zypp/credentials.d/SCCcredentials");
set_var("SCC_DEREGISTER", $credentials);
bmwqemu::save_vars();
select_console $post;
}

sub fill_in_registration_data {
my ($addon, $uc_addon);
Expand Down Expand Up @@ -52,6 +74,7 @@ sub fill_in_registration_data {
next;
}
elsif (match_has_tag("import-untrusted-gpg-key")) {
setup_unregister_hook;
if (check_var("IMPORT_UNTRUSTED_KEY", 1)) {
send_key "alt-t", 1; # import
}
Expand All @@ -61,6 +84,7 @@ sub fill_in_registration_data {
next;
}
elsif (match_has_tag("registration-online-repos")) {
setup_unregister_hook;
if (!get_var('QAM_MINIMAL')) {
send_key "alt-y", 1; # want updates
}
Expand Down Expand Up @@ -95,6 +119,7 @@ sub fill_in_registration_data {
last;
}
}
setup_unregister_hook;

if (check_var('SCC_REGISTER', 'installation')) {
if (check_screen("local-registration-servers", 10)) {
Expand Down
33 changes: 33 additions & 0 deletions postrun.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# SUSE's openQA tests
#
# Copyright © 2016 SUSE LLC
#
# Copying and distribution of this file, with or without modification,
# are permitted in any medium without royalty provided the copyright
# notice and this notice are preserved. This file is offered as-is,
# without any warranty.

use strict;
use warnings;
use testapi;
use LWP::UserAgent;

# poo#11518 - deregister system after job finishes
if (get_var("SCC_DEREGISTER")) {
diag "de-registration from SCC";

my @credentials = split /\r\n/, get_var("SCC_DEREGISTER");

my $ua = LWP::UserAgent->new;
$ua->credentials('scc.suse.com:443', 'SCC Connect API', $credentials[0], $credentials[1]);
my $response = $ua->delete('https://scc.suse.com/connect/systems');

if (!$response->is_success) {
die $response->status_line;
}
}
else {
diag "de-registration not needed";
}

1;
6 changes: 4 additions & 2 deletions tests/jeos/sccreg.pm
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,21 @@
# notice and this notice are preserved. This file is offered as-is,
# without any warranty.

# G-Summary: First commit of JeOS firstrun, diskusage, sccreg, and imgsize tests
# G-Maintainer: Richard Brown <rbrownccb@opensuse.org>
# Summary: Register JeOS using SUSEConnect
# Maintainer: Richard Brown <rbrownccb@opensuse.org>

use base "opensusebasetest";
use strict;
use testapi;
use registration;

sub run() {
my $sccmail = get_var("SCC_EMAIL");
my $scccode = get_var("SCC_REGCODE");
my $url = get_var('SCC_URL', 'https://scc.suse.com');

assert_script_run "SUSEConnect --url=$url -e $sccmail -r $scccode";
setup_unregister_hook;
}

sub test_flags() {
Expand Down

0 comments on commit 701e761

Please sign in to comment.