@@ -48,26 +48,30 @@ function create_containers() {
4848 local platform_name=$( cat ${devices} | grep " $udid " | cut -d ' |' -f 2)
4949 # echo "platform_name: $platform_name"
5050
51- local device_adb_port =$( cat ${devices} | grep " $udid " | cut -d ' |' -f 4)
52- # echo "device_adb_port : $device_adb_port "
51+ local location =$( cat ${devices} | grep " $udid " | cut -d ' |' -f 4)
52+ # echo "location : $location "
5353
54- local stf_min_port =$( cat ${devices} | grep " $udid " | cut -d ' |' -f 5)
55- # echo "stf_min_port : $stf_min_port "
54+ local appium_port =$( cat ${devices} | grep " $udid " | cut -d ' |' -f 5)
55+ # echo "appium_port : $appium_port "
5656
57- local stf_max_port =$( cat ${devices} | grep " $udid " | cut -d ' |' -f 6)
58- # echo "stf_max_port : $stf_max_port "
57+ local device_adb_port =$( cat ${devices} | grep " $udid " | cut -d ' |' -f 6)
58+ # echo "device_adb_port : $device_adb_port "
5959
6060 local proxy_port=$( cat ${devices} | grep " $udid " | cut -d ' |' -f 7)
6161 # echo "proxy_port: $proxy_port"
6262
63- local appium_port=$( cat ${devices} | grep " $udid " | cut -d ' |' -f 8)
64- # echo "appium_port: $appium_port"
63+ local server_proxy_port=$( cat ${devices} | grep " $udid " | cut -d ' |' -f 8)
64+ # echo "server_proxy_port: $server_proxy_port"
65+
66+ local stf_min_port=$( cat ${devices} | grep " $udid " | cut -d ' |' -f 9)
67+ # echo "stf_min_port: $stf_min_port"
6568
66- local wireless=$( cat ${devices} | grep " $udid " | cut -d ' |' -f 9)
69+ local stf_max_port=$( cat ${devices} | grep " $udid " | cut -d ' |' -f 10)
70+ # echo "stf_max_port: $stf_max_port"
71+
72+ local wireless=$( cat ${devices} | grep " $udid " | cut -d ' |' -f 11)
6773 # echo "wireless: $wireless"
6874
69- local server_proxy_port=$( cat ${devices} | grep " $udid " | cut -d ' |' -f 12)
70- # echo "server_proxy_port: $server_proxy_port"
7175
7276 # without 'block_global=false' mitmproxy does not want to accept requests from devices
7377 # --set confdir allows to provide custom folder with CA Authority certificates
@@ -150,7 +154,7 @@ function create_containers() {
150154 -e STF_PROVIDER_DEVICE_NAME=" ${device_name} " \
151155 -e DEVICE_UDID=" $STF_DEVICE_UDID " \
152156 -e STF_PROVIDER_HOST={{ STF_PROVIDER_HOST }} \
153- -e STF_PROVIDER_NAME=" {{ STF_PROVIDER_NAME }}" \
157+ -e STF_PROVIDER_NAME=" {{ STF_PROVIDER_NAME }}${location : +_ $location } " \
154158 -e STF_PROVIDER_MIN_PORT=$stf_min_port \
155159 -e STF_PROVIDER_MAX_PORT=$stf_max_port \
156160 -p $stf_min_port -$stf_max_port :$stf_min_port -$stf_max_port \
@@ -219,7 +223,7 @@ function create_containers() {
219223
220224 # TODO: comment echoing wda related detailes before release
221225 local wdaIpaPath={{ WDA_FILE }}
222- local deviceWdaIpaPath=$( cat ${devices} | grep " $udid " | cut -d ' |' -f 10 )
226+ local deviceWdaIpaPath=$( cat ${devices} | grep " $udid " | cut -d ' |' -f 12 )
223227 if [ ! -z $deviceWdaIpaPath ] && [ ! " $deviceWdaIpaPath " == " /dev/null" ]; then
224228 wdaIpaPath=$deviceWdaIpaPath
225229 fi
@@ -230,7 +234,7 @@ function create_containers() {
230234 echo " wdaIpaPath: $wdaIpaPath "
231235
232236 local wdaBundleId={{ WDA_BUNDLEID }}
233- local deviceWdaBundleId=$( cat ${devices} | grep " $udid " | cut -d ' |' -f 11 )
237+ local deviceWdaBundleId=$( cat ${devices} | grep " $udid " | cut -d ' |' -f 13 )
234238 if [ ! -z $deviceWdaBundleId ]; then
235239 wdaBundleId=$deviceWdaBundleId
236240 fi
@@ -277,7 +281,7 @@ function create_containers() {
277281 -e STF_PROVIDER_DEVICE_NAME=" ${device_name} " \
278282 -e DEVICE_UDID=" ${udid} " \
279283 -e STF_PROVIDER_HOST={{ STF_PROVIDER_HOST }} \
280- -e STF_PROVIDER_NAME=" {{ STF_PROVIDER_NAME }}" \
284+ -e STF_PROVIDER_NAME=" {{ STF_PROVIDER_NAME }}${location : +_ $location } " \
281285 -e STF_PROVIDER_MIN_PORT=$stf_min_port \
282286 -e STF_PROVIDER_MAX_PORT=$stf_max_port \
283287 -p $stf_min_port -$stf_max_port :$stf_min_port -$stf_max_port \
@@ -348,9 +352,9 @@ function stop() {
348352 # if $device is empty do stop for all connected devices otherwise stop only filtered
349353 if [ ! -z $filter_device ] && [ " $filter_device " != " ios" ] && [ " $filter_device " != " android" ]; then
350354 echo stopping containers for $filter_device ...
351- local device_name=$( cat ${devices} | grep " $filter_device " | cut -d ' |' -f 1 )
355+ local device_name=$( cat ${devices} | grep " $filter_device " | cut -d ' |' -f 3 )
352356 local device_name_underscored=${device_name// / _}
353- local udid=$( cat ${devices} | grep " $filter_device " | cut -d ' |' -f 3 )
357+ local udid=$( cat ${devices} | grep " $filter_device " | cut -d ' |' -f 1 )
354358
355359 if [ -z " $device_name " ] || [ -z $udid ]; then
356360 echo_warning " Unable to find device by \" $filter_device \" !"
@@ -361,13 +365,13 @@ function stop() {
361365 else
362366 # as no device filter provided continue with stopping all device containers
363367 while read -r line; do
364- local device_name=$( echo ${line} | grep " $filter_device " | cut -d ' |' -f 1 )
368+ local device_name=$( echo ${line} | grep " $filter_device " | cut -d ' |' -f 3 )
365369 # echo "device_name: $device_name"
366370 local device_name_underscored=${device_name// / _}
367371
368- local udid=$( echo ${line} | grep " $filter_device " | cut -d ' |' -f 3 )
372+ local udid=$( echo ${line} | grep " $filter_device " | cut -d ' |' -f 1 )
369373 # echo "udid: $udid"
370- local wireless=$( echo ${line} | grep " $filter_device " | cut -d ' |' -f 9 )
374+ local wireless=$( echo ${line} | grep " $filter_device " | cut -d ' |' -f 11 )
371375
372376 if [ -L " /dev/device-${device_name} -${udid} " ] || [ " $wireless " == " True" ]; then
373377 stop_containers ${device_name_underscored} ${udid}
@@ -402,9 +406,9 @@ function down() {
402406 # if $device is empty do rm for all connected devices otherwise rm only filtered
403407 if [ ! -z $filter_device ] && [ " $filter_device " != " ios" ] && [ " $filter_device " != " android" ]; then
404408 # echo removing containers for $filter_device...
405- local device_name=$( cat ${devices} | grep " $filter_device " | cut -d ' |' -f 1 )
409+ local device_name=$( cat ${devices} | grep " $filter_device " | cut -d ' |' -f 3 )
406410 local device_name_underscored=${device_name// / _}
407- local udid=$( cat ${devices} | grep " $filter_device " | cut -d ' |' -f 3 )
411+ local udid=$( cat ${devices} | grep " $filter_device " | cut -d ' |' -f 1 )
408412
409413 if [ -z " $device_name " ] || [ -z $udid ]; then
410414 echo_warning " Unable to find device by \" $filter_device \" !"
@@ -414,11 +418,11 @@ function down() {
414418 remove_containers ${device_name_underscored} ${udid}
415419 else
416420 while read -r line; do
417- local device_name=$( echo ${line} | grep " $filter_device " | cut -d ' |' -f 1 )
421+ local device_name=$( echo ${line} | grep " $filter_device " | cut -d ' |' -f 3 )
418422 # echo "device_name: $device_name"
419423 local device_name_underscored=${device_name// / _}
420424
421- local udid=$( echo ${line} | grep " $filter_device " | cut -d ' |' -f 3 )
425+ local udid=$( echo ${line} | grep " $filter_device " | cut -d ' |' -f 1 )
422426 # echo "udid: $udid"
423427 remove_containers ${device_name_underscored} ${udid}
424428 done < ${devices}
@@ -529,7 +533,7 @@ function verify_containers() {
529533 local udid=$2
530534 # echo "udid: $udid"
531535
532- local wireless=$( cat ${devices} | grep " $udid " | cut -d ' |' -f 9 )
536+ local wireless=$( cat ${devices} | grep " $udid " | cut -d ' |' -f 11 )
533537
534538 local container=device-$device -$udid
535539 if [ ! -L " /dev/$container " ] && [ " $wireless " != " True" ]; then
@@ -574,11 +578,11 @@ function verify_containers() {
574578 connectorRestarts=" $( docker inspect --format=' {{ ' {{' }}.RestartCount{{ ' }}' }}' $container -connector) "
575579 fi
576580
577- echo -e " ,Container,State,Status,Uptime,Restarts,
578- ,---------,---------,---------,---------,---------,
579- ,Connector,$connectorState ,$connectorStatus ,$connectorUptime ,$connectorRestarts ,
580- ,Appium,$appiumState ,$appiumStatus ,$appiumUptime ,$appiumRestarts ,
581- ,STF,$stfState ,$stfStatus ,$stfUptime ,$stfRestarts ," | column -t -s ' ,' -o ' | ' -L
581+ echo -e " ,| Container,| State,| Status,| Uptime,| Restarts,|
582+ ,| ---------,| ---------,| ---------,| ---------,| ---------,|
583+ ,| Connector,| $connectorState ,| $connectorStatus ,| $connectorUptime ,| $connectorRestarts ,|
584+ ,| Appium,| $appiumState ,| $appiumStatus ,| $appiumUptime ,| $appiumRestarts ,|
585+ ,| STF,| $stfState ,| $stfStatus ,| $stfUptime ,| $stfRestarts ,| " | column -t -s ' ,'
582586
583587 fi
584588 echo -e " ==============================================================\n"
@@ -590,9 +594,9 @@ function start() {
590594
591595 # if $device is empty do start for all connected devices otherwise start only filtered
592596 if [ ! -z $filter_device ] && [ " $filter_device " != " ios" ] && [ " $filter_device " != " android" ]; then
593- local device_name=$( cat ${devices} | grep " $filter_device " | cut -d ' |' -f 1 )
597+ local device_name=$( cat ${devices} | grep " $filter_device " | cut -d ' |' -f 3 )
594598 local device_name_underscored=${device_name// / _}
595- local udid=$( cat ${devices} | grep " $filter_device " | cut -d ' |' -f 3 )
599+ local udid=$( cat ${devices} | grep " $filter_device " | cut -d ' |' -f 1 )
596600
597601 if [ -z " $device_name " ] || [ -z $udid ]; then
598602 echo_warning " Unable to find device by \" $filter_device \" !"
@@ -603,13 +607,13 @@ function start() {
603607 echo -e " \n-----------------------------------------------------------------"
604608 else
605609 while read -r line; do
606- local device_name=$( echo ${line} | grep " $filter_device " | cut -d ' |' -f 1 )
610+ local device_name=$( echo ${line} | grep " $filter_device " | cut -d ' |' -f 3 )
607611 # echo "device_name: $device_name"
608612 local device_name_underscored=${device_name// / _}
609613
610- local udid=$( echo ${line} | grep " $filter_device " | cut -d ' |' -f 3 )
614+ local udid=$( echo ${line} | grep " $filter_device " | cut -d ' |' -f 1 )
611615 # echo "udid: $udid"
612- local wireless=$( echo ${line} | grep " $filter_device " | cut -d ' |' -f 9 )
616+ local wireless=$( echo ${line} | grep " $filter_device " | cut -d ' |' -f 11 )
613617 if [ -L " /dev/device-${device_name} -${udid} " ] || [ " $wireless " == " True" ]; then
614618 create_containers " ${device_name} " " ${udid} " " ${device_name_underscored} " && start_containers " ${device_name} " " ${udid} " " ${device_name_underscored} "
615619 echo -e " \n-----------------------------------------------------------------"
@@ -643,18 +647,18 @@ function status() {
643647
644648 # if $device is empty do start for all connected devices otherwise start only filtered
645649 if [ ! -z $filter_device ] && [ " $filter_device " != " ios" ] && [ " $filter_device " != " android" ]; then
646- local device_name=$( cat ${devices} | grep " $filter_device " | cut -d ' |' -f 1 )
650+ local device_name=$( cat ${devices} | grep " $filter_device " | cut -d ' |' -f 3 )
647651 # echo "device_name: $device_name"
648652 local device_name_underscored=${device_name// / _}
649- local udid=$( cat ${devices} | grep " $filter_device " | cut -d ' |' -f 3 )
653+ local udid=$( cat ${devices} | grep " $filter_device " | cut -d ' |' -f 1 )
650654 # echo "udid: $udid"
651655 verify_containers " ${device_name_underscored} " " ${udid} "
652656 else
653657 while read -r line; do
654- local device_name=$( echo ${line} | grep " $filter_device " | cut -d ' |' -f 1 )
658+ local device_name=$( echo ${line} | grep " $filter_device " | cut -d ' |' -f 3 )
655659 # echo "device_name: $device_name"
656660 local device_name_underscored=${device_name// / _}
657- local udid=$( echo ${line} | grep " $filter_device " | cut -d ' |' -f 3 )
661+ local udid=$( echo ${line} | grep " $filter_device " | cut -d ' |' -f 1 )
658662 if [ -z $udid ]; then
659663 continue
660664 fi
@@ -680,15 +684,31 @@ function echo_help() {
680684 echo "
681685 Usage: zebrunner-farm [option]
682686 Arguments:
683- status Status of MCloud Agent and each whitelisted device
684- start [udid] Start devices containers or exact device by udid
685- stop [udid] Stop and keep devices containers or exact device by udid
686- restart [udid] Restart all devices containers or exact device by udid
687- down [udid] Stop and remove devices containers"
687+ status Status of MCloud Agent and each whitelisted device
688+ start [udid] Start devices containers or exact device by udid
689+ stop [udid] Stop and keep devices containers or exact device by udid
690+ restart [udid] Restart all devices containers or exact device by udid
691+ down [udid] Stop and remove devices containers
692+ ansible ['devices'] Run ansible-playbook script with custom or predefined args"
688693 echo_telegram
689694 exit 0
690695}
691696
697+ # IMPORTANT! In case of any changes please copy them in ./zebrunner.sh !
698+ function ansible() {
699+ if [[ " $1 " == " " ]]; then
700+ arg=" devices.yml"
701+ elif [[ " $1 " == " devices" ]]; then
702+ arg=" devices.yml --tag registerDevices"
703+ else
704+ arg=" $@ devices.yml"
705+ fi
706+
707+ echo " ansible-playbook -vvv -i hosts $arg "
708+ echo " *******************************************************************"
709+ ansible-playbook -vvv -i hosts $arg
710+ }
711+
692712# CONTAINERS=( `docker ps --format '{{ '{{' }}.Names{{ '}}' }}' | grep device | grep -v appium | cut -d '-' -f 2-` )
693713# echo CONTAINERS: $CONTAINERS
694714
@@ -724,6 +744,9 @@ restart)
724744down)
725745 down $2
726746 ;;
747+ ansible)
748+ ansible " ${@: 2} "
749+ ;;
727750shutdown)
728751 shutdown
729752 ;;
0 commit comments