diff --git a/libmachine/crashreport/crash_report.go b/libmachine/crashreport/crash_report.go index e816ef3b51..de49e40f1a 100644 --- a/libmachine/crashreport/crash_report.go +++ b/libmachine/crashreport/crash_report.go @@ -17,7 +17,6 @@ import ( "github.com/bugsnag/bugsnag-go" "github.com/docker/machine/libmachine/log" - "github.com/docker/machine/libmachine/mcnutils" "github.com/docker/machine/version" ) @@ -146,5 +145,5 @@ func detectUname(metaData *bugsnag.MetaData) { } func detectOSVersion(metaData *bugsnag.MetaData) { - metaData.Add("device", "os version", mcnutils.LocalOSVersion()) + metaData.Add("device", "os version", localOSVersion()) } diff --git a/libmachine/mcnutils/os_darwin.go b/libmachine/crashreport/os_darwin.go similarity index 79% rename from libmachine/mcnutils/os_darwin.go rename to libmachine/crashreport/os_darwin.go index 8de0bdc3d2..2e887e4d10 100644 --- a/libmachine/mcnutils/os_darwin.go +++ b/libmachine/crashreport/os_darwin.go @@ -1,8 +1,8 @@ -package mcnutils +package crashreport import "os/exec" -func LocalOSVersion() string { +func localOSVersion() string { command := exec.Command("bash", "-c", `sw_vers | grep ProductVersion | cut -d$'\t' -f2`) output, err := command.Output() if err != nil { diff --git a/libmachine/mcnutils/os_linux.go b/libmachine/crashreport/os_linux.go similarity index 80% rename from libmachine/mcnutils/os_linux.go rename to libmachine/crashreport/os_linux.go index 0c869f0c5e..31b72a89b0 100644 --- a/libmachine/mcnutils/os_linux.go +++ b/libmachine/crashreport/os_linux.go @@ -1,8 +1,8 @@ -package mcnutils +package crashreport import "os/exec" -func LocalOSVersion() string { +func localOSVersion() string { command := exec.Command("bash", "-c", `cat /etc/os-release | grep 'VERSION=' | cut -d'=' -f2`) output, err := command.Output() if err != nil { diff --git a/libmachine/mcnutils/os_windows.go b/libmachine/crashreport/os_windows.go similarity index 60% rename from libmachine/mcnutils/os_windows.go rename to libmachine/crashreport/os_windows.go index 03cf004ef1..6e3a33cc8d 100644 --- a/libmachine/mcnutils/os_windows.go +++ b/libmachine/crashreport/os_windows.go @@ -1,11 +1,11 @@ -package mcnutils +package crashreport import ( "os/exec" "strings" ) -func LocalOSVersion() string { +func localOSVersion() string { command := exec.Command("ver") output, err := command.Output() if err == nil { @@ -24,10 +24,21 @@ func LocalOSVersion() string { func parseSystemInfoOutput(output string) string { lines := strings.Split(string(output), "\n") for _, line := range lines { - if strings.HasPrefix(line, "OS Version") { + if strings.HasPrefix(line, "OS Version:") { return strings.TrimSpace(line[len("OS Version:"):]) } } + + // If we couldn't find the version, maybe the output is not in english + // Let's parse the fourth line since it seems to be the one always used + // for the version. + if len(lines) >= 4 { + parts := strings.Split(lines[3], ":") + if len(parts) == 2 { + return strings.TrimSpace(parts[1]) + } + } + return "" } diff --git a/libmachine/mcnutils/os_windows_test.go b/libmachine/crashreport/os_windows_test.go similarity index 58% rename from libmachine/mcnutils/os_windows_test.go rename to libmachine/crashreport/os_windows_test.go index a794d5f803..b9cdcdc983 100644 --- a/libmachine/mcnutils/os_windows_test.go +++ b/libmachine/crashreport/os_windows_test.go @@ -1,4 +1,4 @@ -package mcnutils +package crashreport import ( "testing" @@ -27,5 +27,21 @@ OS Build Type: Multiprocessor Free Registered Owner: Windows User ` - assert.Equal(t, "10.0.10240 N/A Build 10240", parseOutput(output)) + assert.Equal(t, "10.0.10240 N/A Build 10240", parseSystemInfoOutput(output)) +} + +func TestParseNonEnglishSystemInfoOutput(t *testing.T) { + output := ` +Ignored: ... +Ignored: ... +Version du Système: 10.0.10350 +` + + assert.Equal(t, "10.0.10350", parseSystemInfoOutput(output)) +} + +func TestParseInvalidSystemInfoOutput(t *testing.T) { + output := "Invalid" + + assert.Empty(t, parseSystemInfoOutput(output)) }