From deafebd3e0ce4b2fd92d35739a5816aba5817871 Mon Sep 17 00:00:00 2001 From: Qiu Jian Date: Sat, 16 Mar 2019 21:34:07 +0800 Subject: [PATCH] fix: 1. remote file will retry glance if peer url is not available 2. ssh authorized keys ends with \n --- pkg/compute/models/hosts.go | 1 + pkg/hostman/guestfs/fsdriver/base.go | 2 +- pkg/hostman/storageman/remotefile/remotefile.go | 12 ++++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/pkg/compute/models/hosts.go b/pkg/compute/models/hosts.go index 0933b3cc0d..e1556945bd 100644 --- a/pkg/compute/models/hosts.go +++ b/pkg/compute/models/hosts.go @@ -2781,6 +2781,7 @@ func (self *SHost) AllowPerformAddNetif(ctx context.Context, } func (self *SHost) PerformAddNetif(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) { + log.Debugf("add_netif %s", data) mac, _ := data.GetString("mac") if len(mac) == 0 || len(netutils.FormatMacAddr(mac)) == 0 { return nil, httperrors.NewBadRequestError("Invaild mac address") diff --git a/pkg/hostman/guestfs/fsdriver/base.go b/pkg/hostman/guestfs/fsdriver/base.go index 81b5751a82..abe4a062b5 100644 --- a/pkg/hostman/guestfs/fsdriver/base.go +++ b/pkg/hostman/guestfs/fsdriver/base.go @@ -182,5 +182,5 @@ func MergeAuthorizedKeys(oldKeys string, pubkeys *sshkeys.SSHKeys) string { for _, val := range allkeys { keys = append(keys, val) } - return strings.Join(keys, "\n") + return strings.Join(keys, "\n") + "\n" } diff --git a/pkg/hostman/storageman/remotefile/remotefile.go b/pkg/hostman/storageman/remotefile/remotefile.go index 5e4685e15f..c7d0c23108 100644 --- a/pkg/hostman/storageman/remotefile/remotefile.go +++ b/pkg/hostman/storageman/remotefile/remotefile.go @@ -147,7 +147,19 @@ func (r *SRemoteFile) fetch(preChksum string) bool { return fetchSucc } +// retry download func (r *SRemoteFile) download(getData bool, preChksum string) bool { + result := r.downloadInternal(getData, preChksum) + if !result && len(r.downloadUrl) > 0 { + log.Errorf("download from cached url %s failed, try direct download from %s ...", r.downloadUrl, r.url) + r.downloadUrl = "" + result = r.downloadInternal(getData, preChksum) + } + return result +} + +func (r *SRemoteFile) downloadInternal(getData bool, preChksum string) bool { + os.Remove(r.tmpPath) fi, err := os.Create(r.tmpPath) if err != nil { log.Errorln(err)