-
Notifications
You must be signed in to change notification settings - Fork 21
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
base: master
Are you sure you want to change the base?
Changes from all commits
61a6061
58a1f62
781ab4d
0e3212f
1d7b3e8
35ec697
7466939
d9ebb41
a051f8f
e94b229
d88f34c
df5bc43
4b85204
40c3caa
8cc9d40
8c7ae21
4de87b6
2476701
1ac18e8
705bdde
786f90b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
} |
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) | ||
} |
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]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same comment re: looping through the compositeEndpoints. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure will change it to a table driven test |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just noting here for exaplanation: |
||
return err | ||
} | ||
|
||
|
@@ -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 | ||
} | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.