Skip to content

Commit

Permalink
Add CPU usage check when HAWK is idle
Browse files Browse the repository at this point in the history
  • Loading branch information
alvarocarvajald committed May 5, 2021
1 parent 8bb84b0 commit 00350f8
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions tests/ha/check_hawk.pm
@@ -1,6 +1,6 @@
# SUSE's openQA tests
#
# Copyright (c) 2018-2019 SUSE LLC
# Copyright (c) 2018-2021 SUSE LLC
#
# Copying and distribution of this file, with or without modification,
# are permitted in any medium without royalty provided the copyright
Expand All @@ -17,21 +17,26 @@ use warnings;
use testapi;
use lockapi;
use hacluster qw(get_cluster_name is_node);
use utils 'systemctl';
use version_utils 'is_sle';
use utils qw(systemctl);
use version_utils qw(is_sle);
use List::Util qw(sum);

sub check_hawk_cpu {
my $cluster_name = get_cluster_name;
my @cpu_usage = ();
my %args = @_;
my $cluster_name = get_cluster_name;
my @cpu_usage = ();
my $threshold = $args{idle_check} ? 10 : 50;
my $idle_check_loops = 60;

# Do not wait on barriers if checking CPU usage while HAWK is idle
barrier_wait("HAWK_GUI_CPU_TEST_START_$cluster_name") unless $args{idle_check};

barrier_wait("HAWK_GUI_CPU_TEST_START_$cluster_name");
while (!barrier_try_wait("HAWK_GUI_CPU_TEST_FINISH_$cluster_name")) {
while ($args{idle_check} || !barrier_try_wait("HAWK_GUI_CPU_TEST_FINISH_$cluster_name")) {
# Wrapping script_output in eval { } as node can be fenced by hawk test from client.
# In fenced node, script_output will croak and kill the test. This prevents it
my $metric = eval {
script_output q@ps axo pcpu,comm | awk '/hawk|puma/ {total += $1} END {print "cpu_usage["total"]"}'@,
proceed_on_failure => 1;
proceed_on_failure => 1, quiet => 1;
};
if ($@) {
# When script_output croaks, command may be typed when SUT is on the grub menu
Expand All @@ -46,15 +51,18 @@ sub check_hawk_cpu {
else {
send_key 'esc' unless check_screen('grub2');
}
barrier_wait("HAWK_GUI_CPU_TEST_FINISH_$cluster_name");
barrier_wait("HAWK_GUI_CPU_TEST_FINISH_$cluster_name") unless $args{idle_check};
last;
}
push @cpu_usage, $metric =~ /cpu_usage\[([\d\.]+)\]/;
sleep bmwqemu::scale_timeout(1);
last if ($args{idle_check} && (--$idle_check_loops < 0));
}
my $cpu_usage = sum(@cpu_usage) / @cpu_usage;
record_info "CPU usage", "HAWK/PUMA CPU usage was $cpu_usage";
record_soft_failure "bsc#1179609 - HAWK/PUMA consume a considerable amount of CPU" if ($cpu_usage >= 50);
my $msg = "HAWK/PUMA CPU usage was $cpu_usage";
$msg .= " while idle" if $args{idle_check};
record_info "CPU usage", $msg;
record_soft_failure "bsc#1179609 - HAWK/PUMA consume a considerable amount of CPU" if ($cpu_usage >= $threshold);
}

sub run {
Expand Down Expand Up @@ -87,6 +95,8 @@ sub run {
# Keep a screenshot for this test
save_screenshot;

check_hawk_cpu(idle_check => 1);

barrier_wait("HAWK_CHECKED_$cluster_name");

# If testing HAWK GUI, also wait for those barriers
Expand Down

0 comments on commit 00350f8

Please sign in to comment.