Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MGMT-20025: Replace encode from yaml to json on Nutanix types #7353

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions internal/installcfg/builder/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,38 @@ aEA8gNEmV+rb7h1v0r3EwDQYJKoZIhvcNAQELBQAwYTELMAkGA1UEBhMCaXMxCzAJBgNVBAgMAmRk
assertVSphereCredentials(result)
})

nutanixInstallConfigOverrides := `{"platform":{"nutanix":{"prismCentral":{"endpoint":{"address":"prismcentral.openshift.com","port":9440},"username":"testUser","password":"testPassword"},"prismElements":[{"uuid": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx","endpoint":{"address":"prism.openshift.com","port":9440}}],"subnetUUIDs":["yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy"],"apiVIPs":["10.0.0.1"],"ingressVIPs":["10.0.0.2"]}}}`

It("Nutanix platform in overrides is decoded correctly - installConfig.applyConfigOverrides", func() {
var result installcfg.InstallerConfigBaremetal
overrides := nutanixInstallConfigOverrides
err := installConfig.applyConfigOverrides(overrides, &result)
Expect(err).ShouldNot(HaveOccurred())
assertNutanixPlatform(result)
})

It("Nutanix platform are unmarshalled correctly - installConfig.GetInstallConfig", func() {
var result installcfg.InstallerConfigBaremetal
mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured().Return(false).Times(2)
cluster.InstallConfigOverrides = nutanixInstallConfigOverrides
data, err := installConfig.GetInstallConfig(&cluster, clusterInfraenvs, "")
Expect(err).ShouldNot(HaveOccurred())
err = json.Unmarshal(data, &result)
Expect(err).ShouldNot(HaveOccurred())
assertNutanixPlatform(result)
})

It("Nutanix credentials are unmarshalled correctly - installConfig.GetInstallConfig", func() {
var result installcfg.InstallerConfigBaremetal
mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured().Return(false).Times(2)
cluster.InstallConfigOverrides = nutanixInstallConfigOverrides
data, err := installConfig.GetInstallConfig(&cluster, clusterInfraenvs, "")
Expect(err).ShouldNot(HaveOccurred())
err = json.Unmarshal(data, &result)
Expect(err).ShouldNot(HaveOccurred())
assertNutanixCredentials(result)
})

It("correctly applies cluster overrides", func() {
var result installcfg.InstallerConfigBaremetal
mockMirrorRegistriesConfigBuilder.EXPECT().IsMirrorRegistriesConfigured().Return(false).Times(2)
Expand Down Expand Up @@ -935,6 +967,24 @@ func assertVSphereCredentials(result installcfg.InstallerConfigBaremetal) {
Expect(result.Platform.Vsphere.FailureDomains[0].Topology.Folder).Should(Equal("/testDatacenter/vm/testFolder"))
}

// asserts platform values against nutanixInstallConfigOverrides
func assertNutanixPlatform(result installcfg.InstallerConfigBaremetal) {
Expect(len(result.Platform.Nutanix.APIVIPs)).Should(Equal(1))
Expect(len(result.Platform.Nutanix.IngressVIPs)).Should(Equal(1))
Expect(result.Platform.Nutanix.PrismCentral.Endpoint.Address).Should(Equal("prismcentral.openshift.com"))
Expect(result.Platform.Nutanix.PrismCentral.Endpoint.Port).Should(Equal(int32(9440)))
Expect(string(result.Platform.Nutanix.PrismElements[0].UUID)).Should(Equal("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"))
Expect(result.Platform.Nutanix.PrismElements[0].Endpoint.Address).Should(Equal("prism.openshift.com"))
Expect(result.Platform.Nutanix.PrismElements[0].Endpoint.Port).Should(Equal(int32(9440)))
Expect(len(result.Platform.Nutanix.SubnetUUIDs)).Should(Equal(1))
}

// asserts platform values against nutanixInstallConfigOverrides
func assertNutanixCredentials(result installcfg.InstallerConfigBaremetal) {
Expect(result.Platform.Nutanix.PrismCentral.Username).Should(Equal("testUser"))
Expect(string(result.Platform.Nutanix.PrismCentral.Password)).Should(Equal("testPassword"))
}

// asserts Baremetal Host BMC Configuration set by InstallConfigOverrides
func assertBaremetalHostBMCConfig(result installcfg.InstallerConfigBaremetal) {
Expect(result.Platform.Baremetal.Hosts[0].Name).Should(Equal("master-0"))
Expand Down
44 changes: 22 additions & 22 deletions internal/installcfg/installcfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,37 +111,37 @@ type VsphereInstallConfigPlatform struct {
}

type NutanixInstallConfigPlatform struct {
ID int `yaml:"-"`
APIVIPs []string `yaml:"apiVIPs,omitempty"`
DeprecatedAPIVIP string `yaml:"apiVIP,omitempty"`
IngressVIPs []string `yaml:"ingressVIPs,omitempty"`
DeprecatedIngressVIP string `yaml:"ingressVIP,omitempty"`
PrismCentral NutanixPrismCentral `yaml:"prismCentral"`
PrismElements []NutanixPrismElement `yaml:"prismElements"`
SubnetUUIDs []strfmt.UUID `yaml:"subnetUUIDs"`
ID int `json:"-"`
APIVIPs []string `json:"apiVIPs,omitempty"`
DeprecatedAPIVIP string `json:"apiVIP,omitempty"`
IngressVIPs []string `json:"ingressVIPs,omitempty"`
DeprecatedIngressVIP string `json:"ingressVIP,omitempty"`
PrismCentral NutanixPrismCentral `json:"prismCentral"`
PrismElements []NutanixPrismElement `json:"prismElements"`
SubnetUUIDs []strfmt.UUID `json:"subnetUUIDs"`
}

type NutanixPrismCentral struct {
ID int `yaml:"-"`
NutanixInstallConfigPlatformID int `yaml:"-"`
Endpoint NutanixEndpoint `yaml:"endpoint"`
Username string `yaml:"username"`
Password strfmt.Password `yaml:"password"`
ID int `json:"-"`
NutanixInstallConfigPlatformID int `json:"-"`
Endpoint NutanixEndpoint `json:"endpoint"`
Username string `json:"username"`
Password strfmt.Password `json:"password"`
}

type NutanixEndpoint struct {
ID int `yaml:"-"`
NutanixPrismCentralID int `yaml:"-"`
Address string `yaml:"address"`
Port int32 `yaml:"port"`
ID int `json:"-"`
NutanixPrismCentralID int `json:"-"`
Address string `json:"address"`
Port int32 `json:"port"`
}

type NutanixPrismElement struct {
ID int `yaml:"-"`
NutanixInstallConfigPlatformID int `yaml:"-"`
Endpoint NutanixEndpoint `yaml:"endpoint"`
UUID strfmt.UUID `yaml:"uuid"`
Name string `yaml:"name"`
ID int `json:"-"`
NutanixInstallConfigPlatformID int `json:"-"`
Endpoint NutanixEndpoint `json:"endpoint"`
UUID strfmt.UUID `json:"uuid"`
Name string `json:"name"`
}

// CloudControllerManager describes the type of cloud controller manager to be enabled.
Expand Down
71 changes: 23 additions & 48 deletions internal/provider/registry/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/openshift/assisted-service/internal/provider/vsphere"
"github.com/openshift/assisted-service/internal/usage"
"github.com/openshift/assisted-service/models"
"gopkg.in/yaml.v2"
)

var (
Expand All @@ -26,47 +25,6 @@ var (

const invalidInventory = "{\"system_vendor\": \"invalid\"}"

const expectedNutanixInstallConfig411 = `apiVIPs:
- 192.168.10.10
apiVIP: 192.168.10.10
ingressVIPs:
- 192.168.10.11
ingressVIP: 192.168.10.11
prismCentral:
endpoint:
address: prism.central.placeholder.address
port: 9440
username: username_placeholder
password: password_placeholder
prismElements:
- endpoint:
address: prism.element.placeholder.address
port: 9440
uuid: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
name: prism_endpoint_name_placeholder
subnetUUIDs:
- yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy
`
const expectedNutanixInstallConfig412 = `apiVIPs:
- 192.168.10.10
ingressVIPs:
- 192.168.10.11
prismCentral:
endpoint:
address: prism.central.placeholder.address
port: 9440
username: username_placeholder
password: password_placeholder
prismElements:
- endpoint:
address: prism.element.placeholder.address
port: 9440
uuid: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
name: prism_endpoint_name_placeholder
subnetUUIDs:
- yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy
`

var _ = Describe("Test GetSupportedProvidersByHosts", func() {
bmInventory := getBaremetalInventoryStr("hostname0", "bootMode", true, false)
vsphereInventory := getVsphereInventoryStr("hostname0", "bootMode", true, false)
Expand Down Expand Up @@ -400,10 +358,18 @@ var _ = Describe("Test AddPlatformToInstallConfig", func() {
err := providerRegistry.AddPlatformToInstallConfig(&cfg, &cluster, nil)
Expect(err).To(BeNil())
Expect(cfg.Platform.Nutanix).ToNot(BeNil())
installConfigByte, err := yaml.Marshal(cfg.Platform.Nutanix)
Expect(err).ToNot(HaveOccurred())
Expect(string(installConfigByte)).To(Equal(expectedNutanixInstallConfig412))
Expect(cfg.Platform.Nutanix.APIVIPs[0]).Should(Equal("192.168.10.10"))
Expect(cfg.Platform.Nutanix.IngressVIPs[0]).Should(Equal("192.168.10.11"))
Expect(cfg.Platform.Nutanix.PrismCentral.Endpoint.Address).Should(Equal("prism.central.placeholder.address"))
Expect(cfg.Platform.Nutanix.PrismCentral.Endpoint.Port).Should(Equal(int32(9440)))
Expect(cfg.Platform.Nutanix.PrismCentral.Username).Should(Equal("username_placeholder"))
Expect(string(cfg.Platform.Nutanix.PrismCentral.Password)).Should(Equal("password_placeholder"))
Expect(string(cfg.Platform.Nutanix.PrismElements[0].UUID)).Should(Equal("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"))
Expect(cfg.Platform.Nutanix.PrismElements[0].Endpoint.Address).Should(Equal("prism.element.placeholder.address"))
Expect(cfg.Platform.Nutanix.PrismElements[0].Endpoint.Port).Should(Equal(int32(9440)))
Expect(string(cfg.Platform.Nutanix.SubnetUUIDs[0])).Should(Equal("yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy"))
})

It("without cluster params openshift version 4.11", func() {
cfg := getInstallerConfigBaremetal()
hosts := make([]*models.Host, 0)
Expand All @@ -418,9 +384,18 @@ var _ = Describe("Test AddPlatformToInstallConfig", func() {
err := providerRegistry.AddPlatformToInstallConfig(&cfg, &cluster, nil)
Expect(err).To(BeNil())
Expect(cfg.Platform.Nutanix).ToNot(BeNil())
installConfigByte, err := yaml.Marshal(cfg.Platform.Nutanix)
Expect(err).ToNot(HaveOccurred())
Expect(string(installConfigByte)).To(Equal(expectedNutanixInstallConfig411))
Expect(cfg.Platform.Nutanix.APIVIPs[0]).Should(Equal("192.168.10.10"))
Expect(cfg.Platform.Nutanix.DeprecatedAPIVIP).Should(Equal("192.168.10.10"))
Expect(cfg.Platform.Nutanix.IngressVIPs[0]).Should(Equal("192.168.10.11"))
Expect(cfg.Platform.Nutanix.DeprecatedIngressVIP).Should(Equal("192.168.10.11"))
Expect(cfg.Platform.Nutanix.PrismCentral.Endpoint.Address).Should(Equal("prism.central.placeholder.address"))
Expect(cfg.Platform.Nutanix.PrismCentral.Endpoint.Port).Should(Equal(int32(9440)))
Expect(cfg.Platform.Nutanix.PrismCentral.Username).Should(Equal("username_placeholder"))
Expect(string(cfg.Platform.Nutanix.PrismCentral.Password)).Should(Equal("password_placeholder"))
Expect(string(cfg.Platform.Nutanix.PrismElements[0].UUID)).Should(Equal("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"))
Expect(cfg.Platform.Nutanix.PrismElements[0].Endpoint.Address).Should(Equal("prism.element.placeholder.address"))
Expect(cfg.Platform.Nutanix.PrismElements[0].Endpoint.Port).Should(Equal(int32(9440)))
Expect(string(cfg.Platform.Nutanix.SubnetUUIDs[0])).Should(Equal("yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy"))
})
})

Expand Down