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

Initial getHomeAZ 404 changes #1994

Merged
merged 3 commits into from
Jun 6, 2023
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
7 changes: 7 additions & 0 deletions cns/restserver/homeazmonitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,13 @@ func (h *HomeAzMonitor) Populate(ctx context.Context) {
h.update(returnCode, returnMessage, cns.HomeAzResponse{IsSupported: true})
return

case http.StatusNotFound:
returnMessage := fmt.Sprintf("[HomeAzMonitor] region does not support AZs, NMAgent returned StatusCode: %d, error: %v", apiError.StatusCode(), err)
// Marking this as success since we don't want to enter the retry loop on DNC side.
returnCode := types.Success
h.update(returnCode, returnMessage, cns.HomeAzResponse{IsSupported: false})
return

default:
returnMessage := fmt.Sprintf("[HomeAzMonitor] failed with StatusCode: %d", apiError.StatusCode())
returnCode := types.UnexpectedError
Expand Down
15 changes: 9 additions & 6 deletions nmagent/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -675,17 +675,24 @@ func TestGetHomeAz(t *testing.T) {
},
true,
},
{
"404 from NMA",
nmagent.AzResponse{},
"/machine/plugins?comp=nmagent&type=GetHomeAz%2Fapi-version%2F1",
map[string]interface{}{
"httpStatusCode": "404",
},
true,
ashvindeodhar marked this conversation as resolved.
Show resolved Hide resolved
},
}

for _, test := range tests {
test := test
t.Run(test.name, func(t *testing.T) {
t.Parallel()

var gotPath string
client := nmagent.NewTestClient(&TestTripper{
RoundTripF: func(req *http.Request) (*http.Response, error) {
gotPath = req.URL.RequestURI()
rr := httptest.NewRecorder()
err := json.NewEncoder(rr).Encode(test.resp)
if err != nil {
Expand All @@ -705,10 +712,6 @@ func TestGetHomeAz(t *testing.T) {
t.Fatal("expected error but received none")
}

if gotPath != test.expPath {
t.Error("paths differ: got:", gotPath, "exp:", test.expPath)
}

if !cmp.Equal(got, test.exp) {
t.Error("response differs from expectation: diff:", cmp.Diff(got, test.exp))
}
Expand Down