Merge lp:~doanac/ubuntu-test-cases/get-opts into lp:ubuntu-test-cases/touch

Proposed by Andy Doan
Status: Merged
Approved by: Paul Larson
Approved revision: 26
Merged at revision: 25
Proposed branch: lp:~doanac/ubuntu-test-cases/get-opts
Merge into: lp:ubuntu-test-cases/touch
Diff against target: 316 lines (+129/-41)
6 files modified
jenkins/templates/touch-autopilot-base.xml.jinja2 (+1/-1)
jenkins/templates/touch-install-and-boot.xml.jinja2 (+4/-4)
scripts/get-adb-id (+1/-0)
scripts/jenkins.sh (+67/-21)
scripts/provision.sh (+55/-14)
utils/host/adb-shell (+1/-1)
To merge this branch: bzr merge lp:~doanac/ubuntu-test-cases/get-opts
Reviewer Review Type Date Requested Status
Paul Larson Approve
Andy Doan (community) Needs Resubmitting
Review via email: mp+186442@code.launchpad.net

Description of the change

Converts jenkins.sh and provision.sh to use getopts rather than environment variables.

NOTE: After merging this branch, we need to re-run setup_jenkins.py so that jobs call the scripts properly.

To post a comment you must log in.
Revision history for this message
Paul Larson (pwlars) wrote :

114 +if [ -z $ANDROID_SERIAL ] ; then
115 + echo "ERROR: No android serial specified"
116 + usage
117 + exit 1
118 +fi

Do we really *need* to specify the serial? If there's just one device, or even if the environment variable is set, adb should "just work" right?

Revision history for this message
Paul Larson (pwlars) wrote :

I should clarify that... when testing things locally, it's sorta nice to be able to run without checking and specifying my adb id, if I just have a single device attached.

Revision history for this message
Joe Talbott (joetalbott) wrote :

On Thu, Sep 19, 2013 at 04:11:19AM -0000, Paul Larson wrote:
> I should clarify that... when testing things locally, it's sorta nice to be able to run without checking and specifying my adb id, if I just have a single device attached.

+1

> --
> https://code.launchpad.net/~doanac/ubuntu-test-cases/get-opts/+merge/186442
> Your team Ubuntu Test Case Developers is requested to review the proposed merge of lp:~doanac/ubuntu-test-cases/get-opts into lp:ubuntu-test-cases/touch.

Revision history for this message
Andy Doan (doanac) wrote :

On 09/19/2013 08:33 AM, Joe Talbott wrote:
> On Thu, Sep 19, 2013 at 04:11:19AM -0000, Paul Larson wrote:
>> >I should clarify that... when testing things locally, it's sorta nice to be able to run without checking and specifying my adb id, if I just have a single device attached.
> +1
>
I'll see what I can do.

26. By Andy Doan

make "-s ANDROID_SERIAL" optional

This also simplifies the use of adb commands in our scripts since
we can assume ANDROID_SERIAL is exported if/when its required.

Revision history for this message
Andy Doan (doanac) wrote :

The last commit addresses the concerns of Joe and Paul.

Paul - I'll let you merge/deploy the changes whenever you are ready for them.

review: Needs Resubmitting
Revision history for this message
Paul Larson (pwlars) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'jenkins/templates/touch-autopilot-base.xml.jinja2'
2--- jenkins/templates/touch-autopilot-base.xml.jinja2 2013-09-13 18:05:45 +0000
3+++ jenkins/templates/touch-autopilot-base.xml.jinja2 2013-09-19 15:29:16 +0000
4@@ -14,7 +14,7 @@
5
6 {% block apptest %}{% endblock %}
7
8-FROM_HOST=1 ${BZRDIR}/scripts/jenkins.sh
9+${BZRDIR}/scripts/jenkins.sh -s $ANDROID_SERIAL -a $APP
10 </command>
11 {% endblock %}
12
13
14=== modified file 'jenkins/templates/touch-install-and-boot.xml.jinja2'
15--- jenkins/templates/touch-install-and-boot.xml.jinja2 2013-09-18 15:29:48 +0000
16+++ jenkins/templates/touch-install-and-boot.xml.jinja2 2013-09-19 15:29:16 +0000
17@@ -15,14 +15,14 @@
18
19 {% include "touch-setup.xml.jinja2" %}
20
21-{% if system_image %}
22-export TOUCH_IMAGE=--ubuntu-bootstrap
23+{% if not system_image %}
24+IMAGE_OPT=-D
25 {% endif %}
26 #Wait for images to actually show up on cdimage
27 sleep 300
28-${BZRDIR}/scripts/provision.sh
29+${BZRDIR}/scripts/provision.sh -s $ANDROID_SERIAL $IMAGE_OPT
30
31-APP="install-and-boot" FROM_HOST=1 ${BZRDIR}/scripts/jenkins.sh
32+${BZRDIR}/scripts/jenkins.sh -s $ANDROID_SERIAL -a install-and-boot
33 </command>
34 {% endblock %}
35
36
37=== modified file 'scripts/get-adb-id'
38--- scripts/get-adb-id 2013-08-30 17:45:20 +0000
39+++ scripts/get-adb-id 2013-09-19 15:29:16 +0000
40@@ -20,6 +20,7 @@
41 "manta-02":"R32D102RPPK",
42 "manta-04":"R32D203DDZR",
43 "manta-05":"R32D203DMBY",
44+"mako-doanac": "00963b879612414a",
45 }
46
47 name = sys.argv[1]
48
49=== modified file 'scripts/jenkins.sh'
50--- scripts/jenkins.sh 2013-09-10 13:27:49 +0000
51+++ scripts/jenkins.sh 2013-09-19 15:29:16 +0000
52@@ -1,11 +1,6 @@
53 #!/bin/bash
54
55 ## This is the script jenkins should run to execute various touch applications
56-## Intersting environment variables that must be set:
57-## ANDROID_SERIAL - specify another android device
58-## APP - the name of the app to test, ie share_app_autopilot
59-## QUICK - if set, skips the reboot and wait-for-network logic
60-## FROM_HOST - if set, runs the test from the host instead of the target
61
62 set -e
63
64@@ -15,11 +10,22 @@
65 UTAHFILE=${RESDIR}/utah.yaml
66 UTAH_PHABLET_CMD="${UTAH_PHABLET_CMD-/usr/share/utah/examples/run_utah_phablet.py}"
67
68-ANDROID_SERIAL="${ANDROID_SERIAL-015d1884b20c1c0f}" #doanac's nexus7 at home
69-
70-TESTSUITE_HOST=$(readlink -f ${BASEDIR}/tests/${APP})
71-TESTSUITE_TARGET_BASE=/tmp/tests
72-TESTSUITE_TARGET=${TESTSUITE_TARGET_BASE}/$(basename ${TESTSUITE_HOST})
73+
74+usage() {
75+ cat <<EOF
76+usage: $0 -a APP [-s ANDROID_SERIAL] [-T] [-Q]
77+
78+Provisions the given device with the latest build
79+
80+OPTIONS:
81+ -h Show this message
82+ -s Specify the serial of the device to install
83+ -a The application under the "tests" directory to test
84+ -T Run the utah test from the target instead of the host
85+ -Q "Quick" don't do a reboot of the device before running the test
86+
87+EOF
88+}
89
90 cleanup() {
91 set +e
92@@ -35,7 +41,6 @@
93 adb shell cp /home/phablet/bin/* /usr/local/bin/
94
95 ${UTAH_PHABLET_CMD} \
96- -s ${ANDROID_SERIAL} \
97 --results-dir ${RESDIR} \
98 --skip-install --skip-network --skip-utah \
99 --pull /var/crash \
100@@ -44,16 +49,16 @@
101 }
102
103 test_from_host() {
104- export ANDROID_SERIAL # need for utils/hosts scripts
105-
106 export PATH=${BASEDIR}/utils/host:${PATH}
107
108 # allow for certain commands to run from host/target
109 # see unity8-autopilot/ts_control for example
110 export TARGET_PREFIX=adb-shell
111
112+ [ -z $ANDROID_SERIAL ] || ADBOPTS="-s $ANDROID_SERIAL"
113+
114 sudo TARGET_PREFIX=$TARGET_PREFIX PATH="${PATH}" ${UTAH_PHABLET_CMD} \
115- -s ${ANDROID_SERIAL} \
116+ ${ADBOPTS} \
117 --from-host \
118 --results-dir ${RESDIR} \
119 --skip-install --skip-network --skip-utah \
120@@ -68,8 +73,8 @@
121
122 # print the build date so the jenkins job can use it as the
123 # build description
124- adb -s ${ANDROID_SERIAL} pull /var/log/installer/media-info ${RESDIR}
125- BUILDID=$(adb -s ${ANDROID_SERIAL} shell cat /home/phablet/.ci-version)
126+ adb pull /var/log/installer/media-info ${RESDIR}
127+ BUILDID=$(adb shell cat /home/phablet/.ci-version)
128 echo "= TOUCH IMAGE VERSION:$BUILDID"
129
130 adb shell "top -n1 -b" > ${RESDIR}/top.log
131@@ -78,19 +83,19 @@
132 adb shell 'rm -f /var/crash/*'
133 if [ -z $QUICK ] ; then
134 # get the phone in sane place
135- adb -s ${ANDROID_SERIAL} reboot
136+ adb reboot
137 # sometimes reboot doesn't happen fast enough, so add a little
138 # delay to help ensure its actually rebooted and we didn't just
139 # connect back to the device before it rebooted
140- adb -s ${ANDROID_SERIAL} wait-for-device
141+ adb wait-for-device
142 sleep 5
143- adb -s ${ANDROID_SERIAL} wait-for-device
144- phablet-network -s ${ANDROID_SERIAL} --skip-setup
145+ adb wait-for-device
146+ phablet-network --skip-setup
147 else
148 echo "SKIPPING phone reboot..."
149 fi
150
151- if [ -z $FROM_HOST ] ; then
152+ if [ ! -z $FROM_TARGET ] ; then
153 echo "launching test on the target...."
154 test_from_target
155 else
156@@ -113,5 +118,46 @@
157 exit $EXITCODE
158 }
159
160+while getopts s:a:TQh opt; do
161+ case $opt in
162+ h)
163+ usage
164+ exit 0
165+ ;;
166+ s)
167+ export ANDROID_SERIAL=$OPTARG
168+ ;;
169+ a)
170+ APP=$OPTARG
171+ ;;
172+ Q)
173+ QUICK=1
174+ ;;
175+ T)
176+ FROM_TARGET=1
177+ ;;
178+ esac
179+done
180+
181+if [ -z $ANDROID_SERIAL ] ; then
182+ # ensure we only have one device attached
183+ lines=$(adb devices | wc -l)
184+ if [ $lines -gt 3 ] ; then
185+ echo "ERROR: More than one device attached, please use -s option"
186+ echo
187+ usage
188+ exit 1
189+ fi
190+fi
191+if [ -z $APP ] ; then
192+ echo "ERROR: No app specified"
193+ usage
194+ exit 1
195+fi
196+
197+TESTSUITE_HOST=$(readlink -f ${BASEDIR}/tests/${APP})
198+TESTSUITE_TARGET_BASE=/tmp/tests
199+TESTSUITE_TARGET=${TESTSUITE_TARGET_BASE}/$(basename ${TESTSUITE_HOST})
200+
201 trap cleanup TERM INT EXIT
202 main
203
204=== modified file 'scripts/provision.sh'
205--- scripts/provision.sh 2013-09-10 13:27:49 +0000
206+++ scripts/provision.sh 2013-09-19 15:29:16 +0000
207@@ -1,41 +1,82 @@
208 #!/bin/bash
209
210 ## This is the script jenkins should run to provision a device in the lab
211-## Intersting environment variables that must be set:
212-## ANDROID_SERIAL - specify another android device
213-## NETWORK_FILE - an alternative network file if you aren't in the lab
214-## TOUCH_IMAGE=--ubuntu-bootstrap (provision with read-only system image)
215
216 set -e
217-set -x
218
219 BASEDIR=$(dirname $(readlink -f $0))
220
221 RESDIR=`pwd`/clientlogs
222+
223 UTAH_PHABLET_CMD="${UTAH_PHABLET_CMD-/usr/share/utah/examples/run_utah_phablet.py}"
224-
225-ANDROID_SERIAL="${ANDROID_SERIAL-015d1884b20c1c0f}" #doanac's nexus7 at home
226 NETWORK_FILE="${NETWORK_FILE-/home/ubuntu/magners-wifi}"
227
228+IMAGE_OPT="--ubuntu-bootstrap"
229+
230+usage() {
231+cat <<EOF
232+usage: $0 [-s ANDROID_SERIAL] [-n NETWORK_FILE] [-D]
233+
234+Provisions the given device with the latest build
235+
236+OPTIONS:
237+ -h Show this message
238+ -s Specify the serial of the device to install
239+ -n Select network file
240+ -D Use a "cdimage-touch" ie developer image rather than an ubuntu-system
241+
242+EOF
243+}
244+
245+while getopts s:n:Dh opt; do
246+ case $opt in
247+ h)
248+ usage
249+ exit 0
250+ ;;
251+ n)
252+ NETWORK_FILE=$OPTARG
253+ ;;
254+ s)
255+ export ANDROID_SERIAL=$OPTARG
256+ ;;
257+ D)
258+ IMAGE_OPT=""
259+ ;;
260+ esac
261+done
262+
263+if [ -z $ANDROID_SERIAL ] ; then
264+ # ensure we only have one device attached
265+ lines=$(adb devices | wc -l)
266+ if [ $lines -gt 3 ] ; then
267+ echo "ERROR: More than one device attached, please use -s option"
268+ echo
269+ usage
270+ exit 1
271+ fi
272+fi
273+
274+set -x
275 rm -rf clientlogs
276 mkdir clientlogs
277
278-${UTAH_PHABLET_CMD} -s ${ANDROID_SERIAL} --results-dir ${RESDIR} --network-file=${NETWORK_FILE} ${TOUCH_IMAGE}
279+${UTAH_PHABLET_CMD} --results-dir ${RESDIR} --network-file=${NETWORK_FILE} ${IMAGE_OPT}
280
281 # mark the version we installed in /home/phablet/.ci-version
282-if [ -n "$TOUCH_IMAGE" ]; then
283- DEVICE_TYPE=$(adb -s ${ANDROID_SERIAL} shell "getprop ro.cm.device" |tr -d '\r')
284+if [ -n "$IMAGE_OPT" ] ; then
285+ DEVICE_TYPE=$(adb shell "getprop ro.cm.device" |tr -d '\r')
286 bzr export si-utils lp:~ubuntu-system-image/ubuntu-system-image/server/utils
287 IMAGEVER=$(si-utils/check-latest ${DEVICE_TYPE} |sed -n 's/Current full image: \([0-9]*\).*ubuntu=\([0-9\.]*\),.*=\([0-9\.]*\))/\1:\2:\3/p')
288 rm -rf si-utils
289 else
290- IMAGEVER=$(adb -s ${ANDROID_SERIAL} shell "cat /var/log/installer/media-info |sed 's/.*(\([0-9\.]*\))/\1/'")
291+ IMAGEVER=$(adb shell "cat /var/log/installer/media-info |sed 's/.*(\([0-9\.]*\))/\1/'")
292 fi
293-adb -s ${ANDROID_SERIAL} shell "echo '${IMAGEVER}' > /home/phablet/.ci-version"
294+adb shell "echo '${IMAGEVER}' > /home/phablet/.ci-version"
295
296 # get our target-based utilities into our PATH
297-adb -s ${ANDROID_SERIAL} push ${BASEDIR}/../utils/target /home/phablet/bin
298+adb push ${BASEDIR}/../utils/target /home/phablet/bin
299
300 # ensure the "edges intro" is disabled so that it doesn't cause noise
301 # in the system
302-adb -s ${ANDROID_SERIAL} shell dbus-send --system --print-reply --dest=org.freedesktop.Accounts /org/freedesktop/Accounts/User32011 org.freedesktop.DBus.Properties.Set string:com.canonical.unity.AccountsService string:demo-edges variant:boolean:false
303+adb shell dbus-send --system --print-reply --dest=org.freedesktop.Accounts /org/freedesktop/Accounts/User32011 org.freedesktop.DBus.Properties.Set string:com.canonical.unity.AccountsService string:demo-edges variant:boolean:false
304
305=== modified file 'utils/host/adb-shell'
306--- utils/host/adb-shell 2013-08-30 17:40:26 +0000
307+++ utils/host/adb-shell 2013-09-19 15:29:16 +0000
308@@ -10,7 +10,7 @@
309 pat='ADB_RC=([[:digit:]]+)'
310
311 {
312- adb -s $ANDROID_SERIAL shell "$* ; echo ADB_RC=\$?"
313+ adb shell "$* ; echo ADB_RC=\$?"
314 } | while read line; do
315 echo $line
316 if [[ $line =~ $pat ]] ; then

Subscribers

People subscribed via source and target branches