From 172ae9ea5da66efea736528d9f8c8417ce6bbaf4 Mon Sep 17 00:00:00 2001 From: Saurabh Date: Mon, 20 May 2024 17:58:48 +0530 Subject: [PATCH 01/11] feat: managed database support for hybrid setup --- agent/bench.py | 42 +++++++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/agent/bench.py b/agent/bench.py index cd6cd8bc..f8c61264 100644 --- a/agent/bench.py +++ b/agent/bench.py @@ -186,20 +186,36 @@ def docker_execute( ) @step("New Site") - def bench_new_site(self, name, mariadb_root_password, admin_password): - site_database, temp_user, temp_password = self.create_mariadb_user( - name, mariadb_root_password - ) - try: - return self.docker_execute( - f"bench new-site --no-mariadb-socket " - f"--mariadb-root-username {temp_user} " - f"--mariadb-root-password {temp_password} " - f"--admin-password {admin_password} " - f"--db-name {site_database} {name}" + def bench_new_site(self, name, mariadb_root_password, admin_password, config=None): + if config.get("managed_databse"): + try: + return self.docker_execute( + f"bench new-site --no-mariadb-socket " + f"--mariadb-root-username {config.get('db_user')} " + f"--mariadb-root-password {config.get('db_password')} " + f"--db-user {config.get('db_user')} " + f"--db-name {config.get('db_name')} " + f"--db-port {config.get('db_port')} " + f"--db-host {config.get('db_host')} " + f"--admin-password {admin_password} " + f"--no-setup-db {name}" + ) + except Exception: + pass + else: + site_database, temp_user, temp_password = self.create_mariadb_user( + name, mariadb_root_password ) - finally: - self.drop_mariadb_user(name, mariadb_root_password, site_database) + try: + return self.docker_execute( + f"bench new-site --no-mariadb-socket " + f"--mariadb-root-username {temp_user} " + f"--mariadb-root-password {temp_password} " + f"--admin-password {admin_password} " + f"--db-name {site_database} {name}" + ) + finally: + self.drop_mariadb_user(name, mariadb_root_password, site_database) @job("Create User", priority="high") def create_user( From 0477780afe68587a0c957b11166e8aa4d21ba80c Mon Sep 17 00:00:00 2001 From: Saurabh Date: Tue, 21 May 2024 12:00:00 +0530 Subject: [PATCH 02/11] feat: manage conf and handle execption --- agent/bench.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/agent/bench.py b/agent/bench.py index f8c61264..4207811a 100644 --- a/agent/bench.py +++ b/agent/bench.py @@ -187,7 +187,7 @@ def docker_execute( @step("New Site") def bench_new_site(self, name, mariadb_root_password, admin_password, config=None): - if config.get("managed_databse"): + if config.get("managed_database"): try: return self.docker_execute( f"bench new-site --no-mariadb-socket " @@ -201,7 +201,7 @@ def bench_new_site(self, name, mariadb_root_password, admin_password, config=Non f"--no-setup-db {name}" ) except Exception: - pass + traceback.print_exc() else: site_database, temp_user, temp_password = self.create_mariadb_user( name, mariadb_root_password @@ -397,7 +397,7 @@ def _inactive_web_sites(bench): def new_site( self, name, config, apps, mariadb_root_password, admin_password, create_user: dict = None ): - self.bench_new_site(name, mariadb_root_password, admin_password) + self.bench_new_site(name, mariadb_root_password, admin_password, config=config) site = Site(name, self) site.install_apps(apps) site.update_config(config) @@ -427,7 +427,7 @@ def new_site_from_backup( skip_failing_patches, ): files = self.download_files(name, database, public, private) - self.bench_new_site(name, mariadb_root_password, admin_password) + self.bench_new_site(name, mariadb_root_password, admin_password, config=default_config) site = Site(name, self) site.update_config(default_config) try: From 64682fc582f166bd729599129ff9ede8a54e441b Mon Sep 17 00:00:00 2001 From: Saurabh Date: Tue, 28 May 2024 18:16:20 +0530 Subject: [PATCH 03/11] feat: support for restore and reinstall operation on managed database --- agent/site.py | 92 +++++++++++++++++++++++++++++++++++---------------- agent/web.py | 4 ++- 2 files changed, 67 insertions(+), 29 deletions(-) diff --git a/agent/site.py b/agent/site.py index 946e1172..f394f6e4 100644 --- a/agent/site.py +++ b/agent/site.py @@ -3,6 +3,7 @@ import re import shutil import time +import traceback from datetime import datetime from typing import Dict, TYPE_CHECKING from shlex import quote @@ -111,6 +112,8 @@ def restore( database_file, public_file, private_file, + managed_database=False, + mariadb_root_user=None, ): sites_directory = self.bench.sites_directory database_file = database_file.replace( @@ -130,23 +133,37 @@ def restore( f"--with-private-files {private_file} " if private_file else "" ) - _, temp_user, temp_password = self.bench.create_mariadb_user( - self.name, mariadb_root_password, self.database - ) - try: - return self.bench_execute( - "--force restore " - f"--mariadb-root-username {temp_user} " - f"--mariadb-root-password {temp_password} " - f"--admin-password {admin_password} " - f"{public_file_option} " - f"{private_file_option} " - f"{database_file}" - ) - finally: - self.bench.drop_mariadb_user( + if managed_database: + try: + return self.bench_execute( + "--force restore " + f"--mariadb-root-username {mariadb_root_user} " + f"--mariadb-root-password {mariadb_root_password} " + f"--admin-password {admin_password} " + f"{public_file_option} " + f"{private_file_option} " + f"{database_file}" + ) + except Exception: + traceback.print_exc() + else: + _, temp_user, temp_password = self.bench.create_mariadb_user( self.name, mariadb_root_password, self.database ) + try: + return self.bench_execute( + "--force restore " + f"--mariadb-root-username {temp_user} " + f"--mariadb-root-password {temp_password} " + f"--admin-password {admin_password} " + f"{public_file_option} " + f"{private_file_option} " + f"{database_file}" + ) + finally: + self.bench.drop_mariadb_user( + self.name, mariadb_root_password, self.database + ) @job("Restore Site") def restore_job( @@ -158,6 +175,8 @@ def restore_job( public, private, skip_failing_patches, + mariadb_root_user, + managed_database, ): files = self.bench.download_files(self.name, database, public, private) try: @@ -167,6 +186,8 @@ def restore_job( files["database"], files["public"], files["private"], + managed_database, + mariadb_root_user, ) finally: self.bench.delete_downloaded_files(files["directory"]) @@ -191,29 +212,44 @@ def reinstall( self, mariadb_root_password, admin_password, + managed_database=False, + mariadb_root_user=None, ): - _, temp_user, temp_password = self.bench.create_mariadb_user( - self.name, mariadb_root_password, self.database - ) - try: - return self.bench_execute( - f"reinstall --yes " - f"--mariadb-root-username {temp_user} " - f"--mariadb-root-password {temp_password} " - f"--admin-password {admin_password}" - ) - finally: - self.bench.drop_mariadb_user( + if managed_database: + try: + return self.bench_execute( + f"reinstall --yes " + f"--mariadb-root-username {mariadb_root_user} " + f"--mariadb-root-password {mariadb_root_password} " + f"--admin-password {admin_password}" + ) + except Exception: + traceback.print_exc() + else: + _, temp_user, temp_password = self.bench.create_mariadb_user( self.name, mariadb_root_password, self.database ) + try: + return self.bench_execute( + f"reinstall --yes " + f"--mariadb-root-username {temp_user} " + f"--mariadb-root-password {temp_password} " + f"--admin-password {admin_password}" + ) + finally: + self.bench.drop_mariadb_user( + self.name, mariadb_root_password, self.database + ) @job("Reinstall Site") def reinstall_job( self, mariadb_root_password, admin_password, + managed_database=False, + mariadb_root_user=None, ): - return self.reinstall(mariadb_root_password, admin_password) + return self.reinstall(mariadb_root_password, admin_password, managed_database, mariadb_root_user) @job("Install App on Site") def install_app_job(self, app): diff --git a/agent/web.py b/agent/web.py index 984434be..84ac1dfe 100644 --- a/agent/web.py +++ b/agent/web.py @@ -423,6 +423,8 @@ def restore_site(bench, site): data.get("public"), data.get("private"), data.get("skip_failing_patches", False), + data.get("managed_database", False), + data.get("mariadb_root_user", "") ) ) return {"job": job} @@ -438,7 +440,7 @@ def reinstall_site(bench, site): Server() .benches[bench] .sites[site] - .reinstall_job(data["mariadb_root_password"], data["admin_password"]) + .reinstall_job(data["mariadb_root_password"], data["admin_password"], data["managed_database"], data["mariadb_root_user"]) ) return {"job": job} From d77134ee59a284c84789155af52ee84a1640b805 Mon Sep 17 00:00:00 2001 From: Saurabh Date: Wed, 29 May 2024 19:03:39 +0530 Subject: [PATCH 04/11] feat: provision to support managed database --- agent/bench.py | 31 ++++++++++++++++++------------- agent/site.py | 23 ++++++++++++----------- agent/web.py | 11 ++++++++--- 3 files changed, 38 insertions(+), 27 deletions(-) diff --git a/agent/bench.py b/agent/bench.py index 4207811a..c27260b1 100644 --- a/agent/bench.py +++ b/agent/bench.py @@ -186,19 +186,14 @@ def docker_execute( ) @step("New Site") - def bench_new_site(self, name, mariadb_root_password, admin_password, config=None): - if config.get("managed_database"): + def bench_new_site(self, name, mariadb_root_password, admin_password, managed_database_config=None): + if managed_database_config: try: return self.docker_execute( f"bench new-site --no-mariadb-socket " - f"--mariadb-root-username {config.get('db_user')} " - f"--mariadb-root-password {config.get('db_password')} " - f"--db-user {config.get('db_user')} " - f"--db-name {config.get('db_name')} " - f"--db-port {config.get('db_port')} " - f"--db-host {config.get('db_host')} " - f"--admin-password {admin_password} " - f"--no-setup-db {name}" + f"--mariadb-root-username {managed_database_config.get('database_user')} " + f"--mariadb-root-password {mariadb_root_password} " + f"--admin-password {admin_password} {name}" ) except Exception: traceback.print_exc() @@ -395,9 +390,12 @@ def _inactive_web_sites(bench): @job("New Site", priority="high") def new_site( - self, name, config, apps, mariadb_root_password, admin_password, create_user: dict = None + self, name, config, apps, mariadb_root_password, admin_password, managed_database_config, create_user: dict = None ): - self.bench_new_site(name, mariadb_root_password, admin_password, config=config) + + self.bench_new_site( + name, mariadb_root_password, admin_password, managed_database_config=managed_database_config + ) site = Site(name, self) site.install_apps(apps) site.update_config(config) @@ -425,11 +423,16 @@ def new_site_from_backup( public, private, skip_failing_patches, + managed_database_config=None, ): files = self.download_files(name, database, public, private) - self.bench_new_site(name, mariadb_root_password, admin_password, config=default_config) + self.bench_new_site( + name, mariadb_root_password, admin_password, managed_database_config=managed_database_config + ) site = Site(name, self) site.update_config(default_config) + managed_database = 1 if managed_database_config else 0 + try: site.restore( mariadb_root_password, @@ -437,6 +440,8 @@ def new_site_from_backup( files["database"], files["public"], files["private"], + managed_database=managed_database, + mariadb_root_user=managed_database_config['database_user'] ) if site_config: site_config = json.loads(site_config) diff --git a/agent/site.py b/agent/site.py index f394f6e4..c3d06960 100644 --- a/agent/site.py +++ b/agent/site.py @@ -47,6 +47,7 @@ def __init__(self, name: str, bench: "Bench"): self.user = self.config["db_name"] self.password = self.config["db_password"] self.host = self.config.get("db_host", self.bench.host) + self.port = self.config.get("db_port", '3306') def bench_execute(self, command, input=None): return self.bench.docker_execute( @@ -175,10 +176,11 @@ def restore_job( public, private, skip_failing_patches, - mariadb_root_user, - managed_database, + managed_database_config=None, ): files = self.bench.download_files(self.name, database, public, private) + + managed_database = 1 if managed_database_config else 0 try: self.restore( mariadb_root_password, @@ -186,8 +188,8 @@ def restore_job( files["database"], files["public"], files["private"], - managed_database, - mariadb_root_user, + managed_database=managed_database, + mariadb_root_user=managed_database_config['database_user'], ) finally: self.bench.delete_downloaded_files(files["directory"]) @@ -212,11 +214,11 @@ def reinstall( self, mariadb_root_password, admin_password, - managed_database=False, - mariadb_root_user=None, + managed_database_config=None ): - if managed_database: + if managed_database_config: try: + mariadb_root_user = managed_database_config["database_user"] return self.bench_execute( f"reinstall --yes " f"--mariadb-root-username {mariadb_root_user} " @@ -246,10 +248,9 @@ def reinstall_job( self, mariadb_root_password, admin_password, - managed_database=False, - mariadb_root_user=None, + managed_database_config=None ): - return self.reinstall(mariadb_root_password, admin_password, managed_database, mariadb_root_user) + return self.reinstall(mariadb_root_password, admin_password, managed_database_config) @job("Install App on Site") def install_app_job(self, app): @@ -580,7 +581,7 @@ def restore_touched_tables(self): output = self.execute( "set -o pipefail && " f"gunzip -c '{backup_file}' | " - f"mysql -h {self.host} -u {self.user} -p{self.password} " + f"mysql -h {self.host} -u {self.user} -p{self.password} -P{self.port}" f"{self.database}", executable="/bin/bash", ) diff --git a/agent/web.py b/agent/web.py index 84ac1dfe..d6c826e6 100644 --- a/agent/web.py +++ b/agent/web.py @@ -374,6 +374,7 @@ def new_site(bench): data["apps"], data["mariadb_root_password"], data["admin_password"], + data.get('managed_database_config', {}), create_user=data.get("create_user"), ) ) @@ -399,6 +400,7 @@ def new_site_from_backup(bench): data.get("public"), data.get("private"), data.get("skip_failing_patches", False), + data.get('managed_database_config', {}) ) ) return {"job": job} @@ -423,8 +425,7 @@ def restore_site(bench, site): data.get("public"), data.get("private"), data.get("skip_failing_patches", False), - data.get("managed_database", False), - data.get("mariadb_root_user", "") + data.get('managed_database_config', {}) ) ) return {"job": job} @@ -440,7 +441,11 @@ def reinstall_site(bench, site): Server() .benches[bench] .sites[site] - .reinstall_job(data["mariadb_root_password"], data["admin_password"], data["managed_database"], data["mariadb_root_user"]) + .reinstall_job( + data["mariadb_root_password"], + data["admin_password"], + data.get('managed_database_config', {}) + ) ) return {"job": job} From 43ea882f5db9895e00bdf417fd10929c066e22ef Mon Sep 17 00:00:00 2001 From: Saurabh Date: Wed, 29 May 2024 19:12:13 +0530 Subject: [PATCH 05/11] chore: change in parameter name --- agent/bench.py | 4 ++-- agent/site.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/agent/bench.py b/agent/bench.py index c27260b1..89236276 100644 --- a/agent/bench.py +++ b/agent/bench.py @@ -191,7 +191,7 @@ def bench_new_site(self, name, mariadb_root_password, admin_password, managed_da try: return self.docker_execute( f"bench new-site --no-mariadb-socket " - f"--mariadb-root-username {managed_database_config.get('database_user')} " + f"--mariadb-root-username {managed_database_config.get('database_root_user')} " f"--mariadb-root-password {mariadb_root_password} " f"--admin-password {admin_password} {name}" ) @@ -441,7 +441,7 @@ def new_site_from_backup( files["public"], files["private"], managed_database=managed_database, - mariadb_root_user=managed_database_config['database_user'] + mariadb_root_user=managed_database_config['database_root_user'] ) if site_config: site_config = json.loads(site_config) diff --git a/agent/site.py b/agent/site.py index c3d06960..1c7ace68 100644 --- a/agent/site.py +++ b/agent/site.py @@ -189,7 +189,7 @@ def restore_job( files["public"], files["private"], managed_database=managed_database, - mariadb_root_user=managed_database_config['database_user'], + mariadb_root_user=managed_database_config['database_root_user'], ) finally: self.bench.delete_downloaded_files(files["directory"]) @@ -218,7 +218,7 @@ def reinstall( ): if managed_database_config: try: - mariadb_root_user = managed_database_config["database_user"] + mariadb_root_user = managed_database_config["database_root_user"] return self.bench_execute( f"reinstall --yes " f"--mariadb-root-username {mariadb_root_user} " From 79abde5fa33e4c0b2349466d9716362a097057c1 Mon Sep 17 00:00:00 2001 From: Saurabh Date: Thu, 30 May 2024 11:24:59 +0530 Subject: [PATCH 06/11] feat: provision to connect mysql on custom port --- agent/site.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/agent/site.py b/agent/site.py index 1c7ace68..f04b0a19 100644 --- a/agent/site.py +++ b/agent/site.py @@ -309,7 +309,7 @@ def create_database_access_credentials(self, mode, mariadb_root_password): ] for query in queries: command = ( - f"mysql -h {self.host} -uroot -p{mariadb_root_password}" + f"mysql -h {self.host} -uroot -p{mariadb_root_password} -P {self.port}" f' -e "{query}"' ) self.execute(command) @@ -325,7 +325,7 @@ def revoke_database_access_credentials(self, user, mariadb_root_password): ] for query in queries: command = ( - f"mysql -h {self.host} -uroot -p{mariadb_root_password}" + f"mysql -h {self.host} -uroot -p{mariadb_root_password} -P {self.port}" f' -e "{query}"' ) self.execute(command) @@ -355,7 +355,7 @@ def restore_site_tables(self): output = self.execute( "set -o pipefail && " f"gunzip -c '{backup_file_path}' | " - f"mysql -h {self.host} -u {self.user} -p{self.password} " + f"mysql -h {self.host} -u {self.user} -p{self.password} -P {self.port}" f"{self.database}", executable="/bin/bash", ) @@ -513,7 +513,7 @@ def tablewise_backup(self): "set -o pipefail && " "mysqldump --single-transaction --quick --lock-tables=false " f"-h {self.host} -u {self.user} -p{self.password} " - f"{self.database} '{table}' " + f"{self.database} -P {self.port} '{table}' " f" | gzip > '{backup_file}'", executable="/bin/bash", ) @@ -581,7 +581,7 @@ def restore_touched_tables(self): output = self.execute( "set -o pipefail && " f"gunzip -c '{backup_file}' | " - f"mysql -h {self.host} -u {self.user} -p{self.password} -P{self.port}" + f"mysql -h {self.host} -u {self.user} -p{self.password} -P {self.port}" f"{self.database}", executable="/bin/bash", ) @@ -596,7 +596,7 @@ def drop_new_tables(self): data = {"dropped": {}} for table in new_tables: output = self.execute( - f"mysql -h {self.host} -u {self.user} -p{self.password} " + f"mysql -h {self.host} -u {self.user} -p{self.password} -P {self.port}" f"{self.database} -e 'DROP TABLE `{table}`'" ) data["dropped"][table] = output @@ -678,7 +678,7 @@ def timezone(self): ) try: timezone = self.execute( - f"mysql -h {self.host} -u{self.database} -p{self.password} " + f"mysql -h {self.host} -u{self.database} -p{self.password} -P {self.port}" f'--connect-timeout 3 -sN -e "{query}"' )["output"].strip() except Exception: @@ -689,7 +689,7 @@ def timezone(self): def tables(self): return self.execute( "mysql --disable-column-names -B -e 'SHOW TABLES' " - f"-h {self.host} -u {self.user} -p{self.password} {self.database}" + f"-h {self.host} -u {self.user} -p{self.password} -P {self.port} {self.database}" )["output"].split("\n") @property @@ -722,7 +722,7 @@ def optimize_tables(self): for table in tables: query = f"OPTIMIZE TABLE `{table}`" self.execute( - f"mysql -sN -h {self.host} -u{self.user} -p{self.password}" + f"mysql -sN -h {self.host} -u{self.user} -p{self.password} -P {self.port}" f" {self.database} -e '{query}'" ) @@ -798,7 +798,7 @@ def get_database_size(self): " GROUP BY `table_schema`" ) command = ( - f"mysql -sN -h {self.host} -u{self.user} -p{self.password}" + f"mysql -sN -h {self.host} -u{self.user} -p{self.password} -P {self.port}" f" -e '{query}'" ) database_size = self.execute(command).get("output") @@ -847,7 +847,7 @@ def get_database_free_size(self): " GROUP BY `table_schema`" ) command = ( - f"mysql -sN -h {self.host} -u{self.user} -p{self.password}" + f"mysql -sN -h {self.host} -u{self.user} -p{self.password} -P {self.port}" f" -e '{query}'" ) database_size = self.execute(command).get("output") @@ -868,7 +868,7 @@ def get_database_free_tables(self): " OR `data_free` > 100 * 1024 * 1024)" ) command = ( - f"mysql -sN -h {self.host} -u{self.user} -p{self.password}" + f"mysql -sN -h {self.host} -u{self.user} -p{self.password} -P {self.port}" f" -e '{query}'" ) output = self.execute(command).get("output") From 8318b82a0f5429c926e453387a876f3bd10ae187 Mon Sep 17 00:00:00 2001 From: Saurabh Date: Thu, 30 May 2024 17:35:30 +0530 Subject: [PATCH 07/11] feat: check db port at bench level if not found at site level --- agent/bench.py | 1 + agent/site.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/agent/bench.py b/agent/bench.py index 89236276..cdca0427 100644 --- a/agent/bench.py +++ b/agent/bench.py @@ -37,6 +37,7 @@ def __init__(self, name, server, mounts=None): self.directory, "sites", "common_site_config.json" ) self.host = self.config.get("db_host", "localhost") + self.db_port = self.config.get("db_port", "3306") self.docker_image = self.bench_config.get("docker_image") self.mounts = mounts if not ( diff --git a/agent/site.py b/agent/site.py index f04b0a19..dfff36b1 100644 --- a/agent/site.py +++ b/agent/site.py @@ -47,7 +47,7 @@ def __init__(self, name: str, bench: "Bench"): self.user = self.config["db_name"] self.password = self.config["db_password"] self.host = self.config.get("db_host", self.bench.host) - self.port = self.config.get("db_port", '3306') + self.port = self.config.get("db_port", self.bench.db_port) def bench_execute(self, command, input=None): return self.bench.docker_execute( From 60290e67830267b9030bdf5fef5d02806f86c102 Mon Sep 17 00:00:00 2001 From: Saurabh Date: Thu, 30 May 2024 19:19:22 +0530 Subject: [PATCH 08/11] fix: spacing --- agent/site.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/agent/site.py b/agent/site.py index dfff36b1..6bbb7612 100644 --- a/agent/site.py +++ b/agent/site.py @@ -355,7 +355,7 @@ def restore_site_tables(self): output = self.execute( "set -o pipefail && " f"gunzip -c '{backup_file_path}' | " - f"mysql -h {self.host} -u {self.user} -p{self.password} -P {self.port}" + f"mysql -h {self.host} -u {self.user} -p{self.password} -P {self.port} " f"{self.database}", executable="/bin/bash", ) @@ -581,7 +581,7 @@ def restore_touched_tables(self): output = self.execute( "set -o pipefail && " f"gunzip -c '{backup_file}' | " - f"mysql -h {self.host} -u {self.user} -p{self.password} -P {self.port}" + f"mysql -h {self.host} -u {self.user} -p{self.password} -P {self.port} " f"{self.database}", executable="/bin/bash", ) @@ -596,7 +596,7 @@ def drop_new_tables(self): data = {"dropped": {}} for table in new_tables: output = self.execute( - f"mysql -h {self.host} -u {self.user} -p{self.password} -P {self.port}" + f"mysql -h {self.host} -u {self.user} -p{self.password} -P {self.port} " f"{self.database} -e 'DROP TABLE `{table}`'" ) data["dropped"][table] = output From 8bb9bcbeb21e383c6b875f72015456fcf5c03624 Mon Sep 17 00:00:00 2001 From: Saurabh Date: Tue, 13 Aug 2024 13:18:30 +0530 Subject: [PATCH 09/11] fix: set port while taking tablewise backup --- agent/site.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/agent/site.py b/agent/site.py index 6bbb7612..13a363d7 100644 --- a/agent/site.py +++ b/agent/site.py @@ -12,7 +12,7 @@ from agent.base import AgentException, Base from agent.job import job, step -from agent.utils import b2mb, get_size +from agent.utils import b2mb, get_size, cint if TYPE_CHECKING: from agent.bench import Bench @@ -47,7 +47,7 @@ def __init__(self, name: str, bench: "Bench"): self.user = self.config["db_name"] self.password = self.config["db_password"] self.host = self.config.get("db_host", self.bench.host) - self.port = self.config.get("db_port", self.bench.db_port) + self.port = cint(self.config.get("db_port", self.bench.db_port)) def bench_execute(self, command, input=None): return self.bench.docker_execute( @@ -505,6 +505,8 @@ def tablewise_backup(self): sort_keys=True, ) data = {"tables": {}} + db_port = self.config.get("db_port", 3306) + for table in tables: backup_file = os.path.join( self.backup_directory, f"{table}.sql.gz" From 9f7d1ac2cc76f4bbbb5f0a4ada086221928a6ae1 Mon Sep 17 00:00:00 2001 From: Saurabh Date: Tue, 3 Sep 2024 13:05:21 +0530 Subject: [PATCH 10/11] fix: port default integer --- agent/bench.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/agent/bench.py b/agent/bench.py index cdca0427..e7d5edc3 100644 --- a/agent/bench.py +++ b/agent/bench.py @@ -37,7 +37,7 @@ def __init__(self, name, server, mounts=None): self.directory, "sites", "common_site_config.json" ) self.host = self.config.get("db_host", "localhost") - self.db_port = self.config.get("db_port", "3306") + self.db_port = self.config.get("db_port", 3306) self.docker_image = self.bench_config.get("docker_image") self.mounts = mounts if not ( From b361ed8e6f4f7729aa61eaa026b4086ea38b8ae6 Mon Sep 17 00:00:00 2001 From: Saurabh Date: Fri, 31 May 2024 15:48:24 +0530 Subject: [PATCH 11/11] feat: escape special chars from root password --- agent/bench.py | 2 +- agent/site.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/agent/bench.py b/agent/bench.py index e7d5edc3..12253568 100644 --- a/agent/bench.py +++ b/agent/bench.py @@ -193,7 +193,7 @@ def bench_new_site(self, name, mariadb_root_password, admin_password, managed_da return self.docker_execute( f"bench new-site --no-mariadb-socket " f"--mariadb-root-username {managed_database_config.get('database_root_user')} " - f"--mariadb-root-password {mariadb_root_password} " + f"--mariadb-root-password '{mariadb_root_password}' " f"--admin-password {admin_password} {name}" ) except Exception: diff --git a/agent/site.py b/agent/site.py index 13a363d7..5d1e8e05 100644 --- a/agent/site.py +++ b/agent/site.py @@ -139,7 +139,7 @@ def restore( return self.bench_execute( "--force restore " f"--mariadb-root-username {mariadb_root_user} " - f"--mariadb-root-password {mariadb_root_password} " + f"--mariadb-root-password '{mariadb_root_password}' " f"--admin-password {admin_password} " f"{public_file_option} " f"{private_file_option} " @@ -222,7 +222,7 @@ def reinstall( return self.bench_execute( f"reinstall --yes " f"--mariadb-root-username {mariadb_root_user} " - f"--mariadb-root-password {mariadb_root_password} " + f"--mariadb-root-password '{mariadb_root_password}' " f"--admin-password {admin_password}" ) except Exception: