Merge pull request #4647 from fidencio/topic/fix-clh-crash-when-booting-up-with-no-network-device

clh: Don't crash if no network device is set by the upper layer
This commit is contained in:
Bin Liu 2022-07-13 21:28:46 +08:00 committed by GitHub
commit 0cc20f014d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -149,6 +149,11 @@ func (c *clhClientApi) VmRemoveDevicePut(ctx context.Context, vmRemoveDevice chc
// This is done in order to be able to override such a function as part of // This is done in order to be able to override such a function as part of
// our unit tests, as when testing bootVM we're on a mocked scenario already. // our unit tests, as when testing bootVM we're on a mocked scenario already.
var vmAddNetPutRequest = func(clh *cloudHypervisor) error { var vmAddNetPutRequest = func(clh *cloudHypervisor) error {
if clh.netDevices == nil {
clh.Logger().Info("No network device has been configured by the upper layer")
return nil
}
addr, err := net.ResolveUnixAddr("unix", clh.state.apiSocket) addr, err := net.ResolveUnixAddr("unix", clh.state.apiSocket)
if err != nil { if err != nil {
return err return err