Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backport: ci: run some cni windows uts in the pipeline (#2925) #2962

Merged
merged 5 commits into from
Aug 28, 2024
Merged
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
92 changes: 2 additions & 90 deletions .pipelines/pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,98 +49,10 @@ stages:
name: "EnvironmentalVariables"
displayName: "Set environmental variables"
condition: always()
- ${{ if contains(variables['Build.SourceBranch'], 'refs/pull') }}:
- stage: test
displayName: Test ACN
dependsOn:
- setup
jobs:
- job: test
displayName: Run Tests
variables:
STORAGE_ID: $[ stagedependencies.setup.env.outputs['EnvironmentalVariables.StorageID'] ]
pool:
name: "$(BUILD_POOL_NAME_DEFAULT)"
steps:
- script: |
make tools
# 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
{ { { {
sudo -E env "PATH=$PATH" make test-all;
echo $? >&3;
} | tee >(build/tools/bin/go-junit-report > report.xml) >&4;
} 3>&1;
} | { read xs; exit $xs; }
} 4>&1
retryCountOnTaskFailure: 3
name: "Test"
displayName: "Run Tests"

- stage: test_windows
displayName: Test ACN Windows
dependsOn:
- setup
jobs:
- job: test
displayName: Run Tests
variables:
STORAGE_ID: $[ stagedependencies.setup.env.outputs['EnvironmentalVariables.StorageID'] ]
pool:
name: "$(BUILD_POOL_NAME_DEFAULT_WINDOWS_ALT)"
steps:
- script: |
cd npm/
go test ./...
retryCountOnTaskFailure: 3
name: "TestWindows"
displayName: "Run Windows Tests"

- ${{ else }}:
- stage: test
displayName: Test ACN
dependsOn:
- setup
jobs:
- job: test
displayName: Run Tests
variables:
STORAGE_ID: $[ stagedependencies.setup.env.outputs['EnvironmentalVariables.StorageID'] ]
pool:
name: "$(BUILD_POOL_NAME_DEFAULT)"
steps:
- script: |
make tools
# 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
{ { { {
sudo -E env "PATH=$PATH" make test-all;
echo $? >&3;
} | tee >(build/tools/bin/go-junit-report > report.xml) >&4;
} 3>&1;
} | { read xs; exit $xs; }
} 4>&1
retryCountOnTaskFailure: 3
name: "Test"
displayName: "Run Tests"

- stage: test_windows
displayName: Test ACN Windows
dependsOn:
- setup
jobs:
- job: test
displayName: Run Tests
variables:
STORAGE_ID: $[ stagedependencies.setup.env.outputs['EnvironmentalVariables.StorageID'] ]
pool:
name: "$(BUILD_POOL_NAME_DEFAULT_WINDOWS_ALT)"
steps:
- script: |
cd npm/
go test ./...
retryCountOnTaskFailure: 3
name: "TestWindows"
displayName: "Run Windows Tests"
- template: templates/run-unit-tests.yaml

- ${{ if not(contains(variables['Build.SourceBranch'], 'refs/pull')) }}:
- stage: binaries
displayName: Build Binaries
dependsOn:
Expand Down
49 changes: 49 additions & 0 deletions .pipelines/templates/run-unit-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
stages:
- stage: test
displayName: Test ACN
dependsOn:
- setup
jobs:
- job: test
displayName: Run Tests
variables:
STORAGE_ID: $[ stagedependencies.setup.env.outputs['EnvironmentalVariables.StorageID'] ]
pool:
name: "$(BUILD_POOL_NAME_DEFAULT)"
steps:
- script: |
make tools
# 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
{ { { {
sudo -E env "PATH=$PATH" make test-all;
echo $? >&3;
} | tee >(build/tools/bin/go-junit-report > report.xml) >&4;
} 3>&1;
} | { read xs; exit $xs; }
} 4>&1
retryCountOnTaskFailure: 3
name: "Test"
displayName: "Run Tests"

- stage: test_windows
displayName: Test ACN Windows
dependsOn:
- setup
jobs:
- job: test
displayName: Run Tests
variables:
STORAGE_ID: $[ stagedependencies.setup.env.outputs['EnvironmentalVariables.StorageID'] ]
pool:
name: "$(BUILD_POOL_NAME_DEFAULT_WINDOWS_ALT)"
steps:
- script: |
cd npm/
go test ./...
cd ../cni/
go test ./...
cd ../platform/
go test ./...
retryCountOnTaskFailure: 3
name: "TestWindows"
displayName: "Run Windows Tests"
94 changes: 11 additions & 83 deletions cni/network/multitenancy_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"errors"
"net"
"runtime"

"github.com/Azure/azure-container-networking/cni"
"github.com/Azure/azure-container-networking/cns"
Expand All @@ -13,7 +12,8 @@ import (
)

type MockMultitenancy struct {
fail bool
fail bool
cnsResponses []*cns.GetNetworkContainerResponse
}

const (
Expand All @@ -25,9 +25,10 @@ const (

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

func NewMockMultitenancy(fail bool) *MockMultitenancy {
func NewMockMultitenancy(fail bool, cnsResponses []*cns.GetNetworkContainerResponse) *MockMultitenancy {
return &MockMultitenancy{
fail: fail,
fail: fail,
cnsResponses: cnsResponses,
}
}

Expand Down Expand Up @@ -55,31 +56,9 @@ func (m *MockMultitenancy) GetNetworkContainer(
return nil, net.IPNet{}, errMockMulAdd
}

cnsResponse := &cns.GetNetworkContainerResponse{
IPConfiguration: cns.IPConfiguration{
IPSubnet: cns.IPSubnet{
IPAddress: "192.168.0.4",
PrefixLength: ipPrefixLen,
},
GatewayIPAddress: "192.168.0.1",
},
LocalIPConfiguration: cns.IPConfiguration{
IPSubnet: cns.IPSubnet{
IPAddress: "169.254.0.4",
PrefixLength: localIPPrefixLen,
},
GatewayIPAddress: "169.254.0.1",
},

PrimaryInterfaceIdentifier: "10.240.0.4/24",
MultiTenancyInfo: cns.MultiTenancyInfo{
EncapType: cns.Vlan,
ID: 1,
},
}
_, ipnet, _ := net.ParseCIDR(cnsResponse.PrimaryInterfaceIdentifier)
_, ipnet, _ := net.ParseCIDR(m.cnsResponses[0].PrimaryInterfaceIdentifier)

return cnsResponse, *ipnet, nil
return m.cnsResponses[0], *ipnet, nil
}

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

cnsResponseOne := &cns.GetNetworkContainerResponse{
IPConfiguration: cns.IPConfiguration{
IPSubnet: cns.IPSubnet{
IPAddress: "20.0.0.10",
PrefixLength: ipPrefixLen,
},
GatewayIPAddress: "20.0.0.1",
},
LocalIPConfiguration: cns.IPConfiguration{
IPSubnet: cns.IPSubnet{
IPAddress: "168.254.0.4",
PrefixLength: localIPPrefixLen,
},
GatewayIPAddress: "168.254.0.1",
},

PrimaryInterfaceIdentifier: "20.240.0.4/24",
MultiTenancyInfo: cns.MultiTenancyInfo{
EncapType: cns.Vlan,
ID: multiTenancyVlan1,
},
}
for _, cnsResp := range m.cnsResponses {
_, ipNet, _ := net.ParseCIDR(cnsResp.PrimaryInterfaceIdentifier)

// TODO: add dual nic test cases for windows
if runtime.GOOS == "windows" {
cnsResponseTwo := &cns.GetNetworkContainerResponse{
IPConfiguration: cns.IPConfiguration{
IPSubnet: cns.IPSubnet{
IPAddress: "10.0.0.10",
PrefixLength: ipPrefixLen,
},
GatewayIPAddress: "10.0.0.1",
},
LocalIPConfiguration: cns.IPConfiguration{
IPSubnet: cns.IPSubnet{
IPAddress: "169.254.0.4",
PrefixLength: localIPPrefixLen,
},
GatewayIPAddress: "169.254.0.1",
},

PrimaryInterfaceIdentifier: "10.240.0.4/24",
MultiTenancyInfo: cns.MultiTenancyInfo{
EncapType: cns.Vlan,
ID: multiTenancyVlan2,
},
}

_, secondIPnet, _ := net.ParseCIDR(cnsResponseTwo.PrimaryInterfaceIdentifier)
ipNets = append(ipNets, *secondIPnet)
cnsResponses = append(cnsResponses, *cnsResponseTwo)
ipNets = append(ipNets, *ipNet)
cnsResponses = append(cnsResponses, *cnsResp)
}

_, firstIPnet, _ := net.ParseCIDR(cnsResponseOne.PrimaryInterfaceIdentifier)

ipNets = append(ipNets, *firstIPnet)
cnsResponses = append(cnsResponses, *cnsResponseOne)

ipamResults := make([]IPAMAddResult, len(cnsResponses))
for i := 0; i < len(cnsResponses); i++ {
ipamResults[i].ncResponse = &cnsResponses[i]
Expand Down
Loading
Loading