diff options
author | jobol <jose.bollo@iot.bzh> | 2018-03-14 13:58:25 +0100 |
---|---|---|
committer | jobol <jose.bollo@iot.bzh> | 2018-03-14 13:58:25 +0100 |
commit | 11575952ece456be4e07c5f24ead3cf8783ddcba (patch) | |
tree | 3bcedc7f83f897960770472617b61ab5ba0b10a7 /common/scripts/service-ids-check.sh | |
parent | 9aae8071429333a24277a9b5685cf06e4f593892 (diff) |
service-ids-check: Add check uid/gid of servicesflounder_5.99.1flounder/5.99.15.99.1
This new test allows to check whether service
run with expected uid and gid. This check doesn't
check that the service runs because there is an
other check for that.
It currently only checks weston service to run as
display/display but it can be easily extended for
checking other services.
Bug-AGL: SPEC-546
Signed-off-by: jobol <jose.bollo@iot.bzh>
Diffstat (limited to 'common/scripts/service-ids-check.sh')
-rwxr-xr-x | common/scripts/service-ids-check.sh | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/common/scripts/service-ids-check.sh b/common/scripts/service-ids-check.sh new file mode 100755 index 0000000..f1fbef1 --- /dev/null +++ b/common/scripts/service-ids-check.sh @@ -0,0 +1,78 @@ +#!/bin/bash +#----------------------------------------------------- +# This scripts allows to check the ids (user and/or group) +# of running services. +# It doesn't check that the service runs because this is +# the object of other tests. +# If a process doesn't run it emits an unknown status for +# the service, but not a fail. +# When there are multiple instance of a service, it checks +# that at least one instance matches expectation. +# Author: jose.bollo@iot.bzh +#----------------------------------------------------- + +# out of LAVA run +if ! type lava-test-case 2>/dev/null; then + lava-test-case() { echo "lava-test-case $*"; } +fi +if ! type lava-test-set 2>/dev/null; then + lava-test-set() { echo "lava-test-set $*"; } +fi + +# extraction of numeric ids for user and group +get-id() { + local id="$1" file="$2" + if grep -q "^${id}:" "$file"; then + grep "^${id}:" "$file" | cut -d: -f3 + else + echo -n "$id" + fi +} +get-uid() { get-id "$1" /etc/passwd; } +get-gid() { get-id "$1" /etc/group; } + +# extraction of numeric effective ids of processes +get-p-id() { + local pid="$1" field="$2" + grep "$field" "/proc/$pid/status" | cut -f3 +} +get-p-uid() { get-p-id "$1" "Uid:"; } +get-p-gid() { get-p-id "$1" "Gid:"; } + +# check the process status +check-p-ids() { + local pid="$1" uid="$2" gid="$3" + local u=$(get-p-uid "$pid") + local g=$(get-p-gid "$pid") + [[ -z "$uid" || "$uid" -eq "$u" ]] && [[ -z "$gid" || "$gid" -eq "$g" ]] +} +check-user-group() { + local service="$1" user="$2" group="$3" + local name="${service}-${user}-${group}" + local pid uid=$(get-uid "$user") gid=$(get-gid "$group") + + if ! pgrep -c "^$service\$" > /dev/null 2>&1; then + lava-test-case "$name" --result unknown + return 0 + fi + + for pid in $(pgrep "^$service\$"); do + if check-p-ids "$pid" "$uid" "$gid"; then + lava-test-case "$name" --result pass + return 0 + fi + done + lava-test-case "$name" --result fail + return 1 +} +check-user() { check-user-group "$1" "$2" ""; } +check-group() { check-user-group "$1" "" "$2"; } + +# the test effective +lava-test-set start check-services-user-group + +check-user-group weston display display + +lava-test-set stop check-services-user-group + +exit 0 |