Commit 909d5ccb authored by Mikhail Zholobov's avatar Mikhail Zholobov

builder/parallels: 'ToolsIsoPath' added

parent 668bd51f
...@@ -27,6 +27,9 @@ type Driver interface { ...@@ -27,6 +27,9 @@ type Driver interface {
// Prlctl executes the given Prlctl command // Prlctl executes the given Prlctl command
Prlctl(...string) error Prlctl(...string) error
// Get the path to the Parallels Tools ISO for the given flavor.
ToolsIsoPath(string) (string, error)
// Verify checks to make sure that this driver should function // Verify checks to make sure that this driver should function
// properly. If there is any indication the driver can't function, // properly. If there is any indication the driver can't function,
// this will return an error. // this will return an error.
......
...@@ -6,6 +6,7 @@ import ( ...@@ -6,6 +6,7 @@ import (
"log" "log"
"os" "os"
"os/exec" "os/exec"
"path/filepath"
"regexp" "regexp"
"strings" "strings"
"time" "time"
...@@ -73,16 +74,21 @@ func getConfigValueFromXpath(path, xpath string) (string, error) { ...@@ -73,16 +74,21 @@ func getConfigValueFromXpath(path, xpath string) (string, error) {
// Finds an application bundle by identifier (for "darwin" platform only) // Finds an application bundle by identifier (for "darwin" platform only)
func getAppPath(bundleId string) (string, error) { func getAppPath(bundleId string) (string, error) {
var stdout bytes.Buffer
cmd := exec.Command("mdfind", "kMDItemCFBundleIdentifier ==", bundleId) cmd := exec.Command("mdfind", "kMDItemCFBundleIdentifier ==", bundleId)
out, err := cmd.Output() cmd.Stdout = &stdout
if err != nil { if err := cmd.Run(); err != nil {
return "", err return "", err
} }
if string(out) == "" {
pathOutput := strings.TrimSpace(stdout.String())
if pathOutput == "" {
return "", fmt.Errorf( return "", fmt.Errorf(
"Could not detect Parallels Desktop! Make sure it is properly installed.") "Could not detect Parallels Desktop! Make sure it is properly installed.")
} }
return string(out), nil
return pathOutput, nil
} }
func (d *Parallels9Driver) IsRunning(name string) (bool, error) { func (d *Parallels9Driver) IsRunning(name string) (bool, error) {
...@@ -251,3 +257,14 @@ func (d *Parallels9Driver) IpAddress(mac string) (string, error) { ...@@ -251,3 +257,14 @@ func (d *Parallels9Driver) IpAddress(mac string) (string, error) {
log.Printf("Found IP lease: %s for MAC address %s\n", ip, mac) log.Printf("Found IP lease: %s for MAC address %s\n", ip, mac)
return ip, nil return ip, nil
} }
func (d *Parallels9Driver) ToolsIsoPath(k string) (string, error) {
appPath, err := getAppPath("com.parallels.desktop.console")
if err != nil {
return "", err
}
toolsPath := filepath.Join(appPath, "Contents", "Resources", "Tools", "prl-tools-"+k+".iso")
log.Printf("Parallels Tools path: '%s'", toolsPath)
return toolsPath, nil
}
...@@ -31,6 +31,11 @@ type DriverMock struct { ...@@ -31,6 +31,11 @@ type DriverMock struct {
SendKeyScanCodesCalls [][]string SendKeyScanCodesCalls [][]string
SendKeyScanCodesErrs []error SendKeyScanCodesErrs []error
ToolsIsoPathCalled bool
ToolsIsoPathFlavor string
ToolsIsoPathResult string
ToolsIsoPathErr error
MacName string MacName string
MacReturn string MacReturn string
MacError error MacError error
...@@ -98,3 +103,9 @@ func (d *DriverMock) IpAddress(mac string) (string, error) { ...@@ -98,3 +103,9 @@ func (d *DriverMock) IpAddress(mac string) (string, error) {
d.IpAddressMac = mac d.IpAddressMac = mac
return d.IpAddressReturn, d.IpAddressError return d.IpAddressReturn, d.IpAddressError
} }
func (d *DriverMock) ToolsIsoPath(flavor string) (string, error) {
d.ToolsIsoPathCalled = true
d.ToolsIsoPathFlavor = flavor
return d.ToolsIsoPathResult, d.ToolsIsoPathErr
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment