Open hickeng opened 6 years ago
Using the following patch we get the body of the fault:
DEBU[0024] Unexpected soap fault type: {VimFault:{MethodFault:{FaultCause:<nil> FaultMessage:[]}} Name:bridge}
index 449808e..958b7b8 100644
--- a/lib/install/management/network.go
+++ b/lib/install/management/network.go
@@ -19,6 +19,8 @@ import (
"github.com/vmware/govmomi/find"
"github.com/vmware/govmomi/object"
+ "github.com/vmware/govmomi/task"
+ "github.com/vmware/govmomi/vim25/soap"
"github.com/vmware/govmomi/vim25/types"
"github.com/vmware/vic/lib/config"
"github.com/vmware/vic/pkg/errors"
@@ -53,8 +55,41 @@ func (d *Dispatcher) createBridgeNetwork(conf *config.VirtualContainerHostConfig
if err = hostNetSystem.AddVirtualSwitch(d.op, name, &types.HostVirtualSwitchSpec{
NumPorts: 1024,
}); err != nil {
- err = errors.Errorf("Failed to add virtual switch (%q): %s", name, err)
- return err
+ handled := false
+ if soap.IsSoapFault(err) {
+ switch f := soap.ToSoapFault(err).VimFault().(type) {
+ case *types.AlreadyExists:
+ handled = true
+ d.op.Debugf("vSwitch already exists with name (soapfault): %s", name)
+ default:
+ d.op.Debugf("Unexpected soap fault type: %+v", f)
+ }
+ }
+
+ if soap.IsVimFault(err) {
+ switch f := soap.ToVimFault(err).(type) {
+ case *types.AlreadyExists:
+ handled = true
+ d.op.Debugf("vSwitch already exists with name (vimfault): %s", name)
+ default:
+ d.op.Debugf("Unexpected vim fault type: %+v", f)
+ }
+ }
+
+ switch err := err.(type) {
+ case task.Error:
+ switch f := err.Fault().(type) {
+ case *types.TaskInProgress:
+ d.op.Debugf("vSwitch already exists with name (fault): %s", name)
+ default:
+ d.op.Debugf("Unexpected vim fault type: %+v", f)
+ }
+ }
+
+ if !handled {
+ err = errors.Errorf("Failed to add virtual switch (%q): %s", name, err)
+ return err
+ }
}
d.op.Infof("Creating Portgroup")
Suggest that we modify https://github.com/vmware/govmomi/blob/d70eca22cace05a6ed7a5787ecd660724d65d911/object/host_network_system.go#L85 so that the AlreadyExists fault is propagated and use that to modify behaviour. (@dougm for thoughts? See the hostd.log output for server side fault details)
As an alternative we can use a Finder call first to determine if the switch already exists.
We are seeing a failure unique to
builds-14.vmware.run
where we fail to create a vswitch calledbridge
with the error that it already exists. However just prior to this we check for it's existence and get the debug message seen belowno such network "bridge"
.Hypothesis: We have aborted during VCH creation after creating a vswitch but before creating the associated port group and we're only searching for a portgroup of the specified name. Search: https://github.com/vmware/vic/blob/e0c8ff5b6a02a4d5c8a04817616fb4f49353962c/lib/install/validate/network.go#L276 Create: https://github.com/vmware/vic/blob/e0c8ff5b6a02a4d5c8a04817616fb4f49353962c/lib/install/management/network.go#L56
Acceptance:
Details: vic-machine.log
hostd.log
govc host.vswitch.info shows that we have a vswitch but no associated portgroup (the VCH bridge portgroups are a test cleanup failure, but not unique to this host):
vic-cmd output shows that we have a vswitch called
bridge
: