Skip to content

Commit

Permalink
Merge pull request #203 from ISISComputingGroup/summer_update
Browse files Browse the repository at this point in the history
Add summer update script
  • Loading branch information
Tom-Willemsen authored Aug 30, 2024
2 parents 57bfd48 + 860e059 commit 77719b4
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 67 deletions.
96 changes: 64 additions & 32 deletions installation_and_upgrade/ibex_install_utils/install_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,21 @@
from ibex_install_utils.tasks.server_tasks import ServerTasks
from ibex_install_utils.tasks.system_tasks import SystemTasks
from ibex_install_utils.tasks.vhd_tasks import VHDTasks
from ibex_install_utils.user_prompt import UserPrompt


class UpgradeInstrument:
"""Class to upgrade the instrument installation to the given version of IBEX."""

def __init__(
self,
user_prompt,
server_source_dir,
client_source_dir,
genie_python3_dir,
ibex_version,
file_utils=FileUtils(),
):
user_prompt: UserPrompt,
server_source_dir: str,
client_source_dir: str,
genie_python3_dir: str,
ibex_version: str,
file_utils: FileUtils = FileUtils(),
) -> None:
"""Initializer.
Args:
Expand Down Expand Up @@ -111,14 +112,14 @@ def __init__(
)

@staticmethod
def icp_in_labview_modules():
def icp_in_labview_modules() -> bool:
"""Condition on which to install ICP_Binaries or
:return: True if the ICP is installed in labview modules, False otherwise
"""
return os.path.exists(LABVIEW_DAE_DIR)

def run_test_update(self):
def run_test_update(self) -> None:
"""Run a complete test upgrade on the current system"""
self._system_tasks.user_confirm_upgrade_type_on_machine("Training Machine")
self._system_tasks.install_or_upgrade_git()
Expand All @@ -136,10 +137,11 @@ def run_test_update(self):
self._system_tasks.upgrade_notepad_pp()
self._server_tasks.setup_log_rotation()

def remove_all_and_install_client_and_server(self):
def remove_all_and_install_client_and_server(self) -> None:
"""Either install or upgrade the ibex client and server"""
self._system_tasks.confirm(
"This script removes IBEX client and server and installs the latest build of both, and upgrade the "
"This script removes IBEX client and server and installs "
"the latest build of both, and upgrade the "
"config/schema without any extra steps. Proceed?"
)

Expand All @@ -153,13 +155,13 @@ def remove_all_and_install_client_and_server(self):
self._server_tasks.upgrade_instrument_configuration()
self._server_tasks.install_shared_scripts_repository()

def run_instrument_tests(self):
def run_instrument_tests(self) -> None:
"""Run through client and server tests once installation / deployment has completed."""
self._client_tasks.perform_client_tests()
self._server_tasks.perform_server_tests()
self._system_tasks.inform_instrument_scientists()

def run_instrument_install(self):
def run_instrument_install(self) -> None:
"""Do a first installation of IBEX on a new instrument."""
self._system_tasks.confirm(
"This script performs a first-time full installation of the IBEX server and client"
Expand Down Expand Up @@ -198,19 +200,20 @@ def run_instrument_install(self):
self._python_tasks.update_script_definitions()
self._server_tasks.setup_log_rotation()

def save_motor_params(self):
def save_motor_params(self) -> None:
self._server_tasks.save_motor_parameters_to_file()

def run_instrument_deploy(self):
def run_instrument_deploy(self) -> None:
"""Deploy a full IBEX upgrade on an existing instrument."""
self._system_tasks.confirm(
"This script performs a full upgrade of the IBEX server and client on an existing instrument. Proceed?"
"This script performs a full upgrade of the IBEX server "
"and client on an existing instrument. Proceed?"
)
self.run_instrument_deploy_pre_stop()
self.run_instrument_deploy_main()
self.run_instrument_deploy_post_start()

def run_instrument_deploy_post_start(self):
def run_instrument_deploy_post_start(self) -> None:
"""Upgrade an instrument. Steps to do after ibex has been started.
Current the server can not be started in this python script.
Expand All @@ -225,8 +228,9 @@ def run_instrument_deploy_post_start(self):
self._system_tasks.put_autostart_script_in_startup_area()
self._system_tasks.inform_instrument_scientists()

def run_instrument_deploy_main(self):
"""Upgrade an instrument. Steps to do after ibex has been stopped but before it is restarted.
def run_instrument_deploy_main(self) -> None:
"""Upgrade an instrument. Steps to do after ibex has been stopped
but before it is restarted.
Current the server can not be started or stopped in this python script.
"""
Expand All @@ -253,7 +257,7 @@ def run_instrument_deploy_main(self):
self._python_tasks.remove_instrument_script_githooks()
self._server_tasks.setup_log_rotation()

def run_instrument_deploy_pre_stop(self):
def run_instrument_deploy_pre_stop(self) -> None:
"""Upgrade an instrument. Steps to do before ibex is stopped.
Current the server can not be started or stopped in this python script.
Expand All @@ -267,7 +271,7 @@ def run_instrument_deploy_pre_stop(self):
bytes(central_inst_info, encoding="utf8")
).decode("utf-8")
central_inst_info = json.loads(central_inst_info)
except:
except Exception:
central_inst_info = {}

central_specific_inst_info = None
Expand All @@ -284,24 +288,38 @@ def run_instrument_deploy_pre_stop(self):

self._server_tasks.save_motor_blocks_blockserver_to_file()

def run_truncate_database(self):
def run_truncate_database(self) -> None:
"""Backup and truncate databases only"""
self._mysql_tasks.backup_database()
self._mysql_tasks.truncate_database()

def run_force_upgrade_mysql(self):
def run_force_upgrade_mysql(self) -> None:
""":key
Do upgrade of mysql, with data dump.
"""
self._mysql_tasks.install_mysql(force=True)

def run_developer_update(self):
def run_upgrade_mysql(self) -> None:
""":key
Do upgrade of mysql with no table recreate.
"""
self._mysql_tasks.install_mysql(force=False)

def run_update_calibrations_repository(self) -> None:
"""update_calibrations_repository"""
self._server_tasks.update_calibrations_repository()

def run_setup_log_rotation(self) -> None:
"""setup_log_rotation"""
self._server_tasks.setup_log_rotation()

def run_developer_update(self) -> None:
"""Update all the developer tools to latest version"""
self._mysql_tasks.install_mysql(force=False)
self._system_tasks.check_java_installation()
self._system_tasks.install_or_upgrade_git()

def run_vhd_creation(self):
def run_vhd_creation(self) -> None:
"""Automated job which creates a set of VHDs containing all IBEX components.
Note: this will run under jenkins, don't add interactive tasks to this list.
Expand Down Expand Up @@ -331,21 +349,23 @@ def run_vhd_creation(self):

self._vhd_tasks.deploy_vhds()

def mount_vhds(self):
def mount_vhds(self) -> None:
"""Task which actually mounts the VHDs (will be run as admin)"""
self._vhd_tasks.mount_vhds()

def dismount_vhds(self):
def dismount_vhds(self) -> None:
"""Task which actually dismounts the VHDs (will be run as admin)"""
self._vhd_tasks.dismount_vhds()

def request_dismount_vhds(self):
def request_dismount_vhds(self) -> None:
"""Standalone task to request VHDs to be dismounted"""
self._vhd_tasks.request_dismount_vhds()

def run_vhd_post_install(self):
"""This job is run by the MDT build system when it has built a windows image and mounted the VHDS
It will tidy up and remaining jobs that were not possible when the vdh was created e.g. register mysql service
def run_vhd_post_install(self) -> None:
"""This job is run by the MDT build system when it has built
a windows image and mounted the VHDS
It will tidy up and remaining jobs that were not possible when
the vdh was created e.g. register mysql service
"""
# self._server_tasks.update_icp(self.icp_in_labview_modules())
self._mysql_tasks.configure_mysql_for_vhd_post_install()
Expand Down Expand Up @@ -388,7 +408,19 @@ def run_vhd_post_install(self):
),
"force_upgrade_mysql": (
UpgradeInstrument.run_force_upgrade_mysql,
"upgrade mysql version to latest",
"upgrade mysql version to latest and recreate tables",
),
"upgrade_mysql": (
UpgradeInstrument.run_upgrade_mysql,
"upgrade mysql version to latest but do not recreate tables",
),
"update_calibrations_repository": (
UpgradeInstrument.run_update_calibrations_repository,
"update calibrations repository",
),
"setup_log_rotation": (
UpgradeInstrument.run_setup_log_rotation,
"setup log rotation",
),
"developer_update": (UpgradeInstrument.run_developer_update, "install latest developer tools"),
"create_vhds": (
Expand Down
12 changes: 7 additions & 5 deletions installation_and_upgrade/ibex_install_utils/tasks/git_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,30 +32,32 @@ def checkout_to_release_branch(self) -> None:
try:
# assumes the alias 'origin' does not exist yet
subprocess.check_call(
f"cd {EPICS_PATH} && git remote add origin http://control-svcs.isis.cclrc.ac.uk/gitroot/releases/{version}/{remote_repo}",
f"cd /d {EPICS_PATH} && git remote add origin http://control-svcs.isis.cclrc.ac.uk/gitroot/releases/{version}/{remote_repo}",
shell=True,
)
print("Added the remote")
except subprocess.CalledProcessError as e:
print(f"Error creating remote: {e}")

try:
subprocess.check_call(f"cd {EPICS_PATH} && git fetch", shell=True)
subprocess.check_call(f"cd /d {EPICS_PATH} && git fetch", shell=True)
print("Fetched remote")
except subprocess.CalledProcessError as e:
print(f"Error fetching remote: {e}")

try:
# run a git status to rebuild index if needed
subprocess.check_call(f"cd {EPICS_PATH} && git status", shell=True)
subprocess.check_call(f"cd /d {EPICS_PATH} && git status", shell=True)
except subprocess.CalledProcessError as e:
print(f"Error running git status: {e}")

try:
subprocess.check_call(f"cd {EPICS_PATH} && git checkout -b %COMPUTERNAME%", shell=True)
subprocess.check_call(
f"cd /d {EPICS_PATH} && git checkout -b %COMPUTERNAME%", shell=True
)
print("Checked out to the new release branch")
subprocess.check_call(
f"cd {EPICS_PATH} && git push -u origin %COMPUTERNAME%", shell=True
f"cd /d {EPICS_PATH} && git push -u origin %COMPUTERNAME%", shell=True
)
print("Pushed to the remote")
except subprocess.CalledProcessError as e:
Expand Down
Loading

0 comments on commit 77719b4

Please sign in to comment.