Repository navigation
MGMT-19001, MGMT-19005: Add dhcp and autoconf fields if missing in nmstate YAML + fix the nmstate flow bug on archs other than x86 #6798
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -61,6 +61,42 @@ func New(log logrus.FieldLogger) StaticNetworkConfig { | |
| } | ||
| } | ||
|
|
||
| // TODO: Temporary workaround until the nmstate team resolves and deploys the following issue - https://issues.redhat.com/browse/RHEL-59935 | ||
| func (s *StaticNetworkConfigGenerator) injectIPV4V6FieldsIfNeeded(networkYaml string) (string, error) { | ||
|
linoyaslan marked this conversation as resolved.
Outdated
|
||
| var config map[string]interface{} | ||
|
|
||
| // Unmarshal the JSON string into the config struct | ||
| err := yaml.Unmarshal([]byte(networkYaml), &config) | ||
| if err != nil { | ||
| s.log.WithError(err).Errorf("Error unmarshalling yaml") | ||
| return "", err | ||
| } | ||
| Interfaces := config["interfaces"].([]interface{}) | ||
| for _, iface := range Interfaces { | ||
| nic := iface.(map[interface{}]interface{}) | ||
| if val, exists := nic["ipv4"].(map[interface{}]interface{}); exists { | ||
| if _, exists := val["dhcp"]; !exists { | ||
| val["dhcp"] = false | ||
| } | ||
| } | ||
| if val, exists := nic["ipv6"].(map[interface{}]interface{}); exists { | ||
| if _, exists := val["dhcp"]; !exists { | ||
| val["dhcp"] = false | ||
| } | ||
| if _, exists := val["autoconf"]; !exists { | ||
| val["autoconf"] = false | ||
|
Comment on lines
86
to
87
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should also check if dhcp is false before setting auto conf + let add this case to tests so we wont have dhcp = true and autoconf = false
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
| } | ||
| } | ||
| // Marshal the updated config back into YAML format | ||
| updatedYaml, err := yaml.Marshal(&config) | ||
| if err != nil { | ||
| s.log.WithError(err).Errorf("Error marshalling yaml") | ||
| return "", err | ||
| } | ||
| return string(updatedYaml), nil | ||
| } | ||
|
|
||
| func (s *StaticNetworkConfigGenerator) injectNMPolicyCaptures(hostConfig *models.HostStaticNetworkConfig) (string, error) { | ||
| interfacesWithCaptures := hostConfig.NetworkYaml | ||
| var config interfaceConfig | ||
|
|
@@ -128,6 +164,12 @@ func (s *StaticNetworkConfigGenerator) GenerateStaticNetworkConfigDataYAML(stati | |
| } | ||
|
|
||
| for i, hostConfig := range staticNetworkConfig { | ||
| modifiedYaml, err := s.injectIPV4V6FieldsIfNeeded(hostConfig.NetworkYaml) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| hostConfig.NetworkYaml = modifiedYaml | ||
|
|
||
| nmpolicy, err := s.injectNMPolicyCaptures(hostConfig) | ||
| if err != nil { | ||
| return nil, err | ||
|
|
@@ -277,7 +319,7 @@ func (s *StaticNetworkConfigGenerator) validateInterfaceNamesExistenceYAML(macIn | |
| // Unmarshal the JSON string into the config struct | ||
| err := yaml.Unmarshal([]byte(networksYaml), &config) | ||
| if err != nil { | ||
| s.log.WithError(err).Errorf("Error unmarshalling JSON") | ||
| s.log.WithError(err).Errorf("Error unmarshalling yaml") | ||
| return err | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -313,7 +313,7 @@ var _ = Describe("Infra_Env", func() { | |
| Expect(s.Size()).ShouldNot(Equal(0)) | ||
| }) | ||
|
|
||
| DescribeTable("download infra-env files static network config file", func(ocpVersion string) { | ||
| DescribeTable("download infra-env files static network config file", func(ocpVersion, arch string) { | ||
| By("Patching the infra env with a static network config") | ||
| netYaml := `interfaces: | ||
| - ipv4: | ||
|
|
@@ -334,7 +334,7 @@ var _ = Describe("Infra_Env", func() { | |
| }, | ||
| }, | ||
| } | ||
| infraEnv = internalRegisterInfraEnv(nil, models.ImageTypeFullIso, "", ocpVersion) | ||
| infraEnv = internalRegisterInfraEnv(nil, models.ImageTypeFullIso, arch, ocpVersion) | ||
| infraEnvID = *infraEnv.ID | ||
| staticNetworkConfigs := []*models.HostStaticNetworkConfig{&staticNetworkConfig} | ||
| updateParams := &installer.UpdateInfraEnvParams{ | ||
|
|
@@ -353,13 +353,15 @@ var _ = Describe("Infra_Env", func() { | |
| contents := buf.String() | ||
| Expect(len(contents)).ShouldNot(Equal(0)) | ||
| Expect(contents).To(ContainSubstring("/etc/assisted/network/host0")) | ||
| if ocpVersion < staticnetworkconfig.MinimalVersionForNmstatectl { | ||
| if ocpVersion < staticnetworkconfig.MinimalVersionForNmstatectl || arch == common.ARM64CPUArchitecture { | ||
| Expect(contents).To(ContainSubstring("192.0.2.1/24")) | ||
| } | ||
| Expect(contents).To(ContainSubstring("eth0")) | ||
| }, | ||
| Entry("ocp versions greater than/ equal to 4.14", staticnetworkconfig.MinimalVersionForNmstatectl), | ||
| Entry("ocp versions less than 4.14", "4.12"), | ||
| Entry("ocp versions greater than/ equal to 4.14, x86 arch", staticnetworkconfig.MinimalVersionForNmstatectl, common.X86CPUArchitecture), | ||
| Entry("ocp versions greater than/ equal to 4.14, arm arch", staticnetworkconfig.MinimalVersionForNmstatectl, common.ARM64CPUArchitecture), | ||
|
Comment on lines
361
to
362
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this a typo ?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. greater than 4.14 / equal to 4.14 |
||
| Entry("ocp versions less than 4.14, x86 arch", "4.12", common.X86CPUArchitecture), | ||
| Entry("ocp versions less than 4.14, arm arch", "4.12", common.ARM64CPUArchitecture), | ||
|
Comment on lines
363
to
364
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure what we are testing here
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For OCP versions below 4.14, the static networking flow follows the older process, without using nmpolicy or the nmstate service. In this case, the files under It might be worth updating the condition in the test to: |
||
| ) | ||
|
|
||
| It("download infra-env files invalid filename option", func() { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.