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

Enable remote docker tests #410

Merged
merged 1 commit into from
Nov 25, 2021
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
58 changes: 37 additions & 21 deletions internal/tests/suite_combinatronics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ package tests

import (
"context"
"io/ioutil"
"net"
"net/url"
"os"
"path/filepath"
"strings"
"testing"
"time"
Expand All @@ -38,9 +42,9 @@ import (
"github.com/networkservicemesh/api/pkg/api/networkservice/mechanisms/wireguard"
"github.com/networkservicemesh/api/pkg/api/networkservice/payload"
"github.com/networkservicemesh/api/pkg/api/registry"
"github.com/networkservicemesh/sdk/pkg/registry/core/adapters"

"github.com/networkservicemesh/api/pkg/api/networkservice"
"github.com/networkservicemesh/sdk/pkg/registry/core/adapters"
"github.com/networkservicemesh/sdk/pkg/tools/log"
"github.com/networkservicemesh/sdk/pkg/tools/log/logruslogger"
"github.com/networkservicemesh/sdk/pkg/tools/spiffejwt"
Expand Down Expand Up @@ -108,14 +112,18 @@ func (f *ForwarderTestSuite) TestCombinations() {
payload.IP: {
kernel.MECHANISM,
memif.MECHANISM,
// wireguard.MECHANISM,
wireguard.MECHANISM,
},
payload.Ethernet: {
kernel.MECHANISM,
memif.MECHANISM,
// vxlan.MECHANISM,
vxlan.MECHANISM,
},
}
isRemote := map[string]bool{
wireguard.MECHANISM: true,
vxlan.MECHANISM: true,
}
for _, pl := range []string{payload.Ethernet, payload.IP} {
payloadName := pl
f.T().Run(strings.Title(strings.ToLower(payloadName)), func(t *testing.T) {
Expand All @@ -133,21 +141,16 @@ func (f *ForwarderTestSuite) TestCombinations() {
defer cancel()
ctx = log.WithFields(ctx, map[string]interface{}{"test": t.Name()})
ctx = log.WithLog(ctx, logruslogger.New(ctx))
networkserviceName := "ns"

_, err = adapters.NetworkServiceEndpointServerToClient(f.registryServer).Register(ctx, &registry.NetworkServiceEndpoint{
Name: "nse",
NetworkServiceNames: []string{"ns"},
Url: f.config.ConnectTo.String(),
})
f.Require().NoError(err)
networkserviceName := "ns" + t.Name()

_, err = adapters.NetworkServiceServerToClient(f.registryNSServer).Register(ctx, &registry.NetworkService{
Name: "ns",
Payload: payloadName,
})
tmpDir, err := ioutil.TempDir("", "nse")
f.Require().NoError(err)
defer func(tmpDir string) { _ = os.Remove(tmpDir) }(tmpDir)
nseURL := url.URL{Scheme: "unix", Path: filepath.Join(tmpDir, "listen.on")}

if isRemote[endpointMechanism] {
nseURL = url.URL{Scheme: "tcp", Host: "127.0.0.1:0"}
}
testRequest := &networkservice.NetworkServiceRequest{
Connection: &networkservice.Connection{
NetworkService: networkserviceName,
Expand All @@ -164,11 +167,26 @@ func (f *ForwarderTestSuite) TestCombinations() {
ep := epFunc(ctx)
networkservice.RegisterNetworkServiceServer(server, ep)
networkservice.RegisterMonitorConnectionServer(server, ep)
registry.RegisterNetworkServiceEndpointRegistryServer(server, f.registryServer)
registry.RegisterNetworkServiceRegistryServer(server, f.registryNSServer)
serverErrCh := f.ListenAndServe(ctx, server)

serverErrCh := f.ListenAndServe(f.ctx, &nseURL, server)
f.Require().Len(serverErrCh, 0)
log.FromContext(ctx).Infof("Launching %s test server (took : %s)", t.Name(), time.Since(now))

_, err = adapters.NetworkServiceEndpointServerToClient(f.registryServer).Register(ctx, &registry.NetworkServiceEndpoint{
Name: "nse-" + t.Name(),
NetworkServiceNames: []string{networkserviceName},
Url: nseURL.String(),
})
f.Require().NoError(err)

_, err = adapters.NetworkServiceServerToClient(f.registryNSServer).Register(ctx, &registry.NetworkService{
Name: networkserviceName,
Payload: payloadName,
})
f.Require().NoError(err)

log.FromContext(ctx).Infof("Registered ns and nse for server %s (took : %s)", t.Name(), time.Since(now))

// ********************************************************************************
log.FromContext(f.ctx).Infof("Sending Request to forwarder (time since start: %s)", time.Since(starttime))
// ********************************************************************************
Expand Down Expand Up @@ -207,9 +225,7 @@ func (f *ForwarderTestSuite) TestCombinations() {
// ********************************************************************************
log.FromContext(f.ctx).Infof("Canceling ctx to end test (time since start: %s)", time.Since(starttime))
// ********************************************************************************
cancel()
err = <-serverErrCh
require.NoError(t, err)
require.Len(t, serverErrCh, 0)
// ********************************************************************************
log.FromContext(f.ctx).Infof("%s completed (time since start: %s)", t.Name(), time.Since(starttime))
// ********************************************************************************
Expand Down
22 changes: 18 additions & 4 deletions internal/tests/suite_kernel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"fmt"
"net"
"os"
"runtime"

"github.com/edwarnicke/exechelper"
"github.com/pkg/errors"
Expand Down Expand Up @@ -80,14 +81,21 @@ func newKernelVerifiableEndpoint(ctx context.Context,
panic(fmt.Sprintf("unable to get root netNs: %+v", err))
}
endpointNSName := fmt.Sprintf("nse-%s", randstr.Hex(4))
runtime.LockOSThread()
defer runtime.UnlockOSThread()
endpointNSHandle, err := netns.NewNamed(endpointNSName)
if err != nil {
panic(fmt.Sprintf("unable create netNs %s: %+v", endpointNSName, err))
}
go func(endpointNsName string) {
if err := netns.Set(rootNSHandle); err != nil {
panic(fmt.Sprintf("unable to set rootNs: %+v", err))
}
go func(endpointNsName string, endpointNSHandle netns.NsHandle) {
<-ctx.Done()
_ = endpointNSHandle.Close()
_ = netns.DeleteNamed(endpointNsName)
}(endpointNSName)
}(endpointNSName, endpointNSHandle)

return &kernelVerifiableEndpoint{
ctx: ctx,
endpointNSName: endpointNSName,
Expand Down Expand Up @@ -150,14 +158,20 @@ func newKernelVerifiableClient(ctx context.Context, sutCC grpc.ClientConnInterfa
panic(fmt.Sprintf("unable to get root netNs: %+v", err))
}
clientNSName := fmt.Sprintf("client-%s", randstr.Hex(4))
runtime.LockOSThread()
defer runtime.UnlockOSThread()
clientNSHandle, err := netns.NewNamed(clientNSName)
if err != nil {
panic(fmt.Sprintf("unable create netNs %s: %+v", clientNSName, err))
}
go func(clientNSName string) {
if err := netns.Set(rootNSHandle); err != nil {
panic(fmt.Sprintf("unable to set rootNs: %+v", err))
}
go func(clientNSName string, clientNSHandle netns.NsHandle) {
<-ctx.Done()
_ = clientNSHandle.Close()
_ = netns.DeleteNamed(clientNSName)
}(clientNSName)
}(clientNSName, clientNSHandle)

rv := &kernelVerifiableClient{
ctx: ctx,
Expand Down
8 changes: 2 additions & 6 deletions internal/tests/suite_setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,8 @@ func (f *ForwarderTestSuite) SetupSuite() {
registry.RegisterNetworkServiceEndpointRegistryServer(server, f.registryServer)
registry.RegisterNetworkServiceRegistryServer(server, f.registryNSServer)

ctx, cancel := context.WithCancel(f.ctx)
defer func(cancel context.CancelFunc, serverErrCh <-chan error) {
cancel()
err = <-serverErrCh
f.Require().NoError(err)
}(cancel, f.ListenAndServe(ctx, server))
f.Require().Len(f.ListenAndServe(f.ctx, &f.config.ConnectTo, server), 0)
ctx := f.ctx

recv, err := adapters.NetworkServiceEndpointServerToClient(memrg).Find(ctx, &registry.NetworkServiceEndpointQuery{
NetworkServiceEndpoint: &registry.NetworkServiceEndpoint{
Expand Down
5 changes: 3 additions & 2 deletions internal/tests/suite_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package tests
import (
"context"
"net"
"net/url"
"time"

"github.com/pkg/errors"
Expand All @@ -37,8 +38,8 @@ const (
serverIP = "10.0.2.3"
)

func (f *ForwarderTestSuite) ListenAndServe(ctx context.Context, server *grpc.Server) <-chan error {
errCh := grpcutils.ListenAndServe(ctx, &f.config.ConnectTo, server)
func (f *ForwarderTestSuite) ListenAndServe(ctx context.Context, listenOn *url.URL, server *grpc.Server) <-chan error {
errCh := grpcutils.ListenAndServe(ctx, listenOn, server)
select {
case err, ok := <-errCh:
f.Require().True(ok)
Expand Down