Skip to content

Commit 8446a6e

Browse files
authored
Merge pull request #556 from nanobox-io/bugfix/554
Improve pre-validation for virtualbox
2 parents cddec11 + fed5d9c commit 8446a6e

File tree

7 files changed

+59
-39
lines changed

7 files changed

+59
-39
lines changed

main.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,12 @@ func main() {
8787

8888
// make sure nanobox has all the necessry parts
8989
if !strings.Contains(command, " config") && !strings.Contains(command, " server") {
90-
valid, missingParts := provider.Valid()
91-
if !valid {
92-
93-
display.MissingDependencies(providerName, missingParts)
90+
err, missingParts := provider.Valid()
91+
if err != nil {
92+
fmt.Printf("Failed to validate provider - %s\n", err.Error())
93+
if len(missingParts) > 0 {
94+
display.MissingDependencies(providerName, missingParts)
95+
}
9496
os.Exit(1)
9597
}
9698
}

util/provider/dockermachine.go

+29-13
Original file line numberDiff line numberDiff line change
@@ -34,39 +34,55 @@ func init() {
3434
}
3535

3636
// Valid ensures docker-machine is installed and available
37-
func (machine DockerMachine) Valid() (bool, []string) {
37+
func (machine DockerMachine) Valid() (error, []string) {
38+
var masterErr error // will hold a collection of any errors hit
3839

3940
missingParts := []string{}
4041

4142
// we install our own docker-machine so we dont need to check
4243

4344
// do you have vbox manage?
44-
if err := exec.Command(vboxManageCmd, "-v").Run(); err != nil {
45+
out, err := exec.Command(vboxManageCmd, "-v").CombinedOutput()
46+
if err != nil {
47+
// append rather than return here so that we can check everything before erroring.
48+
// otherwise a user could error multiple times, learning about one problem at a time.
4549
missingParts = append(missingParts, "vboxmanage")
50+
masterErr = fmt.Errorf("missing vboxmanage - %q", err.Error())
51+
}
52+
// check output for errors/instruction
53+
if bytes.Contains(out, []byte("WARNING")) {
54+
if masterErr == nil {
55+
masterErr = fmt.Errorf("vboxmanage gave warning - \n%s", out)
56+
} else {
57+
masterErr = fmt.Errorf("%s - vboxmanage gave warning - \n%s", masterErr.Error(), out)
58+
}
4659
}
4760

4861
// return early if we are running native mounts
4962
config, _ := models.LoadConfig()
5063

5164
if config.MountType == "native" {
52-
return len(missingParts) == 0, missingParts
53-
}
54-
55-
unixCheck := func() {
56-
// check to see if i am listening on the netfs port
57-
out, err := exec.Command("netstat", "-ln").CombinedOutput()
58-
if err != nil || !bytes.Contains(out, []byte("2049")) {
59-
missingParts = append(missingParts, "netfs")
65+
if len(missingParts) == 0 && masterErr == nil {
66+
return nil, missingParts
6067
}
61-
68+
return masterErr, missingParts
6269
}
6370

6471
// net share checking
6572
switch runtime.GOOS {
6673
case "linux":
67-
unixCheck()
74+
out, err := exec.Command("netstat", "-tln").CombinedOutput()
75+
if err != nil {
76+
missingParts = append(missingParts, "netfs")
77+
masterErr = fmt.Errorf("%s - failed to check for netfs - %q", masterErr.Error(), err.Error())
78+
} else if !bytes.Contains(out, []byte("2049")) {
79+
missingParts = append(missingParts, "netfs")
80+
masterErr = fmt.Errorf("%s - missing or not running netfs - %q", masterErr.Error(), err.Error())
81+
}
82+
6883
if err := exec.Command("exportfs").Run(); err != nil {
6984
missingParts = append(missingParts, "exportfs")
85+
masterErr = fmt.Errorf("%s - missing exportfs - %q", masterErr.Error(), err.Error())
7086
}
7187

7288
case "darwin":
@@ -79,7 +95,7 @@ func (machine DockerMachine) Valid() (bool, []string) {
7995

8096
}
8197

82-
return len(missingParts) == 0, missingParts
98+
return masterErr, missingParts
8399
}
84100

85101
func (machine DockerMachine) Status() string {

util/provider/native.go

+4-7
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,12 @@ func init() {
2525
}
2626

2727
// Valid ensures docker-machine is installed and available
28-
func (native Native) Valid() (bool, []string) {
29-
cmd := exec.Command("docker", "ps")
30-
31-
//
32-
if _, err := cmd.CombinedOutput(); err != nil {
33-
return false, []string{"docker"}
28+
func (native Native) Valid() (error, []string) {
29+
if err := exec.Command("docker", "ps").Run(); err != nil {
30+
return fmt.Errorf("missing docker - %s", err.Error()), []string{"docker"}
3431
}
3532

36-
return true, nil
33+
return nil, nil
3734
}
3835

3936
func (native Native) Status() string {

util/provider/provider.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package provider
22

33
import (
44
"errors"
5+
"fmt"
56

67
"github.com/nanobox-io/nanobox/models"
78
)
@@ -15,7 +16,7 @@ type Provider interface {
1516
HostMntDir() string
1617
HostIP() (string, error)
1718
ReservedIPs() []string
18-
Valid() (bool, []string)
19+
Valid() (error, []string)
1920
Create() error
2021
Reboot() error
2122
Stop() error
@@ -53,11 +54,11 @@ func Display(verb bool) {
5354
}
5455

5556
// Valid ...
56-
func Valid() (bool, []string) {
57+
func Valid() (error, []string) {
5758

5859
p, err := fetchProvider()
5960
if err != nil {
60-
return false, []string{"invalid provider"}
61+
return fmt.Errorf("invalid provider - %s", err.Error()), []string{"invalid provider"}
6162
}
6263

6364
return p.Valid()

vendor/github.com/docker/machine/libmachine/mcnutils/b2d.go

+1-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/docker/machine/version/version.go

+1-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/vendor.json

+14-8
Original file line numberDiff line numberDiff line change
@@ -221,20 +221,26 @@
221221
{
222222
"checksumSHA1": "pfZB2heUOImpxC+LS/xFSFDd2J8=",
223223
"path": "github.com/docker/machine/libmachine/log",
224-
"revision": "85bef344b7be221c79a1e0173acf44715075f0f9",
225-
"revisionTime": "2016-09-08T18:02:50Z"
224+
"revision": "937160559e02cc430fe176991beb9a6ffbfe3de0",
225+
"revisionTime": "2017-07-12T23:53:51Z",
226+
"version": "v0.12.2",
227+
"versionExact": "v0.12.2"
226228
},
227229
{
228-
"checksumSHA1": "QG310EdbozuJynkrfT3wvVm29FY=",
230+
"checksumSHA1": "WZq3NS1/0CN7IyeZqH+AugPzm7k=",
229231
"path": "github.com/docker/machine/libmachine/mcnutils",
230-
"revision": "85bef344b7be221c79a1e0173acf44715075f0f9",
231-
"revisionTime": "2016-09-08T18:02:50Z"
232+
"revision": "937160559e02cc430fe176991beb9a6ffbfe3de0",
233+
"revisionTime": "2017-07-12T23:53:51Z",
234+
"version": "v0.12.2",
235+
"versionExact": "v0.12.2"
232236
},
233237
{
234-
"checksumSHA1": "MotUnJVkO3Cg501ZASzbnwb+Um4=",
238+
"checksumSHA1": "Fn8hXKmkAUxnXi5RrIexvW9BnI8=",
235239
"path": "github.com/docker/machine/version",
236-
"revision": "85bef344b7be221c79a1e0173acf44715075f0f9",
237-
"revisionTime": "2016-09-08T18:02:50Z"
240+
"revision": "937160559e02cc430fe176991beb9a6ffbfe3de0",
241+
"revisionTime": "2017-07-12T23:53:51Z",
242+
"version": "v0.12.2",
243+
"versionExact": "v0.12.2"
238244
},
239245
{
240246
"checksumSHA1": "xgjI2W3RGiQwNlxsOW2V9fJ9kaM=",

0 commit comments

Comments
 (0)