Fix event config: VNFName, ReportingEntityName and ID 17/1017/1
authorKatri Turunen <katri.turunen@nokia.com>
Thu, 26 Sep 2019 09:46:07 +0000 (12:46 +0300)
committerKatri Turunen <katri.turunen@nokia.com>
Thu, 26 Sep 2019 09:47:50 +0000 (12:47 +0300)
Vesmgr configures the Vespa event with the following values:
- VNFName: Value from env variable VESMGR_VNFNAME,
           default, if the env variable does not exist: Vespa
- ReportingEntityName: Vespa
- ReportingEntityId: system UUID read from
                     /sys/class/dmi/id/product_uuid

Change-Id: Ib25d7271be363236f24295df9d5f4e940a741360
Signed-off-by: Katri Turunen <katri.turunen@nokia.com>
README.md
cmd/vesmgr/config.go
cmd/vesmgr/config_test.go
container-tag.yaml

index 96a22cc..06b2cca 100644 (file)
--- a/README.md
+++ b/README.md
@@ -51,6 +51,7 @@ JSON schema v28.4.1:
 
 The VESPA manager container requires the following environment variables:
 
+* VESMGR_VNFNAME - VNF name as a string. Default: Vespa.
 * VESMGR_HB_INTERVAL - VES heartbeat interval as a string. For example: 30s.
 * VESMGR_MEAS_INTERVAL - Measurement interval as a string. For example: 60s.
 * VESMGR_PROMETHEUS_ADDR - Prometheus address. For example: http://127.0.0.1:123
index 8301b0c..77b4ca8 100644 (file)
@@ -20,22 +20,44 @@ package main
 import (
        "encoding/json"
        "io"
+       "io/ioutil"
        "os"
        "strconv"
+       "strings"
        "time"
 
        "gopkg.in/yaml.v2"
 )
 
+const defaultReportingEntityID = "00000000-0000-0000-0000-000000000000"
+const defaultVNFName = "Vespa"
+
+func readSystemUUID() string {
+       data, err := ioutil.ReadFile("/sys/class/dmi/id/product_uuid")
+       if err != nil {
+               return defaultReportingEntityID
+       }
+       return strings.TrimSpace(string(data))
+}
+
+func getVNFName() string {
+       VNFName := os.Getenv("VESMGR_VNFNAME")
+       if VNFName == "" {
+               return defaultVNFName
+       }
+       return VNFName
+}
+
 func basicVespaConf() VESAgentConfiguration {
        var vespaconf = VESAgentConfiguration{
                DataDir: "/tmp/data",
                Debug:   false,
                Event: EventConfiguration{
-                       VNFName:           "vespa-demo",                          // XXX
-                       ReportingEntityID: "1af5bfa9-40b4-4522-b045-40e54f0310f", // XXX
-                       MaxSize:           2000000,
-                       NfNamingCode:      "hsxp",
+                       VNFName:             getVNFName(),
+                       ReportingEntityName: "Vespa",
+                       ReportingEntityID:   readSystemUUID(),
+                       MaxSize:             2000000,
+                       NfNamingCode:        "hsxp",
                        NfcNamingCodes: []NfcNamingCode{
                                NfcNamingCode{
                                        Type:  "oam",
@@ -50,6 +72,8 @@ func basicVespaConf() VESAgentConfiguration {
                        MaxMissed:     2,
                },
                Measurement: MeasurementConfiguration{
+                       // Domain abbreviation has to be set to “Mvfs” for VES 5.3,
+                       // and to “Measurement” for later VES interface versions.
                        DomainAbbreviation:   "Mvfs",
                        MaxBufferingDuration: time.Hour,
                        Prometheus: PrometheusConfig{
index 76793a1..7a07e38 100644 (file)
@@ -34,6 +34,13 @@ 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.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 +48,15 @@ func TestBasicConfigContainsCorrectValues(t *testing.T) {
        testBaseConf(t, vesconf)
 }
 
+func TestBasicConfigContainsCorrectVNFName(t *testing.T) {
+       os.Setenv("VESMGR_VNFNAME", "VNF-111")
+       vesconf := basicVespaConf()
+       assert.Equal(t, vesconf.Event.VNFName, "VNF-111")
+       os.Unsetenv("VESMGR_VNFNAME")
+}
+
 func TestCollectorConfiguration(t *testing.T) {
+       os.Unsetenv("VESMGR_VNFNAME")
        os.Setenv("VESMGR_PRICOLLECTOR_USER", "user123")
        os.Setenv("VESMGR_PRICOLLECTOR_PASSWORD", "pass123")
        os.Setenv("VESMGR_PRICOLLECTOR_PASSPHRASE", "phrase123")
@@ -65,6 +80,7 @@ func TestCollectorConfiguration(t *testing.T) {
 }
 
 func TestCollectorConfigurationWhenEnvironmentVariablesAreNotDefined(t *testing.T) {
+       os.Unsetenv("VESMGR_VNFNAME")
        os.Unsetenv("VESMGR_PRICOLLECTOR_USER")
        os.Unsetenv("VESMGR_PRICOLLECTOR_PASSWORD")
        os.Unsetenv("VESMGR_PRICOLLECTOR_PASSPHRASE")
index fa6e83d..81c78cb 100644 (file)
@@ -1,4 +1,4 @@
 # The Jenkins job uses this string for the tag in the image name
 # for example nexus3.o-ran-sc.org:10004/my-image-name:0.0.1
 ---
-tag: 0.0.5
+tag: 0.0.6