Skip to content

Implement WCM AWS TGW connector NSE config options and composite endpoint stub and add stub unit-tests as well #48

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

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
61a6061
add unit tests for vppagent backend ProcessEndpoint(), ProcessClient(…
Nov 19, 2020
58a1f62
Clean up imports
Nov 19, 2020
781ab4d
Revert "Clean up imports"
Nov 30, 2020
0e3212f
Revert "add unit tests for vppagent backend ProcessEndpoint(), Proces…
Nov 30, 2020
1d7b3e8
Implement WCM AWS TGW connector NSE config options and composite endp…
Dec 2, 2020
35ec697
Merge branch 'master' into nsmnse52
Dec 2, 2020
7466939
Sort imports and add newlines to files where they were missing
Dec 3, 2020
d9ebb41
add unit tests for vppagent backend ProcessEndpoint(), ProcessClient(…
Nov 19, 2020
a051f8f
Implement WCM AWS TGW connector NSE config options and composite endp…
Dec 2, 2020
e94b229
Sort imports and add newlines to files where they were missing
Dec 3, 2020
d88f34c
test: Introduce e2e testing (#35)
ondrej-fabry Nov 19, 2020
df5bc43
Merge branch 'nsmnse52' of github.com:amberimam/nsm-nse into nsmnse52
Dec 3, 2020
4b85204
use contants defined at top of file instead of redeclaring vars in ba…
Dec 3, 2020
40c3caa
format code properly, move newVL3Composite function to top of file si…
Dec 3, 2020
8cc9d40
Merge branch 'master' of https://github.com/cisco-app-networking/nsm-nse
Dec 3, 2020
8c7ae21
add unit tests for vppagent backend ProcessEndpoint(), ProcessClient(…
Nov 19, 2020
4de87b6
Implement WCM AWS TGW connector NSE config options and composite endp…
Dec 2, 2020
2476701
Sort imports and add newlines to files where they were missing
Dec 3, 2020
1ac18e8
use contants defined at top of file instead of redeclaring vars in ba…
Dec 3, 2020
705bdde
format code properly, move newVL3Composite function to top of file si…
Dec 3, 2020
786f90b
Merge branch 'nsmnse52' of github.com:amberimam/nsm-nse into nsmnse52
Dec 3, 2020
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: 58 additions & 0 deletions cmd/vl3-nse/aws_tgw_connect.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package main

import (
"context"

"github.com/golang/protobuf/ptypes/empty"
"github.com/sirupsen/logrus"

"github.com/cisco-app-networking/nsm-nse/pkg/nseconfig"
"github.com/networkservicemesh/networkservicemesh/controlplane/api/connection"
"github.com/networkservicemesh/networkservicemesh/controlplane/api/networkservice"
"github.com/networkservicemesh/networkservicemesh/sdk/endpoint"
)

type AwsTgwConnector struct {
TransitGatewayID string
TransitGatewayName string
}

func newAwsTgwConnector(ate *nseconfig.AwsTgwEndpoint) *AwsTgwConnector {
logrus.Infof("newAwsTgwConnector()")

if ate != nil {
newAwsTgwConnector := &AwsTgwConnector{
TransitGatewayID: ate.TransitGatewayID,
TransitGatewayName: ate.TransitGatewayName,
}

logrus.Infof("newAwsTgwConnector returning object: %v", newAwsTgwConnector)
return newAwsTgwConnector
}

logrus.Errorf("newAwsTgwConnector(): got nil AwsTgwEndpoint, returning nil")

return nil
}

func (atc *AwsTgwConnector) Close(ctx context.Context, conn *connection.Connection) (*empty.Empty, error) {

logrus.Infof("AWS TGW Connector Close()")

if endpoint.Next(ctx) != nil {
return endpoint.Next(ctx).Close(ctx, conn)
}
return &empty.Empty{}, nil
}

func (atc *AwsTgwConnector) Request(ctx context.Context,
request *networkservice.NetworkServiceRequest) (*connection.Connection, error) {

logrus.Infof("AWS TGW Connector Request()")

if endpoint.Next(ctx) != nil {
return endpoint.Next(ctx).Request(ctx, request)
}

return nil, nil
}
61 changes: 61 additions & 0 deletions cmd/vl3-nse/aws_tgw_connect_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package main

import (
"context"
"testing"

"github.com/stretchr/testify/assert"

"github.com/cisco-app-networking/nsm-nse/pkg/nseconfig"
"github.com/networkservicemesh/networkservicemesh/controlplane/api/connection"
"github.com/networkservicemesh/networkservicemesh/controlplane/api/networkservice"
)

const (
TransitGatewayID = "1"
TransitGatewayName = "test"
)

func TestNewAwsTgwConnector(t *testing.T) {

ate := nseconfig.AwsTgwEndpoint{
TransitGatewayID: TransitGatewayID,
TransitGatewayName: TransitGatewayName,
}

expected := &AwsTgwConnector{
TransitGatewayID: TransitGatewayID,
TransitGatewayName: TransitGatewayName,
}

got := newAwsTgwConnector(&ate)

assert.Equal(t, expected, got)
}

func TestNewAwsTgwConnectorNil(t *testing.T) {

got := newAwsTgwConnector(nil)

assert.Nil(t, got)
}

func TestAwsTgwConnector_Request(t *testing.T) {
atc := AwsTgwConnector{}
ctx := context.Background()
request := &networkservice.NetworkServiceRequest{}

_, err := atc.Request(ctx, request)

assert.Nil(t, err)
}

func TestAwsTgwConnector_Close(t *testing.T) {
atc := AwsTgwConnector{}
ctx := context.Background()
conn := &connection.Connection{}

_, err := atc.Close(ctx, conn)

assert.Nil(t, err)
}
5 changes: 5 additions & 0 deletions cmd/vl3-nse/nse.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ func (e vL3CompositeEndpoint) AddCompositeEndpoints(nsConfig *common.NSConfigura
}, ucnfEndpoint.VL3.IPAM.DefaultPrefixPool, ucnfEndpoint.VL3.IPAM.ServerAddress, ucnfEndpoint.NseControl.ConnectivityDomain),
}

if ucnfEndpoint.AwsTgwEndpoint != nil {
awsTgwEndpoint := newAwsTgwConnector(ucnfEndpoint.AwsTgwEndpoint)
compositeEndpoints = append(compositeEndpoints, awsTgwEndpoint)
}

return &compositeEndpoints
}

Expand Down
78 changes: 78 additions & 0 deletions cmd/vl3-nse/nse_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package main

import (
"fmt"
"github.com/cisco-app-networking/nsm-nse/pkg/nseconfig"
"github.com/cisco-app-networking/nsm-nse/pkg/universal-cnf/config"
"github.com/networkservicemesh/networkservicemesh/sdk/common"
"github.com/stretchr/testify/assert"
"testing"
)


func TestAddCompositeEndpoints(t *testing.T) {
vce := vL3CompositeEndpoint{}
nsConfig := &common.NSConfiguration{
IPAddress: "10.0.0.1",
}

ucnfEndpoint := &nseconfig.Endpoint{
VL3: nseconfig.VL3{
IPAM: nseconfig.IPAM{
DefaultPrefixPool: "192.168.0.0/24",
ServerAddress: "192.168.0.1",
},
},
NseControl: &nseconfig.NseControl{},
AwsTgwEndpoint: nil,
}

newVL3ConnectComposite = func(configuration *common.NSConfiguration, vL3NetCidr string, backend config.UniversalCNFBackend, remoteIpList []string, getNseName fnGetNseName, defaultCdPrefix, nseControlAddr, connDomain string) *vL3ConnectComposite {
return nil
}

got := vce.AddCompositeEndpoints(nsConfig, ucnfEndpoint)

assert.NotNil(t, got)
assert.Equal(t, 1, len(*got))

compositeEndpoints := *got
typeofEndpoint := fmt.Sprintf("%T", compositeEndpoints[0])
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this test is actually validating that the AwsTgwConnector endpoint didn't get added. You should loop through the compositeEndpoints to check each element to ensure it's not AwsTgwConnector

Copy link
Author

Choose a reason for hiding this comment

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

Sure, will do.

assert.NotEqual(t, "*main.AwsTgwConnector", typeofEndpoint)
}

func TestAddCompositeEndpointsAws(t *testing.T) {
vce := vL3CompositeEndpoint{}
nsConfig := &common.NSConfiguration{
IPAddress: "10.0.0.1",
}

ucnfEndpoint := &nseconfig.Endpoint{
VL3: nseconfig.VL3{
IPAM: nseconfig.IPAM{
DefaultPrefixPool: "192.168.0.0/24",
ServerAddress: "192.168.0.1",
},
},
NseControl: &nseconfig.NseControl{},
AwsTgwEndpoint: &nseconfig.AwsTgwEndpoint{
TransitGatewayID: "1",
TransitGatewayName: "test",
},
}

newVL3ConnectComposite = func(configuration *common.NSConfiguration, vL3NetCidr string, backend config.UniversalCNFBackend, remoteIpList []string, getNseName fnGetNseName, defaultCdPrefix, nseControlAddr, connDomain string) *vL3ConnectComposite {
return nil
}

got := vce.AddCompositeEndpoints(nsConfig, ucnfEndpoint)

assert.NotNil(t, got)
assert.Equal(t, len(*got), 2)

compositeEndpoints := *got
awsTgwEndpoint := compositeEndpoints[1]
Copy link
Contributor

Choose a reason for hiding this comment

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

same comment re: looping through the compositeEndpoints.

Copy link
Author

Choose a reason for hiding this comment

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

Will do

typeOfEndpoint := fmt.Sprintf("%T", awsTgwEndpoint)

assert.Equal(t, "*main.AwsTgwConnector", typeOfEndpoint )
Copy link
Contributor

Choose a reason for hiding this comment

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

these 2 cases are good candidates to convert to a table driven approach

Copy link
Author

Choose a reason for hiding this comment

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

Sure will change it to a table driven test

}
4 changes: 2 additions & 2 deletions cmd/vl3-nse/service_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (s *serviceRegistry) RegisterWorkload(ctx context.Context, workloadLabels m
logrus.Infof("Sending workload register request: %v", serviceWorkload)
_, err = s.registryClient.RegisterWorkload(ctx, serviceWorkload)
if err != nil {
logrus.Errorf("service registration not successful: %w", err)
logrus.Errorf("service registration not successful: %v", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

are these golint related fixes? if there's a lot of these please add these as a separate PR

Copy link
Author

@amberimam amberimam Dec 4, 2020

Choose a reason for hiding this comment

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

When I tried running the unit tests I wrote for aws_tgw_connect.go there was a build failure for this file that was preventing my tests from running. Failure happened due to having the %w instead of %v.

Copy link
Member

@ondrej-fabry ondrej-fabry Dec 8, 2020

Choose a reason for hiding this comment

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

Just noting here for exaplanation:
This most likely a forgotten formatting directive that was probably copy-pasted from other fmt.Errorf call. The %w is a special specified for errors, read more here: https://golang.org/pkg/fmt/#Errorf Since this is logrus.Errorf that just prints log and does not create error it is incorrect in this case.

return err
}

Expand Down Expand Up @@ -148,7 +148,7 @@ func (s *serviceRegistry) RemoveWorkload(ctx context.Context, workloadLabels map
logrus.Infof("Sending workload remove request: %v", serviceWorkload)
_, err = s.registryClient.RemoveWorkload(ctx, serviceWorkload)
if err != nil {
logrus.Errorf("service removal not successful: %w", err)
logrus.Errorf("service removal not successful: %v", err)
return err
}

Expand Down
Loading