diff --git a/client/driver/rkt.go b/client/driver/rkt.go index c907f5caf..456e4e02b 100644 --- a/client/driver/rkt.go +++ b/client/driver/rkt.go @@ -21,8 +21,8 @@ import ( ) var ( - reRktVersion = regexp.MustCompile("rkt version ([\\d\\.]+).+") - reAppcVersion = regexp.MustCompile("appc version ([\\d\\.]+).+") + reRktVersion = regexp.MustCompile(`rkt version (\d[.\d]+)`) + reAppcVersion = regexp.MustCompile(`appc version (\d[.\d]+)`) ) // RktDriver is a driver for running images via Rkt @@ -67,13 +67,13 @@ func (d *RktDriver) Fingerprint(cfg *config.Config, node *structs.Node) (bool, e out := strings.TrimSpace(string(outBytes)) rktMatches := reRktVersion.FindStringSubmatch(out) - appcMatches := reRktVersion.FindStringSubmatch(out) + appcMatches := reAppcVersion.FindStringSubmatch(out) if len(rktMatches) != 2 || len(appcMatches) != 2 { return false, fmt.Errorf("Unable to parse Rkt version string: %#v", rktMatches) } node.Attributes["driver.rkt"] = "1" - node.Attributes["driver.rkt.version"] = rktMatches[0] + node.Attributes["driver.rkt.version"] = rktMatches[1] node.Attributes["driver.rkt.appc.version"] = appcMatches[1] return true, nil diff --git a/client/driver/rkt_test.go b/client/driver/rkt_test.go index 94d45cdcc..e992266a4 100644 --- a/client/driver/rkt_test.go +++ b/client/driver/rkt_test.go @@ -15,6 +15,21 @@ import ( ctestutils "github.com/hashicorp/nomad/client/testutil" ) +func TestRktVersionRegex(t *testing.T) { + input_rkt := "rkt version 0.8.1" + input_appc := "appc version 1.2.0" + expected_rkt := "0.8.1" + expected_appc := "1.2.0" + rktMatches := reRktVersion.FindStringSubmatch(input_rkt) + appcMatches := reAppcVersion.FindStringSubmatch(input_appc) + if rktMatches[1] != expected_rkt { + fmt.Printf("Test failed; got %q; want %q\n", rktMatches[1], expected_rkt) + } + if appcMatches[1] != expected_appc { + fmt.Printf("Test failed; got %q; want %q\n", appcMatches[1], expected_appc) + } +} + func TestRktDriver_Handle(t *testing.T) { h := &rktHandle{ proc: &os.Process{Pid: 123},