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

builder/parallels: 'ToolsIsoPath' added

parent 668bd51f
......@@ -27,6 +27,9 @@ type Driver interface {
// Prlctl executes the given Prlctl command
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
// properly. If there is any indication the driver can't function,
// this will return an error.
......
......@@ -6,6 +6,7 @@ import (
"log"
"os"
"os/exec"
"path/filepath"
"regexp"
"strings"
"time"
......@@ -73,16 +74,21 @@ func getConfigValueFromXpath(path, xpath string) (string, error) {
// Finds an application bundle by identifier (for "darwin" platform only)
func getAppPath(bundleId string) (string, error) {
var stdout bytes.Buffer
cmd := exec.Command("mdfind", "kMDItemCFBundleIdentifier ==", bundleId)
out, err := cmd.Output()
if err != nil {
cmd.Stdout = &stdout
if err := cmd.Run(); err != nil {
return "", err
}
if string(out) == "" {
pathOutput := strings.TrimSpace(stdout.String())
if pathOutput == "" {
return "", fmt.Errorf(
"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) {
......@@ -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)
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 {
SendKeyScanCodesCalls [][]string
SendKeyScanCodesErrs []error
ToolsIsoPathCalled bool
ToolsIsoPathFlavor string
ToolsIsoPathResult string
ToolsIsoPathErr error
MacName string
MacReturn string
MacError error
......@@ -98,3 +103,9 @@ func (d *DriverMock) IpAddress(mac string) (string, error) {
d.IpAddressMac = mac
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