6
0
mirror of https://github.com/ChristianLight/tutor.git synced 2024-09-28 20:29:02 +00:00
tutor/tests
Kyle McCormick 6a3138152f fix: accurately log shell commands when running jobs
Whenever Tutor executes a shell command, it logs out said
command in order to aid in end user understanding/debugging.

In some cases (notably, when running jobs in containers)
the logged command was not accurately quoted. The command
was run correctly, because it was passed in pieces to
``subprocess.Popen``, which correctly joins the pieces together
into a valid POSIX shell command; however, the logged version
of the command was constructed by simply joining the pieces
with spaces. This usually works, but breaks down when running
complex shell commands with nested quoting.

This commit changes the logging to use ``shlex.join``, which
joins command pieces together in a POSIX-compliant way,
presumably the same way as ``subprocess.Popen``.

Example:

    tutor local importdemocourse

runs the shell command:

    docker-compose -f /home/kyle/.local/share/tutor/env/local/docker-compose.yml -f /home/kyle/.local/share/tutor/env/local/docker-compose.prod.yml -f /home/kyle/.local/share/tutor/env/local/docker-compose.tmp.yml --project-name tutor_local -f /home/kyle/.local/share/tutor/env/local/docker-compose.jobs.yml -f /home/kyle/.local/share/tutor/env/local/docker-compose.jobs.tmp.yml run --rm cms-job sh -e -c 'echo "Loading settings $DJANGO_SE... (several more script lines) ...eindex_course --all --setup'

but the logged shell command was:

    docker-compose -f /home/kyle/.local/share/tutor/env/local/docker-compose.yml -f /home/kyle/.local/share/tutor/env/local/docker-compose.prod.yml -f /home/kyle/.local/share/tutor/env/local/docker-compose.tmp.yml --project-name tutor_local -f /home/kyle/.local/share/tutor/env/local/docker-compose.jobs.yml -f /home/kyle/.local/share/tutor/env/local/docker-compose.jobs.tmp.yml run --rm cms-job sh -e -c echo "Loading settings $DJANGO_SE... (several more script lines) ...eindex_course --all --setup

which will not run if copied and pasted back into the
user's terminal, as the importdemocourse shell script is unquoted.
2022-07-25 22:46:53 +02:00
..
commands fix: avoid double-rendering mounts to docker-compose.tmp.yml (#669) 2022-07-25 15:58:49 +02:00
hooks feat: migrate to plugins.v1 with filters & actions 2022-04-15 15:30:54 +02:00
__init__.py Add unit tests! yay! 2019-03-23 16:16:44 -07:00
helpers.py feat: migrate to plugins.v1 with filters & actions 2022-04-15 15:30:54 +02:00
openedx-lms-common-settings Better dev environment 2019-10-24 20:03:36 +02:00
test_bindmounts.py fix: crash during local quickstart -p 2021-05-07 17:01:09 +02:00
test_config.py feat: introduce tutor dev quickstart 2022-04-19 16:53:57 +02:00
test_env.py v14.0.0: upgrade to Nutmeg 2022-06-09 19:18:20 +02:00
test_images.py refactor: add code coverage, cover CLI commands with tests 2022-01-04 13:40:33 +01:00
test_jobs.py fix: unit tests with v1 plugin installed 2022-04-20 19:48:21 +02:00
test_plugins_v0.py feat: migrate to plugins.v1 with filters & actions 2022-04-15 15:30:54 +02:00
test_serialize.py fix: YamlParamType supports line terminators 2021-04-25 09:14:21 +02:00
test_utils.py fix: accurately log shell commands when running jobs 2022-07-25 22:46:53 +02:00