Skip to content

Commit

Permalink
vcsim: allow VM PowerOff when Host is in maintenance mode
Browse files Browse the repository at this point in the history
e67b1b1 prevented all VM power ops when host is in MM, we should only prevent PowerOn.

Issue #2633
  • Loading branch information
dougm committed Oct 20, 2021
1 parent d99e995 commit 6de12ab
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
9 changes: 6 additions & 3 deletions govc/test/vm.bats
Original file line number Diff line number Diff line change
Expand Up @@ -1130,13 +1130,16 @@ load test_helper
run govc object.collect -s vm/DC0_H0_VM0 guest.ipAddress
assert_success 10.0.0.45

run govc vm.power -off DC0_H0_VM0
assert_success

host=$(govc ls -L "$(govc object.collect -s vm/DC0_H0_VM0 runtime.host)")
run govc host.maintenance.enter "$host"
assert_success

run govc vm.power -off DC0_H0_VM0
assert_success

run govc vm.power -on DC0_H0_VM0
assert_failure # InvalidState

run govc vm.customize -vm DC0_H0_VM0 -ip 10.0.0.45 -netmask 255.255.0.0 -type Linux
assert_failure # InvalidState

Expand Down
8 changes: 4 additions & 4 deletions simulator/virtual_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -1445,10 +1445,6 @@ func (c *powerVMTask) Run(task *Task) (types.AnyType, types.BaseMethodFault) {
}
}

if c.VirtualMachine.hostInMM(c.ctx) {
return nil, new(types.InvalidState)
}

var boot types.AnyType
if c.state == types.VirtualMachinePowerStatePoweredOn {
boot = time.Now()
Expand All @@ -1457,6 +1453,10 @@ func (c *powerVMTask) Run(task *Task) (types.AnyType, types.BaseMethodFault) {
event := c.event()
switch c.state {
case types.VirtualMachinePowerStatePoweredOn:
if c.VirtualMachine.hostInMM(c.ctx) {
return nil, new(types.InvalidState)
}

c.run.start(c.ctx, c.VirtualMachine)
c.ctx.postEvent(
&types.VmStartingEvent{VmEvent: event},
Expand Down

0 comments on commit 6de12ab

Please sign in to comment.