Skip to content

Commit 99a8569

Browse files
tamilmani1989rbtrJungukChovakalapamatmerr
authored
cni/network unit test coverage (#1020)
* adding uts * feat: update cns client (#992) * fix debug commands Signed-off-by: Evan Baker <[email protected]> * fix: update cns client Signed-off-by: Evan Baker <[email protected]> * add ctx to debug calls Signed-off-by: Evan Baker <[email protected]> * repackage cns client Signed-off-by: Evan Baker <[email protected]> * add ctx to all methods and preinit all route urls Signed-off-by: Evan Baker <[email protected]> * down-scope cns client interface and move to consumer packages Signed-off-by: Evan Baker <[email protected]> * no unkeyed struct literals Signed-off-by: Evan Baker <[email protected]> * trace updated client method signatures out through windows paths * delint Signed-off-by: Evan Baker <[email protected]> * fix windows build Signed-off-by: Evan Baker <[email protected]> * delint Signed-off-by: Evan Baker <[email protected]> * Remove dead codes from telemetry package (#1004) * Netlink package interfacing and adding a fake (#996) * Initial pass at Netlink interface * changing some netlink and epc * Resolcing all dependencies on netlink package * first pass at adding a netlinkinterface * windows working now * feat: update cns client (#992) * fix debug commands Signed-off-by: Evan Baker <[email protected]> * fix: update cns client Signed-off-by: Evan Baker <[email protected]> * add ctx to debug calls Signed-off-by: Evan Baker <[email protected]> * repackage cns client Signed-off-by: Evan Baker <[email protected]> * add ctx to all methods and preinit all route urls Signed-off-by: Evan Baker <[email protected]> * down-scope cns client interface and move to consumer packages Signed-off-by: Evan Baker <[email protected]> * no unkeyed struct literals Signed-off-by: Evan Baker <[email protected]> * trace updated client method signatures out through windows paths * delint Signed-off-by: Evan Baker <[email protected]> * fix windows build Signed-off-by: Evan Baker <[email protected]> * delint Signed-off-by: Evan Baker <[email protected]> * windows working now * Some golints checks * commenting a flaky NPM UT and adding some golint checks * renaming fakenetlink to mocknetlink * removing a mock netlink usage * fixing more golints and a test fix * fixing more go lints * Adding in netlink from higher level as input * adding netlinkinterface to windows endpoint impl * removing netlink name confusion Co-authored-by: Evan Baker <[email protected]> * test: add tests for CNI Azure invoker (#1010) * include add tests * test delete * gci * chore: Refactor UTs in telemetry packages (#1011) * Refactor UTs to cleanup UTs and increase UT coverages * User assert for consistency * Applied comments and resolve lint error * Delete unnecessary license header * Add UT coverage ovs_network_client (#1008) * Added ovsctl mock * Changed iptables and ovsctl to use interface instead of concrete classes * Added tests for ovs_networkclient_linux.go * Fix linter issues Co-authored-by: Shriroop <[email protected]> * unitest for add, delete, get added test for handling second add call in windows added linux and windows specific tests added multitenancy, baremetal tests fixed linter errors * fix linter issue * fix nns test added comment linter fixes and dependency injection from top * adding back removed file fixed merge issues * linter fixes Co-authored-by: Evan Baker <[email protected]> Co-authored-by: JungukCho <[email protected]> Co-authored-by: Vamsi Kalapala <[email protected]> Co-authored-by: Mathew Merrick <[email protected]> Co-authored-by: Shriroop Joshi <[email protected]> Co-authored-by: Shriroop <[email protected]>
1 parent 9a84716 commit 99a8569

20 files changed

+1998
-427
lines changed

cni/network/invoker_azure.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ type delegatePlugin interface {
2525
Errorf(format string, args ...interface{}) *cniTypes.Error
2626
}
2727

28-
func NewAzureIpamInvoker(plugin *netPlugin, nwInfo *network.NetworkInfo) *AzureIPAMInvoker {
28+
func NewAzureIpamInvoker(plugin *NetPlugin, nwInfo *network.NetworkInfo) *AzureIPAMInvoker {
2929
return &AzureIPAMInvoker{
3030
plugin: plugin,
3131
nwInfo: nwInfo,

cni/network/invoker_mock.go

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
package network
2+
3+
import (
4+
"errors"
5+
"net"
6+
7+
"github.com/Azure/azure-container-networking/cni"
8+
"github.com/containernetworking/cni/pkg/skel"
9+
"github.com/containernetworking/cni/pkg/types/current"
10+
)
11+
12+
const (
13+
subnetBits = 24
14+
ipv4Bits = 32
15+
subnetv6Bits = 64
16+
ipv6Bits = 128
17+
)
18+
19+
var (
20+
errV4 = errors.New("v4 fail")
21+
errV6 = errors.New("v6 Fail")
22+
errDeleteIpam = errors.New("delete fail")
23+
)
24+
25+
type MockIpamInvoker struct {
26+
isIPv6 bool
27+
v4Fail bool
28+
v6Fail bool
29+
ipMap map[string]bool
30+
}
31+
32+
func NewMockIpamInvoker(ipv6, v4Fail, v6Fail bool) *MockIpamInvoker {
33+
return &MockIpamInvoker{
34+
isIPv6: ipv6,
35+
v4Fail: v4Fail,
36+
v6Fail: v6Fail,
37+
ipMap: make(map[string]bool),
38+
}
39+
}
40+
41+
func (invoker *MockIpamInvoker) Add(nwCfg *cni.NetworkConfig, _ *skel.CmdArgs, subnetPrefix *net.IPNet, options map[string]interface{}) (v4, v6 *current.Result, err error) {
42+
var resultV6 *current.Result
43+
44+
if invoker.v4Fail {
45+
return nil, nil, errV4
46+
}
47+
48+
result := &current.Result{}
49+
50+
ipv4Str := "10.240.0.5"
51+
if _, ok := invoker.ipMap["10.240.0.5/24"]; ok {
52+
ipv4Str = "10.240.0.6"
53+
}
54+
55+
ip := net.ParseIP(ipv4Str)
56+
ipnet := net.IPNet{IP: ip, Mask: net.CIDRMask(subnetBits, ipv4Bits)}
57+
gwIP := net.ParseIP("10.240.0.1")
58+
ipConfig := &current.IPConfig{Address: ipnet, Gateway: gwIP, Version: "4"}
59+
result.IPs = append(result.IPs, ipConfig)
60+
invoker.ipMap[ipnet.String()] = true
61+
if invoker.v6Fail {
62+
return result, nil, errV6
63+
}
64+
65+
if invoker.isIPv6 {
66+
resultV6 = &current.Result{}
67+
ipv6Str := "fc00::2"
68+
if _, ok := invoker.ipMap["fc00::2/128"]; ok {
69+
ipv6Str = "fc00::3"
70+
}
71+
72+
ip := net.ParseIP(ipv6Str)
73+
ipnet := net.IPNet{IP: ip, Mask: net.CIDRMask(subnetv6Bits, ipv6Bits)}
74+
gwIP := net.ParseIP("fc00::1")
75+
ipConfig := &current.IPConfig{Address: ipnet, Gateway: gwIP, Version: "6"}
76+
resultV6.IPs = append(resultV6.IPs, ipConfig)
77+
invoker.ipMap[ipnet.String()] = true
78+
}
79+
80+
return result, resultV6, nil
81+
}
82+
83+
func (invoker *MockIpamInvoker) Delete(address *net.IPNet, nwCfg *cni.NetworkConfig, _ *skel.CmdArgs, options map[string]interface{}) error {
84+
if invoker.v4Fail || invoker.v6Fail {
85+
return errDeleteIpam
86+
}
87+
88+
if address == nil {
89+
return errDeleteIpam
90+
}
91+
92+
if _, ok := invoker.ipMap[address.String()]; !ok {
93+
return errDeleteIpam
94+
}
95+
delete(invoker.ipMap, address.String())
96+
return nil
97+
}

0 commit comments

Comments
 (0)