From 62d987371672211a334c9ede1537b5f58bbad14c Mon Sep 17 00:00:00 2001 From: paulyu Date: Mon, 17 Apr 2023 13:51:22 -0400 Subject: [PATCH 1/5] case insensitive fix --- cns/restserver/util.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cns/restserver/util.go b/cns/restserver/util.go index afbf126d11..e8aabaae5e 100644 --- a/cns/restserver/util.go +++ b/cns/restserver/util.go @@ -853,13 +853,18 @@ func (service *HTTPRestService) isNCWaitingForUpdate( "Skipping GetNCVersionStatus check from NMAgent", ncVersion, ncid) return true, types.NetworkContainerVfpProgramPending, "" } - nmaProgrammedNCVersionStr, ok := ncVersionList[ncid] + + // accept both upper and lower GUID from ncid(Swift_GUID) + // check each ncid in lower case if it's in ncVersionList + nmaProgrammedNCVersionStr, ok := ncVersionList[strings.ToLower(ncid)] if !ok { // NMA doesn't have this NC that we need programmed yet, bail out logger.Printf("[Azure CNS] Failed to get NC %s doesn't exist in NMAgent NC version list "+ "Skipping GetNCVersionStatus check from NMAgent", ncid) return true, types.NetworkContainerVfpProgramPending, "" + } + nmaProgrammedNCVersion, err := strconv.Atoi(nmaProgrammedNCVersionStr) if err != nil { // it's unclear whether or not this can actually happen. In the NMAgent From acb05056d3a302a2110e59a9d47fbad60db64e43 Mon Sep 17 00:00:00 2001 From: paulyu Date: Mon, 17 Apr 2023 21:01:32 -0400 Subject: [PATCH 2/5] cnsclientfix Do() --- cns/client/client.go | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/cns/client/client.go b/cns/client/client.go index f7e41fba23..d3fe3d9a94 100644 --- a/cns/client/client.go +++ b/cns/client/client.go @@ -47,8 +47,6 @@ var clientPaths = []string{ cns.GetHomeAz, } -var ErrAPINotFound error = errors.New("api not found") - type do interface { Do(*http.Request) (*http.Response, error) } @@ -403,16 +401,18 @@ func (c *Client) RequestIPs(ctx context.Context, ipconfig cns.IPConfigsRequest) req.Header.Set(headerContentType, contentTypeJSON) res, err := c.client.Do(req) - // if we get a 404 error - if res.StatusCode == http.StatusNotFound { - return nil, fmt.Errorf("cannot find API RequestIPs %w: %v", ErrAPINotFound, err) //nolint:errorlint // multiple %w not supported in 1.19 - } - if err != nil { return nil, errors.Wrap(err, "http request failed") } defer res.Body.Close() + if res.StatusCode == http.StatusNotFound { + return nil, &CNSClientError{ + Code: types.UnsupportedAPI, + Err: errors.Errorf("Unsupported API"), + } + } + if res.StatusCode != http.StatusOK { return nil, errors.Errorf("http response %d", res.StatusCode) } @@ -445,17 +445,19 @@ func (c *Client) ReleaseIPs(ctx context.Context, ipconfig cns.IPConfigsRequest) } req.Header.Set(headerContentType, contentTypeJSON) res, err := c.client.Do(req) - - // if we get a 404 error - if res.StatusCode == http.StatusNotFound { - return fmt.Errorf("cannot find API ReleaseIPs %w: %v", ErrAPINotFound, err) //nolint:errorlint // multiple %w not supported in 1.19 - } - if err != nil { return errors.Wrap(err, "http request failed") } defer res.Body.Close() + // if we get a 404 error + if res.StatusCode == http.StatusNotFound { + return &CNSClientError{ + Code: types.UnsupportedAPI, + Err: errors.Errorf("Unsupported API"), + } + } + if res.StatusCode != http.StatusOK { return errors.Errorf("http response %d", res.StatusCode) } From fad38060954a9ffb369f32bb4fb6a1aa9193875b Mon Sep 17 00:00:00 2001 From: paulyu Date: Mon, 17 Apr 2023 22:27:56 -0400 Subject: [PATCH 3/5] fix conflicts --- cns/restserver/util.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/cns/restserver/util.go b/cns/restserver/util.go index e8aabaae5e..ea1bd4bd59 100644 --- a/cns/restserver/util.go +++ b/cns/restserver/util.go @@ -854,17 +854,13 @@ func (service *HTTPRestService) isNCWaitingForUpdate( return true, types.NetworkContainerVfpProgramPending, "" } - // accept both upper and lower GUID from ncid(Swift_GUID) - // check each ncid in lower case if it's in ncVersionList - nmaProgrammedNCVersionStr, ok := ncVersionList[strings.ToLower(ncid)] + nmaProgrammedNCVersionStr, ok := ncVersionList[ncid] if !ok { // NMA doesn't have this NC that we need programmed yet, bail out logger.Printf("[Azure CNS] Failed to get NC %s doesn't exist in NMAgent NC version list "+ "Skipping GetNCVersionStatus check from NMAgent", ncid) return true, types.NetworkContainerVfpProgramPending, "" - } - nmaProgrammedNCVersion, err := strconv.Atoi(nmaProgrammedNCVersionStr) if err != nil { // it's unclear whether or not this can actually happen. In the NMAgent From 60d3a8387d670c5b9df29c59092eef6fcefa02fd Mon Sep 17 00:00:00 2001 From: paulyu Date: Mon, 17 Apr 2023 22:28:20 -0400 Subject: [PATCH 4/5] fix conflicts --- cns/restserver/util.go | 1 - 1 file changed, 1 deletion(-) diff --git a/cns/restserver/util.go b/cns/restserver/util.go index ea1bd4bd59..afbf126d11 100644 --- a/cns/restserver/util.go +++ b/cns/restserver/util.go @@ -853,7 +853,6 @@ func (service *HTTPRestService) isNCWaitingForUpdate( "Skipping GetNCVersionStatus check from NMAgent", ncVersion, ncid) return true, types.NetworkContainerVfpProgramPending, "" } - nmaProgrammedNCVersionStr, ok := ncVersionList[ncid] if !ok { // NMA doesn't have this NC that we need programmed yet, bail out From 4a6f2d177347f8e69d6f21216f78a187773161c9 Mon Sep 17 00:00:00 2001 From: paulyu Date: Mon, 17 Apr 2023 22:28:20 -0400 Subject: [PATCH 5/5] fix conflicts --- cns/restserver/util.go | 1 - 1 file changed, 1 deletion(-) diff --git a/cns/restserver/util.go b/cns/restserver/util.go index ea1bd4bd59..afbf126d11 100644 --- a/cns/restserver/util.go +++ b/cns/restserver/util.go @@ -853,7 +853,6 @@ func (service *HTTPRestService) isNCWaitingForUpdate( "Skipping GetNCVersionStatus check from NMAgent", ncVersion, ncid) return true, types.NetworkContainerVfpProgramPending, "" } - nmaProgrammedNCVersionStr, ok := ncVersionList[ncid] if !ok { // NMA doesn't have this NC that we need programmed yet, bail out