Skip to content

Commit

Permalink
roachtest: cleaning up microceph cluster
Browse files Browse the repository at this point in the history
The microceph cluster must be removed at the end of test to allow for the node
to be reused.

Epic: none

Fixes: #138860

Release note: None
  • Loading branch information
sravotto committed Jan 14, 2025
1 parent f665b1f commit fdb8fb2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions pkg/cmd/roachtest/tests/s3_clone_backup_restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func registerBackupS3Clones(r registry.Registry) {
version: cephVersion,
}
ceph.install(ctx)
defer ceph.cleanup(ctx)
v.validateBackupRestore(ctx, ceph)
},
})
Expand Down
21 changes: 20 additions & 1 deletion pkg/cmd/roachtest/tests/s3_microceph.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ import (
const cephDisksScript = `
#!/bin/bash
for l in a b c; do
loop_file="$(sudo mktemp -p /mnt/data1 XXXX.img)"
mkdir -p /mnt/data1/disks
loop_file="$(sudo mktemp -p /mnt/data1/disks XXXX.img)"
sudo truncate -s 4G "${loop_file}"
loop_dev="$(sudo losetup --show -f "${loop_file}")"
# the block-devices plug doesn't allow accessing /dev/loopX
Expand All @@ -37,6 +38,17 @@ for l in a b c; do
sudo microceph disk add --wipe "/dev/sdi${l}"
done`

// cephCleanup remove microceph and the loop devices.
const cephCleanup = `
#!/bin/bash
sudo microceph disable rgw
sudo snap remove microceph --purge
for l in a b c; do
sudo rm -f /dev/sdi${l}
done
sudo rm -rf /mnt/data1/disks
`

const s3cmdSsl = `sudo s3cmd --host localhost --host-bucket="localhost/%%(bucket)" \
--access_key=%s --secret_key=%s --ca-certs=./certs/ca.crt %s`

Expand Down Expand Up @@ -81,6 +93,13 @@ func (m cephManager) getBackupURI(ctx context.Context, dest string) (string, err
return uri, nil
}

func (m cephManager) cleanup(ctx context.Context) {
tmpDir := "/tmp/"
cephCleanupPath := filepath.Join(tmpDir, "cleanup.sh")
m.put(ctx, cephCleanup, cephCleanupPath)
m.run(ctx, "removing ceph", cephCleanupPath, tmpDir)
}

// install a single node microCeph cluster.
// See https://canonical-microceph.readthedocs-hosted.com/en/squid-stable/how-to/single-node/
// It is fatal on errors.
Expand Down

0 comments on commit fdb8fb2

Please sign in to comment.