The following pull request was submitted through Github. It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/7182
This e-mail was sent by the LXC bot, direct replies will not reach the author unless they happen to be subscribed to this list. === Description (from pull-request) === This fixes #7176.
From 3a346d6677c86dafd615997db355bff9469ba7d7 Mon Sep 17 00:00:00 2001 From: Thomas Hipp <thomas.h...@canonical.com> Date: Tue, 14 Apr 2020 11:31:28 +0200 Subject: [PATCH 1/2] lxc/instance/drivers: Set new name before renaming backups This sets the new instance name before renaming the backups. Signed-off-by: Thomas Hipp <thomas.h...@canonical.com> --- lxd/instance/drivers/driver_lxc.go | 6 +++--- lxd/instance/drivers/driver_qemu.go | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lxd/instance/drivers/driver_lxc.go b/lxd/instance/drivers/driver_lxc.go index dd51e600d7..78678f3294 100644 --- a/lxd/instance/drivers/driver_lxc.go +++ b/lxd/instance/drivers/driver_lxc.go @@ -3636,6 +3636,9 @@ func (c *lxc) Rename(newName string) error { } } + // Set the new name in the struct. + c.name = newName + // Rename the backups. backups, err := c.Backups() if err != nil { @@ -3652,9 +3655,6 @@ func (c *lxc) Rename(newName string) error { } } - // Set the new name in the struct. - c.name = newName - // Invalidate the go-lxc cache. if c.c != nil { c.c.Release() diff --git a/lxd/instance/drivers/driver_qemu.go b/lxd/instance/drivers/driver_qemu.go index 9c19e22b9f..4be9021f4a 100644 --- a/lxd/instance/drivers/driver_qemu.go +++ b/lxd/instance/drivers/driver_qemu.go @@ -2253,6 +2253,9 @@ func (vm *qemu) Rename(newName string) error { } } + // Set the new name in the struct. + vm.name = newName + // Rename the backups. backups, err := vm.Backups() if err != nil { @@ -2269,9 +2272,6 @@ func (vm *qemu) Rename(newName string) error { } } - // Set the new name in the struct. - vm.name = newName - // Update lease files. network.UpdateDNSMasqStatic(vm.state, "") From ba355ee37edcfa734ede47ad7aae6c4cf12c96b1 Mon Sep 17 00:00:00 2001 From: Thomas Hipp <thomas.h...@canonical.com> Date: Tue, 14 Apr 2020 11:33:49 +0200 Subject: [PATCH 2/2] test: Extend backup rename This adds tests for renaming instances and their backups. Signed-off-by: Thomas Hipp <thomas.h...@canonical.com> --- test/suites/backup.sh | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/test/suites/backup.sh b/test/suites/backup.sh index 422c050327..e006ada601 100644 --- a/test/suites/backup.sh +++ b/test/suites/backup.sh @@ -383,12 +383,33 @@ test_backup_rename() { false fi - lxc launch testimage c1 + lxc init testimage c1 if ! lxc query -X POST /1.0/containers/c1/backups/backupmissing -d '{\"name\": \"backupnewname\"}' --wait 2>&1 | grep -q "Error:.*No such object" ; then echo "invalid rename response for missing backup" false fi - lxc delete --force c1 + # Create backup + lxc query -X POST --wait -d '{\"name\":\"foo\"}' /1.0/instances/c1/backups + + # All backups should be listed + lxc query /1.0/instances/c1/backups | jq .'[0]' | grep instances/c1/backups/foo + + # The specific backup should exist + lxc query /1.0/instances/c1/backups/foo + + # Rename the container which should rename the backup(s) as well + lxc mv c1 c2 + + # All backups should be listed + lxc query /1.0/instances/c2/backups | jq .'[0]' | grep instances/c2/backups/foo + + # The specific backup should exist + lxc query /1.0/instances/c2/backups/foo + + # The old backup should not exist + ! lxc query /1.0/instances/c1/backups/foo || false + + lxc delete --force c2 }
_______________________________________________ lxc-devel mailing list lxc-devel@lists.linuxcontainers.org http://lists.linuxcontainers.org/listinfo/lxc-devel