From 8bcad097c7b923e8639f2d8d1ec27d2dc8eccb24 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 23 Jul 2025 08:56:44 +0000 Subject: [PATCH 1/9] Initial plan From ae7ada234ff68b944be122db087dce6aab4965f2 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 23 Jul 2025 09:00:45 +0000 Subject: [PATCH 2/9] Initial analysis: Plan for HNS Loadbalancer CI pipeline enhancement Co-authored-by: mdebjit <5107473+mdebjit@users.noreply.github.com> --- go.mod | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 654f56b..9c6c301 100644 --- a/go.mod +++ b/go.mod @@ -11,6 +11,4 @@ require ( require github.com/stretchr/testify v1.9.0 // indirect -retract ( - v0.0.15 // Retract v0.0.15 because it's not a valid version -) +retract v0.0.15 // Retract v0.0.15 because it's not a valid version From 9e74019e7633fa565e2b19c5c3fde6495ad0cd54 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 23 Jul 2025 09:05:16 +0000 Subject: [PATCH 3/9] Add HNS Loadbalancer integration tests to CI pipeline Co-authored-by: mdebjit <5107473+mdebjit@users.noreply.github.com> --- .github/workflows/ci.yml | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c928f6a..8122482 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -51,8 +51,11 @@ jobs: # - name: Run golint # run: golint ./... - - name: Test - run: go test -v ./... - - # - name: Test - # run: go test -v -tags=integration ./... \ No newline at end of file + - name: Test + run: go test -v ./... + + - name: Test HNS Loadbalancer Integration + run: go test -v -tags=integration ./hcn -run="TestCreateDeleteLoadBalancer|TestGetLoadBalancerById|TestListLoadBalancer|TestAddLoadBalancer" + + - name: Test HNS Loadbalancer Advanced Features + run: go test -v -tags=integration ./hcn -run="TestAddDSRLoadBalancer|TestAddILBLoadBalancer|TestLoadBalancerAddRemoveEndpoint" \ No newline at end of file From b22417aed146706f4e67880a6cda4e8bb70184ee Mon Sep 17 00:00:00 2001 From: Prince Pereira Date: Fri, 18 Jul 2025 15:35:00 +0530 Subject: [PATCH 4/9] Introducing pipeline changes to test actual hns apis on a windows container. --- .github/workflows/integration.yml | 21 +++++++++++ Dockerfile.integration | 19 ++++++++++ hcn/hcnnetwork_integration_test.go | 60 ++++++++++++++++++++++++++++++ 3 files changed, 100 insertions(+) create mode 100644 .github/workflows/integration.yml create mode 100644 Dockerfile.integration create mode 100644 hcn/hcnnetwork_integration_test.go diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml new file mode 100644 index 0000000..4374979 --- /dev/null +++ b/.github/workflows/integration.yml @@ -0,0 +1,21 @@ +name: Windows HNS Integration Tests + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + integration: + runs-on: windows-2022 + steps: + - uses: actions/checkout@v4 + + - name: Build Windows container image + run: | + docker build -f Dockerfile.integration -t hnslib-integration . + + - name: Run integration tests in Windows container + run: | + docker run --isolation=hyperv --rm hnslib-integration diff --git a/Dockerfile.integration b/Dockerfile.integration new file mode 100644 index 0000000..65b7aa7 --- /dev/null +++ b/Dockerfile.integration @@ -0,0 +1,19 @@ +# escape=` +FROM mcr.microsoft.com/windows/servercore:ltsc2022 + +WORKDIR /app +COPY . . + +# Set up Go (if not already present in your base image) + +ADD https://golang.org/dl/go1.22.0.windows-amd64.zip C:\go.zip +RUN powershell -Command ` + "Expand-Archive -Path 'C:\\go.zip' -DestinationPath 'C:\\golang'; Remove-Item -Path 'C:\\go.zip'" + +ENV PATH=C:\golang\go\bin;%PATH% + +# Use full path to go.exe for build steps +RUN C:\golang\go\bin\go.exe version +RUN C:\golang\go\bin\go.exe test -c -tags=integration -o integration.test ./hcn + +CMD ["integration.test", "-test.v"] diff --git a/hcn/hcnnetwork_integration_test.go b/hcn/hcnnetwork_integration_test.go new file mode 100644 index 0000000..2f92416 --- /dev/null +++ b/hcn/hcnnetwork_integration_test.go @@ -0,0 +1,60 @@ +//go:build windows && integration +// +build windows,integration + +package hcn + +import ( + "testing" + "time" +) + +func TestIntegration_CreateAndDeleteNetwork(t *testing.T) { + networkName := "integration-test-network" + network := &HostComputeNetwork{ + Type: NAT, + Name: networkName, + Ipams: []Ipam{{ + Type: "Static", + Subnets: []Subnet{{ + IpAddressPrefix: "192.168.250.0/24", + Routes: []Route{{ + NextHop: "192.168.250.1", + DestinationPrefix: "0.0.0.0/0", + }}, + }}, + }}, + SchemaVersion: SchemaVersion{Major: 2, Minor: 0}, + } + + // Create network + created, err := network.Create() + if err != nil { + t.Fatalf("Failed to create network: %v", err) + } + if created == nil { + t.Fatal("Create() returned nil network") + } + + // Verify network exists + found, err := GetNetworkByID(created.Id) + if err != nil { + t.Fatalf("Failed to get network by ID: %v", err) + } + if found == nil || found.Name != networkName { + t.Fatalf("Network not found after creation") + } + + // Delete network + if err := created.Delete(); err != nil { + t.Fatalf("Failed to delete network: %v", err) + } + + // Give HNS a moment to update + time.Sleep(2 * time.Second) + + // Verify network is gone + _, err = GetNetworkByID(created.Id) + if err == nil { + t.Fatalf("Network still exists after deletion") + } +} From 24066d9435d157f35d161a410b6e56a800c826ee Mon Sep 17 00:00:00 2001 From: Prince Pereira Date: Mon, 21 Jul 2025 18:47:22 +0530 Subject: [PATCH 5/9] Running the test on vm. --- .github/workflows/integration.yml | 11 ++++++----- Dockerfile.integration | 19 ------------------- hcn/hcnloadbalancer_test.go | 6 ++++-- hcn/hcnnetwork_integration_test.go | 12 ++++++++++++ 4 files changed, 22 insertions(+), 26 deletions(-) delete mode 100644 Dockerfile.integration diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index 4374979..1129b27 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -12,10 +12,11 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Build Windows container image - run: | - docker build -f Dockerfile.integration -t hnslib-integration . + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: '1.22' - - name: Run integration tests in Windows container + - name: Run integration tests run: | - docker run --isolation=hyperv --rm hnslib-integration + go test -v -tags=integration ./hcn diff --git a/Dockerfile.integration b/Dockerfile.integration deleted file mode 100644 index 65b7aa7..0000000 --- a/Dockerfile.integration +++ /dev/null @@ -1,19 +0,0 @@ -# escape=` -FROM mcr.microsoft.com/windows/servercore:ltsc2022 - -WORKDIR /app -COPY . . - -# Set up Go (if not already present in your base image) - -ADD https://golang.org/dl/go1.22.0.windows-amd64.zip C:\go.zip -RUN powershell -Command ` - "Expand-Archive -Path 'C:\\go.zip' -DestinationPath 'C:\\golang'; Remove-Item -Path 'C:\\go.zip'" - -ENV PATH=C:\golang\go\bin;%PATH% - -# Use full path to go.exe for build steps -RUN C:\golang\go\bin\go.exe version -RUN C:\golang\go\bin\go.exe test -c -tags=integration -o integration.test ./hcn - -CMD ["integration.test", "-test.v"] diff --git a/hcn/hcnloadbalancer_test.go b/hcn/hcnloadbalancer_test.go index 432b2cf..b6dbe20 100644 --- a/hcn/hcnloadbalancer_test.go +++ b/hcn/hcnloadbalancer_test.go @@ -1,5 +1,7 @@ -//go:build windows && integration -// +build windows,integration +//go:build windows && integration_loadbalancer +// +build windows,integration_loadbalancer + +// TODO: https://github.com/microsoft/hnslib/issues/19 package hcn diff --git a/hcn/hcnnetwork_integration_test.go b/hcn/hcnnetwork_integration_test.go index 2f92416..3bec4b4 100644 --- a/hcn/hcnnetwork_integration_test.go +++ b/hcn/hcnnetwork_integration_test.go @@ -8,7 +8,19 @@ import ( "time" ) +func cleanNetworks() { + // This function can be used to clean up any networks created during tests. + networks, err := ListNetworks() + if err != nil { + return + } + for _, network := range networks { + network.Delete() + } +} + func TestIntegration_CreateAndDeleteNetwork(t *testing.T) { + cleanNetworks() networkName := "integration-test-network" network := &HostComputeNetwork{ Type: NAT, From 311d4442459a4ad53cff4bf516e5e5107207bbc3 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 23 Jul 2025 08:56:44 +0000 Subject: [PATCH 6/9] Initial plan From f54401c97f40497e0f297ee108fed95b4718a991 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 23 Jul 2025 08:56:44 +0000 Subject: [PATCH 7/9] Initial plan From b7a4e81fa21bec9da88639849c2a344404a07d06 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 23 Jul 2025 08:56:44 +0000 Subject: [PATCH 8/9] Initial plan From 571e10eeee8ca46d7035971812238d62afec033e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 24 Jul 2025 05:59:03 +0000 Subject: [PATCH 9/9] Replace integration_loadbalancer build tag with integration for loadbalancer tests Co-authored-by: princepereira <6368227+princepereira@users.noreply.github.com> --- hcn/hcnloadbalancer_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hcn/hcnloadbalancer_test.go b/hcn/hcnloadbalancer_test.go index b6dbe20..0c6fc5d 100644 --- a/hcn/hcnloadbalancer_test.go +++ b/hcn/hcnloadbalancer_test.go @@ -1,5 +1,5 @@ -//go:build windows && integration_loadbalancer -// +build windows,integration_loadbalancer +//go:build windows && integration +// +build windows,integration // TODO: https://github.com/microsoft/hnslib/issues/19