Skip to content

Commit 76822f4

Browse files
authored
validating home az value (#1902)
validate home az value change default PopulateHomeAzCacheRetryIntervalSecs value from 15 to 30
1 parent 83104c7 commit 76822f4

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed

cns/configuration/configuration.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,8 @@ func SetCNSConfigDefaults(config *CNSConfig) {
189189
config.SyncHostNCTimeoutMs = 500 //nolint:gomnd // default times
190190
}
191191
if config.PopulateHomeAzCacheRetryIntervalSecs == 0 {
192-
// set the default PopulateHomeAzCache retry interval to 15 seconds
193-
config.PopulateHomeAzCacheRetryIntervalSecs = 15
192+
// set the default PopulateHomeAzCache retry interval to 30 seconds
193+
config.PopulateHomeAzCacheRetryIntervalSecs = 30
194194
}
195195
if config.WireserverIP == "" {
196196
config.WireserverIP = "168.63.129.16"

cns/configuration/configuration_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ func TestSetCNSConfigDefaults(t *testing.T) {
206206
KeyVaultSettings: KeyVaultSettings{
207207
RefreshIntervalInHrs: 12,
208208
},
209-
PopulateHomeAzCacheRetryIntervalSecs: 15,
209+
PopulateHomeAzCacheRetryIntervalSecs: 30,
210210
WireserverIP: "168.63.129.16",
211211
},
212212
},

cns/restserver/homeazmonitor.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,13 @@ func (h *HomeAzMonitor) Populate(ctx context.Context) {
139139
return
140140
}
141141

142+
// validate home az value, HomeAz is a uint, so it's value >=0
143+
if azResponse.HomeAz == 0 {
144+
returnMessage := fmt.Sprintf("[HomeAzMonitor] invalid home az value from nmagent: %d", azResponse.HomeAz)
145+
returnCode := types.UnexpectedError
146+
h.update(returnCode, returnMessage, cns.HomeAzResponse{IsSupported: true})
147+
return
148+
}
142149
h.update(types.Success, "Get Home Az succeeded", cns.HomeAzResponse{IsSupported: true, HomeAz: azResponse.HomeAz})
143150
}
144151

cns/restserver/homeazmonitor_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,19 @@ func TestHomeAzMonitor(t *testing.T) {
4747
cns.HomeAzResponse{},
4848
false,
4949
},
50+
{
51+
"api supported but home az value is not valid",
52+
&fakes.NMAgentClientFake{
53+
SupportedAPIsF: func(ctx context.Context) ([]string, error) {
54+
return []string{GetHomeAzAPIName}, nil
55+
},
56+
GetHomeAzF: func(ctx context.Context) (nmagent.AzResponse, error) {
57+
return nmagent.AzResponse{HomeAz: 0}, nil
58+
},
59+
},
60+
cns.HomeAzResponse{IsSupported: true},
61+
true,
62+
},
5063
{
5164
"api supported but got unexpected errors",
5265
&fakes.NMAgentClientFake{

0 commit comments

Comments
 (0)