Skip to content
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
22 changes: 22 additions & 0 deletions common/ioshim_linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package common

import (
testutils "github.com/Azure/azure-container-networking/test/utils"
utilexec "k8s.io/utils/exec"
)

type IOShim struct {
Exec utilexec.Interface
}

func NewIOShim() *IOShim {
return &IOShim{
Exec: utilexec.New(),
}
}

func NewMockIOShim(calls []testutils.TestCmd) *IOShim {
return &IOShim{
Exec: testutils.GetFakeExecWithScripts(calls),
}
}
26 changes: 26 additions & 0 deletions common/ioshim_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package common

import (
"github.com/Azure/azure-container-networking/network/hnswrapper"
testutils "github.com/Azure/azure-container-networking/test/utils"
utilexec "k8s.io/utils/exec"
)

type IOShim struct {
Exec utilexec.Interface
Hns hnswrapper.HnsV2WrapperInterface
}

func NewIOShim() *IOShim {
return &IOShim{
Exec: utilexec.New(),
Hns: &hnswrapper.Hnsv2wrapper{},
}
}

func NewMockIOShim(calls []testutils.TestCmd) *IOShim {
return &IOShim{
Exec: testutils.GetFakeExecWithScripts(calls),
Hns: &hnswrapper.Hnsv2wrapperFake{},
}
}
32 changes: 26 additions & 6 deletions network/hnswrapper/hnsv2wrapper.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2017 Microsoft. All rights reserved.
// MIT License

//go:build windows
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add the _windows suffix to this filename?

// +build windows

package hnswrapper
Expand All @@ -10,25 +11,32 @@ import (
)

type Hnsv2wrapper struct {

}

func (Hnsv2wrapper) CreateEndpoint(endpoint *hcn.HostComputeEndpoint) (*hcn.HostComputeEndpoint, error) {
func (Hnsv2wrapper) CreateEndpoint(endpoint *hcn.HostComputeEndpoint) (*hcn.HostComputeEndpoint, error) {
return endpoint.Create()
}

func (Hnsv2wrapper) DeleteEndpoint(endpoint *hcn.HostComputeEndpoint) error {
func (Hnsv2wrapper) DeleteEndpoint(endpoint *hcn.HostComputeEndpoint) error {
return endpoint.Delete()
}

func (Hnsv2wrapper) CreateNetwork(network *hcn.HostComputeNetwork) (*hcn.HostComputeNetwork, error) {
func (Hnsv2wrapper) CreateNetwork(network *hcn.HostComputeNetwork) (*hcn.HostComputeNetwork, error) {
return network.Create()
}

func (Hnsv2wrapper) DeleteNetwork(network *hcn.HostComputeNetwork) error {
func (Hnsv2wrapper) DeleteNetwork(network *hcn.HostComputeNetwork) error {
return network.Delete()
}

func (Hnsv2wrapper) AddNetworkPolicy(network *hcn.HostComputeNetwork, networkPolicy hcn.PolicyNetworkRequest) error {
return network.AddPolicy(networkPolicy)
}

func (Hnsv2wrapper) RemoveNetworkPolicy(network *hcn.HostComputeNetwork, networkPolicy hcn.PolicyNetworkRequest) error {
return network.RemovePolicy(networkPolicy)
}

func (w Hnsv2wrapper) GetNamespaceByID(netNamespacePath string) (*hcn.HostComputeNamespace, error) {
return hcn.GetNamespaceByID(netNamespacePath)
}
Expand All @@ -41,10 +49,22 @@ func (w Hnsv2wrapper) RemoveNamespaceEndpoint(namespaceId string, endpointId str
return hcn.RemoveNamespaceEndpoint(namespaceId, endpointId)
}

func (w Hnsv2wrapper) GetNetworkByName(networkName string) (*hcn.HostComputeNetwork, error) {
return hcn.GetNetworkByName(networkName)
}

func (w Hnsv2wrapper) GetNetworkByID(networkId string) (*hcn.HostComputeNetwork, error) {
return hcn.GetNetworkByID(networkId)
}

func (f Hnsv2wrapper) GetEndpointByID(endpointId string) (*hcn.HostComputeEndpoint, error) {
return hcn.GetEndpointByID(endpointId)
}
}

func (f Hnsv2wrapper) ListEndpointsOfNetwork(networkId string) ([]hcn.HostComputeEndpoint, error) {
return hcn.ListEndpointsOfNetwork(networkId)
}

func (f Hnsv2wrapper) ApplyEndpointPolicy(endpoint *hcn.HostComputeEndpoint, requestType hcn.RequestType, endpointPolicy hcn.PolicyEndpointRequest) error {
return endpoint.ApplyPolicy(requestType, endpointPolicy)
}
29 changes: 25 additions & 4 deletions network/hnswrapper/hnsv2wrapperfake.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2017 Microsoft. All rights reserved.
// MIT License

//go:build windows
// +build windows

package hnswrapper
Expand All @@ -13,24 +14,36 @@ type Hnsv2wrapperFake struct {
}

func (f Hnsv2wrapperFake) CreateNetwork(network *hcn.HostComputeNetwork) (*hcn.HostComputeNetwork, error) {
return network,nil
return network, nil
}

func (f Hnsv2wrapperFake) DeleteNetwork(network *hcn.HostComputeNetwork) error {
return nil
}

func (Hnsv2wrapperFake) AddNetworkPolicy(network *hcn.HostComputeNetwork, networkPolicy hcn.PolicyNetworkRequest) error {
return nil
}

func (Hnsv2wrapperFake) RemoveNetworkPolicy(network *hcn.HostComputeNetwork, networkPolicy hcn.PolicyNetworkRequest) error {
return nil
}

func (Hnsv2wrapperFake) GetNetworkByName(networkName string) (*hcn.HostComputeNetwork, error) {
return &hcn.HostComputeNetwork{}, nil
}

func (f Hnsv2wrapperFake) GetNetworkByID(networkId string) (*hcn.HostComputeNetwork, error) {
network := &hcn.HostComputeNetwork{Id: "c84257e3-3d60-40c4-8c47-d740a1c260d3"}
return network,nil
return network, nil
}

func (f Hnsv2wrapperFake) GetEndpointByID(endpointId string) (*hcn.HostComputeEndpoint, error) {
endpoint := &hcn.HostComputeEndpoint{Id: "7a2ae98a-0c84-4b35-9684-1c02a2bf7e03"}
return endpoint,nil
return endpoint, nil
}

func (Hnsv2wrapperFake) CreateEndpoint(endpoint *hcn.HostComputeEndpoint) (*hcn.HostComputeEndpoint, error) {
func (Hnsv2wrapperFake) CreateEndpoint(endpoint *hcn.HostComputeEndpoint) (*hcn.HostComputeEndpoint, error) {
return endpoint, nil
}

Expand All @@ -50,3 +63,11 @@ func (Hnsv2wrapperFake) AddNamespaceEndpoint(namespaceId string, endpointId stri
func (Hnsv2wrapperFake) RemoveNamespaceEndpoint(namespaceId string, endpointId string) error {
return nil
}

func (Hnsv2wrapperFake) ListEndpointsOfNetwork(networkId string) ([]hcn.HostComputeEndpoint, error) {
return []hcn.HostComputeEndpoint{}, nil
}

func (Hnsv2wrapperFake) ApplyEndpointPolicy(endpoint *hcn.HostComputeEndpoint, requestType hcn.RequestType, endpointPolicy hcn.PolicyEndpointRequest) error {
return nil
}
10 changes: 8 additions & 2 deletions network/hnswrapper/hnsv2wrapperinterface.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2017 Microsoft. All rights reserved.
// MIT License

//go:build windows
// +build windows

package hnswrapper
Expand All @@ -11,10 +12,15 @@ type HnsV2WrapperInterface interface {
CreateEndpoint(endpoint *hcn.HostComputeEndpoint) (*hcn.HostComputeEndpoint, error)
DeleteEndpoint(endpoint *hcn.HostComputeEndpoint) error
CreateNetwork(network *hcn.HostComputeNetwork) (*hcn.HostComputeNetwork, error)
DeleteNetwork(network *hcn.HostComputeNetwork) error
DeleteNetwork(network *hcn.HostComputeNetwork) error
AddNetworkPolicy(network *hcn.HostComputeNetwork, networkPolicy hcn.PolicyNetworkRequest) error
RemoveNetworkPolicy(network *hcn.HostComputeNetwork, networkPolicy hcn.PolicyNetworkRequest) error
GetNamespaceByID(netNamespacePath string) (*hcn.HostComputeNamespace, error)
AddNamespaceEndpoint(namespaceId string, endpointId string) error
RemoveNamespaceEndpoint(namespaceId string, endpointId string) error
GetNetworkByName(networkName string) (*hcn.HostComputeNetwork, error)
GetNetworkByID(networkId string) (*hcn.HostComputeNetwork, error)
GetEndpointByID(endpointId string) (*hcn.HostComputeEndpoint, error)
}
ListEndpointsOfNetwork(networkId string) ([]hcn.HostComputeEndpoint, error)
ApplyEndpointPolicy(endpoint *hcn.HostComputeEndpoint, requestType hcn.RequestType, endpointPolicy hcn.PolicyEndpointRequest) error
}
Loading