Skip to content

Commit

Permalink
Merge pull request vmware#2900 from rcw5/issue-2899
Browse files Browse the repository at this point in the history
vcsim: support disconnect/reconnect host
  • Loading branch information
dougm committed Jul 16, 2022
2 parents e0c2c7b + cbfe0c9 commit 87e10de
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 0 deletions.
25 changes: 25 additions & 0 deletions govc/test/host.bats
Original file line number Diff line number Diff line change
Expand Up @@ -246,3 +246,28 @@ load test_helper
run govc host.date.info -json
assert_success
}

@test "host.disconnect and host.reconnect" {
vcsim_env

run govc host.info
assert_success
status=$(govc host.info| grep -i "State"| awk '{print $2}')
assert_equal 'connected' $status

run govc host.disconnect "$GOVC_HOST"
assert_success

run govc host.info
assert_success
status=$(govc host.info| grep -i "State"| awk '{print $2}')
assert_equal 'disconnected' $status

run govc host.reconnect "$GOVC_HOST"
assert_success

run govc host.info
assert_success
status=$(govc host.info| grep -i "State"| awk '{print $2}')
assert_equal 'connected' $status
}
26 changes: 26 additions & 0 deletions simulator/host_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,3 +283,29 @@ func (h *HostSystem) ExitMaintenanceModeTask(ctx *Context, spec *types.ExitMaint
},
}
}

func (h *HostSystem) DisconnectHostTask(ctx *Context, spec *types.DisconnectHost_Task) soap.HasFault {
task := CreateTask(h, "disconnectHost", func(t *Task) (types.AnyType, types.BaseMethodFault) {
h.Runtime.ConnectionState = types.HostSystemConnectionStateDisconnected
return nil, nil
})

return &methods.DisconnectHost_TaskBody{
Res: &types.DisconnectHost_TaskResponse{
Returnval: task.Run(ctx),
},
}
}

func (h *HostSystem) ReconnectHostTask(ctx *Context, spec *types.ReconnectHost_Task) soap.HasFault {
task := CreateTask(h, "reconnectHost", func(t *Task) (types.AnyType, types.BaseMethodFault) {
h.Runtime.ConnectionState = types.HostSystemConnectionStateConnected
return nil, nil
})

return &methods.ReconnectHost_TaskBody{
Res: &types.ReconnectHost_TaskResponse{
Returnval: task.Run(ctx),
},
}
}
51 changes: 51 additions & 0 deletions simulator/host_system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/vmware/govmomi/find"
"github.com/vmware/govmomi/object"
"github.com/vmware/govmomi/simulator/esx"
"github.com/vmware/govmomi/vim25/types"
)

func TestDefaultESX(t *testing.T) {
Expand Down Expand Up @@ -206,3 +207,53 @@ func TestDestroyHostSystem(t *testing.T) {
t.Fatal("host should have been destroyed")
}
}

func TestDisconnect(t *testing.T) {
ctx := context.Background()
m := ESX()

defer m.Remove()

err := m.Create()
if err != nil {
t.Fatal(err)
}

s := m.Service.NewServer()
defer s.Close()

c := m.Service.client

hs := Map.Get(esx.HostSystem.Reference()).(*HostSystem)
host := object.NewHostSystem(c, hs.Self)

task, err := host.Disconnect(ctx)
if err != nil {
t.Fatal(err)
}

err = task.Wait(ctx)
if err != nil {
t.Fatal(err)
}

if hs.Runtime.ConnectionState != types.HostSystemConnectionStateDisconnected {
t.Fatalf("expect ConnectionState to be %s; got %s",
types.HostSystemConnectionStateDisconnected, hs.Runtime.ConnectionState)
}

task, err = host.Reconnect(ctx, nil, nil)
if err != nil {
t.Fatal(err)
}

err = task.Wait(ctx)
if err != nil {
t.Fatal(err)
}

if hs.Runtime.ConnectionState != types.HostSystemConnectionStateConnected {
t.Fatalf("expect ConnectionState to be %s; got %s",
types.HostSystemConnectionStateConnected, hs.Runtime.ConnectionState)
}
}

0 comments on commit 87e10de

Please sign in to comment.