Merge pull request #1133 from nathanleclaire/fix_upgrade_need_started

Add check for machine state before upgrade
This commit is contained in:
Evan Hazlett 2015-05-06 16:10:49 -07:00
commit 6d784fb2fb
2 changed files with 18 additions and 2 deletions

View File

@ -2,6 +2,7 @@ package libmachine
import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"os"
@ -21,8 +22,9 @@ import (
)
var (
validHostNameChars = `[a-zA-Z0-9\-\.]`
validHostNamePattern = regexp.MustCompile(`^` + validHostNameChars + `+$`)
validHostNameChars = `[a-zA-Z0-9\-\.]`
validHostNamePattern = regexp.MustCompile(`^` + validHostNameChars + `+$`)
errMachineMustBeRunningForUpgrade = errors.New("Error: machine must be running to upgrade.")
)
type Host struct {
@ -243,6 +245,15 @@ func (h *Host) Restart() error {
}
func (h *Host) Upgrade() error {
machineState, err := h.Driver.GetState()
if err != nil {
return err
}
if machineState != state.Running {
log.Fatal(errMachineMustBeRunningForUpgrade)
}
provisioner, err := provision.DetectProvisioner(h.Driver)
if err != nil {
return err

View File

@ -119,6 +119,11 @@ buildMachineWithOldIsoCheckUpgrade() {
[[ ${lines[1]} == *"Stopped"* ]]
}
@test "$DRIVER: machine should not allow upgrade when stopped" {
run machine upgrade $NAME
[[ "$status" -eq 1 ]]
}
@test "$DRIVER: start" {
run machine start $NAME
[ "$status" -eq 0 ]