Skip to content

Commit 0f11f3a

Browse files
committed
update for new home az contract
1 parent 5d4c4dc commit 0f11f3a

File tree

5 files changed

+39
-4
lines changed

5 files changed

+39
-4
lines changed

cns/api.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ type NmAgentSupportedApisResponse struct {
356356
type HomeAzResponse struct {
357357
IsSupported bool `json:"isSupported"`
358358
HomeAz uint `json:"homeAz"`
359+
APIVersion uint `json:"apiVersion"`
359360
}
360361

361362
type GetHomeAzResponse struct {

cns/restserver/homeazmonitor.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,15 @@ func (h *HomeAzMonitor) Populate(ctx context.Context) {
154154
h.update(returnCode, returnMessage, cns.HomeAzResponse{IsSupported: true})
155155
return
156156
}
157-
h.update(types.Success, "Get Home Az succeeded", cns.HomeAzResponse{IsSupported: true, HomeAz: azResponse.HomeAz})
157+
// validate APIVersion, APIVersion is a uint, so its value >=0
158+
// 0 should be valid when NMA version is old and does not have the apiVersion value in home az response
159+
if azResponse.APIVersion > 0 && azResponse.APIVersion != 2 {
160+
returnMessage := fmt.Sprintf("[HomeAzMonitor] invalid APIVersion value from nmagent: %d", azResponse.APIVersion)
161+
returnCode := types.UnexpectedError
162+
h.update(returnCode, returnMessage, cns.HomeAzResponse{IsSupported: true})
163+
return
164+
}
165+
h.update(types.Success, "Get Home Az succeeded", cns.HomeAzResponse{IsSupported: true, HomeAz: azResponse.HomeAz, APIVersion: azResponse.APIVersion})
158166
}
159167

160168
// update constructs a GetHomeAzResponse entity and update its cache

cns/restserver/homeazmonitor_test.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ func TestHomeAzMonitor(t *testing.T) {
2828
return []string{"GetHomeAz"}, nil
2929
},
3030
GetHomeAzF: func(ctx context.Context) (nmagent.AzResponse, error) {
31-
return nmagent.AzResponse{HomeAz: uint(1)}, nil
31+
return nmagent.AzResponse{HomeAz: uint(1), APIVersion: uint(2)}, nil
3232
},
3333
},
34-
cns.HomeAzResponse{IsSupported: true, HomeAz: uint(1)},
34+
cns.HomeAzResponse{IsSupported: true, HomeAz: uint(1), APIVersion: uint(2)},
3535
false,
3636
},
3737
{
@@ -60,6 +60,19 @@ func TestHomeAzMonitor(t *testing.T) {
6060
cns.HomeAzResponse{IsSupported: true},
6161
true,
6262
},
63+
{
64+
"api supported but apiVersion value is not valid",
65+
&fakes.NMAgentClientFake{
66+
SupportedAPIsF: func(ctx context.Context) ([]string, error) {
67+
return []string{GetHomeAzAPIName}, nil
68+
},
69+
GetHomeAzF: func(ctx context.Context) (nmagent.AzResponse, error) {
70+
return nmagent.AzResponse{HomeAz: uint(1), APIVersion: uint(3)}, nil
71+
},
72+
},
73+
cns.HomeAzResponse{IsSupported: true},
74+
true,
75+
},
6376
{
6477
"api supported but got unexpected errors",
6578
&fakes.NMAgentClientFake{

nmagent/client_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,18 @@ func TestGetHomeAz(t *testing.T) {
756756
map[string]interface{}{
757757
"httpStatusCode": "200",
758758
"HomeAz": 1,
759+
"APIVersion": 0,
760+
},
761+
false,
762+
},
763+
{
764+
"happy path with new version",
765+
nmagent.AzResponse{HomeAz: uint(1), APIVersion: uint(2)},
766+
"/machine/plugins?comp=nmagent&type=GetHomeAz%2Fapi-version%2F1",
767+
map[string]interface{}{
768+
"httpStatusCode": "200",
769+
"HomeAz": 1,
770+
"APIVersion": 2,
759771
},
760772
false,
761773
},

nmagent/responses.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ type NCVersionList struct {
3838
}
3939

4040
type AzResponse struct {
41-
HomeAz uint `json:"homeAz"`
41+
HomeAz uint `json:"homeAz"`
42+
APIVersion uint `json:"apiVersion"`
4243
}
4344

4445
type NodeIP struct {

0 commit comments

Comments
 (0)