Skip to content

Commit

Permalink
cluster up: Fix the regular expression used to parse openshift version
Browse files Browse the repository at this point in the history
  • Loading branch information
csrwng committed Jul 5, 2017
1 parent c9f829c commit 7dc2264
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
8 changes: 5 additions & 3 deletions pkg/bootstrap/docker/openshift/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -669,15 +669,17 @@ func (h *Helper) ServerPrereleaseVersion() (semver.Version, error) {
if len(versionStr) == 0 {
return semver.Version{}, fmt.Errorf("did not find version in command output")
}
return parseOpenshiftVersion(versionStr)
}

func parseOpenshiftVersion(versionStr string) (semver.Version, error) {
// The OCP version may have > 4 parts to the version string,
// e.g. 3.5.1.1-prerelease, whereas Origin will be 3.5.1-prerelease,
// drop the 4th digit for OCP.
re := regexp.MustCompile("([0-9]+).([0-9]+).([0-9]+).([0-9]+)(.*)")
re := regexp.MustCompile("([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.([0-9]+)(.*)")
versionStr = re.ReplaceAllString(versionStr, "${1}.${2}.${3}${5}")

version, err := semver.Parse(versionStr)
return version, err
return semver.Parse(versionStr)
}

func useDNSIP(version semver.Version) bool {
Expand Down
44 changes: 44 additions & 0 deletions pkg/bootstrap/docker/openshift/helper_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package openshift

import (
"testing"
)

func TestParseOpenshiftVersion(t *testing.T) {
tests := []struct {
input string
expected string
}{
{
input: "1.3.1",
expected: "1.3.1",
},
{
input: "3.5.5.4",
expected: "3.5.5",
},
{
input: "3.5.5.18-alpha.3",
expected: "3.5.5-alpha.3",
},
{
input: "3.4.144.2-1",
expected: "3.4.144-1",
},
{
input: "3.6.0-alpha.2+2a00043-774",
expected: "3.6.0-alpha.2+2a00043-774",
},
}

for _, test := range tests {
v, err := parseOpenshiftVersion(test.input)
if err != nil {
t.Errorf("unexpected error for %s: %v", test.input, err)
continue
}
if v.String() != test.expected {
t.Errorf("unexpected output. Got: %v, expected: %s", v, test.expected)
}
}
}

0 comments on commit 7dc2264

Please sign in to comment.