From d98a34ad1b4f55bac4ce39ddd100e1c8b0fcb6e1 Mon Sep 17 00:00:00 2001 From: Scott Little Date: Mon, 31 Jan 2022 13:16:38 -0500 Subject: [PATCH] import-stx: Avoid divide by zero Fix a divide by zero error seen when the number_of_users function returns zero. At issue is that 'users' only counts logins, and can miss builds running under automation such as jenkins. Add code to detect potential automation accounts, just jenkins so far, and to always return a value greater than zero. Also adding a few .gitignore entries for files generated by stx build related scripts. Closes-bug: 1959606 Signed-off-by: Scott Little Change-Id: I1369aa159088a17c24cc996be1ef2d36ecdc9cf6 --- .gitignore | 4 ++++ import-stx | 18 +++++++++++++++++- stx/lib/stx/.gitignore | 1 + 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 stx/lib/stx/.gitignore diff --git a/.gitignore b/.gitignore index 20552688..a7d8edf2 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,7 @@ doc/build/ # Release Notes documentation releasenotes/build + +# stx init/config/controller files +stx.conf +minikube_history.log diff --git a/import-stx b/import-stx index 684364ee..a64ff04f 100644 --- a/import-stx +++ b/import-stx @@ -41,7 +41,23 @@ if [ ! -f "stx.conf" ]; then fi number_of_users () { - users | tr ' ' '\n' | sort --uniq | wc -l + local count + + count=$(users | tr ' ' '\n' | sort --uniq | wc -l) + + # Add in non-login users that might trigger a parallel build + # based on a timer, or other trigger. + if getent passwd | grep -q jenkins; then + count=$((count+1)) + fi + + # Always return at least one. i.e. someone is + # running this script. + if [ $count -le 0 ]; then + count=1 + fi + + echo $count } number_of_cpus () { diff --git a/stx/lib/stx/.gitignore b/stx/lib/stx/.gitignore new file mode 100644 index 00000000..bee8a64b --- /dev/null +++ b/stx/lib/stx/.gitignore @@ -0,0 +1 @@ +__pycache__