all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: "Michael Köppl" <m.koeppl@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH e2e-tests 19/38] tests: container: verify application containers from OCI images
Date: Wed,  4 Nov 2026 20:03:26 +0100	[thread overview]
Message-ID: <20261104190345.2573464-20-m.koeppl@proxmox.com> (raw)
In-Reply-To: <20261104190345.2573464-1-m.koeppl@proxmox.com>

Create a container from the OCI image built during setup and check
that the image's entrypoint, environment, user, working directory
and stop signal end up in the config, and that the host manages the
network.

Then check that init runs the entrypoint with the image's user,
working directory and environment, including a variable added
through the 'env' property, and that the image's volume path
exists. Since 'pct exec' does not get variables that are meant for
init only, the test reads them from /proc/1/environ. Finally, shut
the container down. The image's init only exits on the image's stop
signal, so the shutdown fails if that signal is not taken over from
the OCI image.

Signed-off-by: Michael Köppl <m.koeppl@proxmox.com>
---
 tests/pve_ct_oci.pl | 190 ++++++++++++++++++++++++++++++++++++++++++++
 tests/testcases.ron |   9 +++
 2 files changed, 199 insertions(+)
 create mode 100755 tests/pve_ct_oci.pl

diff --git a/tests/pve_ct_oci.pl b/tests/pve_ct_oci.pl
new file mode 100755
index 0000000..b987a8a
--- /dev/null
+++ b/tests/pve_ct_oci.pl
@@ -0,0 +1,190 @@
+#!/usr/bin/perl
+
+=head1 NAME
+
+C<pve_ct_oci> - Test an application container created from an OCI image.
+
+=head1 DESCRIPTION
+
+This testcase creates an unprivileged container from the minimal OCI image that
+the setup plan builds and puts into pve1's local storage. It verifies that the
+image's entrypoint and command, environment, user, working directory and stop
+signal are taken over into the container config and that the network is managed
+by the host, since the image has no network management of its own.
+
+It then adds an environment variable through the API and starts the container.
+It verifies that the image's entrypoint runs as init with the image's user,
+working directory and environment, including the added variable, that the
+image's volume path exists, and that the container is reachable from the node
+at its host-configured address. Finally, it shuts the container down. The
+image's init only exits on the image's stop signal.
+
+=cut
+
+use strict;
+use warnings;
+
+use Test::More;
+
+use lib '.';
+use Proxmox::Test::Helper qw(get_pve_instance);
+use Proxmox::Test::Testcase;
+use Proxmox::Test::Util qw(poll_until);
+
+my $pve = get_pve_instance('pve1');
+my $node = $pve->get_nodename();
+my $client = $pve->client();
+
+my $ct_ip = '10.250.252.10';
+my $node_ip = '10.250.252.1';
+
+my $test_container = {
+    vmid => $client->get('/cluster/nextid'),
+    node => $node,
+    ostemplate => 'local:vztmpl/e2e-oci.tar',
+    rootfs => 'local-lvm:1',
+    storage => 'local-lvm',
+    memory => 256,
+    unprivileged => 1,
+    hostname => 'ct-oci',
+    net0 => "name=eth0,bridge=vmbr0,ip=$ct_ip/24",
+};
+
+my $vmid = $test_container->{vmid};
+my $env_marker_key = 'MARKER_ENV';
+my $env_marker_value = 'test';
+
+Proxmox::Test::Testcase->new('pve_ct_oci')->with([{}])->step(
+    'create container from OCI image',
+    sub {
+        my $upid = $client->post("/nodes/$node/lxc", $test_container);
+        $pve->task_ok($upid, "created container $vmid from OCI image")
+            or die "creating container $vmid failed\n";
+    },
+    sub {
+        $pve->destroy_guest('lxc', $vmid);
+    },
+)->step(
+    'verify config taken from the image',
+    sub {
+        my $conf = $client->get("/nodes/$node/lxc/$vmid/config", {});
+
+        is(
+            $conf->{entrypoint},
+            '/entrypoint.sh e2e-cmd',
+            'entrypoint and command are taken from the image',
+        );
+        is($conf->{cmode}, 'console', 'console mode is used for the custom entrypoint');
+        # This is set by the OCI image.
+        is($conf->{env}, "PATH=/bin\0E2E_IMAGE_ENV=from-image", 'image environment is set');
+        like($conf->{net0} // '', qr/\bhost-managed=1\b/, 'network is managed by the host');
+
+        my %raw = map { $_->[0] => $_->[1] } ($conf->{lxc} // [])->@*;
+        is($raw{'lxc.init.uid'}, 1000, 'init user is resolved from the image user database');
+        is($raw{'lxc.init.gid'}, 1000, 'init group is resolved from the image group database');
+        is($raw{'lxc.init.cwd'}, '/home/e2e', 'working directory is taken from the image');
+        is($raw{'lxc.signal.halt'}, 'SIGUSR1', 'stop signal is taken from the image');
+    },
+)->step(
+    'add environment variable',
+    sub {
+        my $env = $client->get("/nodes/$node/lxc/$vmid/config", {})->{env};
+        $client->put(
+            "/nodes/$node/lxc/$vmid/config",
+            { env => "$env\0$env_marker_key=$env_marker_value" },
+        );
+
+        my $conf = $client->get("/nodes/$node/lxc/$vmid/config", {});
+        like(
+            $conf->{env} // '',
+            qr/\0$env_marker_key=$env_marker_value$/,
+            'config has the added variable',
+        );
+    },
+)->step(
+    'add node address on vmbr0',
+    sub {
+        $pve->run_command("ip addr add $node_ip/24 dev vmbr0");
+    },
+    sub {
+        $pve->run_command("ip addr del $node_ip/24 dev vmbr0 2>/dev/null; true");
+    },
+)->step(
+    'start container',
+    sub {
+        $pve->start_guest('lxc', $vmid);
+    },
+)->step(
+    'verify the image entrypoint runs as init',
+    sub {
+        is(
+            $pve->ct_exec($vmid, 'cat /proc/1/cmdline'),
+            "/bin/sh\0/entrypoint.sh\0e2e-cmd\0",
+            'init runs the entrypoint with the command as argument',
+        );
+
+        my $status = $pve->ct_exec($vmid, 'cat /proc/1/status');
+        like($status, qr/^Uid:\s+1000\s+1000\s+1000\s+1000$/m, 'init runs as the image user');
+        like($status, qr/^Gid:\s+1000\s+1000\s+1000\s+1000$/m,
+            'init runs with the image group');
+
+        is(
+            $pve->ct_exec($vmid, 'readlink /proc/1/cwd'),
+            "/home/e2e\n",
+            'init runs in the working directory',
+        );
+    },
+)->step(
+    'verify the environment of init',
+    sub {
+        my %env =
+            map { split(/=/, $_, 2) } split(/\0/, $pve->ct_exec($vmid, 'cat /proc/1/environ'));
+
+        is($env{E2E_IMAGE_ENV}, 'from-image', 'init has the image environment');
+        is($env{$env_marker_key}, $env_marker_value, 'init has the added variable');
+    },
+)->step(
+    'verify the image volume path exists',
+    sub {
+        ok(
+            eval { $pve->ct_exec($vmid, 'test -d /data'); 1 },
+            'directory for the image volume exists',
+        );
+    },
+)->step(
+    'verify host-managed network',
+    sub {
+        poll_until(
+            sub {
+                $pve->ct_exec($vmid, 'ip -4 addr show dev eth0') =~ m/\binet \Q$ct_ip\E\/24\b/;
+            },
+            timeout => 30,
+            interval => 2,
+            description => "eth0 in container $vmid to get $ct_ip",
+        );
+        pass("host configured $ct_ip on eth0 in container $vmid");
+
+        poll_until(
+            sub { $pve->node_can_ping($ct_ip) },
+            timeout => 30,
+            interval => 3,
+            description => "container $vmid to be pingable from the node",
+        );
+        ok($pve->node_can_ping($ct_ip), "node can ping container $vmid");
+    },
+)->step(
+    'shutdown container',
+    sub {
+        my $upid = $client->post("/nodes/$node/lxc/$vmid/status/shutdown", { timeout => 30 });
+        $pve->task_ok($upid, "shut down container $vmid")
+            or die "shutting down container $vmid failed\n";
+
+        is(
+            $client->get("/nodes/$node/lxc/$vmid/status/current", {})->{status},
+            'stopped',
+            "container $vmid reports status 'stopped' after shutdown",
+        );
+    },
+)->run();
+
+done_testing();
diff --git a/tests/testcases.ron b/tests/testcases.ron
index 1d5b7ad..afbaa5b 100644
--- a/tests/testcases.ron
+++ b/tests/testcases.ron
@@ -178,6 +178,15 @@ TestcaseConfig(
             ],
             tag: "extended",
         ),
+        Testcase(
+            name: "pve_ct_oci",
+            run: "./tests/pve_ct_oci.pl",
+            timeout: 600,
+            instances: [
+                "pve1",
+            ],
+            tag: "extended",
+        ),
         Testcase(
             name: "pve_ha_resource_config",
             run: "./tests/pve_ha_resource_config.pl",
-- 
2.47.3





  parent reply	other threads:[~2026-11-04 19:07 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-04 19:03 [PATCH e2e-tests/test-tools 00/38] tests: add tests for guests, Ceph, PBS and cluster workflows Michael Köppl
2026-11-04 19:03 ` [PATCH test-tools 01/38] ansible: rename snd_test bridge to tt_test as multi-purpose bridge Michael Köppl
2026-11-04 19:03 ` [PATCH e2e-tests 02/38] plans: rename sdn_test bridge to tt_test Michael Köppl
2026-11-04 19:03 ` [PATCH e2e-tests 03/38] debian: add missing jq dependency Michael Köppl
2026-11-04 19:03 ` [PATCH e2e-tests 04/38] test framework: move the default container template to the helper Michael Köppl
2026-11-04 19:03 ` [PATCH e2e-tests 05/38] lib: instance: add helper to check if an address answers ping Michael Köppl
2026-11-04 19:03 ` [PATCH e2e-tests 06/38] lib: pveinstance: look up disks by their SCSI serial Michael Köppl
2026-11-04 19:03 ` [PATCH e2e-tests 07/38] lib: pveinstance: add helper to find a task started by another task Michael Köppl
2026-11-04 19:03 ` [PATCH e2e-tests 08/38] lib: pveinstance: add helpers to start and stop guests Michael Köppl
2026-11-04 19:03 ` [PATCH e2e-tests 09/38] lib: pveinstance: add helper to run commands in containers Michael Köppl
2026-11-04 19:03 ` [PATCH e2e-tests 10/38] lib: pveinstance: add helper to wait for qmeventd's cleanup Michael Köppl
2026-11-04 19:03 ` [PATCH e2e-tests 11/38] lib: pveinstance: add helper to check if guest exists Michael Köppl
2026-11-04 19:03 ` [PATCH e2e-tests 12/38] lib: add helpers to use a PBS datastore as PVE storage Michael Köppl
2026-11-04 19:03 ` [PATCH e2e-tests 13/38] scripts: retry container template download, fail if it fails Michael Köppl
2026-11-04 19:03 ` [PATCH e2e-tests 14/38] tests: container: verify lifecycle and guest setup Michael Köppl
2026-11-04 19:03 ` [PATCH e2e-tests 15/38] tests: container: verify volume and bind mountpoints Michael Köppl
2026-11-04 19:03 ` [PATCH e2e-tests 16/38] tests: container: verify snapshots, clones, templates Michael Köppl
2026-11-04 19:03 ` [PATCH e2e-tests 17/38] tests: container: verify device passthrough Michael Köppl
2026-11-04 19:03 ` [PATCH e2e-tests 18/38] plans,scripts: build a minimal OCI image onto pve1 Michael Köppl
2026-11-04 19:03 ` Michael Köppl [this message]
2026-11-04 19:03 ` [PATCH e2e-tests 20/38] tests: vm: verify snapshots, clones, templates Michael Köppl
2026-11-04 19:03 ` [PATCH e2e-tests 21/38] tests: vm: verify adding, resizing, and removing disks Michael Köppl
2026-11-04 19:03 ` [PATCH e2e-tests 22/38] plans,scripts: download a Debian cloud image onto pve1 Michael Köppl
2026-11-04 19:03 ` [PATCH e2e-tests 23/38] tests: vm: verify lifecycle operations and cloud-init guest setup Michael Köppl
2026-11-04 19:03 ` [PATCH e2e-tests 24/38] plans,scripts: install Ceph Tentacle on the cluster nodes Michael Köppl
2026-11-04 19:03 ` [PATCH e2e-tests 25/38] test framework: add Ceph test helpers Michael Köppl
2026-11-06 12:24   ` Kefu Chai
2026-11-06 13:04     ` Michael Köppl
2026-11-04 19:03 ` [PATCH e2e-tests 26/38] tests: ceph: verify setting up a hyper-converged cluster Michael Köppl
2026-11-06 12:50   ` Kefu Chai
2026-11-06 13:05     ` Michael Köppl
2026-11-04 19:03 ` [PATCH e2e-tests 27/38] tests: ceph: verify guests on RBD storage Michael Köppl
2026-11-06 13:01   ` Kefu Chai
2026-11-06 13:07     ` Michael Köppl
2026-11-04 19:03 ` [PATCH e2e-tests 28/38] tests: ceph: verify setting up, using and destroying a CephFS Michael Köppl
2026-11-04 19:03 ` [PATCH e2e-tests 29/38] tests: ceph: verify replacing an OSD Michael Köppl
2026-11-06 13:14   ` Kefu Chai
2026-11-04 19:03 ` [PATCH e2e-tests 30/38] tests: ceph: drop the outdated Ceph setup Michael Köppl
2026-11-04 19:03 ` [PATCH e2e-tests 31/38] tests: pbs: verify container backup and restore Michael Köppl
2026-11-04 19:03 ` [PATCH e2e-tests 32/38] tests: backup: verify VM backup and restore, locally and on PBS Michael Köppl
2026-11-04 19:03 ` [PATCH e2e-tests 33/38] tests: pbs: verify single file restore from a container backup Michael Köppl
2026-11-04 19:03 ` [PATCH e2e-tests 34/38] tests: storage: verify moving guest volumes between storages Michael Köppl
2026-11-04 19:03 ` [PATCH e2e-tests 35/38] tests: migration: verify container migration between nodes Michael Köppl
2026-11-04 19:03 ` [PATCH e2e-tests 36/38] tests: migration: verify VM migration with local disks Michael Köppl
2026-11-04 19:03 ` [PATCH e2e-tests 37/38] tests: ha: verify moving guests off a node for maintenance Michael Köppl
2026-11-04 19:03 ` [PATCH e2e-tests 38/38] tests: migration: verify migrating guests in bulk Michael Köppl
2026-11-06 13:25 ` [PATCH e2e-tests/test-tools 00/38] tests: add tests for guests, Ceph, PBS and cluster workflows Kefu Chai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261104190345.2573464-20-m.koeppl@proxmox.com \
    --to=m.koeppl@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal