Normalize ceph-ansible version format

This commit is contained in:
AKYD 2022-05-25 11:49:04 +03:00
parent 43df70b181
commit 763e5ecd21
2 changed files with 11 additions and 0 deletions

View File

@ -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

View File

@ -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"},