From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id 25F8C1FF0C0 for ; Wed, 04 Nov 2026 20:05:02 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 5C7C621716; Wed, 04 Nov 2026 20:04:00 +0100 (CET) From: =?UTF-8?q?Michael=20K=C3=B6ppl?= To: pve-devel@lists.proxmox.com Subject: [PATCH e2e-tests 05/38] lib: instance: add helper to check if an address answers ping Date: Wed, 4 Nov 2026 20:03:12 +0100 Message-ID: <20261104190345.2573464-6-m.koeppl@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261104190345.2573464-1-m.koeppl@proxmox.com> References: <20261104190345.2573464-1-m.koeppl@proxmox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1793819033677 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.221 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) 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 Message-ID-Hash: AH5REN6E5QC6PIALX4RWCDJRS2BMCM5S X-Message-ID-Hash: AH5REN6E5QC6PIALX4RWCDJRS2BMCM5S X-MailFrom: m.koeppl@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Move the helper function from pve_firewall to Proxmox::Test::Instance because it's about to be used for additional tests. Signed-off-by: Michael Köppl --- Proxmox/Test/Instance.pm | 7 +++++++ tests/pve_firewall.pl | 23 ++++++++++++----------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/Proxmox/Test/Instance.pm b/Proxmox/Test/Instance.pm index 38f1607..8c0f710 100644 --- a/Proxmox/Test/Instance.pm +++ b/Proxmox/Test/Instance.pm @@ -74,4 +74,11 @@ sub run_command { return ($stdout, $stderr); } +# Returns true if $ip answers a ping sent from this instance. +sub node_can_ping { + my ($self, $ip) = @_; + + return eval { $self->run_command("ping -c2 -W2 $ip"); 1 } ? 1 : 0; +} + 1; diff --git a/tests/pve_firewall.pl b/tests/pve_firewall.pl index fab35b5..d3991a9 100755 --- a/tests/pve_firewall.pl +++ b/tests/pve_firewall.pl @@ -34,11 +34,6 @@ my $vmid = $client->get('/cluster/nextid'); my $ct_ip = '10.250.250.10'; my $node_ip = '10.250.250.1'; -# Returns true if the node can ping the container. -my $can_ping = sub { - return eval { $pve->run_command("ping -c2 -W2 $ct_ip"); 1 } ? 1 : 0; -}; - # Create and start the container my $upid = $client->post( @@ -65,12 +60,15 @@ $pve->run_command("ip addr add $node_ip/24 dev vmbr0"); eval { # Baseline: ping works before any firewall poll_until( - $can_ping, + sub { $pve->node_can_ping($ct_ip) }, timeout => 30, interval => 3, description => "container $vmid to be pingable", ); - ok($can_ping->(), 'node can ping the container before the firewall is enabled'); + ok( + $pve->node_can_ping($ct_ip), + 'node can ping the container before the firewall is enabled', + ); # Enable the datacenter and container firewall $client->put('/cluster/firewall/options', { enable => 1 }); @@ -79,12 +77,15 @@ eval { # With the firewall enabled the default inbound policy is DROP, so ping is blocked. pve-firewall # applies config changes asynchronously, so poll for the effect. poll_until( - sub { !$can_ping->() }, + sub { !$pve->node_can_ping($ct_ip) }, timeout => 30, interval => 3, description => "the firewall to block ICMP to the container", ); - ok(!$can_ping->(), 'ping is blocked once the container firewall defaults to DROP'); + ok( + !$pve->node_can_ping($ct_ip), + 'ping is blocked once the container firewall defaults to DROP', + ); # Add an ACCEPT rule for ICMP: ping works again $client->post( @@ -99,12 +100,12 @@ eval { ); poll_until( - $can_ping, + sub { $pve->node_can_ping($ct_ip) }, timeout => 30, interval => 3, description => "the ACCEPT rule to allow ICMP to the container", ); - ok($can_ping->(), 'ping works again after adding an ACCEPT rule for ICMP'); + ok($pve->node_can_ping($ct_ip), 'ping works again after adding an ACCEPT rule for ICMP'); 1; } or do { -- 2.47.3