summaryrefslogtreecommitdiff
path: root/util/aliases
blob: 269b559ada85a7683378d1d33d6d2047ce1c1c1e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# This file contains shell aliases to make working with testlab less painful.
# Linking it to ~/.bash_aliases file might prove itself useful.

. /opt/testlab-major/tsp/common.sh

export TARGET_LIST="$(sd-mux-ctrl --list | awk '/^Dev/ {sub(/_.*,/, "", $6); print $6}' | sort -u)"
export DEVICES_LIST="$(sd-mux-ctrl --list | awk '/^Dev/ {sub(/,/, "", $6); print $6}')"

alias pls='sudo $(history -p !!)'

# hurry makes requested task from given target queue urgent, i.e. moves it to
# the front of said queue; it takes two mandatory arguments:
# - target queue name
# - task number (its ID)
hurry() {
        local target="$1"
        local nr="$2"
        test -n "$target" || echo "Missing argument: target"
        test -n "$nr" || echo "Missing argument: nr"
        tsrun_target $target -u `tsrun_target $target | grep $nr | cut -d' ' -f 1`
}

# redownload forces downloading all images from requested prerelease/snapshot
# project again; it takes one mandatory argument:
# - project URL (its root; remember that it must end with slash!)
redownload() {
        echo "$1" >> $WS_WATCHER/manual_urls
}

# get_device retrieves device name from results database for requested task
# number (helper for retry, see below); it takes one mandatory argument:
# - task number (its ID)
get_device() {
        local nr="$1"
        test -n "$nr" || echo "Missing argument: nr"
        sqlite3 ~/ws/publish/results.db3 "SELECT device.dname FROM test INNER JOIN device ON test.tdid = device.did WHERE tbuildnr = $nr;"
}

# retry forces rescheduling requested task; it takes one mandatory argument:
# - task number (its ID)
retry() {
        local target="$1"
        local nr="$2"
        test -n "$target" || echo "Missing argument: target"
        test -n "$nr" || echo "Missing argument: nr"
        tsrun_target $target sh /opt/testlab-major/tsp/jobs/../jobs/common_prep_flash_conf.sh $nr "$(get_device $nr)"
}

# retrigger forces rescheduling requested task; it takes two mandatory
# arguments:
# - task number (its ID)
# - target queue name
retrigger() {
        local nr="$1"
        local target="$2"
        test -n "$nr" || echo "Missing argument: nr"
        test -n "$target" || echo "Missing argument: target"
        tsmaster sh /opt/testlab-major/tsp/jobs/img_test_common.sh "$nr" "$target"
}

# enter_maintenance shrinks capacity on all target queues to a single slot and
# blocks them by scheduling a sleep job; it takes one optional argument:
# - sleep duration (in coreutils sleep units; default: 3h)
enter_maintenance() {
	local duration="${1:-3h}"
	for target in ${TARGET_LIST}; do
		echo "$target"
		# limit task queue to single slot and lock it with sleep
		tsrun_target "$target" -S 1
		tsrun_target "$target" sleep "$duration"
	done
}

# exit_maintenance kills currently run jobs on all target queues (e.g. sleep
# jobs from enter_maintenance)
exit_maintenance() {
	# TODO: you might shoot yourself in foot easily;
	# following kills ANY currently running task (not just sleeps)
	for target in ${TARGET_LIST}; do
		echo "$target"
		tsrun_target "$target" -k
	done
	echo "Remember to increase slot sizes!"
}

# get_uuid retrieves UUID of second partition for a device; it assumes there
# is exactly one device available at the time of its call
#
# following might seem hard to read due to glueing single quoted strings with
# actual single quotation marks in double quotes, but it's worth it - this way
# neither alias not AWK script won't be interpreted prior execution
alias get_uuid='ls -la /dev/disk/by-uuid/ | awk '"'"'/2$/ {print $(NF-2)}'"'"

# set_uuid writes actual UUID of second partition for requested device to file
# used by testlab-major to identify block devices; it takes one mandatory
# argument:
# - device name
set_uuid() {
	local device="$1"
	test -n "$device" || echo "Missing argument: device"
	sd-mux-ctrl -e "$device" -s
	get_uuid > "/var/tmp/uuid-${device}"
}

# uuid_healthcheck checks if there are mismatches between files used by
# testlab-major to identify block devices and actual UUIDs for corresponding
# devices
uuid_healthcheck() {
	for device in ${DEVICES_LIST}; do
		echo "$device"
		sd-mux-ctrl -e "$device" -s
		sleep 20 # TODO: implement device detection
		get_uuid | diff -s "/var/tmp/uuid-${device}" - || true # ignore non-zero status if difference is found
		sd-mux-ctrl -e "$device" -d
	done
}