Skip to content

Commit

Permalink
Testing IPv6 for changes
Browse files Browse the repository at this point in the history
Rewrote `makeNode()` to create IPv6 as well, added some test cases for IPv6
  • Loading branch information
heschlie committed Jul 19, 2017
1 parent 190b9a2 commit e8ed9aa
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
2 changes: 1 addition & 1 deletion calico_node/startup/startup.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ func getNode(client *client.Client, nodeName string) *api.Node {
}

// configureIPsAndSubnets updates the supplied node resource with IP and Subnet
// information to use for BGP.
// information to use for BGP. This returns true if we detect a change in Node IP address.
func configureIPsAndSubnets(node *api.Node) bool {
// If the node resource currently has no BGP configuration, add an empty
// set of configuration as it makes the processing below easier, and we
Expand Down
34 changes: 24 additions & 10 deletions calico_node/startup/startup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,26 @@ import (

var exitCode int

var ip4, ip4net, _ = net.ParseCIDR("192.168.1.10/24")

func fakeExitFunction(ec int) {
exitCode = ec
}

func makeNode() *api.Node {
var ip4, ip4net, _ = net.ParseCIDR("192.168.1.10/24")
// makeNode creates an api.Node with some BGPSpec info populated.
func makeNode(ipv4 string, ipv6 string) *api.Node {
ip4, ip4net, _ := net.ParseCIDR(ipv4)
ip4net.IP = ip4.IP

ip6, ip6net, _ := net.ParseCIDR(ipv6)
// Guard against nil here in case we pass in an empty string for IPv6.
if ip6 != nil {
ip6net.IP = ip6.IP
}

n := &api.Node{
Spec: api.NodeSpec{
BGP: &api.NodeBGPSpec{
IPv4Address: ip4net,
IPv6Address: ip6net,
},
},
}
Expand Down Expand Up @@ -311,17 +318,24 @@ var _ = Describe("FV tests against a real etcd", func() {
var _ = Describe("UT for Node IP assignment and conflict checking.", func() {

DescribeTable("Test variations on how IPs are detected.",
func(node *api.Node, item EnvItem, expected bool) {
func(node *api.Node, items []EnvItem, expected bool) {

for _, item := range items {
os.Setenv(item.key, item.value)
}

os.Setenv(item.key, item.value)
check := configureIPsAndSubnets(node)

Expect(check).To(Equal(expected))
},

Entry("Test with no \"IP\" env var set", &api.Node{}, EnvItem{"IP", ""}, true),
Entry("Test with \"IP\" env var set to IP", &api.Node{}, EnvItem{"IP", "192.168.1.10/24"}, true),
Entry("Test with \"IP\" env var set to IP and BGP spec populated", makeNode(), EnvItem{"IP", "192.168.1.10/24"}, false),
Entry("Test with \"IP\" env var set to IP and BGP spec populated", makeNode(), EnvItem{"IP", "192.168.1.11/24"}, true),
Entry("Test with no \"IP\" env var set", &api.Node{}, []EnvItem{{"IP", ""}}, true),
Entry("Test with \"IP\" env var set to IP", &api.Node{}, []EnvItem{{"IP", "192.168.1.10/24"}}, true),
Entry("Test with \"IP\" env var set to IP and BGP spec populated with same IP", makeNode("192.168.1.10/24", ""), []EnvItem{{"IP", "192.168.1.10/24"}}, false),
Entry("Test with \"IP\" env var set to IP and BGP spec populated with different IP", makeNode("192.168.1.10/24", ""), []EnvItem{{"IP", "192.168.1.11/24"}}, true),
Entry("Test with no \"IP6\" env var set", &api.Node{}, []EnvItem{{"IP6", ""}}, true),
Entry("Test with \"IP6\" env var set to IP", &api.Node{}, []EnvItem{{"IP6", "2001:db8:85a3:8d3:1319:8a2e:370:7348/32"}}, true),
Entry("Test with \"IP6\" env var set to IP and BGP spec populated with same IP", makeNode("192.168.1.10/24", "2001:db8:85a3:8d3:1319:8a2e:370:7348/32"), []EnvItem{{"IP", "192.168.1.10/24"}, {"IP6", "2001:db8:85a3:8d3:1319:8a2e:370:7348/32"}}, false),
Entry("Test with \"IP6\" env var set to IP and BGP spec populated with different IP", makeNode("192.168.1.10/24", "2001:db8:85a3:8d3:1319:8a2e:370:7348/32"), []EnvItem{{"IP", "192.168.1.10/24"}, {"IP6", "2001:db8:85a3:8d3:1319:8a2e:370:7349/32"}}, true),
)
})

0 comments on commit e8ed9aa

Please sign in to comment.