Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

installdependencies.sh returns success when there are errors on Ubuntu #3499

Open
milivoj-persson-northvolt opened this issue Oct 10, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@milivoj-persson-northvolt
Copy link

milivoj-persson-northvolt commented Oct 10, 2024

Describe the bug
On Ubuntu, if you try to run installdependencies.sh and if no packages, of the ones listed in the script, exist the script still returns success.

To Reproduce
Steps to reproduce the behavior:

  1. Edit installdependencies.sh and make sure that no packages actually match real packages
  2. Run it and see that the script returns success:
root@7774063ae328:~# ./installdependencies.sh
--------OS Information--------
PRETTY_NAME="Ubuntu 22.04.5 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.5 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=jammy
------------------------------
The current OS is Debian based
--------Debian Version--------
bookworm/sid
------------------------------
/usr/bin/apt-get
Hit:1 http://security.ubuntu.com/ubuntu jammy-security InRelease
Hit:2 http://archive.ubuntu.com/ubuntu jammy InRelease
Hit:3 http://archive.ubuntu.com/ubuntu jammy-updates InRelease
Hit:4 http://archive.ubuntu.com/ubuntu jammy-backports InRelease
Reading package lists... Done
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
libkrb5-3 is already the newest version (1.19.2-2ubuntu0.4).
zlib1g is already the newest version (1:1.2.11.dfsg-2ubuntu9.2).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: Unable to locate package asdfasdfliblttng-ust1
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: Unable to locate package asdfasdfliblttng-ust0
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: Unable to locate package libssl1.1$
E: Couldn't find any package by glob 'libssl1.1$'
E: Couldn't find any package by regex 'libssl1.1$'
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: Unable to locate package libssl1.0.2$
E: Couldn't find any package by glob 'libssl1.0.2$'
E: Couldn't find any package by regex 'libssl1.0.2$'
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: Unable to locate package libssl1.0.0$
E: Couldn't find any package by glob 'libssl1.0.0$'
E: Couldn't find any package by regex 'libssl1.0.0$'
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: Unable to locate package asdfasdflibicu72
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: Unable to locate package asdfasdflibicu71
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: Unable to locate package asdfasdflibicu70
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: Unable to locate package asdfasdflibicu69
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: Unable to locate package asdfasdflibicu68
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: Unable to locate package asdfasdflibicu67
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: Unable to locate package asdfasdflibicu66
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: Unable to locate package asdfasdflibicu65
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: Unable to locate package asdfasdflibicu63
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: Unable to locate package asdfasdflibicu60
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: Unable to locate package asdfasdflibicu57
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: Unable to locate package asdfasdflibicu55
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: Unable to locate package asdfasdflibicu52
-----------------------------
 Finish Install Dependencies
-----------------------------
root@7774063ae328:~# echo $?
0

Expected behavior
If one or more required packages aren't installed it should return an error/set an exit code != 0 and print out some error text.

Runner Version and Platform

v2.320.0

OS of the machine running the runner? Ubuntu 22.04.5 LTS

What's not working?

Installing dependencies with the installdependencies.sh doesn't show correct output when there are failures on Ubuntu.

The issue is a combination of:

  1. Assigning the exit code to a variable after running apt, without acting on an any error directly, (which resets the exit code to 0 since the assignment was successful) here:

  2. Then trying to read out the error code and print the error afterwards, which of course doesn't work since assigning the exit code to the variable worked and that exit code is 0, e.g. here:

Suggestion is to move all the error handling that is repeated into the apt_get_with_fallbacks function itself:

        apt_get_with_fallbacks() {
            $apt_get install -y $1
            fail=$?
            if [ $fail -eq 0 ]
            then
                if [ "${1#"${1%?}"}" = '$' ]; then
                    dpkg -l "${1%?}" > /dev/null 2> /dev/null
                    fail=$?
                fi
            fi
            if [ $fail -ne 0 ]
            then
                shift
                if [ -n "$1" ]
                then
                    apt_get_with_fallbacks "$@"
                else
                    echo "'$apt_get' failed with exit code '$fail'"
                    print_errormessage
                    exit 1
                fi
            fi
        }

Job Log Output

If applicable, include the relevant part of the job / step log output here. All sensitive information should already be masked out, but please double-check before pasting here.

Runner and Worker's Diagnostic Logs

If applicable, add relevant diagnostic log information. Logs are located in the runner's _diag folder. The runner logs are prefixed with Runner_ and the worker logs are prefixed with Worker_. Each job run correlates to a worker log. All sensitive information should already be masked out, but please double-check before pasting here.

@milivoj-persson-northvolt milivoj-persson-northvolt added the bug Something isn't working label Oct 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant