Skip to content

Commit 78afd2a

Browse files
committed
Run MySQL during config upgrade
1 parent 15677e2 commit 78afd2a

File tree

2 files changed

+52
-36
lines changed

2 files changed

+52
-36
lines changed

installation_and_upgrade/ibex_install_utils/install_tasks.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,12 @@ def run_vhd_creation(self):
276276
self._mysql_tasks.install_mysql_for_vhd()
277277
self._client_tasks.install_ibex_client()
278278
self._server_tasks.setup_config_repository()
279-
self._server_tasks.upgrade_instrument_configuration()
279+
280+
# Some config upgrade steps require MySQL to be running
281+
# For the VHD build, we can always assume we have a MYSQL_PASSWORD env variable
282+
with self._mysql_tasks.temporarily_run_mysql(os.getenv("MYSQL_PASSWORD")):
283+
self._server_tasks.upgrade_instrument_configuration()
284+
280285
self._server_tasks.setup_calibrations_repository()
281286
self._server_tasks.update_calibrations_repository()
282287
self._vhd_tasks.initialize_var_dir()

installation_and_upgrade/ibex_install_utils/tasks/mysql_tasks.py

Lines changed: 46 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import contextlib
12
import os
23
import shutil
34
import subprocess
@@ -159,45 +160,18 @@ def _initialize_mysql_data_area_for_vhd(self):
159160
]
160161
).run()
161162

162-
def _setup_database_users_and_tables(self, vhd_install=True):
163+
@contextlib.contextmanager
164+
def temporarily_run_mysql(self, sql_password: str):
163165
mysqld = os.path.join(MYSQL8_INSTALL_DIR, "bin", "mysqld.exe")
164166

165-
sql_password = self.prompt.prompt("Enter the MySQL root password:", UserPrompt.ANY,
166-
os.getenv("MYSQL_PASSWORD", "environment variable not set"),
167-
show_automatic_answer=False)
168-
169-
if vhd_install: # Service won't have been started yet
170-
# spawn service in background
171-
subprocess.Popen(mysqld, creationflags=DETACHED_PROCESS)
167+
# spawn service in background
168+
subprocess.Popen(mysqld, creationflags=DETACHED_PROCESS)
172169

173-
sleep(5) # Chance for the service to spawn
170+
sleep(5) # Chance for the service to spawn
174171

175-
RunProcess(
176-
executable_directory=os.path.join(MYSQL8_INSTALL_DIR, "bin"),
177-
working_dir=os.path.join(MYSQL8_INSTALL_DIR, "bin"),
178-
executable_file="mysql.exe",
179-
prog_args=[
180-
'-u',
181-
'root',
182-
'-e',
183-
f'ALTER USER \'root\'@\'localhost\' IDENTIFIED WITH mysql_native_password BY \'{sql_password}\';FLUSH '
184-
f'privileges; '
185-
,
186-
187-
],
188-
log_command_args=False, # To make sure password doesn't appear in jenkins log.
189-
).run()
190-
191-
RunProcess(
192-
working_dir=SYSTEM_SETUP_PATH,
193-
executable_directory=SYSTEM_SETUP_PATH,
194-
executable_file="config_mysql.bat",
195-
prog_args=[sql_password],
196-
log_command_args=False, # To make sure password doesn't appear in jenkins log.
197-
).run()
198-
199-
if vhd_install:
200-
# For VHD install only, stop mysql when done
172+
try:
173+
yield
174+
finally:
201175
RunProcess(
202176
executable_directory=os.path.join(MYSQL8_INSTALL_DIR, "bin"),
203177
working_dir=os.path.join(MYSQL8_INSTALL_DIR, "bin"),
@@ -211,6 +185,43 @@ def _setup_database_users_and_tables(self, vhd_install=True):
211185
log_command_args=False, # To make sure password doesn't appear in jenkins log.
212186
).run()
213187

188+
def _setup_database_users_and_tables(self, vhd_install=True):
189+
sql_password = self.prompt.prompt("Enter the MySQL root password:", UserPrompt.ANY,
190+
os.getenv("MYSQL_PASSWORD", "environment variable not set"),
191+
show_automatic_answer=False)
192+
193+
if vhd_install:
194+
# In the VHD install, need to explicitly temporarily run MySQL.
195+
cm = self.temporarily_run_mysql(sql_password)
196+
else:
197+
# In normal installs, MySQL is already running as a service so do nothing
198+
cm = contextlib.nullcontext()
199+
200+
with cm:
201+
RunProcess(
202+
executable_directory=os.path.join(MYSQL8_INSTALL_DIR, "bin"),
203+
working_dir=os.path.join(MYSQL8_INSTALL_DIR, "bin"),
204+
executable_file="mysql.exe",
205+
prog_args=[
206+
'-u',
207+
'root',
208+
'-e',
209+
f'ALTER USER \'root\'@\'localhost\' IDENTIFIED WITH mysql_native_password BY \'{sql_password}\';FLUSH '
210+
f'privileges; '
211+
,
212+
213+
],
214+
log_command_args=False, # To make sure password doesn't appear in jenkins log.
215+
).run()
216+
217+
RunProcess(
218+
working_dir=SYSTEM_SETUP_PATH,
219+
executable_directory=SYSTEM_SETUP_PATH,
220+
executable_file="config_mysql.bat",
221+
prog_args=[sql_password],
222+
log_command_args=False, # To make sure password doesn't appear in jenkins log.
223+
).run()
224+
214225
def _setup_mysql8_service(self):
215226
mysqld = os.path.join(MYSQL8_INSTALL_DIR, "bin", "mysqld.exe")
216227
admin_commands = AdminCommandBuilder()

0 commit comments

Comments
 (0)