root/build-tools
M. Vefa Bicakci 818830b25e Debian/stx: utils: Minor run_shell_cmd fix-ups
This commit fixes various minor issues in utils.py Python module's
run_shell_cmd function:

- Fix "local variable 'process' referenced before assignment" exception
  that can occur while handling exceptions raised by subprocess.Popen().
  This appears to only occur when a forked/child process cannot execute
  a program, which is a programming error, which in turn is a minor
  issue.

  Before this commit, attempting to run a non-existent program with, for
  example: 'run_shell_command("/bin/abc", ...)' would result in the
  exception "local variable 'process' referenced before assignment"
  while handling the exception "[Errno 2] No such file or directory:
  '/bin/abc'".

  With this commit, only the latter exception is reported, but in the
  following form, as part of a single/non-nested exception:

    [ Failed to execute command: "['/bin/abc']" Exception: "[Errno 2] \
      No such file or directory: '/bin/abc'" ]

- Avoid making Python print two tracebacks when handling exceptions
  raised by subprocess.Popen(). Logging a one-line description of the
  exception encountered by subprocess.Popen() (via "{e}", where "e" is
  an Exception object) is sufficient on its own to debug the encountered
  issue. (Please see above for an example.)

- Always log standard error of the command. While most of the messages
  logged to the standard error are debugging-oriented or point at minor
  issues, ignoring standard error still causes us to miss non-critical
  warning messages. In addition, change the log level for standard error
  output from "error" to "debug" to avoid panicking build system users
  due to the non-critical messages that will appear, such as the
  following:

  dpkg-architecture: warning: cannot determine CC system type, falling \
    back to default (native compilation)
  dpkg-source --before-build .
  dpkg-buildpackage: warning: building a source package without \
    cleaning up as you asked; it might contain undesired files
  dpkg-source -b .
  dpkg-genbuildinfo --build=source
  dpkg-genchanges --build=source >../mlnx-ofed-kernel_....changes
  dpkg-genchanges: info: not including original source code in upload

- In the logs, prefix the command's standard output with "stdout: " and
  its standard error with "stderr: ". This allows distinguishing between
  the command's messages emitted via standard output and standard error.

- Note that adding the "stdout: " prefix to each line of each command's
  standard output increases the log file's size by about 190 KiB,
  according to the following results from a fresh build with
  'build-pkgs -b std,rt -c -a':

    $ grep -e '2022-09-1[67] .*stdout: ' builder.log | wc -l
    24391 # num_lines
    $ echo $(( 24391 * 8 )) # i.e., num_lines * strlen("stdout: ")
    195128 # bytes

  Logging each command's standard error (along with prefixing each line
  with "stderr: ") adds about 1.87 MiB of output to the build logs,
  which corresponds to an increase of approximately 21 percent:

    $ grep -e '2022-09-1[67] .*stderr: ' builder.log | wc -c
    1963024
    $ grep -e '2022-09-1[67] ' builder.log | wc -c
    11164207
    $ echo 'scale=2; print 1963024.0/(11164207-1963024) * 100,"%\n";' \
        | bc
    21.00%

  Despite the increase in the log file size, logging the standard error
  uncovers some issues, mostly relating to the debian/changelog file
  formatting used by StarlingX developers, which are admittedly minor.
  Examples include:

  ... stderr: dpkg-genchanges: warning: debian/changelog(l...): \
    badly formatted trailer line
  ... stderr: dpkg-genchanges: warning: debian/changelog(l...): \
    found end of file where expected more change data or trailer

- Log the return code of the command if it fails. This provides
  additional information regarding why a command failed, in case the
  command's output is not sufficient to determine the reason.

- Prefer to log the command as a list/tuple if it is provided with that
  type, for easier correlation with the code and for consistency with
  the rest of the logging in the function.

- Improve logging and reduce the duplication involved in log message
  construction.

Verification
- 'build-pkgs -b rt,std -c -a' runs without issues with this patch, but
  emits additional output due to logging the standard error streams of
  executed commands.

Closes-Bug: 1989009
Closes-Bug: 1990177
Change-Id: I6b3c4dc70fb1404280ea15e8dcc573c83792f9b1
Signed-off-by: M. Vefa Bicakci <vefa.bicakci@windriver.com>
2022-09-19 17:01:13 +00:00
..
branching Add --exclude-projects option to branch management scripts 2022-07-28 14:39:07 -04:00
build_guest build-guest: update RPM lists + misc fixes 2021-08-09 13:25:28 -04:00
build_iso minimal_rpm_list.txt: ebtables->iptables-ebtables 2021-10-29 16:21:19 -04:00
build_minimal_iso Add support CentOS-8/dnf/mock-2.6 based builds 2020-12-08 14:13:28 -05:00
build-docker-images Add app-sriov-fec-operator container image tags. 2022-09-15 12:47:59 -07:00
build-wheels build-wheels: add missing python wheels for debian 2022-09-14 10:56:06 -04:00
certificates StarlingX open source release updates 2018-06-01 07:45:23 -07:00
deb-utils debian: port helm chart script to debian 2022-05-10 17:13:13 -04:00
mk Uprev grub2 and shim 2018-06-27 13:04:02 -04:00
repo_files centos7: delete yum.pid after yum-builddep 2021-03-25 18:25:23 -04:00
requirements Temporary downgrade SQLAlchemy version in mock environments 2021-08-17 14:26:54 +03:00
signing StarlingX open source release updates 2018-06-01 07:45:23 -07:00
stx Debian/stx: utils: Minor run_shell_cmd fix-ups 2022-09-19 17:01:13 +00:00
unit-tests debian: port helm chart script to debian 2022-05-10 17:13:13 -04:00
audit-pkgs Build script readiness for renaming cgcs-centos-repo to centos-repo 2020-09-24 11:59:55 -04:00
build-avoidance-utils.sh build-avoidance: ensure we can write to a copied build environment. 2022-01-17 11:24:33 -05:00
build-guest build-guest: accept extra RPMs on command line 2021-08-16 09:29:05 -04:00
build-helm-charts.sh Merge "FluxCD: Add image versions from image record files" 2022-06-08 17:10:45 +00:00
build-img build-img: build PATCH.img-addon as REL and non-RR patch 2021-04-21 09:43:47 -03:00
build-iso build-iso: Create package_checksums file within iso 2022-05-03 12:41:05 -04:00
build-pkg-srpm StarlingX open source release updates 2018-06-01 07:45:23 -07:00
build-pkgs Add support CentOS-8/dnf/mock-2.6 based builds 2020-12-08 14:13:28 -05:00
build-pkgs-parallel Remove references to cgcs-3rd-party-repo 2020-10-27 14:26:03 -04:00
build-pkgs-serial Remove references to cgcs-3rd-party-repo 2020-10-27 14:26:03 -04:00
build-remote-cli.sh Support custom docker registries for remote cli 2020-03-18 16:29:49 +02:00
build-rpms Build Avoidance 2018-09-17 16:41:31 -04:00
build-rpms-parallel Fix memory overcommit that caused OOM killer 2021-03-10 10:05:20 -05:00
build-rpms-serial Fix memory overcommit that caused OOM killer 2021-03-10 10:05:20 -05:00
build-srpms Build Avoidance 2018-09-17 16:41:31 -04:00
build-srpms-common.sh Eliminate intermediate .tox files during build 2020-08-27 11:01:45 -05:00
build-srpms-parallel Exclude .tox folder when checking file ages 2020-12-21 15:25:27 -05:00
build-srpms-serial Exclude .tox folder when checking file ages 2020-12-21 15:25:27 -05:00
Cached_Data.txt StarlingX open source release updates 2018-06-01 07:45:23 -07:00
classify Build: Improved logging, error handling, and other small fixes 2018-08-29 16:31:09 -04:00
create_dependancy_cache.py Build script readiness for renaming cgcs-tis-repo to local-repo 2020-09-24 12:03:00 -04:00
create-yum-conf centos7: delete yum.pid after yum-builddep 2021-03-25 18:25:23 -04:00
deb-utils.sh debian: port helm chart script to debian 2022-05-10 17:13:13 -04:00
default_build_srpm Add support CentOS-8/dnf/mock-2.6 based builds 2020-12-08 14:13:28 -05:00
find_klm StarlingX open source release updates 2018-06-01 07:45:23 -07:00
find_patched_srpms_needing_upgrade StarlingX open source release updates 2018-06-01 07:45:23 -07:00
git-repo-utils.sh branching: Add retries to git push/review commands 2021-12-16 15:16:30 -05:00
git-utils.sh branching: Add retries to git push/review commands 2021-12-16 15:16:30 -05:00
helm_chart_modify.py Merge "FluxCD: Add image versions from image record files" 2022-06-08 17:10:45 +00:00
image-utils.sh Update to build tools to support Build layering. 2020-02-07 16:36:40 -05:00
ip_report.py Remove references to cgcs-3rd-party-repo 2020-10-27 14:26:03 -04:00
make-installer-images.sh update-pxe-network-installer: add updated firmwares 2022-05-23 14:18:43 +00:00
mock_cfg_to_yum_conf.py Python 3 compatibility: use print as a function. 2018-10-12 13:42:44 +00:00
mockchain-parallel Add support CentOS-8/dnf/mock-2.6 based builds 2020-12-08 14:13:28 -05:00
mockchain-parallel-1.3.4 Update to build tools to support Build layering. 2020-02-07 16:36:40 -05:00
mockchain-parallel-1.4.16 Update to build tools to support Build layering. 2020-02-07 16:36:40 -05:00
mockchain-parallel-2.6 Add support CentOS-8/dnf/mock-2.6 based builds 2020-12-08 14:13:28 -05:00
mockchain-parallel-2.7 Support mock >= 2.7 2021-02-19 12:33:58 -05:00
modify-build-cfg centos7: delete yum.pid after yum-builddep 2021-03-25 18:25:23 -04:00
patch_rebase_1 Build script readiness for renaming cgcs-centos-repo to centos-repo 2020-09-24 11:59:55 -04:00
patch_rebase_2 Build script readiness for renaming cgcs-centos-repo to centos-repo 2020-09-24 11:59:55 -04:00
patch_rebase_3 Build script readiness for renaming cgcs-centos-repo to centos-repo 2020-09-24 11:59:55 -04:00
patch_rebase_4 Build script readiness for renaming cgcs-centos-repo to centos-repo 2020-09-24 11:59:55 -04:00
patch-iso patch-iso: Fix up paths 2022-04-11 09:25:08 -04:00
pkg-manager-utils.sh Add support CentOS-8/dnf/mock-2.6 based builds 2020-12-08 14:13:28 -05:00
repo-utils.sh manifest_get_default_revision must deal with / in branch names 2022-02-01 11:03:43 -05:00
sign_iso_formal.sh cleanup signing scripts 2018-09-07 14:44:37 -04:00
sign_patch_formal.sh cleanup signing scripts 2018-09-07 14:44:37 -04:00
sign-rpms Prepare the build tools for code restucturing 2019-09-05 15:18:10 -04:00
sign-secure-boot Add -v flag to warn secure boot signing of the /var prefix 2021-12-30 16:35:52 -05:00
source_lookup.txt Remove 'django_openstack_auth' reference from source_lookup.txt 2021-07-13 23:16:25 +05:30
spec-utils enable pbr version 2020-06-08 16:54:14 +08:00
srpm-utils srpm-utils: Recognize /usr/bin/mkdir as well 2021-10-27 13:35:09 -04:00
stxRpmUtils.py Correct build failure after mock updrade 2019-06-06 13:39:34 -04:00
sync_jenkins.sh Remove references to cgcs-3rd-party-repo 2020-10-27 14:26:03 -04:00
sync-jenkins Remove references to cgcs-3rd-party-repo 2020-10-27 14:26:03 -04:00
tis.macros StarlingX open source release updates 2018-06-01 07:45:23 -07:00
update-efiboot-image Merge "Fix update-efiboot-image loop device leak" 2020-10-28 13:46:04 +00:00
update-pxe-network-installer build-tools: discover firmware files for installer 2022-06-03 10:55:56 -04:00
url_utils.sh branching: better control over reviews & manifests 2021-06-22 12:58:34 -04:00
utils.sh debian: code cleanup 2022-05-10 17:09:08 -04:00
wheel-utils.sh Enable build of docker images, charts and wheels from a layered build 2020-04-08 13:58:41 -04:00
wrs_orig.txt StarlingX open source release updates 2018-06-01 07:45:23 -07:00
yum-builddep-wrapper centos7: delete yum.pid after yum-builddep 2021-03-25 18:25:23 -04:00