Skip to content

Commit

Permalink
distro/rhel9: handle two-digit minor version without the dot
Browse files Browse the repository at this point in the history
Let's gracefully handle the "old" naming scheme without a dot to separate
the major and minor version also for two-digit minor versions. RHEL-9
parser is now consistent with RHEL-8. The motivation behind this change
is to not introduce any breaking changes within the RHEL-9 major
version.

Signed-off-by: Tomáš Hozza <[email protected]>
  • Loading branch information
thozza authored and achilleas-k committed Feb 1, 2024
1 parent 9f3c548 commit a085315
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
7 changes: 5 additions & 2 deletions pkg/distro/rhel9/distro.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,14 +474,17 @@ func ParseID(idStr string) (*distro.ID, error) {
return nil, fmt.Errorf("invalid distro name: %s", id.Name)
}

// Backward compatibility layer for "rhel-93" and friends
// Backward compatibility layer for "rhel-93" or "rhel-910"
if id.Name == "rhel" && id.MinorVersion == -1 {
if id.MajorVersion/10 == 9 {
// handle single digit minor version
id.MinorVersion = id.MajorVersion % 10
id.MajorVersion = 9
} else if id.MajorVersion/100 == 9 {
// handle two digit minor version
id.MinorVersion = id.MajorVersion % 100
id.MajorVersion = 9
}
// two digit minor versions in the old format are not supported
}

if id.MajorVersion != 9 {
Expand Down
4 changes: 2 additions & 2 deletions pkg/distro/rhel9/distro_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ func TestDistroFactory(t *testing.T) {
expected: newDistro("rhel", 3),
},
{
strID: "rhel-910", // this is intentionally not supported for el9
expected: nil,
strID: "rhel-910",
expected: newDistro("rhel", 10),
},
{
strID: "rhel-9.10",
Expand Down
8 changes: 8 additions & 0 deletions pkg/distrofactory/distrofactory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ func TestGetDistroDefaultList(t *testing.T) {
strID: "rhel-9.1",
expectedDistroName: "rhel-9.1",
},
{
strID: "rhel-910",
expectedDistroName: "rhel-9.10",
},
{
strID: "rhel-9.10",
expectedDistroName: "rhel-9.10",
},
{
strID: "fedora-38",
expectedDistroName: "fedora-38",
Expand Down
2 changes: 1 addition & 1 deletion pkg/distroidparser/idparser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func TestDefaltParser(t *testing.T) {
},
{
idStr: "rhel-910",
expected: &distro.ID{Name: "rhel", MajorVersion: 910, MinorVersion: -1},
expected: &distro.ID{Name: "rhel", MajorVersion: 9, MinorVersion: 10},
},
{
idStr: "rhel-9.10",
Expand Down

0 comments on commit a085315

Please sign in to comment.