Skip to content

Commit

Permalink
Parallels driver: Refactor "upgrade" approach according to dockerGH-920
Browse files Browse the repository at this point in the history
Signed-off-by: Mikhail Zholobov <[email protected]>
  • Loading branch information
legal90 committed Mar 31, 2015
1 parent 300446f commit 23d6021
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 61 deletions.
64 changes: 3 additions & 61 deletions drivers/parallels/parallels.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,7 @@ func (d *Driver) PreCreateCheck() error {

func (d *Driver) Create() error {
var (
err error
isoURL string
err error
)

// Check that prctl exists and works
Expand All @@ -168,40 +167,8 @@ func (d *Driver) Create() error {
}

b2dutils := utils.NewB2dUtils("", "")
imgPath := utils.GetMachineCacheDir()
commonIsoPath := filepath.Join(imgPath, isoFilename)
// just in case boot2docker.iso has been manually deleted
if _, err := os.Stat(imgPath); os.IsNotExist(err) {
if err := os.Mkdir(imgPath, 0700); err != nil {
return err
}
}

if d.Boot2DockerURL != "" {
isoURL = d.Boot2DockerURL
log.Infof("Downloading %s from %s...", isoFilename, isoURL)
if err := b2dutils.DownloadISO(d.storePath, isoFilename, isoURL); err != nil {
return err
}
} else {
// todo: check latest release URL, download if it's new
// until then always use "latest"
isoURL, err = b2dutils.GetLatestBoot2DockerReleaseURL()
if err != nil {
log.Warnf("Unable to check for the latest release: %s", err)
}

if _, err := os.Stat(commonIsoPath); os.IsNotExist(err) {
log.Infof("Downloading %s to %s...", isoFilename, commonIsoPath)
if err := b2dutils.DownloadISO(imgPath, isoFilename, isoURL); err != nil {
return err
}
}

isoDest := filepath.Join(d.storePath, isoFilename)
if err := utils.CopyFile(commonIsoPath, isoDest); err != nil {
return err
}
if err := b2dutils.CopyIsoToMachineDir(d.Boot2DockerURL, d.MachineName); err != nil {
return err
}

log.Infof("Creating SSH key...")
Expand Down Expand Up @@ -372,31 +339,6 @@ func (d *Driver) Kill() error {
return prlctl("stop", d.MachineName, "--kill")
}

func (d *Driver) Upgrade() error {
log.Infof("Stopping machine...")
if err := d.Stop(); err != nil {
return err
}

b2dutils := utils.NewB2dUtils("", "")
isoURL, err := b2dutils.GetLatestBoot2DockerReleaseURL()
if err != nil {
return err
}

log.Infof("Downloading boot2docker...")
if err := b2dutils.DownloadISO(d.storePath, isoFilename, isoURL); err != nil {
return err
}

log.Infof("Starting machine...")
if err := d.Start(); err != nil {
return err
}

return nil
}

func (d *Driver) GetState() (state.State, error) {
stdout, stderr, err := prlctlOutErr("list", d.MachineName, "--output", "status", "--no-header")
if err != nil {
Expand Down
15 changes: 15 additions & 0 deletions test/integration/driver-parallels.bats
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ findCPUCount() {
run bash -c "prlctl list -i $NAME | grep -o 'cpus=\d*' | cut -d'=' -f2"
}

buildMachineWithOldIsoCheckUpgrade() {
run wget https://github.com/boot2docker/boot2docker/releases/download/v1.4.1/boot2docker.iso -O $MACHINE_STORAGE_PATH/cache/boot2docker.iso
run machine create -d $DRIVER $NAME
run machine upgrade $NAME
}

@test "$DRIVER: machine should not exist" {
run machine active $NAME
[ "$status" -eq 1 ]
Expand Down Expand Up @@ -280,6 +286,15 @@ findCPUCount() {
[ "$status" -eq 0 ]
}

@test "$DRIVER: upgrade should work" {
buildMachineWithOldIsoCheckUpgrade
[ "$status" -eq 0 ]
}

@test "$DRIVER: remove machine after upgrade test" {
run machine rm -f $NAME
}

@test "$DRIVER: cleanup" {
run rm -rf $MACHINE_STORAGE_PATH
[ "$status" -eq 0 ]
Expand Down

0 comments on commit 23d6021

Please sign in to comment.