public inbox for pve-devel@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 28/38] tests: ceph: verify setting up, using and destroying a CephFS
Date: Wed,  4 Nov 2026 20:03:35 +0100	[thread overview]
Message-ID: <20261104190345.2573464-29-m.koeppl@proxmox.com> (raw)
In-Reply-To: <20261104190345.2573464-1-m.koeppl@proxmox.com>

Create a metadata server on every node and a CephFS with a storage
for it. Check that the CephFS gets its own pools, that one metadata
server becomes active with the others on standby, and that the
storage is mounted on every node. Backup a container to the storage
and restore it on another node, which lists the backup, as the
storage is shared.

Destroy the CephFS as the documentation describes. Destroying it
together with its storage is refused while the storage is enabled
(based on `man pveceph(1)`). Once the storage is disabled and unmounted
and the metadata servers are stopped, it succeeds and removes the
storage and the pools too.

Signed-off-by: Michael Köppl <m.koeppl@proxmox.com>
---
 tests/ceph/test_ceph_cephfs.pl | 311 +++++++++++++++++++++++++++++++++
 tests/testcases.ron            |  11 ++
 2 files changed, 322 insertions(+)
 create mode 100755 tests/ceph/test_ceph_cephfs.pl

diff --git a/tests/ceph/test_ceph_cephfs.pl b/tests/ceph/test_ceph_cephfs.pl
new file mode 100755
index 0000000..40fdb3c
--- /dev/null
+++ b/tests/ceph/test_ceph_cephfs.pl
@@ -0,0 +1,311 @@
+#!/usr/bin/perl
+
+=head1 NAME
+
+C<test_ceph_cephfs> - Test setting up, using and destroying a CephFS.
+
+=head1 DESCRIPTION
+
+This testcase sets up Ceph on the cluster nodes and creates an MDS on every
+node, which are all on standby while there is no CephFS. It then creates a
+CephFS together with a storage for it and verifies that the CephFS has its
+own data and metadata pool, that one MDS became active with the others
+still on standby (only one can be active at a time), and that the storage is
+active and mounted on every node.
+
+It backs up a container on the first node to the CephFS storage and restores
+the backup on the second node, which lists it as the storage is shared.
+
+Finally, it destroys the CephFS as the documentation describes. Destroying it
+together with its storage must be refused while the storage is enabled. Once
+the storage is disabled and unmounted on every node and all MDS are stopped,
+destroying the CephFS must remove it together with its storage and its pools.
+
+=cut
+
+use strict;
+use warnings;
+
+use Test::More;
+
+use JSON;
+
+use lib '.';
+use Proxmox::Test::Ceph qw(check_storage_active create_ceph_cluster wait_for_ceph);
+use Proxmox::Test::Helper qw(CONTAINER_TEMPLATE get_pve_instances);
+use Proxmox::Test::Testcase;
+use Proxmox::Test::Util qw(poll_until);
+
+my $pve_instances = get_pve_instances();
+die "not enough PVE instances" if scalar($pve_instances->@*) < 3;
+
+my $first = $pve_instances->[0];
+my $second = $pve_instances->[1];
+my $node = $first->get_nodename();
+my $target = $second->get_nodename();
+my $client = $first->client();
+
+my $fs = 'e2e-cephfs';
+my $mountpoint = "/mnt/pve/$fs";
+my $marker = 'e2e-cephfs-backup';
+
+my $ctid;
+my $restored_ctid;
+my $backup_volid;
+
+# The state of every MDS by name, as reported by the API.
+my $mds_states = sub {
+    my $list = $client->get("/nodes/$node/ceph/mds", {});
+    return { map { $_->{name} => $_->{state} // '' } $list->@* };
+};
+
+my $wait_for_mds_states = sub {
+    my ($active, $standby) = @_;
+
+    my $states;
+    eval {
+        poll_until(
+            sub {
+                $states = $mds_states->();
+                my @values = values $states->%*;
+                return scalar(grep { $_ eq 'up:active' } @values) == $active
+                    && scalar(grep { $_ eq 'up:standby' } @values) == $standby;
+            },
+            timeout => 120,
+            interval => 2,
+            description => "$active active and $standby standby MDS",
+        );
+    };
+    diag('MDS states: ' . encode_json($states // {})) if $@;
+    return $states;
+};
+
+my $is_mounted = sub {
+    my ($instance) = @_;
+    my ($fstype) = eval { $instance->run_command("findmnt -n -o FSTYPE $mountpoint") };
+    return ($fstype // '') eq "ceph\n";
+};
+
+my $cephfs_entry = sub {
+    my ($entry) = grep { $_->{name} eq $fs } $client->get("/nodes/$node/ceph/fs", {})->@*;
+    return $entry;
+};
+
+Proxmox::Test::Testcase->new('ceph_cephfs')->before_all(sub {
+    create_ceph_cluster($pve_instances);
+})->with([{}])->step(
+        'create metadata servers',
+        sub {
+            for my $instance ($pve_instances->@*) {
+                my $name = $instance->get_nodename();
+                my $upid = $instance->client()->post("/nodes/$name/ceph/mds/$name", {});
+                $instance->task_ok($upid, "created MDS on '$name'")
+                or die "creating the MDS on '$name' failed\n";
+            }
+
+            my $states = $wait_for_mds_states->(0, scalar($pve_instances->@*));
+            is_deeply(
+                [sort keys $states->%*],
+                [sort map { $_->get_nodename() } $pve_instances->@*],
+                'every node has an MDS',
+            );
+            ok(
+                !(grep { $_ ne 'up:standby' } values $states->%*),
+                'all MDS are on standby without a CephFS',
+            );
+        },
+)->step(
+    'create CephFS with storage',
+    sub {
+        my $upid =
+            $client->post("/nodes/$node/ceph/fs/$fs", { pg_num => 32, 'add-storage' => 1 });
+        $first->task_ok($upid, "created CephFS '$fs'") or die "creating the CephFS failed\n";
+
+        my $entry = $cephfs_entry->();
+        ok($entry, "CephFS '$fs' is listed") or die "CephFS '$fs' not found\n";
+        is($entry->{metadata_pool}, "${fs}_metadata", 'CephFS has its own metadata pool');
+        is_deeply($entry->{data_pools}, ["${fs}_data"], 'CephFS has its own data pool');
+
+        my $states = $wait_for_mds_states->(1, scalar($pve_instances->@*) - 1);
+        my ($active) = grep { $states->{$_} eq 'up:active' } keys $states->%*;
+        ok($active, "MDS on '" . ($active // '') . "' became active for the CephFS");
+
+        my $storage = $client->get("/storage/$fs", {});
+        is($storage->{type}, 'cephfs', "CephFS storage '$fs' was added");
+        is($storage->{'fs-name'}, $fs, "storage '$fs' uses the new CephFS");
+        like($storage->{content} // '', qr/\bbackup\b/, "storage '$fs' can hold backups");
+
+        # The fs is not immediately available on all nodes. It is mounted on the first and mounted
+        # shortly after on the other nodes by pvestatd. When querying this too early, the storage
+        # is reported ad inactive.
+        for my $instance ($pve_instances->@*) {
+            my $name = $instance->get_nodename();
+            eval {
+                poll_until(
+                    sub { $is_mounted->($instance) },
+                    timeout => 60,
+                    interval => 2,
+                    description => "CephFS to be mounted on '$name'",
+                );
+            };
+            ok($is_mounted->($instance), "CephFS is mounted at $mountpoint on '$name'");
+            check_storage_active($instance, $fs);
+        }
+
+        wait_for_ceph($first);
+    },
+)->step(
+    'back up container to CephFS',
+    sub {
+        $ctid = $client->get('/cluster/nextid');
+        my $upid = $client->post(
+            "/nodes/$node/lxc",
+            {
+                vmid => $ctid,
+                ostemplate => CONTAINER_TEMPLATE,
+                rootfs => 'local-lvm:2',
+                memory => 256,
+                unprivileged => 1,
+                features => 'nesting=1',
+                hostname => 'ct-cephfs-backup',
+            },
+        );
+        $first->task_ok($upid, "created container $ctid") or die "creating container failed\n";
+
+        $first->start_guest('lxc', $ctid);
+        $first->ct_exec($ctid, "sh -c 'echo $marker > /root/marker'");
+
+        $upid = $client->post(
+            "/nodes/$node/vzdump",
+            { vmid => $ctid, storage => $fs, mode => 'snapshot' },
+        );
+        $first->task_ok($upid, 'backed up the container to CephFS') or die "backup failed\n";
+
+        my $content = $client->get("/nodes/$node/storage/$fs/content", { content => 'backup' });
+        ($backup_volid) = map { $_->{volid} } grep { ($_->{vmid} // 0) == $ctid } $content->@*;
+        ok($backup_volid, 'backup is listed on the CephFS storage')
+            or die "backup not found\n";
+    },
+    sub {
+        $first->destroy_guest('lxc', $ctid) if defined($ctid);
+    },
+)->step(
+    'restore backup on another node',
+    sub {
+        my $target_client = $second->client();
+
+        my $content =
+            $target_client->get("/nodes/$target/storage/$fs/content", { content => 'backup' });
+        ok(
+            (grep { $_->{volid} eq $backup_volid } $content->@*),
+            "node '$target' lists the backup on the shared storage",
+        );
+
+        $restored_ctid = $client->get('/cluster/nextid');
+        my $upid = $target_client->post(
+            "/nodes/$target/lxc",
+            {
+                vmid => $restored_ctid,
+                ostemplate => $backup_volid,
+                restore => 1,
+                storage => 'local-lvm',
+            },
+        );
+        $second->task_ok($upid, "restored the backup as container $restored_ctid on '$target'")
+            or die "restoring the backup failed\n";
+
+        $second->start_guest('lxc', $restored_ctid);
+        is(
+            $second->ct_exec($restored_ctid, 'cat /root/marker'),
+            "$marker\n",
+            'restored container has the data from the backup',
+        );
+        $second->stop_guest('lxc', $restored_ctid);
+    },
+    sub {
+        $second->destroy_guest('lxc', $restored_ctid) if defined($restored_ctid);
+    },
+)->step(
+    'destroying CephFS with an enabled storage is refused',
+    sub {
+        my $upid = eval {
+            $client->delete(
+                "/nodes/$node/ceph/fs/$fs",
+                { 'remove-storages' => 1, 'remove-pools' => 1 },
+            );
+        };
+        my $status = defined($upid) ? $first->wait_for_task($upid, 1) : "API error: $@";
+        ok(!$first->task_successful($status), 'destroying the CephFS is refused');
+        like($status, qr/not disabled/, 'destroying is refused because the storage is enabled');
+        ok($cephfs_entry->(), 'CephFS still exists');
+    },
+)->step(
+    'destroy CephFS',
+    sub {
+        $client->put("/storage/$fs", { disable => 1 });
+
+        # Done manually according to the admin guide.
+        for my $instance ($pve_instances->@*) {
+            $instance->run_command("umount $mountpoint") if $is_mounted->($instance);
+            ok(
+                !$is_mounted->($instance),
+                "CephFS is unmounted on '" . $instance->get_nodename() . "'",
+            );
+        }
+
+        # Stop the standby MDS first, so that none of them takes over from the active one.
+        my $states = $mds_states->();
+        my @standby = grep { $states->{$_} ne 'up:active' } sort keys $states->%*;
+        my @active = grep { $states->{$_} eq 'up:active' } sort keys $states->%*;
+        for my $name (@standby, @active) {
+            my ($instance) = grep { $_->get_nodename() eq $name } $pve_instances->@*;
+            my $upid =
+                $instance->client()->post("/nodes/$name/ceph/stop", { service => "mds.$name" });
+            $instance->task_ok($upid, "stopped MDS on '$name'")
+                or die "stopping the MDS on '$name' failed\n";
+        }
+
+        poll_until(
+            sub {
+                my ($out) = $first->run_command("ceph fs get $fs --format json");
+                return !(keys(decode_json($out)->{mdsmap}->{up}->%*));
+            },
+            timeout => 120,
+            interval => 2,
+            description => "CephFS '$fs' to have no MDS up",
+        );
+
+        my $upid = $client->delete(
+            "/nodes/$node/ceph/fs/$fs",
+            { 'remove-storages' => 1, 'remove-pools' => 1 },
+        );
+        $first->task_ok($upid, "destroyed CephFS '$fs'")
+            or die "destroying the CephFS failed\n";
+
+        ok(!$cephfs_entry->(), 'CephFS is gone');
+
+        my $storages = $client->get('/storage', {});
+        ok(!(grep { $_->{storage} eq $fs } $storages->@*), "storage '$fs' is removed");
+
+        # Pool deletion runs in the background.
+        my %pools;
+        eval {
+            poll_until(
+                sub {
+                    %pools =
+                        map { $_->{pool_name} => 1 } $client->get("/nodes/$node/ceph/pool", {})->@*;
+                    return !$pools{"${fs}_data"} && !$pools{"${fs}_metadata"};
+                },
+                timeout => 60,
+                interval => 2,
+                description => 'the pools of the CephFS to be removed',
+            );
+        };
+        ok(
+            !$pools{"${fs}_data"} && !$pools{"${fs}_metadata"},
+            'pools of the CephFS are removed',
+        );
+    },
+)->run();
+
+done_testing();
diff --git a/tests/testcases.ron b/tests/testcases.ron
index fec8667..9a94d11 100644
--- a/tests/testcases.ron
+++ b/tests/testcases.ron
@@ -414,6 +414,17 @@ TestcaseConfig(
             ],
             tag: "ceph",
         ),
+        Testcase(
+            name: "ceph_cephfs",
+            run: "./tests/ceph/test_ceph_cephfs.pl",
+            timeout: 1800,
+            instances: [
+                "pve1-cluster",
+                "pve2-cluster",
+                "pve3-cluster",
+            ],
+            tag: "ceph",
+        ),
     ],
     rollback_between_tests: Some("pre-test"),
 )
-- 
2.47.3





  parent reply	other threads:[~2026-11-04 19:08 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 ` [PATCH e2e-tests 19/38] tests: container: verify application containers from OCI images Michael Köppl
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 ` Michael Köppl [this message]
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-29-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal