X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=cmd%2Fvesmgr%2Fconfig_test.go;h=da135b46d04c717c55d277cdf53bf03a891bbbbd;hb=070b3653202d9db994834cbdc175044a80e8278a;hp=76793a12176566198908ad8028bdd46167465cbf;hpb=fc77ebb24a8627ccfb18edd8b5dbc038da475eab;p=ric-plt%2Fvespamgr.git diff --git a/cmd/vesmgr/config_test.go b/cmd/vesmgr/config_test.go old mode 100644 new mode 100755 index 76793a1..da135b4 --- a/cmd/vesmgr/config_test.go +++ b/cmd/vesmgr/config_test.go @@ -13,6 +13,9 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. + * + * This source code is part of the near-RT RIC (RAN Intelligent Controller) + * platform project (RICP). */ package main @@ -34,6 +37,14 @@ func testBaseConf(t *testing.T, vesconf VESAgentConfiguration) { assert.Equal(t, vesconf.Event.MaxMissed, 2) assert.Equal(t, vesconf.Event.RetryInterval, time.Second*5) assert.Equal(t, vesconf.Measurement.Prometheus.KeepAlive, time.Second*30) + assert.Equal(t, vesconf.Event.VNFName, defaultVNFName) + assert.Equal(t, vesconf.Event.NfNamingCode, defaultNFNamingCode) + assert.Equal(t, vesconf.Event.ReportingEntityName, "Vespa") + // depending on the credentials with which this test is run, + // root or non-root, the code either reads the UUID from the file or + // ends up using the default id. Just check the length here, + // not the actual value. + assert.Len(t, vesconf.Event.ReportingEntityID, len(defaultReportingEntityID)) } func TestBasicConfigContainsCorrectValues(t *testing.T) { @@ -41,7 +52,19 @@ func TestBasicConfigContainsCorrectValues(t *testing.T) { testBaseConf(t, vesconf) } +func TestBasicConfigContainsCorrectVNFName(t *testing.T) { + os.Setenv("VESMGR_VNFNAME", "VNF-111") + os.Setenv("VESMGR_NFNAMINGCODE", "code55") + vesconf := basicVespaConf() + assert.Equal(t, vesconf.Event.VNFName, "VNF-111") + assert.Equal(t, vesconf.Event.NfNamingCode, "code55") + os.Unsetenv("VESMGR_VNFNAME") + os.Unsetenv("VESMGR_NFNAMINGCODE") +} + func TestCollectorConfiguration(t *testing.T) { + os.Unsetenv("VESMGR_VNFNAME") + os.Unsetenv("VESMGR_NFNAMINGCODE") os.Setenv("VESMGR_PRICOLLECTOR_USER", "user123") os.Setenv("VESMGR_PRICOLLECTOR_PASSWORD", "pass123") os.Setenv("VESMGR_PRICOLLECTOR_PASSPHRASE", "phrase123") @@ -65,6 +88,8 @@ func TestCollectorConfiguration(t *testing.T) { } func TestCollectorConfigurationWhenEnvironmentVariablesAreNotDefined(t *testing.T) { + os.Unsetenv("VESMGR_VNFNAME") + os.Unsetenv("VESMGR_NFNAMINGCODE") os.Unsetenv("VESMGR_PRICOLLECTOR_USER") os.Unsetenv("VESMGR_PRICOLLECTOR_PASSWORD") os.Unsetenv("VESMGR_PRICOLLECTOR_PASSPHRASE") @@ -132,15 +157,15 @@ func metricsStringToInterfaceArray(metrics string) []interface{} { func TestParseMetricsRules(t *testing.T) { metricsJSON := `{"metrics": [ - { "name": "ricxapp_RMR_Received", "objectName": "ricxappRMRreceivedCounter", "objectInstance": "ricxappRMRReceived" }, - { "name": "ricxapp_RMR_ReceiveError", "objectName": "ricxappRMRReceiveErrorCounter", "objectInstance": "ricxappRMRReceiveError" }, - { "name": "ricxapp_RMR_Transmitted", "objectName": "ricxappRMRTransmittedCounter", "objectInstance": "ricxappRMRTransmitted" }, - { "name": "ricxapp_RMR_TransmitError", "objectName": "ricxappRMRTransmitErrorCounter", "objectInstance": "ricxappRMRTransmitError" }, - { "name": "ricxapp_SDL_Stored", "objectName": "ricxappSDLStoredCounter", "objectInstance": "ricxappSDLStored" }, - { "name": "ricxapp_SDL_StoreError", "objectName": "ricxappSDLStoreErrorCounter", "objectInstance": "ricxappSDLStoreError" } ]}` + { "name": "ricxapp_RMR_Received", "objectName": "ricxappRMRreceivedCounter", "objectInstance": "ricxappRMRReceived", "counterId": "0011" }, + { "name": "ricxapp_RMR_ReceiveError", "objectName": "ricxappRMRReceiveErrorCounter", "objectInstance": "ricxappRMRReceiveError", "counterId": "0011" }, + { "name": "ricxapp_RMR_Transmitted", "objectName": "ricxappRMRTransmittedCounter", "objectInstance": "ricxappRMRTransmitted", "counterId": "0011" }, + { "name": "ricxapp_RMR_TransmitError", "objectName": "ricxappRMRTransmitErrorCounter", "objectInstance": "ricxappRMRTransmitError", "counterId": "0011" }, + { "name": "ricxapp_SDL_Stored", "objectName": "ricxappSDLStoredCounter", "objectInstance": "ricxappSDLStored", "counterId": "0011" }, + { "name": "ricxapp_SDL_StoreError", "objectName": "ricxappSDLStoreErrorCounter", "objectInstance": "ricxappSDLStoreError", "counterId": "0011" } ]}` appMetrics := make(AppMetrics) m := metricsStringToInterfaceArray(metricsJSON) - appMetrics = parseMetricsRules(m, appMetrics) + appMetrics = parseMetricsRules(m, appMetrics, "SEP/XAPP", "X2", "1234", "60") assert.Len(t, appMetrics, 6) assert.Equal(t, "ricxappRMRreceivedCounter", appMetrics["ricxapp_RMR_Received"].ObjectName) assert.Equal(t, "ricxappRMRTransmitErrorCounter", appMetrics["ricxapp_RMR_TransmitError"].ObjectName) @@ -151,16 +176,16 @@ func TestParseMetricsRulesNoMetrics(t *testing.T) { appMetrics := make(AppMetrics) metricsJSON := `{"metrics": []` m := metricsStringToInterfaceArray(metricsJSON) - appMetrics = parseMetricsRules(m, appMetrics) + appMetrics = parseMetricsRules(m, appMetrics, "SEP/XAPP", "X2", "1234", "60") assert.Empty(t, appMetrics) } func TestParseMetricsRulesAdditionalFields(t *testing.T) { appMetrics := make(AppMetrics) metricsJSON := `{"metrics": [ - { "additionalField": "valueIgnored", "name": "ricxapp_RMR_Received", "objectName": "ricxappRMRreceivedCounter", "objectInstance": "ricxappRMRReceived" }]}` + { "additionalField": "valueIgnored", "name": "ricxapp_RMR_Received", "objectName": "ricxappRMRreceivedCounter", "objectInstance": "ricxappRMRReceived", "counterId": "0011" }]}` m := metricsStringToInterfaceArray(metricsJSON) - appMetrics = parseMetricsRules(m, appMetrics) + appMetrics = parseMetricsRules(m, appMetrics, "SEP/XAPP", "X2", "1234", "60") assert.Len(t, appMetrics, 1) assert.Equal(t, "ricxappRMRreceivedCounter", appMetrics["ricxapp_RMR_Received"].ObjectName) assert.Equal(t, "ricxappRMRReceived", appMetrics["ricxapp_RMR_Received"].ObjectInstance) @@ -169,11 +194,11 @@ func TestParseMetricsRulesAdditionalFields(t *testing.T) { func TestParseMetricsRulesMissingFields(t *testing.T) { appMetrics := make(AppMetrics) metricsJSON := `{"metrics": [ - { "name": "ricxapp_RMR_Received", "objectName": "ricxappRMRreceivedCounter", "objectInstance": "ricxappRMRReceived" }, + { "name": "ricxapp_RMR_Received", "objectName": "ricxappRMRreceivedCounter", "objectInstance": "ricxappRMRReceived", "counterId": "0011" }, { "name": "ricxapp_RMR_ReceiveError", "objectInstance": "ricxappRMRReceiveError" }, - { "name": "ricxapp_RMR_Transmitted", "objectName": "ricxappRMRTransmittedCounter", "objectInstance": "ricxappRMRTransmitted" }]}` + { "name": "ricxapp_RMR_Transmitted", "objectName": "ricxappRMRTransmittedCounter", "objectInstance": "ricxappRMRTransmitted", "counterId": "0011" }]}` m := metricsStringToInterfaceArray(metricsJSON) - appMetrics = parseMetricsRules(m, appMetrics) + appMetrics = parseMetricsRules(m, appMetrics, "SEP/XAPP", "X2", "1234", "60") assert.Len(t, appMetrics, 2) assert.Equal(t, "ricxappRMRreceivedCounter", appMetrics["ricxapp_RMR_Received"].ObjectName) assert.Equal(t, "ricxappRMRTransmittedCounter", appMetrics["ricxapp_RMR_Transmitted"].ObjectName) @@ -184,11 +209,11 @@ func TestParseMetricsRulesMissingFields(t *testing.T) { func TestParseMetricsRulesDuplicateDefinitionIsIgnored(t *testing.T) { appMetrics := make(AppMetrics) metricsJSON := `{"metrics": [ - { "name": "ricxapp_RMR_Received", "objectName": "ricxappRMRreceivedCounter", "objectInstance": "ricxappRMRReceived" }, - { "name": "ricxapp_RMR_Received", "objectName": "ricxappRMRreceivedCounterXXX", "objectInstance": "ricxappRMRReceivedXXX" }, - { "name": "ricxapp_RMR_Transmitted", "objectName": "ricxappRMRTransmittedCounter", "objectInstance": "ricxappRMRTransmitted" }]}` + { "name": "ricxapp_RMR_Received", "objectName": "ricxappRMRreceivedCounter", "objectInstance": "ricxappRMRReceived", "counterId": "0011" }, + { "name": "ricxapp_RMR_Received", "objectName": "ricxappRMRreceivedCounterXXX", "objectInstance": "ricxappRMRReceivedXXX", "counterId": "0011" }, + { "name": "ricxapp_RMR_Transmitted", "objectName": "ricxappRMRTransmittedCounter", "objectInstance": "ricxappRMRTransmitted", "counterId": "0011" }]}` m := metricsStringToInterfaceArray(metricsJSON) - appMetrics = parseMetricsRules(m, appMetrics) + appMetrics = parseMetricsRules(m, appMetrics, "SEP/XAPP", "X2", "1234", "60") assert.Len(t, appMetrics, 2) assert.Equal(t, "ricxappRMRreceivedCounter", appMetrics["ricxapp_RMR_Received"].ObjectName) assert.Equal(t, "ricxappRMRReceived", appMetrics["ricxapp_RMR_Received"].ObjectInstance) @@ -197,13 +222,13 @@ func TestParseMetricsRulesDuplicateDefinitionIsIgnored(t *testing.T) { func TestParseMetricsRulesIncrementalFillOfAppMetrics(t *testing.T) { appMetrics := make(AppMetrics) metricsJSON1 := `{"metrics": [ - { "name": "ricxapp_RMR_Received", "objectName": "ricxappRMRreceivedCounter", "objectInstance": "ricxappRMRReceived" }]}` + { "name": "ricxapp_RMR_Received", "objectName": "ricxappRMRreceivedCounter", "objectInstance": "ricxappRMRReceived", "counterId": "0011" }]}` metricsJSON2 := `{"metrics": [ - { "name": "ricxapp_RMR_Transmitted", "objectName": "ricxappRMRTransmittedCounter", "objectInstance": "ricxappRMRTransmitted" }]}` + { "name": "ricxapp_RMR_Transmitted", "objectName": "ricxappRMRTransmittedCounter", "objectInstance": "ricxappRMRTransmitted", "counterId": "0011" }]}` m1 := metricsStringToInterfaceArray(metricsJSON1) m2 := metricsStringToInterfaceArray(metricsJSON2) - appMetrics = parseMetricsRules(m1, appMetrics) - appMetrics = parseMetricsRules(m2, appMetrics) + appMetrics = parseMetricsRules(m1, appMetrics, "SEP/XAPP", "X2", "1234", "60") + appMetrics = parseMetricsRules(m2, appMetrics, "SEP/XAPP", "X2", "1234", "60") assert.Len(t, appMetrics, 2) assert.Equal(t, "ricxappRMRreceivedCounter", appMetrics["ricxapp_RMR_Received"].ObjectName) assert.Equal(t, "ricxappRMRReceived", appMetrics["ricxapp_RMR_Received"].ObjectInstance)