Skip to content

Commit

Permalink
Merge pull request #18657 from zexi/automated-cherry-pick-of-#18655-u…
Browse files Browse the repository at this point in the history
…pstream-master

Automated cherry pick of #18655: fix(host): catch init error
  • Loading branch information
zexi authored Nov 13, 2023
2 parents 22d5a01 + 22b2eab commit 71b8f5b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
9 changes: 8 additions & 1 deletion pkg/hostman/host_services.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
package hostman

import (
"time"

execlient "yunion.io/x/executor/client"
"yunion.io/x/log"

Expand Down Expand Up @@ -77,7 +79,12 @@ func (host *SHostService) RunService() {

hostInstance := hostinfo.Instance()
if err := hostInstance.Init(); err != nil {
log.Fatalf("Host instance init error: %v", err)
log.Errorf("Host instance init error: %v", err)
for {
// to catch error
time.Sleep(10 * time.Second)
}
// log.Fatalf("Host instance init error: %v", err)
}

app_common.InitAuth(&options.HostOptions.CommonOptions, func() {
Expand Down
10 changes: 4 additions & 6 deletions pkg/hostman/hostinfo/hostinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,7 @@ func (h *SHostInfo) Init() error {
}

if err := hostbridge.Prepare(options.HostOptions.BridgeDriver); err != nil {
err := errors.Errorf("Prepare host bridge %q error: %v", options.HostOptions.BridgeDriver, err)
log.Errorln(err)
return err
return errors.Wrapf(err, "Prepare host bridge %q", options.HostOptions.BridgeDriver)
}

log.Infof("Start parseConfig")
Expand Down Expand Up @@ -302,7 +300,7 @@ func (h *SHostInfo) parseConfig() error {
if len(options.HostOptions.Networks) == 0 {
netConf, err := h.generateLocalNetworkConfig()
if err != nil {
return err
return errors.Wrap(err, "generateLocalNetworkConfig")
}
log.Infof("Generate network config %s", netConf)
options.HostOptions.Networks = []string{netConf}
Expand All @@ -319,13 +317,13 @@ func (h *SHostInfo) parseConfig() error {
for _, n := range options.HostOptions.Networks {
nic, err := NewNIC(n)
if err != nil {
return err
return errors.Wrapf(err, "NewNIC %s", n)
}
h.Nics = append(h.Nics, nic)
}
for i := 0; i < len(h.Nics); i++ {
if err := h.Nics[i].SetupDhcpRelay(); err != nil {
return err
return errors.Wrapf(err, "SetupDhcpRelay %s/%s/%s", h.Nics[i].Inter, h.Nics[i].Bridge, h.Nics[i].Ip)
}
}
if len(options.HostOptions.ListenInterface) > 0 {
Expand Down
11 changes: 4 additions & 7 deletions pkg/hostman/hostinfo/hostinfohelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,27 +274,24 @@ func NewNIC(desc string) (*SNIC, error) {
nic.BridgeDev, err = hostbridge.NewDriver(options.HostOptions.BridgeDriver,
nic.Bridge, nic.Inter, nic.Ip)
if err != nil {
log.Errorln(err)
return nil, err
return nil, errors.Wrapf(err, "hostbridge.NewDriver driver: %s, bridge: %s, interface: %s, ip: %s", options.HostOptions.BridgeDriver, nic.Bridge, nic.Inter, nic.Ip)
}

confirm, err := nic.BridgeDev.ConfirmToConfig()
if err != nil {
log.Errorln(err)
return nil, err
return nil, errors.Wrapf(err, "nic.BridgeDev.ConfirmToConfig %#v", nic.BridgeDev)
}
if !confirm {
log.Infof("Not confirm to configuration")
if err = nic.BridgeDev.Setup(nic.BridgeDev); err != nil {
log.Errorln(err)
return nil, err
return nil, errors.Wrapf(err, "nic.BridgeDev.Setup %v", nic.BridgeDev)
}
time.Sleep(time.Second * 1)
} else {
log.Infof("Confirm to configuration!!")
}
if err := nic.BridgeDev.PersistentConfig(); err != nil {
return nil, err
return nil, errors.Wrapf(err, "nic.BridgeDev.PersistentConfig %v", nic.BridgeDev)
}
if isDHCP, err := nic.BridgeDev.DisableDHCPClient(); err != nil {
return nil, errors.Wrap(err, "disable dhcp client")
Expand Down

0 comments on commit 71b8f5b

Please sign in to comment.