diff --git a/lxd/instance/drivers/driver_common.go b/lxd/instance/drivers/driver_common.go index 087d76784da8..f9b933e3ac01 100644 --- a/lxd/instance/drivers/driver_common.go +++ b/lxd/instance/drivers/driver_common.go @@ -631,12 +631,15 @@ func (d *common) rebuildCommon(inst instance.Instance, img *api.Image, op *opera // Rebuild as empty if there is no image provided. if img == nil { - return pool.CreateInstance(inst, nil) - } - - err = pool.CreateInstanceFromImage(inst, img.Fingerprint, op) - if err != nil { - return err + err = pool.CreateInstance(inst, nil) + if err != nil { + return err + } + } else { + err = pool.CreateInstanceFromImage(inst, img.Fingerprint, op) + if err != nil { + return err + } } err = d.state.DB.Cluster.Transaction(context.TODO(), func(ctx context.Context, tx *db.ClusterTx) error { @@ -645,9 +648,11 @@ func (d *common) rebuildCommon(inst instance.Instance, img *api.Image, op *opera return err } - err = tx.UpdateImageLastUseDate(ctx, inst.Project().Name, img.Fingerprint, time.Now().UTC()) - if err != nil { - return err + if img != nil { + err = tx.UpdateImageLastUseDate(ctx, inst.Project().Name, img.Fingerprint, time.Now().UTC()) + if err != nil { + return err + } } return nil diff --git a/test/suites/basic.sh b/test/suites/basic.sh index cf10f22a2bbd..6e71ce6e2921 100644 --- a/test/suites/basic.sh +++ b/test/suites/basic.sh @@ -646,6 +646,7 @@ test_basic_usage() { # Test rebuilding an instance with an empty file system. lxc init testimage c1 lxc rebuild c1 --empty + ! lxc config show c1 | grep -q 'image.*' || false lxc delete c1 -f # Test assigning an empty profile (with no root disk device) to an instance.