Skip to content

Commit

Permalink
fix(ovirt): use default values for platform attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
bl4ko committed Sep 9, 2024
1 parent 0b26538 commit eba786c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
9 changes: 6 additions & 3 deletions internal/source/ovirt/ovirt_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,9 @@ func (o *OVirtSource) syncHosts(nbi *inventory.NetboxInventory) error {
}
platformName := utils.GeneratePlatformName(osDistribution, osVersion, cpuArch)
hostPlatformStruct := &objects.Platform{
Name: platformName,
Slug: utils.Slugify(platformName),
Name: platformName,
Slug: utils.Slugify(platformName),
Manufacturer: hostManufacturer,

Check warning on line 265 in internal/source/ovirt/ovirt_sync.go

View check run for this annotation

Codecov / codecov/patch

internal/source/ovirt/ovirt_sync.go#L263-L265

Added lines #L263 - L265 were not covered by tests
}
hostPlatform, err = nbi.AddPlatform(o.Ctx, hostPlatformStruct)
if err != nil {
Expand Down Expand Up @@ -799,7 +800,9 @@ func (o *OVirtSource) extractVMData(nbi *inventory.NetboxInventory, vmID string,

// VM's Platform
var vmPlatform *objects.Platform
var vmOsType, vmOsVersion, vmCPUArch string
vmOsType := constants.DefaultOSName
vmCPUArch := constants.DefaultCPUArch
vmOsVersion := constants.DefaultOSVersion

Check warning on line 805 in internal/source/ovirt/ovirt_sync.go

View check run for this annotation

Codecov / codecov/patch

internal/source/ovirt/ovirt_sync.go#L803-L805

Added lines #L803 - L805 were not covered by tests
if guestOs, exists := vm.GuestOperatingSystem(); exists {
if guestOsType, exists := guestOs.Distribution(); exists {
vmOsType = guestOsType
Expand Down
14 changes: 8 additions & 6 deletions internal/utils/dcim.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,13 @@ func GeneratePlatformName(osDistribution string, osMajorVersion string, cpuArch
if osDistribution != "" {
osDistribution = SerializeOSName(osDistribution)
} else {
return constants.DefaultOSName
osDistribution = constants.DefaultOSName
}

if osMajorVersion != "" {
if !strings.Contains(osDistribution, "(") {
osMajorVersion = fmt.Sprintf(" %s", osMajorVersion)
} else {
osMajorVersion = ""
}
osMajorVersion = fmt.Sprintf(" %s", osMajorVersion)
}

if cpuArch != "" {
// Check if cpuArch was extreacted from osDistribution
if !strings.Contains(osDistribution, "(") {
Expand All @@ -71,6 +69,7 @@ func GeneratePlatformName(osDistribution string, osMajorVersion string, cpuArch
cpuArch = ""
}
}

return fmt.Sprintf("%s%s%s", osDistribution, osMajorVersion, cpuArch)
}

Expand Down Expand Up @@ -147,6 +146,9 @@ var UniversalOSMap = map[string]string{

// SerializeOSName returns serialized OS name from the given string.
func SerializeOSName(os string) string {
if os == constants.DefaultOSName {
return os
}
for regex, name := range SpecificOSMap {
matched, _ := regexp.MatchString(regex, os)
if matched {
Expand Down
7 changes: 7 additions & 0 deletions internal/utils/dcim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,13 @@ func TestSerializeOSName(t *testing.T) {
},
want: "Custom OS",
},
{
name: "Don't serialize default OS name",
args: args{
os: constants.DefaultOSName,
},
want: constants.DefaultOSName,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit eba786c

Please sign in to comment.