From 6feeff2009dfb7ec4539b63dc166e4662bd96726 Mon Sep 17 00:00:00 2001 From: wanyaoqi Date: Tue, 30 Jun 2020 22:00:34 +0800 Subject: [PATCH] fix deploy backup server order --- pkg/compute/tasks/guest_deploy_task.go | 7 +++++-- pkg/compute/tasks/ha_guest_deploy_task.go | 8 +++++--- pkg/hostman/storageman/storage_nfs.go | 2 +- pkg/util/procutils/procutils.go | 9 +++++++++ 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/pkg/compute/tasks/guest_deploy_task.go b/pkg/compute/tasks/guest_deploy_task.go index 2371fb642d..d93e298c80 100644 --- a/pkg/compute/tasks/guest_deploy_task.go +++ b/pkg/compute/tasks/guest_deploy_task.go @@ -42,11 +42,14 @@ func (self *GuestDeployTask) OnInit(ctx context.Context, obj db.IStandaloneModel } func (self *GuestDeployTask) OnGuestNetworkReady(ctx context.Context, guest *models.SGuest) { + self.SetStage("OnDeployWaitServerStop", nil) if jsonutils.QueryBoolean(self.Params, "restart", false) { - self.SetStage("OnDeployWaitServerStop", nil) guest.StartGuestStopTask(ctx, self.UserCred, false, self.GetTaskId()) } else { - self.OnDeployWaitServerStop(ctx, guest, nil) + // Note: have to use LocalTaskRun, run to another place implement OnDeployWaitServerStop + taskman.LocalTaskRun(self, func() (jsonutils.JSONObject, error) { + return nil, nil + }) } } diff --git a/pkg/compute/tasks/ha_guest_deploy_task.go b/pkg/compute/tasks/ha_guest_deploy_task.go index d69ddeeca8..48a6abf0bf 100644 --- a/pkg/compute/tasks/ha_guest_deploy_task.go +++ b/pkg/compute/tasks/ha_guest_deploy_task.go @@ -36,10 +36,10 @@ type HAGuestDeployTask struct { GuestDeployTask } -func (self *HAGuestDeployTask) OnDeployGuestComplete( +func (self *HAGuestDeployTask) OnDeployWaitServerStop( ctx context.Context, guest *models.SGuest, data jsonutils.JSONObject, ) { - self.DeployBackup(ctx, guest, data) + self.DeployBackup(ctx, guest, nil) } func (self *HAGuestDeployTask) DeployBackup(ctx context.Context, guest *models.SGuest, data jsonutils.JSONObject) { @@ -57,7 +57,9 @@ func (self *HAGuestDeployTask) DeployBackup(ctx context.Context, guest *models.S func (self *HAGuestDeployTask) OnDeploySlaveGuestComplete( ctx context.Context, guest *models.SGuest, data jsonutils.JSONObject, ) { - self.GuestDeployTask.OnDeployGuestComplete(ctx, guest, data) + host := guest.GetHost() + self.SetStage("OnDeployGuestComplete", nil) + self.DeployOnHost(ctx, guest, host) } func (self *HAGuestDeployTask) OnDeploySlaveGuestCompleteFailed( diff --git a/pkg/hostman/storageman/storage_nfs.go b/pkg/hostman/storageman/storage_nfs.go index d47eecdf0b..91509db009 100644 --- a/pkg/hostman/storageman/storage_nfs.go +++ b/pkg/hostman/storageman/storage_nfs.go @@ -108,7 +108,7 @@ func (s *SNFSStorage) checkAndMount() error { } ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() - err = procutils.NewCommandContext(ctx, + err = procutils.NewRemoteCommandContextAsFarAsPossible(ctx, "mount", "-t", "nfs", fmt.Sprintf("%s:%s", host, sharedDir), s.Path).Run() if err != nil { return err diff --git a/pkg/util/procutils/procutils.go b/pkg/util/procutils/procutils.go index 834229390b..9d0c75140a 100644 --- a/pkg/util/procutils/procutils.go +++ b/pkg/util/procutils/procutils.go @@ -61,6 +61,15 @@ func NewRemoteCommandAsFarAsPossible(name string, args ...string) *Command { } } +func NewRemoteCommandContextAsFarAsPossible(ctx context.Context, name string, args ...string) *Command { + return &Command{ + path: name, + args: args, + cmd: execInstance.CommandContext(ctx, name, args...), + remoteCmd: true, + } +} + func (c *Command) StdinPipe() (io.WriteCloser, error) { return c.cmd.StdinPipe() }