diff --git a/tutor/commands/upgrade/common.py b/tutor/commands/upgrade/common.py index 154a8755a8..86537bff02 100644 --- a/tutor/commands/upgrade/common.py +++ b/tutor/commands/upgrade/common.py @@ -4,7 +4,7 @@ from tutor import config as tutor_config from tutor import fmt, plugins -from tutor.types import Config +from tutor.types import Config, ConfigValue def upgrade_from_lilac(config: Config) -> None: @@ -47,21 +47,31 @@ def get_mysql_change_authentication_plugin_query(config: Config) -> str: """Helper function to generate queries depending on the loaded plugins""" loaded_plugins = list(plugins.iter_loaded()) - def generate_mysql_authentication_plugin_update_query(username: str, password: str, host: str) -> str: + def generate_mysql_authentication_plugin_update_query( + username: ConfigValue, password: ConfigValue, host: str + ) -> str: return f"ALTER USER '{username}'@'{host}' IDENTIFIED with caching_sha2_password BY '{password}';" host = "%" query = "" query += generate_mysql_authentication_plugin_update_query( - config["MYSQL_ROOT_USERNAME"], config["MYSQL_ROOT_PASSWORD"], host) + config["MYSQL_ROOT_USERNAME"], config["MYSQL_ROOT_PASSWORD"], host + ) query += generate_mysql_authentication_plugin_update_query( - config["OPENEDX_MYSQL_USERNAME"], config["OPENEDX_MYSQL_PASSWORD"], host) + config["OPENEDX_MYSQL_USERNAME"], config["OPENEDX_MYSQL_PASSWORD"], host + ) for plugin in loaded_plugins: plugin_uppercase = plugin.upper() - if f"{plugin_uppercase}_MYSQL_USERNAME" in config and f"{plugin_uppercase}_MYSQL_PASSWORD" in config: + if ( + f"{plugin_uppercase}_MYSQL_USERNAME" in config + and f"{plugin_uppercase}_MYSQL_PASSWORD" in config + ): query += generate_mysql_authentication_plugin_update_query( - config[f"{plugin_uppercase}_MYSQL_USERNAME"], config[f"{plugin_uppercase}_MYSQL_PASSWORD"], host) + config[f"{plugin_uppercase}_MYSQL_USERNAME"], + config[f"{plugin_uppercase}_MYSQL_PASSWORD"], + host, + ) return query diff --git a/tutor/commands/upgrade/compose.py b/tutor/commands/upgrade/compose.py index 4a67104621..add13fc77c 100644 --- a/tutor/commands/upgrade/compose.py +++ b/tutor/commands/upgrade/compose.py @@ -176,10 +176,9 @@ def upgrade_from_quince(context: click.Context, config: Config) -> None: # Revert the MySQL image first to build data dictionary on v8.1 old_mysql_docker_image = "docker.io/mysql:8.1.0" - new_mysql_docker_image = config["DOCKER_IMAGE_MYSQL"] + new_mysql_docker_image = str(config["DOCKER_IMAGE_MYSQL"]) config["DOCKER_IMAGE_MYSQL"] = old_mysql_docker_image - click.echo( - fmt.title(f"Upgrading MySQL to v{new_mysql_docker_image.split(':')[1]}")) + click.echo(fmt.title(f"Upgrading MySQL to v{new_mysql_docker_image.split(':')[1]}")) tutor_env.save(context.obj.root, config) context.invoke(compose.start, detach=True, services=["mysql"]) fmt.echo_info("Waiting for MySQL to boot...") @@ -195,12 +194,13 @@ def upgrade_from_quince(context: click.Context, config: Config) -> None: "bash", "-e", "-c", - f"mysql --user={config['MYSQL_ROOT_USERNAME']} --password='{config['MYSQL_ROOT_PASSWORD']}' --host={config['MYSQL_HOST']} --port={config['MYSQL_PORT']} --skip-column-names --silent " + shlex.join([ - f"--database={config['OPENEDX_MYSQL_DATABASE']}", "-e", query]) - + f"mysql --user={config['MYSQL_ROOT_USERNAME']} --password='{config['MYSQL_ROOT_PASSWORD']}' --host={config['MYSQL_HOST']} --port={config['MYSQL_PORT']} --skip-column-names --silent " + + shlex.join( + [f"--database={config['OPENEDX_MYSQL_DATABASE']}", "-e", query] + ), ], ) - + # Upgrade back to v8.4 config["DOCKER_IMAGE_MYSQL"] = new_mysql_docker_image tutor_env.save(context.obj.root, config) diff --git a/tutor/commands/upgrade/k8s.py b/tutor/commands/upgrade/k8s.py index f961164157..fee9918993 100644 --- a/tutor/commands/upgrade/k8s.py +++ b/tutor/commands/upgrade/k8s.py @@ -171,7 +171,7 @@ def upgrade_from_quince(config: Config) -> None: upgrade_mongodb(config, "5.0.26", "5.0") upgrade_mongodb(config, "6.0.14", "6.0") upgrade_mongodb(config, "7.0.7", "7.0") - + if not config["RUN_MYSQL"]: fmt.echo_info( "You are not running MySQL (RUN_MYSQL=false). It is your " @@ -179,9 +179,9 @@ def upgrade_from_quince(config: Config) -> None: "nothing left to do to upgrade from Quince." ) return - + query = common_upgrade.get_mysql_change_authentication_plugin_query(config) - + # We need to first revert MySQL back to v8.1 to build the data dictionary on it # And also to update the authentication plugin as it is disabled on v8.4 message = f"""Automatic release upgrade is unsupported in Kubernetes. If you are upgrading from Olive or an earlier release to Redwood, you