Skip to content

Commit 6de12ab

Browse files
committed
vcsim: allow VM PowerOff when Host is in maintenance mode
e67b1b1 prevented all VM power ops when host is in MM, we should only prevent PowerOn. Issue #2633
1 parent d99e995 commit 6de12ab

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

govc/test/vm.bats

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,13 +1130,16 @@ load test_helper
11301130
run govc object.collect -s vm/DC0_H0_VM0 guest.ipAddress
11311131
assert_success 10.0.0.45
11321132

1133-
run govc vm.power -off DC0_H0_VM0
1134-
assert_success
1135-
11361133
host=$(govc ls -L "$(govc object.collect -s vm/DC0_H0_VM0 runtime.host)")
11371134
run govc host.maintenance.enter "$host"
11381135
assert_success
11391136

1137+
run govc vm.power -off DC0_H0_VM0
1138+
assert_success
1139+
1140+
run govc vm.power -on DC0_H0_VM0
1141+
assert_failure # InvalidState
1142+
11401143
run govc vm.customize -vm DC0_H0_VM0 -ip 10.0.0.45 -netmask 255.255.0.0 -type Linux
11411144
assert_failure # InvalidState
11421145

simulator/virtual_machine.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1445,10 +1445,6 @@ func (c *powerVMTask) Run(task *Task) (types.AnyType, types.BaseMethodFault) {
14451445
}
14461446
}
14471447

1448-
if c.VirtualMachine.hostInMM(c.ctx) {
1449-
return nil, new(types.InvalidState)
1450-
}
1451-
14521448
var boot types.AnyType
14531449
if c.state == types.VirtualMachinePowerStatePoweredOn {
14541450
boot = time.Now()
@@ -1457,6 +1453,10 @@ func (c *powerVMTask) Run(task *Task) (types.AnyType, types.BaseMethodFault) {
14571453
event := c.event()
14581454
switch c.state {
14591455
case types.VirtualMachinePowerStatePoweredOn:
1456+
if c.VirtualMachine.hostInMM(c.ctx) {
1457+
return nil, new(types.InvalidState)
1458+
}
1459+
14601460
c.run.start(c.ctx, c.VirtualMachine)
14611461
c.ctx.postEvent(
14621462
&types.VmStartingEvent{VmEvent: event},

0 commit comments

Comments
 (0)