Skip to content

Commit

Permalink
fix deploy backup server order
Browse files Browse the repository at this point in the history
  • Loading branch information
wanyaoqi committed Jun 30, 2020
1 parent 9fb62eb commit 207cd93
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
7 changes: 5 additions & 2 deletions pkg/compute/tasks/guest_deploy_task.go
Expand Up @@ -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
})
}
}

Expand Down
8 changes: 5 additions & 3 deletions pkg/compute/tasks/ha_guest_deploy_task.go
Expand Up @@ -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) {
Expand All @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion pkg/hostman/storageman/storage_nfs.go
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions pkg/util/procutils/procutils.go
Expand Up @@ -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()
}
Expand Down

0 comments on commit 207cd93

Please sign in to comment.