Skip to content
Closed
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
74 changes: 1 addition & 73 deletions pkg/staticnetworkconfig/backward_compatibility.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,73 +25,6 @@ func (s *StaticNetworkConfigGenerator) NMStatectlServiceSupported(version string
return versionOK, nil
}

// CheckConfigForGlobalDnsCase detect whether any of the host-provided YAML configurations contain an interface with auto-dns: false, dhcp: true.
// TODO: This is a temporary workaround and should be removed once the auto-dns:false, dhcp:true bug is fixed
func (s *StaticNetworkConfigGenerator) CheckConfigForGlobalDnsCase(staticNetworkConfigStr string) (bool, error) {
staticNetworkConfig, err := s.decodeStaticNetworkConfig(staticNetworkConfigStr)
if err != nil {
s.log.WithError(err).Errorf("Failed to decode static network config")
return false, err
}

for _, hostConfig := range staticNetworkConfig {
isIncludeAutoDnsSetToFalse, err := s.hasDisabledAutoDnsWithDhcp(hostConfig.NetworkYaml)
if err != nil {
return false, err
}
if isIncludeAutoDnsSetToFalse {
return true, nil
}
}
return false, nil
}

func (s *StaticNetworkConfigGenerator) hasDisabledAutoDnsWithDhcp(networksYaml string) (bool, error) {
var config map[string]interface{}

// Unmarshal the YAML string into the config struct
err := yaml.Unmarshal([]byte(networksYaml), &config)
if err != nil {
s.log.WithError(err).Errorf("Error unmarshalling yaml")
return false, err
}

interfaces, exists := config["interfaces"]
if !exists || interfaces == nil {
return false, nil
}
interfacesSlice, ok := interfaces.([]interface{})
if !ok {
return false, nil
}

isDHCPButNoAutoDNS := func(ipConfig map[interface{}]interface{}) bool {
autoDNSDisabled := false
dhcpEnabled := false

if autoDns, exists := ipConfig["auto-dns"]; exists && autoDns == false {
autoDNSDisabled = true
}
if dhcp, exists := ipConfig["dhcp"]; exists && dhcp == true {
dhcpEnabled = true
}

return autoDNSDisabled && dhcpEnabled
}

for _, iface := range interfacesSlice {
nic := iface.(map[interface{}]interface{})

if ipv4, exists := nic["ipv4"].(map[interface{}]interface{}); exists && isDHCPButNoAutoDNS(ipv4) {
return true, nil
}
if ipv6, exists := nic["ipv6"].(map[interface{}]interface{}); exists && isDHCPButNoAutoDNS(ipv6) {
return true, nil
}
}
return false, nil
}

// CheckConfigForMACIdentifier TODO: This is a temporary workaround and should be removed once the mac-identifier bug in nmstate is fixed - RHEL-72440.
func (s *StaticNetworkConfigGenerator) CheckConfigForMACIdentifier(staticNetworkConfigStr string) (bool, error) {
staticNetworkConfig, err := s.decodeStaticNetworkConfig(staticNetworkConfigStr)
Expand Down Expand Up @@ -148,14 +81,9 @@ func (s *StaticNetworkConfigGenerator) ShouldUseNmstateService(staticNetworkConf
return false, err
}

includeAutoDnsSetToFalse, err := s.CheckConfigForGlobalDnsCase(staticNetworkConfigStr)
if err != nil {
return false, err
}

isNmstateServiceSupported, err := s.NMStatectlServiceSupported(openshiftVersion)
if err != nil {
return false, err
}
return isNmstateServiceSupported && !includesMACIdentifier && !includeAutoDnsSetToFalse, nil
return isNmstateServiceSupported && !includesMACIdentifier, nil
}
14 changes: 1 addition & 13 deletions pkg/staticnetworkconfig/backward_compatibility_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,6 @@ var _ = Describe("ShouldUseNmstateService", func() {
address:
- ip: 192.0.2.1
prefix-length: 24`
withAutoDnsSetToFalseDhcpTrue = `interfaces:
- ipv4:
auto-dns: false
dhcp: true
enabled: true
ipv6:
enabled: false
name: eth0
state: up
type: ethernet
`
)
table.DescribeTable("different scenarios", func(YAML, version string, expectedResult bool) {
escapedYamlContent, err := escapeYAMLForJSON(YAML)
Expand All @@ -58,6 +47,5 @@ var _ = Describe("ShouldUseNmstateService", func() {
table.Entry("If the YAML contains a mac-identifier, and the version is >= MinimalVersionForNmstatectl, we shouldn't use the nmstate service flow", withMacIdentifier, common.MinimalVersionForNmstatectl, false),
table.Entry("If the YAML contains a mac-identifier, and the version is < MinimalVersionForNmstatectl, we shouldn't use the nmstate service flow", withMacIdentifier, "4.12", false),
table.Entry("If the YAML doesn't contain a mac-identifier and the version is >= MinimalVersionForNmstatectl, we should use the nmstate service flow", withoutMacIdentifier, common.MinimalVersionForNmstatectl, true),
table.Entry("If the YAML doesn't contain a mac-identifier, and the version < MinimalVersionForNmstatectl we shouldn't use the nmstate service flow.", withoutMacIdentifier, "4.12", false),
table.Entry("If the YAML contains a auto-dns: false, dhcp: true, and the version >= MinimalVersionForNmstatectl we shouldn't use the nmstate service flow.", withAutoDnsSetToFalseDhcpTrue, common.MinimalVersionForNmstatectl, false))
table.Entry("If the YAML doesn't contain a mac-identifier, and the version < MinimalVersionForNmstatectl we shouldn't use the nmstate service flow.", withoutMacIdentifier, "4.12", false))
})