Merge pull request #2373 from jeanlaurent/paused

Fixes #2372, add test for #2356 ( stop and remove paused vm )
This commit is contained in:
David Gageot 2015-11-20 18:19:14 +01:00
commit 076bbf8bce
3 changed files with 102 additions and 55 deletions

View File

@ -481,6 +481,18 @@ func (d *Driver) Start() error {
}
func (d *Driver) Stop() error {
currentState, err := d.GetState()
if err != nil {
return err
}
if currentState == state.Paused {
if err := d.vbm("controlvm", d.MachineName, "resume"); err != nil { // , "--type", "headless"
return err
}
log.Infof("Resuming VM ...")
}
if err := d.vbm("controlvm", d.MachineName, "acpipowerbutton"); err != nil {
return err
}
@ -495,6 +507,7 @@ func (d *Driver) Stop() error {
break
}
}
log.Infof("Stopping VM...")
d.IPAddress = ""

View File

@ -0,0 +1,89 @@
#!/usr/bin/env bats
load ${BASE_TEST_DIR}/helpers.bash
## THIS IS VIRTUALBOX ONLY
force_env DRIVER virtualbox
@test "$DRIVER: create a new virtualbox machine" {
run machine create -d $DRIVER $NAME
echo ${output}
[ "$status" -eq 0 ]
}
@test "$DRIVER: pause the newly created machine" {
run vboxmanage controlvm $NAME pause
echo ${output}
[ "$status" -eq 0 ]
}
@test "$DRIVER: status should show paused after pause" {
run machine status $NAME
echo ${output}
[ "$status" -eq 0 ]
[[ ${output} == *"Paused"* ]]
}
@test "$DRIVER: should stop a paused machine" {
run machine stop $NAME
echo ${output}
[ "$status" -eq 0 ]
}
@test "$DRIVER: status should show Stopped after stop" {
run machine status $NAME
echo ${output}
[ "$status" -eq 0 ]
[[ ${output} == *"Stopped"* ]]
}
@test "$DRIVER: restart the machine" {
run machine start $NAME
echo ${output}
[ "$status" -eq 0 ]
}
@test "$DRIVER: status should show Running after restart" {
run machine status $NAME
echo ${output}
[ "$status" -eq 0 ]
[[ ${output} == *"Running"* ]]
}
@test "$DRIVER: savestate the machine" {
run VBoxManage controlvm $NAME savestate
[ "$status" -eq 0 ]
}
@test "$DRIVER: status should show Saved after save" {
run machine status $NAME
echo ${output}
[ "$status" -eq 0 ]
[[ ${output} == *"Saved"* ]]
}
@test "$DRIVER: should start after save" {
run machine start $NAME
echo ${output}
[ "$status" -eq 0 ]
}
@test "$DRIVER: status should show Running after restart" {
run machine status $NAME
echo ${output}
[ "$status" -eq 0 ]
[[ ${output} == *"Running"* ]]
}
@test "$DRIVER: pause the machine again" {
run vboxmanage controlvm $NAME pause
echo ${output}
[ "$status" -eq 0 ]
}
@test "$DRIVER: remove the paused machine" {
run machine rm $NAME
echo ${output}
[ "$status" -eq 0 ]
}

View File

@ -1,55 +0,0 @@
#!/usr/bin/env bats
load ${BASE_TEST_DIR}/helpers.bash
force_env DRIVER virtualbox
@test "$DRIVER: create" {
run machine create -d $DRIVER $NAME
[ "$status" -eq 0 ]
}
@test "$DRIVER: VBoxManage pause" {
run VBoxManage controlvm $NAME pause
[ "$status" -eq 0 ]
}
@test "$DRIVER: machine should show paused after VBoxManage pause" {
run machine ls
[ "$status" -eq 0 ]
[[ ${lines[1]} == *"Paused"* ]]
}
@test "$DRIVER: start after paused" {
run machine start $NAME
[ "$status" -eq 0 ]
}
@test "$DRIVER: machine should show running after start" {
run machine ls
[ "$status" -eq 0 ]
[[ ${lines[1]} == *"Running"* ]]
}
@test "$DRIVER: VBoxManage savestate" {
run VBoxManage controlvm $NAME savestate
[ "$status" -eq 0 ]
}
@test "$DRIVER: machine should show saved after VBoxManage savestate" {
run machine ls
[ "$status" -eq 0 ]
[[ ${lines[1]} == *"$NAME"* ]]
[[ ${lines[1]} == *"Saved"* ]]
}
@test "$DRIVER: start after saved" {
run machine start $NAME
[ "$status" -eq 0 ]
}
@test "$DRIVER: machine should show running after start" {
run machine ls
[ "$status" -eq 0 ]
[[ ${lines[1]} == *"Running"* ]]
}