diff --git a/etc/evergreen_yml_components/definitions.yml b/etc/evergreen_yml_components/definitions.yml index 4c29bf896d8..f79abd0ed48 100644 --- a/etc/evergreen_yml_components/definitions.yml +++ b/etc/evergreen_yml_components/definitions.yml @@ -808,6 +808,15 @@ functions: dir: src/buildscripts/antithesis/base_images/workload/src - *configure_evergreen_api_credentials + "do pre workstation setup": + - command: manifest.load + - *git_get_shallow_project + - *f_expansions_write + - *restore_git_history_and_tags + - *add_git_tag + - *kill_processes + - *cleanup_environment + "do non-compile setup": - command: manifest.load - *git_get_shallow_project @@ -1267,6 +1276,17 @@ functions: - *check_run_tests_infrastructure_failure - *check_resmoke_failure + "set up then check workstation script": + - command: subprocess.exec + params: + binary: bash + args: + - "-c" + - | + cd ./src + ./etc/set_up_workstation.sh + ./evergreen/check_workstation_setup.sh + "run tests": - *f_expansions_write - *configure_evergreen_api_credentials diff --git a/etc/evergreen_yml_components/tasks/resmoke/non_server_teams/tasks.yml b/etc/evergreen_yml_components/tasks/resmoke/non_server_teams/tasks.yml index 2eda4949361..44a778c8e50 100644 --- a/etc/evergreen_yml_components/tasks/resmoke/non_server_teams/tasks.yml +++ b/etc/evergreen_yml_components/tasks/resmoke/non_server_teams/tasks.yml @@ -116,6 +116,13 @@ tasks: vars: resmoke_jobs_max: 1 + - name: check_workstation_setup_script + tags: ["assigned_to_jira_team_devprod_correctness", "development_critical"] + depends_on: [] + commands: + - func: "do pre workstation setup" + - func: "set up then check workstation script" + - <<: *gen_burn_in_task_template name: burn_in_tags_gen tags: ["assigned_to_jira_team_devprod_correctness", "auxiliary"] diff --git a/etc/evergreen_yml_components/variants/misc/misc_master_branch_only.yml b/etc/evergreen_yml_components/variants/misc/misc_master_branch_only.yml index 452d699ac25..4cd609e8400 100644 --- a/etc/evergreen_yml_components/variants/misc/misc_master_branch_only.yml +++ b/etc/evergreen_yml_components/variants/misc/misc_master_branch_only.yml @@ -26,6 +26,9 @@ buildvariants: - name: monitor_build_status distros: - ubuntu2404-large + - name: check_workstation_setup_script + distros: + - ubuntu2204-arm64-small # Experimental variant running bazel targets for integration tests. To be removed with SERVER-103537. - name: bazel-integration-tests diff --git a/etc/gdb_init b/etc/gdb_init new file mode 100644 index 00000000000..f0f658ab870 --- /dev/null +++ b/etc/gdb_init @@ -0,0 +1,38 @@ +add-auto-load-safe-path / + +set pagination off +set print object on + +set print static-members off +set print pretty on +#set print elements 0 + +# include venv in the Python path +python +import os, subprocess, sys +try: + gdb_python_version = sys.version.split()[0] + shell_python_version = subprocess.check_output('python -c "import sys;print(sys.version.split()[0])"', shell=True).decode("utf-8").strip() + if gdb_python_version == shell_python_version: + # Execute a Python using the user's shell and pull out the sys.path (for site-packages) + shell_paths = subprocess.check_output('python -c "import os,sys;print(os.linesep.join(sys.path).strip())"', shell=True).decode("utf-8").split() + # Extend GDB's Python's search path + sys.path.extend(path for path in shell_paths if not path in sys.path) + print("Included venv Python path") + else: + print("Failed to include venv Python path: Python version mismatch (shell {}, gdb {})".format(shell_python_version, gdb_python_version)) +except Exception as e: + print("Failed to include venv Python path: " + str(e)) +end + +# register boost pretty printers +python +import sys, pathlib +try: + sys.path.insert(1, os.path.join(pathlib.Path.home(), 'Boost-Pretty-Printer')) + import boost + boost.register_printers(boost_version=(1,60,0)) + print("Loaded boost pretty printers") +except Exception as e: + print("Failed to load the boost pretty printers: " + str(e)) +end \ No newline at end of file diff --git a/etc/set_up_workstation.sh b/etc/set_up_workstation.sh new file mode 100755 index 00000000000..9c325e87316 --- /dev/null +++ b/etc/set_up_workstation.sh @@ -0,0 +1,162 @@ +silent_grep() { + command grep -q > /dev/null 2>&1 "$@" +} + +idem_file_append() { + if [[ -z "$1" ]]; then + return 1 + fi + if [[ ! -f "$1" && -n "${4-}" ]]; then + return + fi + if [[ -z "$2" ]]; then + return 2 + fi + if [[ -z "$3" ]]; then + return 3 + fi + local start_marker="# BEGIN $2" + local end_marker="# END $2" + if ! silent_grep "^$start_marker" "$1"; then + { + echo -e "\n$start_marker"; + echo -e "$3"; + echo -e "$end_marker"; + } >> "$1" + fi +} + +setup_bash() { + # Bash profile should source .bashrc + echo "################################################################################" + echo "Setting up bash..." + local block=$(cat < /dev/null; then + echo "'poetry' command exists; skipping setup" + else + pipx install poetry==2.0.0 + echo "Finished installing poetry..." + fi +} + +setup_pipx() { + echo "################################################################################" + echo "Installing 'pipx' command..." + if command -v pipx &> /dev/null; then + echo "'pipx' command exists; skipping setup" + else + export PATH="$PATH:$HOME/.local/bin" + local venv_name="tmp-pipx-venv" + /opt/mongodbtoolchain/v4/bin/python3 -m venv $venv_name + + # virtualenv doesn't like nounset + set +o nounset + source $venv_name/bin/activate + set -o nounset + + python -m pip install --upgrade "pip<20.3" + python -m pip install pipx + + pipx install pipx --python /opt/mongodbtoolchain/v4/bin/python3 --force + pipx ensurepath --force + + set +o nounset + deactivate + set -o nounset + + rm -rf $venv_name + + source ~/.bashrc + + echo "Finished installing pipx..." + fi +} + +setup_db_contrib_tool() { + echo "################################################################################" + echo "Installing 'db-contrib-tool' command..." + export PATH="$PATH:$HOME/.local/bin" + if command -v db-contrib-tool &> /dev/null; then + echo "'db-contrib-tool' command exists; skipping setup" + else + pipx install db-contrib-tool + echo "Finished installing db-contrib-tool" + fi +} + +setup_gdb() { + echo "################################################################################" + echo "Setting up GDB..." + + cwd=$(pwd) + cd .. + if [[ -d 'Boost-Pretty-Printer' ]]; then + echo "'Boost-Pretty-Printer' dir exists; skipping setup" + else + git clone https://github.com/mongodb-forks/Boost-Pretty-Printer.git + + # the original version of this script just appended this line, so we + # have to grep for it manually + if ! silent_grep "source $HOME/gdbinit" ~/.gdbinit; then + idem_file_append ~/.gdbinit "Server Workflow Tool gdbinit" "source $HOME/gdbinit" + fi + + echo "Finished installing pretty printers..." + fi + cd $cwd +} + +run_setup() { + set +o nounset + source ~/.bashrc + set -o nounset + + setup_bash + + setup_gdb + setup_pipx + setup_db_contrib_tool # This step requires `setup_pipx` to have been run. + setup_poetry # This step requires `setup_pipx` to have been run. + + setup_mongo_venv # This step requires `setup_poetry` to have been run. + + echo "Please run 'source ~/.bashrc' to complete setup!" +} + +run_setup diff --git a/evergreen/check_workstation_setup.sh b/evergreen/check_workstation_setup.sh new file mode 100755 index 00000000000..98478673e51 --- /dev/null +++ b/evergreen/check_workstation_setup.sh @@ -0,0 +1,51 @@ +failed_setup=false + +source ~/.bashrc + +if command -v pipx &> /dev/null; then + echo "'pipx' command exists" +else + echo "pipx command not found - failed setup" + failed_setup=true +fi + +if command -v poetry &> /dev/null; then + echo "'poetry' command exists" +else + echo "poetry command not found - failed setup" + failed_setup=true +fi + +if command -v db-contrib-tool &> /dev/null; then + echo "'db-contrib-tool' command exists" +else + echo "db-contrib-tool command not found - failed setup" + failed_setup=true +fi + +if test -d "./python3-venv"; then + echo "Venv directory exists, checking activation" + . python3-venv/bin/activate + ./buildscripts/resmoke.py run --help &> /dev/null + if [ $? -eq 0 ]; then + echo "Virtual workstation set up correctly" + else + echo "Virtual workstation failed activation" + failed_setup=true + fi + deactivate +else + echo "mongo virtual environment not created correctly - failed setup" + failed_setup=true +fi + +if test -d "../Boost-Pretty-Printer"; then + echo "Pretty printers set up correctly" +else + echo "Pretty printers failed setup" + failed_setup=true +fi + +if $failed_setup; then + exit 1 +fi