From fd38dfd826e18877d1b29139351d82941a82d038 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mois=C3=A9s=20Gonz=C3=A1lez?= Date: Wed, 3 Dec 2025 17:35:18 -0400 Subject: [PATCH] fix: improve mongo and mysql delete commands Include the ReplicaSet configuration in the mongosh command. Delete the notes user if the notes plugin is enabled. --- CHANGELOG.md | 10 ++++++++ drydock/plugin.py | 64 ++++++++++++++++++++++++++++++++++++++--------- pyproject.toml | 2 +- uv.lock | 2 +- 4 files changed, 64 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 927aae0..a4ac7bc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,16 @@ See the fragment files in the [changelog.d/ directory](./changelog.d). + +## 20.1.1 — 2025-12-04 + +### Fixed + +- Adjust the drop-db command to properly handle replica set configuration if + available. Remove the Notes user if the Notes plugin is enabled. +- Avoid erroring when calling `iter_mfes` if the MFE plugin is not enabled. + Useful for testing with the minimal dependencies. + ## v20.1.0 (2025-11-10) diff --git a/drydock/plugin.py b/drydock/plugin.py index 59501be..cd95a3d 100644 --- a/drydock/plugin.py +++ b/drydock/plugin.py @@ -245,21 +245,61 @@ def delete_dbs_command(): MONGO_DROP_COMMAND = """ mongosh \ - {% if MONGODB_ROOT_USERNAME and MONGODB_ROOT_PASSWORD %} \ - mongodb://{{ MONGODB_ROOT_USERNAME }}:{{ MONGODB_ROOT_PASSWORD }}@{{ MONGODB_HOST }}:{{ MONGODB_PORT }}/{{ MONGODB_DATABASE }}?authSource={{ MONGODB_AUTH_SOURCE }} --eval 'db.dropDatabase()' - {% else %} \ - mongodb://{{ MONGODB_HOST }}:{{ MONGODB_PORT }}/{{ MONGODB_DATABASE }}?authSource={{ MONGODB_AUTH_SOURCE }} --eval 'db.dropDatabase()' - {% if 'forum' in PLUGINS %} - mongodb://{{ MONGODB_HOST }}:{{ MONGODB_PORT }}/{{ FORUM_MONGODB_DATABASE }}?authSource={{ MONGODB_AUTH_SOURCE }} --eval 'db.dropDatabase()' - {% endif %} - {% endif %} + --host {% if MONGODB_REPLICA_SET %}{{ MONGODB_REPLICA_SET }}/{% endif %}{{ MONGODB_HOST }} \ + --port {{ MONGODB_PORT }} \ + {% if MONGODB_ROOT_USERNAME %} \ + --username {{ MONGODB_ROOT_USERNAME }} \ + {% endif %} \ + {% if MONGODB_ROOT_PASSWORD %} \ + --password {{ MONGODB_ROOT_PASSWORD }} \ + {% endif %} \ + --authenticationDatabase {{ MONGODB_AUTH_SOURCE }} \ + {% if MONGODB_USE_SSL %} --tls true {% endif %} \ + {{ MONGODB_DATABASE }} \ + --eval 'db.dropDatabase()' + + {% if 'forum' in PLUGINS %} + mongosh \ + --host {% if MONGODB_REPLICA_SET %}{{ MONGODB_REPLICA_SET }}/{% endif %}{{ MONGODB_HOST }} \ + --port {{ MONGODB_PORT }} \ + {% if MONGODB_ROOT_USERNAME %} \ + --username {{ MONGODB_ROOT_USERNAME }} \ + {% endif %} \ + {% if MONGODB_ROOT_PASSWORD %} \ + --password {{ MONGODB_ROOT_PASSWORD }} \ + {% endif %} \ + --authenticationDatabase {{ MONGODB_AUTH_SOURCE }} \ + {% if MONGODB_USE_SSL %} --tls true {% endif %} \ + {{ FORUM_MONGODB_DATABASE }} \ + --eval 'db.dropDatabase()' + {% endif %} """ MYSQL_DROP_COMMAND = """ - mysql -u {{ MYSQL_ROOT_USERNAME }} --password="{{ MYSQL_ROOT_PASSWORD }}" --host "{{ MYSQL_HOST }}" --port {{ MYSQL_PORT }} -e "DROP DATABASE IF EXISTS {{ OPENEDX_MYSQL_DATABASE }};" - mysql -u {{ MYSQL_ROOT_USERNAME }} --password="{{ MYSQL_ROOT_PASSWORD }}" --host "{{ MYSQL_HOST }}" --port {{ MYSQL_PORT }} -e "DROP USER IF EXISTS '{{ OPENEDX_MYSQL_USERNAME }}';" + mysql \ + --user {{ MYSQL_ROOT_USERNAME }} \ + --password="{{ MYSQL_ROOT_PASSWORD }}" \ + --host "{{ MYSQL_HOST }}" \ + --port {{ MYSQL_PORT }} \ + --execute "DROP DATABASE IF EXISTS {{ OPENEDX_MYSQL_DATABASE }};" + mysql \ + --user {{ MYSQL_ROOT_USERNAME }} \ + --password="{{ MYSQL_ROOT_PASSWORD }}" \ + --host "{{ MYSQL_HOST }}" \ + --port {{ MYSQL_PORT }} \ + --execute "DROP USER IF EXISTS '{{ OPENEDX_MYSQL_USERNAME }}';" \ {% if 'notes' in PLUGINS %} - mysql -u {{ MYSQL_ROOT_USERNAME }} --password="{{ MYSQL_ROOT_PASSWORD }}" --host "{{ MYSQL_HOST }}" --port {{ MYSQL_PORT }} -e 'DROP DATABASE IF EXISTS {{ NOTES_MYSQL_DATABASE }};' - mysql -u {{ MYSQL_ROOT_USERNAME }} --password="{{ MYSQL_ROOT_PASSWORD }}" --host "{{ MYSQL_HOST }}" --port {{ MYSQL_PORT }} -e "DROP USER IF EXISTS '{{ NOTES_MYSQL_USERNAME }}';" + mysql \ + --user {{ MYSQL_ROOT_USERNAME }} \ + --password="{{ MYSQL_ROOT_PASSWORD }}" \ + --host "{{ MYSQL_HOST }}" \ + --port {{ MYSQL_PORT }} \ + --execute 'DROP DATABASE IF EXISTS {{ NOTES_MYSQL_DATABASE }};' \ + mysql \ + --user {{ MYSQL_ROOT_USERNAME }} \ + --password="{{ MYSQL_ROOT_PASSWORD }}" \ + --host "{{ MYSQL_HOST }}" \ + --port {{ MYSQL_PORT }} \ + --execute 'DROP USER IF EXISTS {{ NOTES_MYSQL_USERNAME }};' \ {% endif %} """ do_callback( diff --git a/pyproject.toml b/pyproject.toml index 8842605..568a184 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "tutor-contrib-drydock" -version = "20.1.0" +version = "20.1.1" description = "A Tutor plugin to manage our opinionated Open edX operations" readme = "README.md" requires-python = ">=3.10" diff --git a/uv.lock b/uv.lock index 6b8c8bf..5d5456f 100644 --- a/uv.lock +++ b/uv.lock @@ -801,7 +801,7 @@ sdist = { url = "https://files.pythonhosted.org/packages/f9/8f/423a562a1873b376a [[package]] name = "tutor-contrib-drydock" -version = "20.1.0" +version = "20.1.1" source = { editable = "." } dependencies = [ { name = "tutor" },