Skip to content

Commit

Permalink
vcsim: fix MAC Addresses to be unique
Browse files Browse the repository at this point in the history
  • Loading branch information
dougm committed Nov 16, 2023
1 parent e19137f commit 2f1fefa
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 1 deletion.
12 changes: 12 additions & 0 deletions govc/test/network.bats
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ load test_helper
assert_equal cdp "$(jq -r .config.linkDiscoveryProtocolConfig.protocol <<<"$dvs")"
assert_equal 1500 "$(jq -r .config.maxMtu <<<"$dvs")"
assert_equal 6.6.0 "$(jq -r .summary.productInfo.version <<<"$dvs")"

run govc dvs.add -dvs DVS1 DC0_H0
assert_success

run govc events -type DvsHostJoinedEvent
assert_success
assert_matches "DC0_H0 joined the vSphere Distributed Switch DVS1"
}

@test "network dvs backing" {
Expand Down Expand Up @@ -150,6 +157,11 @@ load test_helper

run govc device.info -vm $vm ethernet-*
assert_success

dups=$(govc vm.info -json '*' | jq -r '.virtualMachines[].config.hardware.device[].macAddress | select(. != null)' | uniq -d)
if [ -n "$dups" ] ; then
flunk "duplicate MACs: $dups"
fi
}

@test "network adapter" {
Expand Down
16 changes: 16 additions & 0 deletions simulator/dvs.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,10 @@ func (s *DistributedVirtualSwitch) ReconfigureDvsTask(ctx *Context, req *types.R
}
}

ctx.postEvent(&types.DvsHostJoinedEvent{
DvsEvent: s.event(),
HostJoined: *host.eventArgument(),
})
case types.ConfigSpecOperationRemove:
for _, ref := range host.Vm {
vm := ctx.Map.Get(ref).(*VirtualMachine)
Expand All @@ -249,6 +253,11 @@ func (s *DistributedVirtualSwitch) ReconfigureDvsTask(ctx *Context, req *types.R
}

RemoveReference(&members, member.Host)

ctx.postEvent(&types.DvsHostLeftEvent{
DvsEvent: s.event(),
HostLeft: *host.eventArgument(),
})
case types.ConfigSpecOperationEdit:
return nil, &types.NotSupported{}
}
Expand All @@ -258,6 +267,11 @@ func (s *DistributedVirtualSwitch) ReconfigureDvsTask(ctx *Context, req *types.R
{Name: "summary.hostMember", Val: members},
})

ctx.postEvent(&types.DvsReconfiguredEvent{
DvsEvent: s.event(),
ConfigSpec: spec,
})

return nil, nil
})

Expand All @@ -278,6 +292,8 @@ func (s *DistributedVirtualSwitch) FetchDVPorts(req *types.FetchDVPorts) soap.Ha

func (s *DistributedVirtualSwitch) DestroyTask(ctx *Context, req *types.Destroy_Task) soap.HasFault {
task := CreateTask(s, "destroy", func(t *Task) (types.AnyType, types.BaseMethodFault) {
// TODO: should return ResourceInUse fault if any VM is using a port on this switch
// and past that, remove refs from each host.Network, etc
f := ctx.Map.getEntityParent(s, "Folder").(*Folder)
folderRemoveChild(ctx, &f.Folder, s.Reference())
ctx.postEvent(&types.DvsDestroyedEvent{DvsEvent: s.event()})
Expand Down
18 changes: 18 additions & 0 deletions simulator/esx/event_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,24 @@ var EventInfo = []types.EventDescriptionEventDetail{
Category: "info",
FullFormat: "vSphere Distributed Switch {{.Dvs.Name}} in {{.Datacenter.Name}} was deleted.",
},
{
Key: "DvsReconfiguredEvent",
Description: "vSphere Distributed Switch reconfigured",
Category: "info",
FullFormat: "The vSphere Distributed Switch {{.Dvs.Name}} in {{.Datacenter.Name}} was reconfigured.",
},
{
Key: "DvsHostJoinedEvent",
Description: "Host joined the vSphere Distributed Switch",
Category: "info",
FullFormat: "The host {{.HostJoined.Name}} joined the vSphere Distributed Switch {{.Dvs.Name}} in {{.Datacenter.Name}}.",
},
{
Key: "DvsHostLeftEvent",
Description: "Host left vSphere Distributed Switch",
Category: "info",
FullFormat: "The host {{.HostLeft.Name}} left the vSphere Distributed Switch {{.Dvs.Name}} in {{.Datacenter.Name}}.",
},
{
Key: "DVPortgroupCreatedEvent",
Description: "dvPort group created",
Expand Down
5 changes: 4 additions & 1 deletion simulator/simulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,14 @@ func (s *Service) RoundTrip(ctx context.Context, request, response soap.HasFault

// Every request has a "This" field.
this := req.Elem().FieldByName("This")
// Copy request body
body := reflect.New(req.Type().Elem())
deepCopy(req.Interface(), body.Interface())

method := &Method{
Name: req.Elem().Type().Name(),
This: this.Interface().(types.ManagedObjectReference),
Body: req.Interface(),
Body: body.Interface(),
}

res := s.call(&Context{
Expand Down

0 comments on commit 2f1fefa

Please sign in to comment.