Normalize ceph-ansible version format
This commit is contained in:
parent
43df70b181
commit
763e5ecd21
|
@ -17,6 +17,7 @@ package ceph
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
@ -89,6 +90,10 @@ func (version *Version) String() string {
|
|||
|
||||
// ParseCephVersion parses the given ceph version string to a *Version or error
|
||||
func ParseCephVersion(cephVersion string) (*Version, error) {
|
||||
// standardize ceph-ansible version format
|
||||
var re = regexp.MustCompile(`(\d+\.\d+\.\d+-\d+)\.(.*)`)
|
||||
cephVersion = re.ReplaceAllString(cephVersion, `$1-$2`)
|
||||
|
||||
splitVersion := strings.Split(cephVersion, " ")
|
||||
if len(splitVersion) < 3 {
|
||||
return nil, ErrInvalidVersion
|
||||
|
|
|
@ -47,6 +47,12 @@ func TestParseCephVersion(t *testing.T) {
|
|||
want: &Version{Major: 14, Minor: 2, Patch: 18, Revision: 97, Commit: "gcc1e126"},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "nautilus-ceph-ansible",
|
||||
args: args{cephVersion: "ceph version 14.2.11-184.el8cp (44441323476fee97be0ff7a92c6065958c77f1b9) nautilus (stable)"},
|
||||
want: &Version{Major: 14, Minor: 2, Patch: 11, Revision: 184, Commit: "el8cp"},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "octopus",
|
||||
args: args{cephVersion: "ceph version 15.2.0-1-gcc1e126"},
|
||||
|
|
Loading…
Reference in New Issue