From fc9a4cbc77e964273c9a1d1088df5e26f3e50153 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Luis=20Cano=20Rodr=C3=ADguez?= Date: Mon, 13 Apr 2026 11:04:41 +0200 Subject: [PATCH] Properly raise error if initialization fails --- machines/src/mysql_vm_helpers.py | 2 +- machines/tests/unit/test_mysqlsh_helpers.py | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/machines/src/mysql_vm_helpers.py b/machines/src/mysql_vm_helpers.py index 658b2bc35..3eb4fa4d1 100644 --- a/machines/src/mysql_vm_helpers.py +++ b/machines/src/mysql_vm_helpers.py @@ -339,7 +339,7 @@ def initialise_mysqld(self) -> None: try: self.reset_data_dir() - subprocess.run(bootstrap_command) # noqa: S603 + subprocess.run(bootstrap_command, check=True) # noqa: S603 except subprocess.CalledProcessError: logger.exception("Failed to initialise MySQL data directory") raise MySQLInitialiseMySQLDError from None diff --git a/machines/tests/unit/test_mysqlsh_helpers.py b/machines/tests/unit/test_mysqlsh_helpers.py index e2a7cedf2..a0e2a699b 100644 --- a/machines/tests/unit/test_mysqlsh_helpers.py +++ b/machines/tests/unit/test_mysqlsh_helpers.py @@ -481,12 +481,15 @@ def test_initialise_mysqld(self, _subprocess_run, _reset_data_dir): self.mysql.initialise_mysqld() _reset_data_dir.assert_called_once() - _subprocess_run.assert_called_once_with([ - "/usr/bin/sudo", - "/snap/bin/charmed-mysql.mysqld-initialize", - "--datadir", - "/var/snap/charmed-mysql/common/var/lib/mysql", - ]) + _subprocess_run.assert_called_once_with( + [ + "/usr/bin/sudo", + "/snap/bin/charmed-mysql.mysqld-initialize", + "--datadir", + "/var/snap/charmed-mysql/common/var/lib/mysql", + ], + check=True, + ) @patch("mysql_vm_helpers.MySQL.reset_data_dir") @patch("subprocess.run")