diff --git a/cns/configuration/configuration.go b/cns/configuration/configuration.go index 8366b6cd4a..d12f203fac 100644 --- a/cns/configuration/configuration.go +++ b/cns/configuration/configuration.go @@ -189,8 +189,8 @@ func SetCNSConfigDefaults(config *CNSConfig) { config.SyncHostNCTimeoutMs = 500 //nolint:gomnd // default times } if config.PopulateHomeAzCacheRetryIntervalSecs == 0 { - // set the default PopulateHomeAzCache retry interval to 15 seconds - config.PopulateHomeAzCacheRetryIntervalSecs = 15 + // set the default PopulateHomeAzCache retry interval to 30 seconds + config.PopulateHomeAzCacheRetryIntervalSecs = 30 } if config.WireserverIP == "" { config.WireserverIP = "168.63.129.16" diff --git a/cns/configuration/configuration_test.go b/cns/configuration/configuration_test.go index 3e2e40278e..a1cfaa3ce5 100644 --- a/cns/configuration/configuration_test.go +++ b/cns/configuration/configuration_test.go @@ -206,7 +206,7 @@ func TestSetCNSConfigDefaults(t *testing.T) { KeyVaultSettings: KeyVaultSettings{ RefreshIntervalInHrs: 12, }, - PopulateHomeAzCacheRetryIntervalSecs: 15, + PopulateHomeAzCacheRetryIntervalSecs: 30, WireserverIP: "168.63.129.16", }, }, diff --git a/cns/restserver/homeazmonitor.go b/cns/restserver/homeazmonitor.go index 81b892d793..4cac0cbb51 100644 --- a/cns/restserver/homeazmonitor.go +++ b/cns/restserver/homeazmonitor.go @@ -139,6 +139,13 @@ func (h *HomeAzMonitor) Populate(ctx context.Context) { return } + // validate home az value, HomeAz is a uint, so it's value >=0 + if azResponse.HomeAz == 0 { + returnMessage := fmt.Sprintf("[HomeAzMonitor] invalid home az value from nmagent: %d", azResponse.HomeAz) + returnCode := types.UnexpectedError + h.update(returnCode, returnMessage, cns.HomeAzResponse{IsSupported: true}) + return + } h.update(types.Success, "Get Home Az succeeded", cns.HomeAzResponse{IsSupported: true, HomeAz: azResponse.HomeAz}) } diff --git a/cns/restserver/homeazmonitor_test.go b/cns/restserver/homeazmonitor_test.go index 1b699c1ea8..b435f3cde1 100644 --- a/cns/restserver/homeazmonitor_test.go +++ b/cns/restserver/homeazmonitor_test.go @@ -47,6 +47,19 @@ func TestHomeAzMonitor(t *testing.T) { cns.HomeAzResponse{}, false, }, + { + "api supported but home az value is not valid", + &fakes.NMAgentClientFake{ + SupportedAPIsF: func(ctx context.Context) ([]string, error) { + return []string{GetHomeAzAPIName}, nil + }, + GetHomeAzF: func(ctx context.Context) (nmagent.AzResponse, error) { + return nmagent.AzResponse{HomeAz: 0}, nil + }, + }, + cns.HomeAzResponse{IsSupported: true}, + true, + }, { "api supported but got unexpected errors", &fakes.NMAgentClientFake{