Skip to content

Commit 90301c2

Browse files
committed
address comment
1 parent 25e7ef1 commit 90301c2

File tree

4 files changed

+16
-8
lines changed

4 files changed

+16
-8
lines changed

cns/api.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -354,9 +354,9 @@ type NmAgentSupportedApisResponse struct {
354354
}
355355

356356
type HomeAzResponse struct {
357-
IsSupported bool `json:"isSupported"`
358-
HomeAz uint `json:"homeAz"`
359-
APIVersion uint `json:"apiVersion"`
357+
IsSupported bool `json:"isSupported"`
358+
HomeAz uint `json:"homeAz"`
359+
NmaAppliedTheIPV6Fix bool `json:"NmaAppliedTheIPV6Fix"`
360360
}
361361

362362
type GetHomeAzResponse struct {

cns/restserver/homeazmonitor.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,15 +154,14 @@ func (h *HomeAzMonitor) Populate(ctx context.Context) {
154154
h.update(returnCode, returnMessage, cns.HomeAzResponse{IsSupported: true})
155155
return
156156
}
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 {
157+
// validate APIVersion value
158+
if !azResponse.Valid() {
160159
returnMessage := fmt.Sprintf("[HomeAzMonitor] invalid APIVersion value from nmagent: %d", azResponse.APIVersion)
161160
returnCode := types.UnexpectedError
162161
h.update(returnCode, returnMessage, cns.HomeAzResponse{IsSupported: true})
163162
return
164163
}
165-
h.update(types.Success, "Get Home Az succeeded", cns.HomeAzResponse{IsSupported: true, HomeAz: azResponse.HomeAz, APIVersion: azResponse.APIVersion})
164+
h.update(types.Success, "Get Home Az succeeded", cns.HomeAzResponse{IsSupported: true, HomeAz: azResponse.HomeAz, NmaAppliedTheIPV6Fix: azResponse.NmaAppliedTheIPV6Fix()})
166165
}
167166

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

cns/restserver/homeazmonitor_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func TestHomeAzMonitor(t *testing.T) {
3131
return nmagent.AzResponse{HomeAz: uint(1), APIVersion: uint(2)}, nil
3232
},
3333
},
34-
cns.HomeAzResponse{IsSupported: true, HomeAz: uint(1), APIVersion: uint(2)},
34+
cns.HomeAzResponse{IsSupported: true, HomeAz: uint(1), NmaAppliedTheIPV6Fix: true},
3535
false,
3636
},
3737
{

nmagent/responses.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ type AzResponse struct {
4242
APIVersion uint `json:"apiVersion"`
4343
}
4444

45+
func (az AzResponse) Valid() bool {
46+
// 0 should be valid when NMA version is old and does not have the apiVersion value in home az response
47+
return az.APIVersion == 0 || az.APIVersion == 2
48+
}
49+
50+
func (az AzResponse) NmaAppliedTheIPV6Fix() bool {
51+
return az.APIVersion == 2
52+
}
53+
4554
type NodeIP struct {
4655
Address IPAddress `xml:"Address,attr"`
4756
IsPrimary bool `xml:"IsPrimary,attr"`

0 commit comments

Comments
 (0)