azure-container-networking/network/mock_namespace.go

61 строка
1.4 KiB
Go
Исходник Обычный вид История

feat: cni refactor for swift v2 (#2330) * feat: update contracts to support swift 2 * add comments * rename AddressType to NICType * update contract names and comments * address comments * feat: update invokers to support swift 2 * address comments * address comments * refactor cns invoker per comments * update invokers based on contract change * update test * update with contract changes * fix linter errs * fix naming * fix linter * fix linter * address comments * update tests * add tests * address nit comments * add comments * address comments * fix casing * address comments * feat: update invokers to support swift 2 * address comments * feat: update invokers to support swift 2 * feat: update invokers to support swift 2 * feat: update endpoint clients for swift 2 * address comments * fix lint errs * update endpoint clients based on contract changes * update tests * only skip adding default route * modify AddEndpoints per comments * address comments * update deleteendpoint * enter ns before moving interface back to vm ns * update delete endpoint test * add namespace interface for testing * fix lint * fix lint * add comment * add extra delete endpoint test * update test * feat: update invokers to support swift 2 * address comments * address comments * feat: refactor endpoint create/delete flow for swift 2 * address comments * address comments * address linter * update based on contract changes * update with contract changes * add more tests and address comments * modify AddEndpoints per comments * update test for invoker add and endpoint client add failure * address comments * fix lint * update windows tests * update refactor with namespace interface * fix lint * rebasing fixes * address comments --------- Co-authored-by: Jaeryn <tsch@microsoft.com>
2023-11-01 22:50:35 +03:00
// Copyright 2017 Microsoft. All rights reserved.
// MIT License
package network
import "github.com/pkg/errors"
var errMockEnterNamespaceFailure = errors.New("failed to enter namespace")
const failToEnterNamespaceName = "failns"
type MockNamespace struct {
namespace string
}
type MockNamespaceClient struct{}
func NewMockNamespaceClient() *MockNamespaceClient {
return &MockNamespaceClient{}
}
// OpenNamespace creates a new namespace object for the given netns path.
func (c *MockNamespaceClient) OpenNamespace(ns string) (NamespaceInterface, error) {
if ns == "" {
return nil, errFileNotExist
}
return &MockNamespace{namespace: ns}, nil
}
// GetCurrentThreadNamespace returns the caller thread's current namespace.
func (c *MockNamespaceClient) GetCurrentThreadNamespace() (NamespaceInterface, error) {
return c.OpenNamespace("")
}
// Close releases the resources associated with the namespace object.
func (ns *MockNamespace) Close() error {
return nil
}
// GetFd returns the file descriptor of the namespace.
func (ns *MockNamespace) GetFd() uintptr {
return 1
}
func (ns *MockNamespace) GetName() string {
return ns.namespace
}
// Enter puts the caller thread inside the namespace.
func (ns *MockNamespace) Enter() error {
if ns.namespace == failToEnterNamespaceName {
return errMockEnterNamespaceFailure
}
return nil
}
// Exit puts the caller thread to its previous namespace.
func (ns *MockNamespace) Exit() error {
return nil
}