Skip to content

Commit

Permalink
e2e: Add dhcp unaware DNS tests (#955)
Browse files Browse the repository at this point in the history
Signed-off-by: Radim Hrazdil <[email protected]>
  • Loading branch information
rhrazdil authored Jan 26, 2022
1 parent b32e3c1 commit 1c09459
Showing 1 changed file with 218 additions and 45 deletions.
263 changes: 218 additions & 45 deletions test/e2e/handler/dns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ package handler

import (
"fmt"
"strings"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

nmstate "github.com/nmstate/kubernetes-nmstate/api/shared"
)

func dnsConfig(searchDomain1, searchDomain2, server1, server2, ipFamily, ipFamily1, dnsTestNic string) nmstate.State {
func dhcpAwareDNSConfig(searchDomain1, searchDomain2, server1, server2, dnsTestNic string) nmstate.State {
return nmstate.NewState(fmt.Sprintf(`dns-resolver:
config:
search:
Expand All @@ -39,34 +40,117 @@ interfaces:
- name: %s
type: ethernet
state: up
%s:
ipv4:
auto-dns: false
enabled: true
dhcp: true
%s:
ipv6:
enabled: true
dhcp: true
auto-dns: false
`, searchDomain1, searchDomain2, server1, server2, dnsTestNic))
}

`, searchDomain1, searchDomain2, server1, server2, dnsTestNic, ipFamily, ipFamily1))
func staticIPAndGwConfig(searchDomain1, searchDomain2, server1, server2, dnsTestNic, dnsTestNicIP string) nmstate.State {
return nmstate.NewState(fmt.Sprintf(`
dns-resolver:
config:
search:
- %s
- %s
server:
- %s
- %s
routes:
config:
- destination: 0.0.0.0/0
metric: 100
next-hop-address: %s
next-hop-interface: %s
table-id: 253
- destination: 0::/0
metric: 100
next-hop-address: fd80:0:0:0::1
next-hop-interface: eth1
table-id: 253
interfaces:
- name: %s
type: ethernet
state: up
ipv4:
address:
- ip: %s
prefix-length: 24
enabled: true
dhcp: false
auto-dns: false
- name: eth1
type: ethernet
state: up
ipv6:
enabled: true
dhcp: false
auto-dns: false
address:
- ip: 2001:db8::1:1
prefix-length: 64
`, searchDomain1, searchDomain2, server1, server2, dnsTestNicIP, dnsTestNic, dnsTestNic, dnsTestNicIP))
}

func dnsAbsent(dnsTestNic string) nmstate.State {
func staticIPAbsentAndRoutesAbsent(dnsTestNic, dnsTestNicIP string) nmstate.State {
return nmstate.NewState(fmt.Sprintf(`dns-resolver:
config:
server: []
search: []
routes:
config:
- destination: 0.0.0.0/0
metric: 100
state: absent
next-hop-address: %s
next-hop-interface: %s
table-id: 253
- destination: 0::/0
state: absent
metric: 100
next-hop-address: fd80:0:0:0::1
next-hop-interface: eth1
table-id: 253
interfaces:
- name: %s
type: ethernet
state: up
ipv4:
dhcp: true
enabled: true
auto-dns: true
enabled: true
dhcp: true
ipv6:
auto-dns: true
enabled: true
dhcp: true
- name: eth1
type: ethernet
state: down
`, dnsTestNicIP, dnsTestNic, dnsTestNic))
}

func dhcpAwareDNSAbsent(dnsTestNic string) nmstate.State {
return nmstate.NewState(fmt.Sprintf(`dns-resolver:
config:
server: []
search: []
interfaces:
- name: %s
type: ethernet
state: up
ipv4:
auto-dns: true
enabled: true
dhcp: true
ipv6:
auto-dns: true
enabled: true
dhcp: true
`, dnsTestNic))
}

Expand All @@ -78,51 +162,140 @@ var _ = Describe("Dns configuration", func() {
server1V4 = "8.8.9.9"
server1V6 = "2001:db8::1:2"
)
extractDNSServerAddress := func(dnsServer string) string {
return strings.Split(dnsServer, "%")[0]
}

Context("with V4 upstream servers", func() {
BeforeEach(func() {
// read primary DNS server from one of the nodes
serverList := dnsResolverForNode(nodes[0], "dns-resolver.running.server")
updateDesiredStateAndWait(dnsConfig(searchDomain1, searchDomain2, serverList[0], server1V4, "ipv4", "ipv6", dnsTestNic))
})
AfterEach(func() {
updateDesiredStateAndWait(dnsAbsent(dnsTestNic))
for _, node := range nodes {
dnsResolverServerForNodeEventually(node).ShouldNot(ContainElement(server1V4))
dnsResolverSearchForNodeEventually(node).ShouldNot(ContainElement(searchDomain1))
dnsResolverSearchForNodeEventually(node).ShouldNot(ContainElement(searchDomain2))
}
resetDesiredStateForNodes()
Context("with DHCP aware interface", func() {
Context("with V4 upstream servers", func() {
BeforeEach(func() {
// read primary DNS server from one of the nodes
serverList := dnsResolverForNode(nodes[0], "dns-resolver.running.server")
updateDesiredStateAndWait(
dhcpAwareDNSConfig(
searchDomain1,
searchDomain2,
extractDNSServerAddress(serverList[0]),
server1V4,
dnsTestNic,
),
)
})
AfterEach(func() {
updateDesiredStateAndWait(dhcpAwareDNSAbsent(dnsTestNic))
for _, node := range nodes {
dnsResolverServerForNodeEventually(node).ShouldNot(ContainElement(server1V4))
dnsResolverSearchForNodeEventually(node).ShouldNot(ContainElement(searchDomain1))
dnsResolverSearchForNodeEventually(node).ShouldNot(ContainElement(searchDomain2))
}
resetDesiredStateForNodes()
})
It("should have the static V4 address", func() {
for _, node := range nodes {
dnsResolverServerForNodeEventually(node).Should(ContainElement(server1V4))
dnsResolverSearchForNodeEventually(node).Should(ContainElement(searchDomain1))
dnsResolverSearchForNodeEventually(node).Should(ContainElement(searchDomain2))
}
})
})
It("should have the static V4 address", func() {
for _, node := range nodes {
dnsResolverServerForNodeEventually(node).Should(ContainElement(server1V4))
dnsResolverSearchForNodeEventually(node).Should(ContainElement(searchDomain1))
dnsResolverSearchForNodeEventually(node).Should(ContainElement(searchDomain2))
}
Context("with V6 upstream servers", func() {
BeforeEach(func() {
// read primary DNS server from one of the nodes
serverList := dnsResolverForNode(nodes[0], "dns-resolver.running.server")
updateDesiredStateAndWait(
dhcpAwareDNSConfig(
searchDomain1,
searchDomain2,
extractDNSServerAddress(serverList[0]),
server1V6,
dnsTestNic,
),
)
})
AfterEach(func() {
updateDesiredStateAndWait(dhcpAwareDNSAbsent(dnsTestNic))
for _, node := range nodes {
dnsResolverServerForNodeEventually(node).ShouldNot(ContainElement(server1V6))
dnsResolverSearchForNodeEventually(node).ShouldNot(ContainElement(searchDomain1))
dnsResolverSearchForNodeEventually(node).ShouldNot(ContainElement(searchDomain2))
}
resetDesiredStateForNodes()
})
It("should have the static V6 address", func() {
for _, node := range nodes {
dnsResolverServerForNodeEventually(node).Should(ContainElement(server1V6))
dnsResolverSearchForNodeEventually(node).Should(ContainElement(searchDomain1))
dnsResolverSearchForNodeEventually(node).Should(ContainElement(searchDomain2))
}
})
})
})
Context("with V6 upstream servers", func() {
Context("with DHCP unaware interface", func() {
var (
designatedNode string
designatedNodeIP string
)
BeforeEach(func() {
// read primary DNS server from one of the nodes
serverList := dnsResolverForNode(nodes[0], "dns-resolver.running.server")
updateDesiredStateAndWait(dnsConfig(searchDomain1, searchDomain2, serverList[0], server1V6, "ipv6", "ipv4", dnsTestNic))
designatedNode = nodes[0]
designatedNodeIP = ipv4Address(designatedNode, dnsTestNic)
})
AfterEach(func() {
updateDesiredStateAndWait(dnsAbsent(dnsTestNic))
for _, node := range nodes {
dnsResolverServerForNodeEventually(node).ShouldNot(ContainElement(server1V6))
dnsResolverSearchForNodeEventually(node).ShouldNot(ContainElement(searchDomain1))
dnsResolverSearchForNodeEventually(node).ShouldNot(ContainElement(searchDomain2))
}
resetDesiredStateForNodes()
Context("with V4 upstream servers", func() {
BeforeEach(func() {
// read primary DNS server from one of the nodes
serverList := dnsResolverForNode(designatedNode, "dns-resolver.running.server")
updateDesiredStateAtNodeAndWait(
designatedNode,
staticIPAndGwConfig(
searchDomain1,
searchDomain2,
extractDNSServerAddress(serverList[0]),
server1V4,
dnsTestNic,
designatedNodeIP,
),
)
})
AfterEach(func() {
updateDesiredStateAtNodeAndWait(designatedNode, staticIPAbsentAndRoutesAbsent(dnsTestNic, designatedNodeIP))
dnsResolverServerForNodeEventually(designatedNode).ShouldNot(ContainElement(server1V4))
dnsResolverSearchForNodeEventually(designatedNode).ShouldNot(ContainElement(searchDomain1))
dnsResolverSearchForNodeEventually(designatedNode).ShouldNot(ContainElement(searchDomain2))
resetDesiredStateForNodes()
})
It("should have the static V4 address", func() {
dnsResolverServerForNodeEventually(designatedNode).Should(ContainElement(server1V4))
dnsResolverSearchForNodeEventually(designatedNode).Should(ContainElement(searchDomain1))
dnsResolverSearchForNodeEventually(designatedNode).Should(ContainElement(searchDomain2))
})
})
It("should have the static V6 address", func() {
for _, node := range nodes {
dnsResolverServerForNodeEventually(node).Should(ContainElement(server1V6))
dnsResolverSearchForNodeEventually(node).Should(ContainElement(searchDomain1))
dnsResolverSearchForNodeEventually(node).Should(ContainElement(searchDomain2))
}
Context("with V6 upstream servers", func() {
BeforeEach(func() {
// read primary DNS server from one of the nodes
serverList := dnsResolverForNode(designatedNode, "dns-resolver.running.server")
updateDesiredStateAtNodeAndWait(
designatedNode,
staticIPAndGwConfig(
searchDomain1,
searchDomain2,
extractDNSServerAddress(serverList[0]),
server1V6,
dnsTestNic,
designatedNodeIP,
),
)
})
AfterEach(func() {
updateDesiredStateAtNodeAndWait(designatedNode, staticIPAbsentAndRoutesAbsent(dnsTestNic, designatedNodeIP))
dnsResolverServerForNodeEventually(designatedNode).ShouldNot(ContainElement(server1V6))
dnsResolverSearchForNodeEventually(designatedNode).ShouldNot(ContainElement(searchDomain1))
dnsResolverSearchForNodeEventually(designatedNode).ShouldNot(ContainElement(searchDomain2))
resetDesiredStateForNodes()
})
It("should have the static V6 address", func() {
dnsResolverServerForNodeEventually(designatedNode).Should(ContainElement(server1V6))
dnsResolverSearchForNodeEventually(designatedNode).Should(ContainElement(searchDomain1))
dnsResolverSearchForNodeEventually(designatedNode).Should(ContainElement(searchDomain2))
})
})
})
})
Expand Down

0 comments on commit 1c09459

Please sign in to comment.