]> git.stg.codes - stg.git/blob - functest/test_services.sh
3323123f513c7b4b84ef351c00d63f74a4b524b0
[stg.git] / functest / test_services.sh
1 #!/bin/sh
2
3 BASEPATH=$1
4
5 SGCONFPATH="$BASEPATH/stg/projects/sgconf"
6
7 RES=`"$SGCONFPATH/sgconf" -s localhost -p 5555 -u admin -w 123456 --get-services`
8
9 if [ "$?" != "0" ]
10 then
11     printf "Failed to get services list. Result:\n$RES\n"
12     exit 0
13 fi
14
15 printf "Got services list:\n"
16
17 NAMES=""
18 OLDIFS=$IFS
19 IFS=$(printf "\n")
20 for LINE in $RES
21 do
22     printf -- "$LINE\n"
23     NAME=`printf "$LINE" | grep name`
24     if [ "$?" == "0" ]
25     then
26         NAMES="$NAMES\n"`printf "$NAME" | cut -d: -f2 | sed -e 's/^ *//' -e 's/ *$//'`
27     fi
28 done
29 IFS=$OLDIFS
30
31 printf "Names:\n$NAMES\n"
32
33 NUM=`printf "$NAMES" | wc -l`
34
35 printf -- "--------\n$NUM\n\n"
36
37 if [ "$NUM" != "0" ]
38 then
39     printf "Services list should be empty.\n"
40     exit 0
41 fi
42
43 RES=`"$SGCONFPATH/sgconf" -s localhost -p 5555 -u admin -w 123456 --add-service test`
44
45 if [ "$?" != "0" ]
46 then
47     printf "Failed to add new service. Result:\n$RES\n"
48     exit 0
49 fi
50
51 RES=`"$SGCONFPATH/sgconf" -s localhost -p 5555 -u admin -w 123456 --get-services`
52
53 if [ "$?" != "0" ]
54 then
55     printf "Failed to get services list. Result:\n$RES\n"
56     exit 0
57 fi
58
59 printf "Got services list:\n"
60
61 NAMES=""
62 OLDIFS=$IFS
63 IFS=$(printf "\n")
64 for LINE in $RES
65 do
66     printf -- "$LINE\n"
67     NAME=`printf "$LINE" | grep name`
68     if [ "$?" == "0" ]
69     then
70         NAMES="$NAMES\n"`printf "$NAME" | cut -d: -f2 | sed -e 's/^ *//' -e 's/ *$//'`
71     fi
72 done
73 IFS=$OLDIFS
74
75 printf "Names:\n$NAMES\n"
76
77 NUM=`printf "$NAMES" | wc -l`
78
79 printf -- "--------\n$NUM\n\n"
80
81 if [ "$NUM" != "1" ]
82 then
83     printf "Services list should have exactly one entry.\n"
84     exit 0
85 fi
86
87 RES=`"$SGCONFPATH/sgconf" -s localhost -p 5555 -u admin -w 123456 --del-service test`
88
89 if [ "$?" != "0" ]
90 then
91     printf "Failed to delete a service. Result:\n$RES\n"
92     exit 0
93 fi
94
95 RES=`"$SGCONFPATH/sgconf" -s localhost -p 5555 -u admin -w 123456 --get-services`
96
97 if [ "$?" != "0" ]
98 then
99     printf "Failed to get services list. Result:\n$RES\n"
100     exit 0
101 fi
102
103 printf "Got services list:\n"
104
105 NAMES=""
106 OLDIFS=$IFS
107 IFS=$(printf "\n")
108 for LINE in $RES
109 do
110     printf -- "$LINE\n"
111     NAME=`printf "$LINE" | grep name`
112     if [ "$?" == "0" ]
113     then
114         NAMES="$NAMES\n"`printf "$NAME" | cut -d: -f2 | sed -e 's/^ *//' -e 's/ *$//'`
115     fi
116 done
117 IFS=$OLDIFS
118
119 printf "Names:\n$NAMES\n"
120
121 NUM=`printf "$NAMES" | wc -l`
122
123 printf -- "--------\n$NUM\n\n"
124
125 if [ "$NUM" != "1" ]
126 then
127     printf "Services list should be empty.\n"
128     exit 0
129 fi