Skip to content

Commit

Permalink
refactor: fix linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Danyal-Faheem committed Jul 19, 2024
1 parent e7497c0 commit 56feb06
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 16 deletions.
22 changes: 16 additions & 6 deletions tutor/commands/upgrade/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand Down
14 changes: 7 additions & 7 deletions tutor/commands/upgrade/compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -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...")
Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions tutor/commands/upgrade/k8s.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,17 +171,17 @@ 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 "
"responsibility to upgrade your MySQL instance to v8.4. There is "
"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
Expand Down

0 comments on commit 56feb06

Please sign in to comment.