Merge pull request #2572 from jeanlaurent/osversion

Add OS Version  to crash report
This commit is contained in:
David Gageot
2015-12-14 15:43:00 +01:00
5 changed files with 75 additions and 0 deletions

View File

@@ -16,6 +16,7 @@ import (
"github.com/bugsnag/bugsnag-go"
"github.com/docker/machine/commands/mcndirs"
"github.com/docker/machine/libmachine/log"
"github.com/docker/machine/libmachine/mcnutils"
"github.com/docker/machine/version"
)
@@ -65,6 +66,7 @@ func Send(err error, context string, driverName string, command string) error {
detectRunningShell(&metaData)
detectUname(&metaData)
detectOSVersion(&metaData)
var buffer bytes.Buffer
for _, message := range log.History() {
@@ -101,3 +103,7 @@ func detectUname(metaData *bugsnag.MetaData) {
}
metaData.Add("device", "uname", string(output))
}
func detectOSVersion(metaData *bugsnag.MetaData) {
metaData.Add("device", "os version", mcnutils.LocalOSVersion())
}

View File

@@ -0,0 +1,12 @@
package mcnutils
import "os/exec"
func LocalOSVersion() string {
command := exec.Command("bash", "-c", `sw_vers | grep ProductVersion | cut -d$'\t' -f2`)
output, err := command.Output()
if err != nil {
return ""
}
return string(output)
}

View File

@@ -0,0 +1,12 @@
package mcnutils
import "os/exec"
func LocalOSVersion() string {
command := exec.Command("bash", "-c", `cat /etc/os-release | grep 'VERSION=' | cut -d'=' -f2`)
output, err := command.Output()
if err != nil {
return ""
}
return string(output)
}

View File

@@ -0,0 +1,25 @@
package mcnutils
import (
"os/exec"
"strings"
)
func LocalOSVersion() string {
command := exec.Command(`systeminfo`)
output, err := command.Output()
if err != nil {
return ""
}
return parseOutput(string(output))
}
func parseOutput(output string) string {
lines := strings.Split(string(output), "\n")
for _, line := range lines {
if strings.HasPrefix(line, "OS Version") {
return strings.TrimSpace(line[len("OS Version:"):])
}
}
return ""
}

View File

@@ -0,0 +1,20 @@
package mcnutils
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestOSWindows(t *testing.T) {
output := `
Host Name: DESKTOP-3A5PULA
OS Name: Microsoft Windows 10 Enterprise
OS Version: 10.0.10240 N/A Build 10240
OS Manufacturer: Microsoft Corporation
OS Configuration: Standalone Workstation
OS Build Type: Multiprocessor Free
Registered Owner: Windows User
`
assert.Equal(t, "10.0.10240 N/A Build 10240", parseOutput(output))
}