2 ==================================================================================
3 Copyright (c) 2019 AT&T Intellectual Property.
4 Copyright (c) 2019 Nokia
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17 ==================================================================================
28 "gerrit.oran-osc.org/r/ric-plt/appmgr/pkg/appmgr"
29 "gerrit.oran-osc.org/r/ric-plt/appmgr/pkg/models"
30 "gerrit.oran-osc.org/r/ric-plt/appmgr/pkg/util"
33 var helmStatusOutput = `
34 LAST DEPLOYED: Sat Mar 9 06:50:45 2019
40 NAME READY STATUS RESTARTS AGE
41 dummy-xapp-8984fc9fd-bkcbp 1/1 Running 0 55m
42 dummy-xapp-8984fc9fd-l6xch 1/1 Running 0 55m
43 dummy-xapp-8984fc9fd-pp4hg 1/1 Running 0 55m
46 NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
47 dummy-xapp-dummy-xapp-chart ClusterIP 10.102.184.212 <none> 80/TCP 55m
49 ==> v1beta1/Deployment
50 NAME READY UP-TO-DATE AVAILABLE AGE
51 dummy-xapp 3/3 3 3 55m
54 var helListOutput = `Next: ""
57 Chart: dummy-xapp-chart-0.1.0
62 Updated: Mon Mar 11 06:55:05 2019
64 Chart: dummy-xapp-chart-0.1.0
69 Updated: Mon Mar 11 06:55:05 2019
76 Updated: Sun Mar 24 07:17:00 2019`
79 func TestMain(m *testing.M) {
81 appmgr.Logger.SetLevel(0)
87 func TestHelmStatus(t *testing.T) {
88 //NewHelm().SetCM(&ConfigMap{})
89 util.KubectlExec = func(args string) (out []byte, err error) {
90 return []byte("10.102.184.212"), nil
92 xapp, err := NewHelm().ParseStatus("dummy-xapp", helmStatusOutput)
94 t.Errorf("Helm install failed: %v", err)
99 if *x.Name != *xapp.Name || x.Status != xapp.Status || x.Version != xapp.Version {
100 t.Errorf("\n%v \n%v", *xapp.Name, *x.Name)
103 if *x.Instances[0].Name != *xapp.Instances[0].Name || x.Instances[0].Status != xapp.Instances[0].Status {
104 t.Errorf("\n1:%v 2:%v", *x.Instances[0].Name, *xapp.Instances[0].Name)
107 if x.Instances[0].IP != xapp.Instances[0].IP || x.Instances[0].Port != xapp.Instances[0].Port {
108 t.Errorf("\n1:%v 2:%v", x.Instances[0].IP, xapp.Instances[0].IP)
112 func TestHelmLists(t *testing.T) {
113 names, err := NewHelm().GetNames(helListOutput)
115 t.Errorf("Helm status failed: %v", err)
118 if !reflect.DeepEqual(names, []string{"dummy-xapp", "dummy-xapp2"}) {
119 t.Errorf("Helm status failed: %v", err)
123 func TestAddTillerEnv(t *testing.T) {
124 if NewHelm().AddTillerEnv() != nil {
125 t.Errorf("TestAddTillerEnv failed!")
129 func TestGetInstallArgs(t *testing.T) {
131 x := models.XappDescriptor{XappName: &name, Namespace: "ricxapp"}
133 expectedArgs := "install helm-repo/dummy-xapp --namespace=ricxapp --name=dummy-xapp"
134 if args := NewHelm().GetInstallArgs(x, false); args != expectedArgs {
135 t.Errorf("TestGetInstallArgs failed: expected %v, got %v", expectedArgs, args)
138 x.HelmVersion = "1.2.3"
139 expectedArgs = "install helm-repo/dummy-xapp --namespace=ricxapp --version=1.2.3 --name=dummy-xapp"
140 if args := NewHelm().GetInstallArgs(x, false); args != expectedArgs {
141 t.Errorf("TestGetInstallArgs failed: expected %v, got %v", expectedArgs, args)
144 x.ReleaseName = "ueec-xapp"
145 expectedArgs = "install helm-repo/dummy-xapp --namespace=ricxapp --version=1.2.3 --name=ueec-xapp"
146 if args := NewHelm().GetInstallArgs(x, false); args != expectedArgs {
147 t.Errorf("TestGetInstallArgs failed: expected %v, got %v", expectedArgs, args)
151 func getXappData() (x models.Xapp) {
152 //name1 := "dummy-xapp-8984fc9fd-l6xch"
153 //name2 := "dummy-xapp-8984fc9fd-pp4hg"
154 x = generateXapp("dummy-xapp", "deployed", "1.0", "dummy-xapp-8984fc9fd-bkcbp", "running", "service-ricxapp-dummy-xapp-rmr.ricxapp", "4560")
155 //x.Instances = append(x.Instances, x.Instances[0])
156 //x.Instances = append(x.Instances, x.Instances[0])
157 //x.Instances[1].Name = &name1
158 //x.Instances[2].Name = &name2
163 func generateXapp(name, status, ver, iname, istatus, ip, port string) (x models.Xapp) {
167 p, _ := strconv.Atoi(port)
168 var msgs appmgr.RtmData
170 instance := &models.XappInstance{
175 TxMessages: msgs.TxMessages,
176 RxMessages: msgs.RxMessages,
178 x.Instances = append(x.Instances, instance)