package main
import (
- "testing"
- "reflect"
- "errors"
"encoding/json"
+ "errors"
"log"
+ "reflect"
+ "testing"
)
var helmSearchOutput = `
`
type ConfigSample struct {
- Level int
- Host string
+ Level int
+ Host string
}
type MockedConfigMapper struct {
return
}
-func (cm *MockedConfigMapper) CreateConfigMap(r XAppConfig) (errList []CMError, err error){
+func (cm *MockedConfigMapper) CreateConfigMap(r XAppConfig) (errList []CMError, err error) {
return
}
return []byte(kubectlConfigmapOutput), nil
}
- result := cm.GetMessages("dummy-xapp")
+ result := cm.GetMessages("dummy-xapp")
if !reflect.DeepEqual(result, expectedMsgs) {
t.Errorf("TestGetMessages failed: expected: %v, got: %v", expectedMsgs, result)
}
cm := ConfigMap{}
if cm.GetNamespace("pltxapp") != "pltxapp" {
- t.Errorf("getNamespace failed!")
+ t.Errorf("getNamespace failed!")
}
- if cm.GetNamespace("") != "ricxapp" {
- t.Errorf("getNamespace failed!")
+ if cm.GetNamespace("") != "default" {
+ t.Errorf("getNamespace failed!")
}
}
}
log.Println("Feedbacks: ", feedback)
-}
\ No newline at end of file
+}
return
}
+func (h *Helm) GetEndpointInfo(name string) (ip string, port int) {
+ args := fmt.Sprintf(" get endpoints -o=jsonpath='{.subsets[*].addresses[*].ip}' %s -n %s", name, h.cm.GetNamespace(""))
+ out, err := KubectlExec(args)
+ if err != nil {
+ return
+ }
+
+ return string(out), 4560
+}
+
func (h *Helm) GetNames(out string) (names []string, err error) {
re := regexp.MustCompile(`Name: .*`)
result := re.FindAllStringSubmatch(out, -1)
}
func (h *Helm) FillInstanceData(name string, out string, xapp *Xapp, msgs MessageTypes) {
- ip, port := h.GetAddress(out)
+ ip, port := h.GetEndpointInfo(name)
+ if ip == "" {
+ Logger.Info("Endpoint IP address not found, using CluserIP")
+ ip, _ = h.GetAddress(out)
+ }
var tmp string
r := regexp.MustCompile(`.*(?s)(Running|Pending|Succeeded|Failed|Unknown).*?\r?\n\r?\n`)
fmt.Sscanf(v[0], "%s %s %s", &x.Name, &tmp, &x.Status)
x.Status = strings.ToLower(x.Status)
x.Ip = ip
- x.Port, _ = strconv.Atoi(strings.Split(port, "/")[0])
+ x.Port = port
x.TxMessages = msgs.TxMessages
x.RxMessages = msgs.RxMessages
xapp.Instances = append(xapp.Instances, x)
package main
import (
- "testing"
- "reflect"
+ "reflect"
+ "testing"
)
-
var helmStatusOutput = `
LAST DEPLOYED: Sat Mar 9 06:50:45 2019
NAMESPACE: default
Status: DEPLOYED
Updated: Sun Mar 24 07:17:00 2019`
-
var h = Helm{}
func TestHelmStatus(t *testing.T) {
h.SetCM(&ConfigMap{})
+ KubectlExec = func(args string) (out []byte, err error) {
+ return []byte("10.102.184.212"), nil
+ }
xapp, err := h.ParseStatus("dummy-xapp", helmStatusOutput)
- if err != nil {
- t.Errorf("Helm install failed: %v", err)
+ if err != nil {
+ t.Errorf("Helm install failed: %v", err)
}
- x := getXappData()
- xapp.Version = "1.0"
+ x := getXappData()
+ xapp.Version = "1.0"
- if !reflect.DeepEqual(xapp, x) {
- t.Errorf("\n%v \n%v", xapp, x)
- }
+ if !reflect.DeepEqual(xapp, x) {
+ t.Errorf("\n%v \n%v", xapp, x)
+ }
}
func TestHelmLists(t *testing.T) {
- names, err := h.GetNames(helListOutput)
- if err != nil {
- t.Errorf("Helm status failed: %v", err)
+ names, err := h.GetNames(helListOutput)
+ if err != nil {
+ t.Errorf("Helm status failed: %v", err)
}
- if !reflect.DeepEqual(names, []string{"dummy-xapp", "dummy-xapp2"}) {
- t.Errorf("Helm status failed: %v", err)
- }
+ if !reflect.DeepEqual(names, []string{"dummy-xapp", "dummy-xapp2"}) {
+ t.Errorf("Helm status failed: %v", err)
+ }
}
func TestAddTillerEnv(t *testing.T) {
- if addTillerEnv() != nil {
- t.Errorf("TestAddTillerEnv failed!")
+ if addTillerEnv() != nil {
+ t.Errorf("TestAddTillerEnv failed!")
}
}
expectedArgs := "install helm-repo/dummy-xapp --name=dummy-xapp --namespace=ricxapp"
if args := getInstallArgs(x, false); args != expectedArgs {
- t.Errorf("TestGetInstallArgs failed: expected %v, got %v", expectedArgs, args)
+ t.Errorf("TestGetInstallArgs failed: expected %v, got %v", expectedArgs, args)
}
x.ImageRepo = "localhost:5000"
expectedArgs = expectedArgs + " --set global.repository=" + "localhost:5000"
if args := getInstallArgs(x, false); args != expectedArgs {
- t.Errorf("TestGetInstallArgs failed: expected %v, got %v", expectedArgs, args)
+ t.Errorf("TestGetInstallArgs failed: expected %v, got %v", expectedArgs, args)
}
x.ServiceName = "xapp"
expectedArgs = expectedArgs + " --set ricapp.service.name=" + "xapp"
if args := getInstallArgs(x, false); args != expectedArgs {
- t.Errorf("TestGetInstallArgs failed: expected %v, got %v", expectedArgs, args)
+ t.Errorf("TestGetInstallArgs failed: expected %v, got %v", expectedArgs, args)
}
x.ServiceName = "xapp"
expectedArgs = expectedArgs + " --set ricapp.appconfig.override=dummy-xapp-appconfig"
if args := getInstallArgs(x, true); args != expectedArgs {
- t.Errorf("TestGetInstallArgs failed: expected %v, got %v", expectedArgs, args)
+ t.Errorf("TestGetInstallArgs failed: expected %v, got %v", expectedArgs, args)
}
}
func getXappData() (x Xapp) {
- x = generateXapp("dummy-xapp", "deployed", "1.0", "dummy-xapp-8984fc9fd-bkcbp", "running", "10.102.184.212", "80")
- x.Instances = append(x.Instances, x.Instances[0])
- x.Instances = append(x.Instances, x.Instances[0])
- x.Instances[1].Name = "dummy-xapp-8984fc9fd-l6xch"
- x.Instances[2].Name = "dummy-xapp-8984fc9fd-pp4hg"
+ x = generateXapp("dummy-xapp", "deployed", "1.0", "dummy-xapp-8984fc9fd-bkcbp", "running", "10.102.184.212", "4560")
+ x.Instances = append(x.Instances, x.Instances[0])
+ x.Instances = append(x.Instances, x.Instances[0])
+ x.Instances[1].Name = "dummy-xapp-8984fc9fd-l6xch"
+ x.Instances[2].Name = "dummy-xapp-8984fc9fd-pp4hg"
- return x
+ return x
}
-
package main
import (
+ mdclog "gerrit.o-ran-sc.org/r/com/golog"
"net/http"
"time"
- mdclog "gerrit.o-ran-sc.org/r/com/golog"
)
type Log struct {
}
func (l *Log) Error(pattern string, args ...interface{}) {
- l.SetMdc("time", time.Now().Format("2019-01-02 15:04:05"))
+ l.SetMdc("time", time.Now().Format(time.RFC3339))
l.logger.Error(pattern, args...)
}
func (l *Log) Warn(pattern string, args ...interface{}) {
- l.SetMdc("time", time.Now().Format("2019-01-02 15:04:05"))
+ l.SetMdc("time", time.Now().Format(time.RFC3339))
l.logger.Warning(pattern, args...)
}
func (l *Log) Info(pattern string, args ...interface{}) {
- l.SetMdc("time", time.Now().Format("2019-01-02 15:04:05"))
+ l.SetMdc("time", time.Now().Format(time.RFC3339))
l.logger.Info(pattern, args...)
}
func (l *Log) Debug(pattern string, args ...interface{}) {
- l.SetMdc("time", time.Now().Format("2019-01-02 15:04:05"))
+ l.SetMdc("time", time.Now().Format(time.RFC3339))
l.logger.Debug(pattern, args...)
}