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
9 changes: 5 additions & 4 deletions cns/NetworkContainerContract.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,10 +529,11 @@ func (p PublishNetworkContainerResponse) String() string {

// UnpublishNetworkContainerRequest specifies request to unpublish network container via NMAgent.
type UnpublishNetworkContainerRequest struct {
NetworkID string
NetworkContainerID string
JoinNetworkURL string
DeleteNetworkContainerURL string
NetworkID string
NetworkContainerID string
JoinNetworkURL string
DeleteNetworkContainerURL string
DeleteNetworkContainerRequestBody []byte
}

// UnpublishNetworkContainerResponse specifies the response to unpublish network container request.
Expand Down
6 changes: 3 additions & 3 deletions cns/fakes/wireserverproxyfake.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
type WireserverProxyFake struct {
JoinNetworkFunc func(context.Context, string) (*http.Response, error)
PublishNCFunc func(context.Context, cns.NetworkContainerParameters, []byte) (*http.Response, error)
UnpublishNCFunc func(context.Context, cns.NetworkContainerParameters) (*http.Response, error)
UnpublishNCFunc func(context.Context, cns.NetworkContainerParameters, []byte) (*http.Response, error)
}

const defaultResponseBody = `{"httpStatusCode":"200"}`
Expand Down Expand Up @@ -41,9 +41,9 @@ func (w *WireserverProxyFake) PublishNC(ctx context.Context, ncParams cns.Networ
return defaultResponse(), nil
}

func (w *WireserverProxyFake) UnpublishNC(ctx context.Context, ncParams cns.NetworkContainerParameters) (*http.Response, error) {
func (w *WireserverProxyFake) UnpublishNC(ctx context.Context, ncParams cns.NetworkContainerParameters, payload []byte) (*http.Response, error) {
if w.UnpublishNCFunc != nil {
return w.UnpublishNCFunc(ctx, ncParams)
return w.UnpublishNCFunc(ctx, ncParams, payload)
}

return defaultResponse(), nil
Expand Down
2 changes: 1 addition & 1 deletion cns/restserver/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1298,7 +1298,7 @@ func (service *HTTPRestService) unpublishNetworkContainer(w http.ResponseWriter,
logger.Printf("[Azure-CNS] joined vnet %s during nc %s unpublish. wireserver response: %v", req.NetworkID, req.NetworkContainerID, string(joinBytes))
}

publishResp, err := service.wsproxy.UnpublishNC(ctx, ncParams)
publishResp, err := service.wsproxy.UnpublishNC(ctx, ncParams, req.DeleteNetworkContainerRequestBody)
if err != nil {
resp := cns.UnpublishNetworkContainerResponse{
Response: cns.Response{
Expand Down
20 changes: 11 additions & 9 deletions cns/restserver/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -955,7 +955,7 @@ func TestUnpublishNCViaCNS(t *testing.T) {

func TestUnpublishNCViaCNS401(t *testing.T) {
wsproxy := fakes.WireserverProxyFake{
UnpublishNCFunc: func(_ context.Context, _ cns.NetworkContainerParameters) (*http.Response, error) {
UnpublishNCFunc: func(_ context.Context, _ cns.NetworkContainerParameters, i []byte) (*http.Response, error) {
return &http.Response{
StatusCode: http.StatusOK,
Body: io.NopCloser(bytes.NewBufferString(`{"httpStatusCode":"401"}`)),
Expand All @@ -974,10 +974,11 @@ func TestUnpublishNCViaCNS401(t *testing.T) {
joinNetworkURL := "http://" + nmagentEndpoint + "/dummyVnetURL"

unpublishNCRequest := &cns.UnpublishNetworkContainerRequest{
NetworkID: networkID,
NetworkContainerID: networkContainerID,
JoinNetworkURL: joinNetworkURL,
DeleteNetworkContainerURL: deleteNetworkContainerURL,
NetworkID: networkID,
NetworkContainerID: networkContainerID,
JoinNetworkURL: joinNetworkURL,
DeleteNetworkContainerURL: deleteNetworkContainerURL,
DeleteNetworkContainerRequestBody: []byte("{}"),
}

var body bytes.Buffer
Expand Down Expand Up @@ -1035,10 +1036,11 @@ func unpublishNCViaCNS(networkID, networkContainerID, deleteNetworkContainerURL
joinNetworkURL := "http://" + nmagentEndpoint + "/dummyVnetURL"

unpublishNCRequest := &cns.UnpublishNetworkContainerRequest{
NetworkID: networkID,
NetworkContainerID: networkContainerID,
JoinNetworkURL: joinNetworkURL,
DeleteNetworkContainerURL: deleteNetworkContainerURL,
NetworkID: networkID,
NetworkContainerID: networkContainerID,
JoinNetworkURL: joinNetworkURL,
DeleteNetworkContainerURL: deleteNetworkContainerURL,
DeleteNetworkContainerRequestBody: []byte("{}"),
}

var body bytes.Buffer
Expand Down
2 changes: 1 addition & 1 deletion cns/restserver/restserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type nmagentClient interface {
type wireserverProxy interface {
JoinNetwork(ctx context.Context, vnetID string) (*http.Response, error)
PublishNC(ctx context.Context, ncParams cns.NetworkContainerParameters, payload []byte) (*http.Response, error)
UnpublishNC(ctx context.Context, ncParams cns.NetworkContainerParameters) (*http.Response, error)
UnpublishNC(ctx context.Context, ncParams cns.NetworkContainerParameters, payload []byte) (*http.Response, error)
}

// HTTPRestService represents http listener for CNS - Container Networking Service.
Expand Down
11 changes: 9 additions & 2 deletions cns/wireserver/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,17 @@ func (p *Proxy) PublishNC(ctx context.Context, ncParams cns.NetworkContainerPara
return resp, nil
}

func (p *Proxy) UnpublishNC(ctx context.Context, ncParams cns.NetworkContainerParameters) (*http.Response, error) {
func (p *Proxy) UnpublishNC(ctx context.Context, ncParams cns.NetworkContainerParameters, payload []byte) (*http.Response, error) {
reqURL := fmt.Sprintf(unpublishNCURLFmt, p.Host, ncParams.AssociatedInterfaceID, ncParams.NCID, ncParams.AuthToken)

req, err := http.NewRequestWithContext(ctx, http.MethodPost, reqURL, bytes.NewBufferString(`""`))
// a POST to wireserver must contain a body. For legacy purposes,
// an empty json string (two quote characters) should be sent by default.
body := []byte(`""`)
if len(payload) > 0 {
body = payload
}

req, err := http.NewRequestWithContext(ctx, http.MethodPost, reqURL, bytes.NewBuffer(body))
if err != nil {
return nil, errors.Wrap(err, "wireserver proxy: unpublish nc: could not build http request")
}
Expand Down
4 changes: 3 additions & 1 deletion nmagent/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,9 @@ var _ Request = DeleteContainerRequest{}
// DeleteContainerRequest represents all information necessary to request that
// NMAgent delete a particular network container
type DeleteContainerRequest struct {
NCID string `json:"-"` // the Network Container ID
NCID string `json:"-"` // the Network Container ID
AzID uint `json:"azID"` // home AZ of the Network Container
EnableAZR bool `json:"enableAZR"` // whether AZR is enabled or not

// PrimaryAddress is the primary customer address of the interface in the
// management VNET
Expand Down