9e3a92c8ca21c1e3311501e76d0d465907636441
[src/qa-testdefinitions.git] / common / scripts / application-lifecycle.sh
1 #!/bin/sh
2
3 export TERM=dumb
4
5 while [ $# -ge 1 ]
6 do
7         case $1 in
8         -b)
9                 shift
10                 BASEURL=$1
11                 shift
12         ;;
13         *)
14                 echo "Unknown argument $1"
15                 exit 1
16         ;;
17         esac
18 done
19
20 if [ -z "$BASEURL" ]; then
21         echo "$0: missing BASEURL"
22         echo "Usage: $0 -b BASEURL"
23         exit 1
24 fi
25
26 wget -q $BASEURL -O index.html
27 if [ $? -ne 0 ];then
28         echo "ERROR: Cannot wget $BASEURL"
29         exit 1
30 fi
31
32 grep -o '[a-z-]*.wgt' index.html | sort | uniq |
33 while read wgtfile
34 do
35         WGTNAME=$(echo $wgtfile | sed 's,.wgt$,,')
36         echo "DEBUG: fetch $wgtfile"
37         wget -q $BASEURL/$wgtfile
38         if [ $? -ne 0 ];then
39                 echo "ERROR: wget from $BASEURL/$wgtfile"
40                 continue
41         fi
42
43         echo "DEBUG: analyse wgt file"
44         unzip $wgtfile
45         if [ $? -eq 0 ];then
46                 grep hidden config.xml
47                 if [ $? -eq 0 ];then
48                         echo "DEBUG: hidden package"
49                 else
50                         echo "DEBUG: not hidden package"
51                 fi
52         else
53                 echo "DEBUG: fail to unzip"
54         fi
55
56         echo "DEBUG: list current pkgs"
57         # TODO mktemp
58         LIST='list'
59         afm-util list --all > $LIST
60         if [ $? -ne 0 ];then
61                 echo "ERROR: afm-util list exit with error"
62                 continue
63         fi
64         if [ ! -s "$LIST" ];then
65                 echo "ERROR: afm-util list is empty"
66                 continue
67         fi
68
69         echo "DEBUG: check presence of $WGTNAME"
70         NAMEID=$(grep id\\\":\\\"${WGTNAME}@ $LIST | cut -d\" -f4 | cut -d\\ -f1)
71         if [ ! -z "$NAMEID" ];then
72                 echo "DEBUG: $WGTNAME already installed as $NAMEID"
73                 # need to kill then deinstall
74                 afm-util ps | grep -q $WGTNAME
75                 if [ $? -eq 0 ];then
76                         echo "DEBUG: kill $WGTNAME"
77                         afm-util kill $WGTNAME
78                         if [ $? -ne 0 ];then
79                                 echo "ERROR: afm-util kill"
80                                 lava-test-case afm-util-pre-kill-$WGTNAME --result fail
81                                 continue
82                         else
83                                 lava-test-case afm-util-pre-kill-$WGTNAME --result pass
84                         fi
85                 else
86                         echo "DEBUG: no need to kill $WGTNAME"
87                 fi
88
89                 echo "DEBUG: deinstall $WGTNAME"
90                 afm-util remove $NAMEID
91                 if [ $? -ne 0 ];then
92                         echo "ERROR: afm-util remove"
93                         lava-test-case afm-util-remove-$WGTNAME --result fail
94                         continue
95                 else
96                         lava-test-case afm-util-remove-$WGTNAME --result pass
97                 fi
98         else
99                 echo "DEBUG: $WGTNAME not installed"
100         fi
101         grep id $LIST
102
103         echo "DEBUG: install $wgtfile"
104         OUT="out"
105         afm-util install $wgtfile > $OUT
106         if [ $? -ne 0 ];then
107                 echo "ERROR: afm-util install"
108                 lava-test-case afm-util-install-$WGTNAME --result fail
109                 continue
110         else
111                 lava-test-case afm-util-install-$WGTNAME --result pass
112         fi
113         # message is like \"added\":\"mediaplayer@0.1\"
114         NAMEID=$(grep d\\\":\\\"${WGTNAME}@ $OUT | cut -d\" -f4 | cut -d\\ -f1)
115         if [ -z "$NAMEID" ];then
116                 echo "ERROR: Cannot get nameid"
117                 continue
118         fi
119         echo "DEBUG: $WGTNAME is installed as $NAMEID"
120
121         afm-util list --all > $LIST
122         if [ $? -ne 0 ];then
123                 echo "ERROR: afm-util list exit with error"
124                 continue
125         fi
126         if [ ! -s "$LIST" ];then
127                 echo "ERROR: afm-util list is empty"
128                 continue
129         fi
130         echo "DEBUG: Verify that $WGTNAME is installed"
131         grep -q $NAMEID $LIST
132         if [ $? -ne 0 ];then
133                 echo "ERROR: $WGTNAME is not installed"
134                 # for debugging, give full output
135                 echo "DEBUG: start of list"
136                 cat $LIST
137                 echo "DEBUG: end of list"
138         fi
139
140         afm-util info $NAMEID
141         if [ $? -ne 0 ];then
142                 echo "ERROR: afm-util info"
143                 lava-test-case afm-util-info-$WGTNAME --result fail
144         else
145                 lava-test-case afm-util-info-$WGTNAME --result pass
146         fi
147
148         echo "DEBUG: check if we see the package with systemctl list-units (before start)"
149         systemctl list-units --full | grep "afm.*$WGTNAME"
150         echo "DEBUG: check if we see the package with systemctl -a (before start)"
151         systemctl -a |grep "afm.*$WGTNAME"
152
153         echo "DEBUG: start $NAMEID"
154         afm-util start $NAMEID > "rid"
155         if [ $? -ne 0 ];then
156                 echo "ERROR: afm-util start"
157                 lava-test-case afm-util-start-$WGTNAME --result fail
158                 continue
159         else
160                 lava-test-case afm-util-start-$WGTNAME --result pass
161         fi
162
163         echo "DEBUG: check if we see the package with systemctl list-units (after start)"
164         systemctl list-units --full | grep "afm.*$WGTNAME"
165         echo "DEBUG: check if we see the package with systemctl -a (after start)"
166         systemctl -a |grep "afm.*$WGTNAME"
167
168         echo "DEBUG: Get RID for $NAMEID"
169         PSLIST="pslist"
170         afm-util ps > $PSLIST
171         if [ $? -ne 0 ];then
172                 echo "ERROR: afm-util ps"
173                 lava-test-case afm-util-ps-$WGTNAME --result fail
174                 continue
175         else
176                 cat $PSLIST
177                 lava-test-case afm-util-ps-$WGTNAME --result pass
178         fi
179         # TODO, compare RID with the list in $PSLIST"
180         RID="$(cat rid)"
181
182         echo "DEBUG: status $NAMEID ($RID)"
183         afm-util status $RID
184         if [ $? -ne 0 ];then
185                 echo "ERROR: afm-util status"
186                 lava-test-case afm-util-status-$WGTNAME --result fail
187                 continue
188         else
189                 lava-test-case afm-util-status-$WGTNAME --result pass
190         fi
191
192         echo "DEBUG: kill $NAMEID ($RID)"
193         afm-util kill $NAMEID
194         if [ $? -ne 0 ];then
195                 echo "ERROR: afm-util kill"
196                 lava-test-case afm-util-kill-$WGTNAME --result fail
197                 continue
198         else
199                 lava-test-case afm-util-kill-$WGTNAME --result pass
200         fi
201
202         echo "DEBUG: start2 $NAMEID"
203         afm-util start $NAMEID
204         if [ $? -ne 0 ];then
205                 echo "ERROR: afm-util start2"
206                 lava-test-case afm-util-start2-$WGTNAME --result fail
207                 continue
208         else
209                 lava-test-case afm-util-start2-$WGTNAME --result pass
210         fi
211 done