Skip to content

Commit e43adc3

Browse files
authored
backport: ci: run some cni windows uts in the pipeline (#2925) (#2962)
* ci: run some cni windows uts in the pipeline (#2925) * make windows uts pass * separate multitenancy uts for windows into platform specific file * move ut testing to separate template * address linter issue * run windows platform tests * revert removing test create bridge * remove parameter from ut template * remove cns tests unrelated to backport * cherry pick files to mock if hns v2 is supported * modify multitenancy cni tests to reflect 1.5.x behavior - updates mock network manager to use the network id passed in - updates mock network manager to get all endpoint infos based on a network id - updates mock network manager find network id from net ns to reflect dualnic get network id behavior (gets multiple networks because on deletion, you have one less endpoint that matches the netns/netnspath, and so use the network id of the other endpoint for deletion) - updates windows tests to use eth1 to avoid mock endpoint client from throwing a duplicate endpoint id error - separates windows and linux multitenancy tests because their behavior is different - updates windows unit tests to allow passing in an expected num of endpoints for EACH network id after EACH command is run during delete test * remove test not relevant to 1.5.x and clean up logic
1 parent c07a4a2 commit e43adc3

File tree

12 files changed

+468
-376
lines changed

12 files changed

+468
-376
lines changed

.pipelines/pipeline.yaml

Lines changed: 2 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -49,98 +49,10 @@ stages:
4949
name: "EnvironmentalVariables"
5050
displayName: "Set environmental variables"
5151
condition: always()
52-
- ${{ if contains(variables['Build.SourceBranch'], 'refs/pull') }}:
53-
- stage: test
54-
displayName: Test ACN
55-
dependsOn:
56-
- setup
57-
jobs:
58-
- job: test
59-
displayName: Run Tests
60-
variables:
61-
STORAGE_ID: $[ stagedependencies.setup.env.outputs['EnvironmentalVariables.StorageID'] ]
62-
pool:
63-
name: "$(BUILD_POOL_NAME_DEFAULT)"
64-
steps:
65-
- script: |
66-
make tools
67-
# run test, echo exit status code to fd 3, pipe output from test to tee, which splits output to stdout and go-junit-report (which converts test output to report.xml), stdout from tee is redirected to fd 4. Take output written to fd 3 (which is the exit code of test), redirect to stdout, pipe to read from stdout then exit with that status code. Read all output from fd 4 (output from tee) and write to top stdout
68-
{ { { {
69-
sudo -E env "PATH=$PATH" make test-all;
70-
echo $? >&3;
71-
} | tee >(build/tools/bin/go-junit-report > report.xml) >&4;
72-
} 3>&1;
73-
} | { read xs; exit $xs; }
74-
} 4>&1
75-
retryCountOnTaskFailure: 3
76-
name: "Test"
77-
displayName: "Run Tests"
78-
79-
- stage: test_windows
80-
displayName: Test ACN Windows
81-
dependsOn:
82-
- setup
83-
jobs:
84-
- job: test
85-
displayName: Run Tests
86-
variables:
87-
STORAGE_ID: $[ stagedependencies.setup.env.outputs['EnvironmentalVariables.StorageID'] ]
88-
pool:
89-
name: "$(BUILD_POOL_NAME_DEFAULT_WINDOWS_ALT)"
90-
steps:
91-
- script: |
92-
cd npm/
93-
go test ./...
94-
retryCountOnTaskFailure: 3
95-
name: "TestWindows"
96-
displayName: "Run Windows Tests"
9752
98-
- ${{ else }}:
99-
- stage: test
100-
displayName: Test ACN
101-
dependsOn:
102-
- setup
103-
jobs:
104-
- job: test
105-
displayName: Run Tests
106-
variables:
107-
STORAGE_ID: $[ stagedependencies.setup.env.outputs['EnvironmentalVariables.StorageID'] ]
108-
pool:
109-
name: "$(BUILD_POOL_NAME_DEFAULT)"
110-
steps:
111-
- script: |
112-
make tools
113-
# run test, echo exit status code to fd 3, pipe output from test to tee, which splits output to stdout and go-junit-report (which converts test output to report.xml), stdout from tee is redirected to fd 4. Take output written to fd 3 (which is the exit code of test), redirect to stdout, pipe to read from stdout then exit with that status code. Read all output from fd 4 (output from tee) and write to top stdout
114-
{ { { {
115-
sudo -E env "PATH=$PATH" make test-all;
116-
echo $? >&3;
117-
} | tee >(build/tools/bin/go-junit-report > report.xml) >&4;
118-
} 3>&1;
119-
} | { read xs; exit $xs; }
120-
} 4>&1
121-
retryCountOnTaskFailure: 3
122-
name: "Test"
123-
displayName: "Run Tests"
124-
125-
- stage: test_windows
126-
displayName: Test ACN Windows
127-
dependsOn:
128-
- setup
129-
jobs:
130-
- job: test
131-
displayName: Run Tests
132-
variables:
133-
STORAGE_ID: $[ stagedependencies.setup.env.outputs['EnvironmentalVariables.StorageID'] ]
134-
pool:
135-
name: "$(BUILD_POOL_NAME_DEFAULT_WINDOWS_ALT)"
136-
steps:
137-
- script: |
138-
cd npm/
139-
go test ./...
140-
retryCountOnTaskFailure: 3
141-
name: "TestWindows"
142-
displayName: "Run Windows Tests"
53+
- template: templates/run-unit-tests.yaml
14354

55+
- ${{ if not(contains(variables['Build.SourceBranch'], 'refs/pull')) }}:
14456
- stage: binaries
14557
displayName: Build Binaries
14658
dependsOn:
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
stages:
2+
- stage: test
3+
displayName: Test ACN
4+
dependsOn:
5+
- setup
6+
jobs:
7+
- job: test
8+
displayName: Run Tests
9+
variables:
10+
STORAGE_ID: $[ stagedependencies.setup.env.outputs['EnvironmentalVariables.StorageID'] ]
11+
pool:
12+
name: "$(BUILD_POOL_NAME_DEFAULT)"
13+
steps:
14+
- script: |
15+
make tools
16+
# run test, echo exit status code to fd 3, pipe output from test to tee, which splits output to stdout and go-junit-report (which converts test output to report.xml), stdout from tee is redirected to fd 4. Take output written to fd 3 (which is the exit code of test), redirect to stdout, pipe to read from stdout then exit with that status code. Read all output from fd 4 (output from tee) and write to top stdout
17+
{ { { {
18+
sudo -E env "PATH=$PATH" make test-all;
19+
echo $? >&3;
20+
} | tee >(build/tools/bin/go-junit-report > report.xml) >&4;
21+
} 3>&1;
22+
} | { read xs; exit $xs; }
23+
} 4>&1
24+
retryCountOnTaskFailure: 3
25+
name: "Test"
26+
displayName: "Run Tests"
27+
28+
- stage: test_windows
29+
displayName: Test ACN Windows
30+
dependsOn:
31+
- setup
32+
jobs:
33+
- job: test
34+
displayName: Run Tests
35+
variables:
36+
STORAGE_ID: $[ stagedependencies.setup.env.outputs['EnvironmentalVariables.StorageID'] ]
37+
pool:
38+
name: "$(BUILD_POOL_NAME_DEFAULT_WINDOWS_ALT)"
39+
steps:
40+
- script: |
41+
cd npm/
42+
go test ./...
43+
cd ../cni/
44+
go test ./...
45+
cd ../platform/
46+
go test ./...
47+
retryCountOnTaskFailure: 3
48+
name: "TestWindows"
49+
displayName: "Run Windows Tests"

cni/network/multitenancy_mock.go

Lines changed: 11 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"errors"
66
"net"
7-
"runtime"
87

98
"github.com/Azure/azure-container-networking/cni"
109
"github.com/Azure/azure-container-networking/cns"
@@ -13,7 +12,8 @@ import (
1312
)
1413

1514
type MockMultitenancy struct {
16-
fail bool
15+
fail bool
16+
cnsResponses []*cns.GetNetworkContainerResponse
1717
}
1818

1919
const (
@@ -25,9 +25,10 @@ const (
2525

2626
var errMockMulAdd = errors.New("multitenancy fail")
2727

28-
func NewMockMultitenancy(fail bool) *MockMultitenancy {
28+
func NewMockMultitenancy(fail bool, cnsResponses []*cns.GetNetworkContainerResponse) *MockMultitenancy {
2929
return &MockMultitenancy{
30-
fail: fail,
30+
fail: fail,
31+
cnsResponses: cnsResponses,
3132
}
3233
}
3334

@@ -55,31 +56,9 @@ func (m *MockMultitenancy) GetNetworkContainer(
5556
return nil, net.IPNet{}, errMockMulAdd
5657
}
5758

58-
cnsResponse := &cns.GetNetworkContainerResponse{
59-
IPConfiguration: cns.IPConfiguration{
60-
IPSubnet: cns.IPSubnet{
61-
IPAddress: "192.168.0.4",
62-
PrefixLength: ipPrefixLen,
63-
},
64-
GatewayIPAddress: "192.168.0.1",
65-
},
66-
LocalIPConfiguration: cns.IPConfiguration{
67-
IPSubnet: cns.IPSubnet{
68-
IPAddress: "169.254.0.4",
69-
PrefixLength: localIPPrefixLen,
70-
},
71-
GatewayIPAddress: "169.254.0.1",
72-
},
73-
74-
PrimaryInterfaceIdentifier: "10.240.0.4/24",
75-
MultiTenancyInfo: cns.MultiTenancyInfo{
76-
EncapType: cns.Vlan,
77-
ID: 1,
78-
},
79-
}
80-
_, ipnet, _ := net.ParseCIDR(cnsResponse.PrimaryInterfaceIdentifier)
59+
_, ipnet, _ := net.ParseCIDR(m.cnsResponses[0].PrimaryInterfaceIdentifier)
8160

82-
return cnsResponse, *ipnet, nil
61+
return m.cnsResponses[0], *ipnet, nil
8362
}
8463

8564
func (m *MockMultitenancy) GetAllNetworkContainers(
@@ -96,64 +75,13 @@ func (m *MockMultitenancy) GetAllNetworkContainers(
9675
var cnsResponses []cns.GetNetworkContainerResponse
9776
var ipNets []net.IPNet
9877

99-
cnsResponseOne := &cns.GetNetworkContainerResponse{
100-
IPConfiguration: cns.IPConfiguration{
101-
IPSubnet: cns.IPSubnet{
102-
IPAddress: "20.0.0.10",
103-
PrefixLength: ipPrefixLen,
104-
},
105-
GatewayIPAddress: "20.0.0.1",
106-
},
107-
LocalIPConfiguration: cns.IPConfiguration{
108-
IPSubnet: cns.IPSubnet{
109-
IPAddress: "168.254.0.4",
110-
PrefixLength: localIPPrefixLen,
111-
},
112-
GatewayIPAddress: "168.254.0.1",
113-
},
114-
115-
PrimaryInterfaceIdentifier: "20.240.0.4/24",
116-
MultiTenancyInfo: cns.MultiTenancyInfo{
117-
EncapType: cns.Vlan,
118-
ID: multiTenancyVlan1,
119-
},
120-
}
78+
for _, cnsResp := range m.cnsResponses {
79+
_, ipNet, _ := net.ParseCIDR(cnsResp.PrimaryInterfaceIdentifier)
12180

122-
// TODO: add dual nic test cases for windows
123-
if runtime.GOOS == "windows" {
124-
cnsResponseTwo := &cns.GetNetworkContainerResponse{
125-
IPConfiguration: cns.IPConfiguration{
126-
IPSubnet: cns.IPSubnet{
127-
IPAddress: "10.0.0.10",
128-
PrefixLength: ipPrefixLen,
129-
},
130-
GatewayIPAddress: "10.0.0.1",
131-
},
132-
LocalIPConfiguration: cns.IPConfiguration{
133-
IPSubnet: cns.IPSubnet{
134-
IPAddress: "169.254.0.4",
135-
PrefixLength: localIPPrefixLen,
136-
},
137-
GatewayIPAddress: "169.254.0.1",
138-
},
139-
140-
PrimaryInterfaceIdentifier: "10.240.0.4/24",
141-
MultiTenancyInfo: cns.MultiTenancyInfo{
142-
EncapType: cns.Vlan,
143-
ID: multiTenancyVlan2,
144-
},
145-
}
146-
147-
_, secondIPnet, _ := net.ParseCIDR(cnsResponseTwo.PrimaryInterfaceIdentifier)
148-
ipNets = append(ipNets, *secondIPnet)
149-
cnsResponses = append(cnsResponses, *cnsResponseTwo)
81+
ipNets = append(ipNets, *ipNet)
82+
cnsResponses = append(cnsResponses, *cnsResp)
15083
}
15184

152-
_, firstIPnet, _ := net.ParseCIDR(cnsResponseOne.PrimaryInterfaceIdentifier)
153-
154-
ipNets = append(ipNets, *firstIPnet)
155-
cnsResponses = append(cnsResponses, *cnsResponseOne)
156-
15785
ipamResults := make([]IPAMAddResult, len(cnsResponses))
15886
for i := 0; i < len(cnsResponses); i++ {
15987
ipamResults[i].ncResponse = &cnsResponses[i]

0 commit comments

Comments
 (0)