From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 0DDD371BB1; Fri, 9 Apr 2021 10:45:14 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 0043B238CA; Fri, 9 Apr 2021 10:44:43 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 29ECF23895; Fri, 9 Apr 2021 10:44:42 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id E79FC41FD3; Fri, 9 Apr 2021 10:44:41 +0200 (CEST) From: Fabian Ebner To: pve-devel@lists.proxmox.com, pbs-devel@lists.proxmox.com Date: Fri, 9 Apr 2021 10:44:35 +0200 Message-Id: <20210409084436.2454-7-f.ebner@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210409084436.2454-1-f.ebner@proxmox.com> References: <20210409084436.2454-1-f.ebner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.007 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [restenvironment.pm, tools.pm] Subject: [pbs-devel] [PATCH/RFC v2 common 6/7] allow workers to count warnings and finish tasks in a WARNINGS state X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 09 Apr 2021 08:45:14 -0000 as is already supported by the UI (and PBS). A nice bonus is that warn() can be used by both workers and non-workers. For workers, the output is redirected/duplicated as set up by {fork,tee}_worker(), and non-erroring workers that issued a warning will end in a WARNINGS state. Signed-off-by: Fabian Ebner --- Changes from v1: * use chomp in warn(), so it can also be called with newline-terminated strings src/PVE/RESTEnvironment.pm | 22 ++++++++++++++++++++-- src/PVE/Tools.pm | 2 ++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/PVE/RESTEnvironment.pm b/src/PVE/RESTEnvironment.pm index d5b84d0..e8a466c 100644 --- a/src/PVE/RESTEnvironment.pm +++ b/src/PVE/RESTEnvironment.pm @@ -115,7 +115,10 @@ sub init { # priv ... access from private server (pvedaemon) # ha ... access from HA resource manager agent (pve-ha-manager) - my $self = { type => $type }; + my $self = { + type => $type, + warning_count => 0, + }; bless $self, $class; @@ -448,7 +451,6 @@ my $tee_worker = sub { } } - # get status (error or OK) POSIX::read($ctrlfd, $readbuf, 4096); if ($readbuf =~ m/^TASK OK\n?$/) { # skip printing to stdout @@ -456,6 +458,9 @@ my $tee_worker = sub { } elsif ($readbuf =~ m/^TASK ERROR: (.*)\n?$/) { print STDERR "$1\n"; print $taskfh "\n$readbuf"; # ensure start on new line for webUI + } elsif ($readbuf =~ m/^TASK WARNINGS: (\d+)\n?$/) { + print STDERR "Task finished with $1 warning(s)!\n"; + print $taskfh "\n$readbuf"; # ensure start on new line for webUI } else { die "got unexpected control message: $readbuf\n"; } @@ -617,6 +622,9 @@ sub fork_worker { syslog('err', $err); $msg = "TASK ERROR: $err\n"; $exitcode = -1; + } elsif (my $warnings = $self->{warning_count}) { + $msg = "TASK WARNINGS: $warnings\n"; + $exitcode = 0; } else { $msg = "TASK OK\n"; $exitcode = 0; @@ -703,6 +711,16 @@ sub fork_worker { return wantarray ? ($upid, $res) : $upid; } +sub warn { + my ($self, $message) = @_; + + chomp($message); + + print STDERR "WARN: $message\n"; + + $self->{warning_count}++; +} + # Abstract function sub log_cluster_msg { diff --git a/src/PVE/Tools.pm b/src/PVE/Tools.pm index 2a91a92..16ae3d2 100644 --- a/src/PVE/Tools.pm +++ b/src/PVE/Tools.pm @@ -1156,6 +1156,8 @@ sub upid_read_status { return 'OK'; } elsif ($line =~ m/^TASK ERROR: (.+)$/) { return $1; + } elsif ($line =~ m/^TASK (WARNINGS: \d+)$/) { + return $1; } else { return "unexpected status"; } -- 2.20.1