fix: save guest image with empty partition fail (#14189)

Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
This commit is contained in:
Jian Qiu
2022-05-02 16:29:27 +08:00
committed by GitHub
co-authored by Qiu Jian
parent 4375bad382
commit a393b65903
6 changed files with 13 additions and 5 deletions
+2
View File
@@ -24,6 +24,8 @@ import (
type GuestImageDetails struct {
apis.SharableVirtualResourceDetails
apis.EncryptedResourceDetails
SGuestImage
//Status string `json:"status"`
+1 -2
View File
@@ -15,7 +15,6 @@
package diskutils
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
@@ -149,7 +148,7 @@ func (d *SKVMGuestDisk) mountKvmRootfs(readonly bool) (fsdriver.IRootFsDriver, e
}
}
if len(partitions) == 0 {
return nil, fmt.Errorf("not found any partitions")
return nil, errors.Wrap(errors.ErrNotFound, "not found any partitions")
}
return nil, errors.NewAggregate(errs)
}
@@ -233,8 +233,11 @@ func (*DeployerServer) SaveToGlance(ctx context.Context, req *deployapi.SaveToGl
if req.Compress {
kvmDisk.Zerofree()
}
} else if errors.Cause(err) == errors.ErrNotFound {
// ignore no partition error
err = nil
} else {
log.Errorf("")
log.Errorf("SaveToGlance: MountKvmRootfs fail: %s", err)
}
return err
}()
+3 -1
View File
@@ -388,6 +388,7 @@ func (s *SLocalStorage) SaveToGlance(ctx context.Context, params interface{}) (j
func (s *SLocalStorage) saveToGlance(ctx context.Context, imageId, imagePath string,
compress bool, format string, encryptKey string, encFormat qemuimg.TEncryptFormat, encAlg seclib2.TSymEncAlg) error {
log.Infof("saveToGlance %s", imagePath)
diskInfo := &deployapi.DiskInfo{
Path: imagePath,
}
@@ -396,9 +397,10 @@ func (s *SLocalStorage) saveToGlance(ctx context.Context, imageId, imagePath str
diskInfo.EncryptFormat = string(encFormat)
diskInfo.EncryptAlg = string(encAlg)
}
ret, err := deployclient.GetDeployClient().SaveToGlance(context.Background(),
ret, err := deployclient.GetDeployClient().SaveToGlance(ctx,
&deployapi.SaveToGlanceParams{DiskInfo: diskInfo, Compress: compress})
if err != nil {
log.Errorf("GetDeployClient.SaveToGlance fail %s", err)
return err
}
+2
View File
@@ -362,10 +362,12 @@ func (manager *SGuestImageManager) FetchCustomizeColumns(
rows := make([]api.GuestImageDetails, len(objs))
virtRows := manager.SSharableVirtualResourceBaseManager.FetchCustomizeColumns(ctx, userCred, query, objs, fields, isList)
encRows := manager.SEncryptedResourceManager.FetchCustomizeColumns(ctx, userCred, query, objs, fields, isList)
for i := range rows {
rows[i] = api.GuestImageDetails{
SharableVirtualResourceDetails: virtRows[i],
EncryptedResourceDetails: encRows[i],
}
guestImage := objs[i].(*SGuestImage)
rows[i] = guestImage.getMoreDetails(ctx, userCred, query, rows[i])
+1 -1
View File
@@ -2023,7 +2023,7 @@ func (img *SImage) Pipeline(ctx context.Context, userCred mcclient.TokenCredenti
if img.Status != api.IMAGE_STATUS_ACTIVE {
img.SetStatus(userCred, api.IMAGE_STATUS_ACTIVE, "image pipeline complete")
}
if updated {
if updated && img.IsGuestImage.IsFalse() {
kwargs := jsonutils.NewDict()
kwargs.Set("name", jsonutils.NewString(img.GetName()))
osType, err := ImagePropertyManager.GetProperty(img.Id, api.IMAGE_OS_TYPE)