Skip to content

Commit 35af8d0

Browse files
Shiva Kumarshivakunv
authored andcommitted
apt(-get) operations that require network: do not suppress stdout/err, timeout-control
Signed-off-by: Shiva Kumar (SW-CLOUD) <shivaku@nvidia.com>
1 parent 4fcdbb0 commit 35af8d0

6 files changed

Lines changed: 111 additions & 27 deletions

File tree

ubuntu22.04/nvidia-driver

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,24 @@ DRIVER_ARCH=${TARGETARCH/amd64/x86_64} && DRIVER_ARCH=${DRIVER_ARCH/arm64/aarch6
2525

2626
echo "DRIVER_ARCH is $DRIVER_ARCH"
2727

28+
# Run apt-get -qq quietly, on failure print actual error to stdout and exit.
29+
_apt_quiet() {
30+
local err_file
31+
err_file=$(mktemp)
32+
trap "rm -f \"$err_file\"" RETURN
33+
if ! apt-get -qq "$@" 2>"$err_file"; then
34+
echo "ERROR: apt-get failed (exit $?): $*"
35+
echo "apt-get stderr:"
36+
cat "$err_file"
37+
return 1
38+
fi
39+
return 0
40+
}
41+
2842
_enable_fips_if_required() {
2943
if [[ -n "${UBUNTU_PRO_TOKEN}" && ${KERNEL_VERSION} =~ "fips" ]]; then
3044
echo "Ubuntu Pro token and FIPS kernel detected"
31-
apt-get -qq install --no-install-recommends ubuntu-advantage-tools > /dev/null
45+
_apt_quiet install --no-install-recommends ubuntu-advantage-tools
3246
echo "Attaching Ubuntu Pro token..."
3347
pro attach --no-auto-enable "${UBUNTU_PRO_TOKEN}"
3448
echo "Enabling FIPS apt repo access..."
@@ -39,7 +53,7 @@ _enable_fips_if_required() {
3953
_update_package_cache() {
4054
if [ "${PACKAGE_TAG:-}" != "builtin" ]; then
4155
echo "Updating the package cache..."
42-
if ! apt-get -qq update; then
56+
if ! _apt_quiet update; then
4357
echo "ERROR: Failed to update package cache. "\
4458
"Ensure that the cluster can access the proper networks."
4559
exit 1
@@ -89,11 +103,11 @@ _install_prerequisites() (
89103
mkdir -p /lib/modules/${KERNEL_VERSION}/proc
90104

91105
echo "Installing Linux kernel headers..."
92-
apt-get -qq install --no-install-recommends linux-headers-${KERNEL_VERSION} > /dev/null
106+
_apt_quiet install --no-install-recommends linux-headers-${KERNEL_VERSION}
93107

94108
echo "Installing Linux kernel module files..."
95-
apt-get -qq download linux-image-${KERNEL_VERSION} && dpkg -x linux-image*.deb .
96-
{ apt-get -qq download linux-modules-${KERNEL_VERSION} && dpkg -x linux-modules*.deb . || true; } 2> /dev/null
109+
_apt_quiet download linux-image-${KERNEL_VERSION} && dpkg -x linux-image*.deb .
110+
{ _apt_quiet download linux-modules-${KERNEL_VERSION} && dpkg -x linux-modules*.deb . || true; }
97111
mv lib/modules/${KERNEL_VERSION}/modules.* /lib/modules/${KERNEL_VERSION}
98112
mv lib/modules/${KERNEL_VERSION}/kernel /lib/modules/${KERNEL_VERSION}
99113
depmod ${KERNEL_VERSION}
@@ -111,7 +125,7 @@ _install_prerequisites() (
111125
# Cleanup the prerequisites installed above.
112126
_remove_prerequisites() {
113127
if [ "${PACKAGE_TAG:-}" != "builtin" ]; then
114-
apt-get -qq purge linux-headers-${KERNEL_VERSION} > /dev/null
128+
_apt_quiet purge linux-headers-${KERNEL_VERSION}
115129
# TODO remove module files not matching an existing driver package.
116130
fi
117131
}

ubuntu22.04/precompiled/nvidia-driver

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,24 @@ nvsdm_install() {
7575
fi
7676
}
7777

78+
# Run apt-get -qq quietly, on failure print actual error to stdout and exit.
79+
_apt_quiet() {
80+
local err_file
81+
err_file=$(mktemp)
82+
trap "rm -f \"$err_file\"" RETURN
83+
if ! apt-get -qq "$@" 2>"$err_file"; then
84+
echo "ERROR: apt-get failed (exit $?): $*"
85+
echo "apt-get stderr:"
86+
cat "$err_file"
87+
return 1
88+
fi
89+
return 0
90+
}
91+
7892
_update_package_cache() {
7993
if [ "${PACKAGE_TAG:-}" != "builtin" ]; then
8094
echo "Updating the package cache..."
81-
if ! apt-get -qq update; then
95+
if ! _apt_quiet update; then
8296
echo "ERROR: Failed to update package cache. "\
8397
"Ensure that the cluster can access the proper networks."
8498
exit 1

ubuntu24.04/nvidia-driver

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,24 @@ DRIVER_ARCH=${TARGETARCH/amd64/x86_64} && DRIVER_ARCH=${DRIVER_ARCH/arm64/aarch6
2525

2626
echo "DRIVER_ARCH is $DRIVER_ARCH"
2727

28+
# Run apt-get -qq quietly, on failure print actual error to stdout and exit.
29+
_apt_quiet() {
30+
local err_file
31+
err_file=$(mktemp)
32+
trap "rm -f \"$err_file\"" RETURN
33+
if ! apt-get -qq "$@" 2>"$err_file"; then
34+
echo "ERROR: apt-get failed (exit $?): $*"
35+
echo "apt-get stderr:"
36+
cat "$err_file"
37+
return 1
38+
fi
39+
return 0
40+
}
41+
2842
_enable_fips_if_required() {
2943
if [[ -n "${UBUNTU_PRO_TOKEN}" && ${KERNEL_VERSION} =~ "fips" ]]; then
3044
echo "Ubuntu Pro token and FIPS kernel detected"
31-
apt-get -qq install --no-install-recommends ubuntu-advantage-tools > /dev/null
45+
_apt_quiet install --no-install-recommends ubuntu-advantage-tools
3246

3347
# This workaround is needed in Ubuntu 24.04 as OpenSSL attempts to leverage the FIPS provider
3448
# when the underlying kernel is FIPS enabled.
@@ -39,7 +53,7 @@ _enable_fips_if_required() {
3953
echo "Enabling FIPS apt repo access..."
4054
pro enable --access-only --assume-yes fips-updates
4155
echo "Installing the OpenSSL FIPS modules"
42-
apt-get -qq install --no-install-recommends ubuntu-fips-userspace > /dev/null
56+
_apt_quiet install --no-install-recommends ubuntu-fips-userspace
4357

4458
# With the OpenSSL FIPS module installed, OpenSSL can now work with the default settings,
4559
unset OPENSSL_FORCE_FIPS_MODE
@@ -49,7 +63,7 @@ _enable_fips_if_required() {
4963
_update_package_cache() {
5064
if [ "${PACKAGE_TAG:-}" != "builtin" ]; then
5165
echo "Updating the package cache..."
52-
if ! apt-get -qq update; then
66+
if ! _apt_quiet update; then
5367
echo "ERROR: Failed to update package cache. "\
5468
"Ensure that the cluster can access the proper networks."
5569
exit 1
@@ -99,11 +113,11 @@ _install_prerequisites() (
99113
mkdir -p /lib/modules/${KERNEL_VERSION}/proc
100114

101115
echo "Installing Linux kernel headers..."
102-
apt-get -qq install --no-install-recommends linux-headers-${KERNEL_VERSION} > /dev/null
116+
_apt_quiet install --no-install-recommends linux-headers-${KERNEL_VERSION}
103117

104118
echo "Installing Linux kernel module files..."
105-
apt-get -qq download linux-image-${KERNEL_VERSION} && dpkg -x linux-image*.deb .
106-
{ apt-get -qq download linux-modules-${KERNEL_VERSION} && dpkg -x linux-modules*.deb . || true; } 2> /dev/null
119+
_apt_quiet download linux-image-${KERNEL_VERSION} && dpkg -x linux-image*.deb .
120+
{ _apt_quiet download linux-modules-${KERNEL_VERSION} && dpkg -x linux-modules*.deb . || true; }
107121
mv lib/modules/${KERNEL_VERSION}/modules.* /lib/modules/${KERNEL_VERSION}
108122
mv lib/modules/${KERNEL_VERSION}/kernel /lib/modules/${KERNEL_VERSION}
109123
depmod ${KERNEL_VERSION}
@@ -121,7 +135,7 @@ _install_prerequisites() (
121135
# Cleanup the prerequisites installed above.
122136
_remove_prerequisites() {
123137
if [ "${PACKAGE_TAG:-}" != "builtin" ]; then
124-
apt-get -qq purge linux-headers-${KERNEL_VERSION} > /dev/null
138+
_apt_quiet purge linux-headers-${KERNEL_VERSION}
125139
# TODO remove module files not matching an existing driver package.
126140
fi
127141
}

ubuntu24.04/precompiled/nvidia-driver

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,24 @@ nvsdm_install() {
7676
fi
7777
}
7878

79+
# Run apt-get -qq quietly, on failure print actual error to stdout and exit.
80+
_apt_quiet() {
81+
local err_file
82+
err_file=$(mktemp)
83+
trap "rm -f \"$err_file\"" RETURN
84+
if ! apt-get -qq "$@" 2>"$err_file"; then
85+
echo "ERROR: apt-get failed (exit $?): $*"
86+
echo "apt-get stderr:"
87+
cat "$err_file"
88+
return 1
89+
fi
90+
return 0
91+
}
92+
7993
_update_package_cache() {
8094
if [ "${PACKAGE_TAG:-}" != "builtin" ]; then
8195
echo "Updating the package cache..."
82-
if ! apt-get -qq update; then
96+
if ! _apt_quiet update; then
8397
echo "ERROR: Failed to update package cache. "\
8498
"Ensure that the cluster can access the proper networks."
8599
exit 1

vgpu-manager/ubuntu22.04/nvidia-driver

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,24 @@ MODPROBE_CONFIG_DIR="/etc/modprobe.d"
1313

1414
export DEBIAN_FRONTEND=noninteractive
1515

16+
# Run apt-get -qq quietly, on failure print actual error to stdout and exit.
17+
_apt_quiet() {
18+
local err_file
19+
err_file=$(mktemp)
20+
trap "rm -f \"$err_file\"" RETURN
21+
if ! apt-get -qq "$@" 2>"$err_file"; then
22+
echo "ERROR: apt-get failed (exit $?): $*"
23+
echo "apt-get stderr:"
24+
cat "$err_file"
25+
return 1
26+
fi
27+
return 0
28+
}
29+
1630
_update_package_cache() {
1731
if [ "${PACKAGE_TAG:-}" != "builtin" ]; then
1832
echo "Updating the package cache..."
19-
apt-get -qq update
33+
_apt_quiet update
2034
fi
2135
}
2236

@@ -56,13 +70,13 @@ _install_prerequisites() {
5670
mkdir -p /lib/modules/${KERNEL_VERSION}/proc
5771

5872
echo "Installing Linux kernel headers..."
59-
apt-get -qq install --no-install-recommends linux-headers-${KERNEL_VERSION} > /dev/null
73+
_apt_quiet install --no-install-recommends linux-headers-${KERNEL_VERSION}
6074

6175
echo "Installing Linux kernel module files..."
62-
apt-get -qq download linux-image-${KERNEL_VERSION} && dpkg -x linux-image*.deb .
63-
{ apt-get -qq download linux-modules-${KERNEL_VERSION} && dpkg -x linux-modules*.deb . || true; } 2> /dev/null
76+
_apt_quiet download linux-image-${KERNEL_VERSION} && dpkg -x linux-image*.deb .
77+
{ _apt_quiet download linux-modules-${KERNEL_VERSION} && dpkg -x linux-modules*.deb . || true; }
6478
# linux-modules-extra contains pci-pf-stub which is required when enabling SR-IOV on a physical GPU
65-
{ apt-get -qq download linux-modules-extra-${KERNEL_VERSION} && dpkg -x linux-modules-extra*.deb . || true; } 2> /dev/null
79+
{ _apt_quiet download linux-modules-extra-${KERNEL_VERSION} && dpkg -x linux-modules-extra*.deb . || true; }
6680
mv lib/modules/${KERNEL_VERSION}/modules.* /lib/modules/${KERNEL_VERSION}
6781
mv lib/modules/${KERNEL_VERSION}/kernel /lib/modules/${KERNEL_VERSION}
6882
depmod ${KERNEL_VERSION}
@@ -80,7 +94,7 @@ _install_prerequisites() {
8094
# Cleanup the prerequisites installed above.
8195
_remove_prerequisites() {
8296
if [ "${PACKAGE_TAG:-}" != "builtin" ]; then
83-
apt-get -qq purge linux-headers-${KERNEL_VERSION} > /dev/null
97+
_apt_quiet purge linux-headers-${KERNEL_VERSION}
8498
# TODO remove module files not matching an existing driver package.
8599
fi
86100
}

vgpu-manager/ubuntu24.04/nvidia-driver

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,24 @@ MODPROBE_CONFIG_DIR="/etc/modprobe.d"
1313

1414
export DEBIAN_FRONTEND=noninteractive
1515

16+
# Run apt-get -qq quietly, on failure print actual error to stdout and exit.
17+
_apt_quiet() {
18+
local err_file
19+
err_file=$(mktemp)
20+
trap "rm -f \"$err_file\"" RETURN
21+
if ! apt-get -qq "$@" 2>"$err_file"; then
22+
echo "ERROR: apt-get failed (exit $?): $*"
23+
echo "apt-get stderr:"
24+
cat "$err_file"
25+
return 1
26+
fi
27+
return 0
28+
}
29+
1630
_update_package_cache() {
1731
if [ "${PACKAGE_TAG:-}" != "builtin" ]; then
1832
echo "Updating the package cache..."
19-
apt-get -qq update
33+
_apt_quiet update
2034
fi
2135
}
2236

@@ -56,13 +70,13 @@ _install_prerequisites() {
5670
mkdir -p /lib/modules/${KERNEL_VERSION}/proc
5771

5872
echo "Installing Linux kernel headers..."
59-
apt-get -qq install --no-install-recommends linux-headers-${KERNEL_VERSION} > /dev/null
73+
_apt_quiet install --no-install-recommends linux-headers-${KERNEL_VERSION}
6074

6175
echo "Installing Linux kernel module files..."
62-
apt-get -qq download linux-image-${KERNEL_VERSION} && dpkg -x linux-image*.deb .
63-
{ apt-get -qq download linux-modules-${KERNEL_VERSION} && dpkg -x linux-modules*.deb . || true; } 2> /dev/null
76+
_apt_quiet download linux-image-${KERNEL_VERSION} && dpkg -x linux-image*.deb .
77+
{ _apt_quiet download linux-modules-${KERNEL_VERSION} && dpkg -x linux-modules*.deb . || true; }
6478
# linux-modules-extra contains pci-pf-stub which is required when enabling SR-IOV on a physical GPU
65-
{ apt-get -qq download linux-modules-extra-${KERNEL_VERSION} && dpkg -x linux-modules-extra*.deb . || true; } 2> /dev/null
79+
{ _apt_quiet download linux-modules-extra-${KERNEL_VERSION} && dpkg -x linux-modules-extra*.deb . || true; }
6680
mv lib/modules/${KERNEL_VERSION}/modules.* /lib/modules/${KERNEL_VERSION}
6781
mv lib/modules/${KERNEL_VERSION}/kernel /lib/modules/${KERNEL_VERSION}
6882
depmod ${KERNEL_VERSION}
@@ -80,7 +94,7 @@ _install_prerequisites() {
8094
# Cleanup the prerequisites installed above.
8195
_remove_prerequisites() {
8296
if [ "${PACKAGE_TAG:-}" != "builtin" ]; then
83-
apt-get -qq purge linux-headers-${KERNEL_VERSION} > /dev/null
97+
_apt_quiet purge linux-headers-${KERNEL_VERSION}
8498
# TODO remove module files not matching an existing driver package.
8599
fi
86100
}

0 commit comments

Comments
 (0)