Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update for training machine #53

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions installation_and_upgrade/IBEX_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ def _get_latest_release_path(release_dir):
parser.add_argument("--client_e4_dir", default=None, help="Directory from which IBEX E4 client should be installed")
parser.add_argument("--genie_python3_dir", default=None,
help="Directory from which genie_python_3 should be installed")
parser.add_argument("--script_generator_source_dir", default=None,
help="Directory from which script generator should be installed")
parser.add_argument("--confirm_step", default=False, action="store_true",
help="Confirm each major action before performing it")
parser.add_argument("--quiet", default=False, action="store_true",
Expand All @@ -73,6 +75,11 @@ def _get_latest_release_path(release_dir):
server_dir = os.path.join(current_release_dir, "EPICS")
client_dir = os.path.join(current_release_dir, "Client")
genie_python3_dir = os.path.join(current_release_dir, "genie_python_3")

print("The script generator build is not yet in release so it gets the latest build!!")
# Should be: script_generator_source_dir = os.path.join(current_release_dir, "script_generator")
script_generator_build_dir = os.path.join(os.path.join(current_release_dir, os.pardir, os.pardir), "script_generator")
script_generator_source_dir = _get_latest_directory_path(script_generator_build_dir, "BUILD")
elif args.kits_icp_dir is not None:
if args.deployment_type == 'install_latest_incr':
epics_build_dir = os.path.join(args.kits_icp_dir, "EPICS", args.server_build_prefix+"_win7_x64")
Expand All @@ -89,20 +96,25 @@ def _get_latest_release_path(release_dir):
genie_python3_build_dir = os.path.join(args.kits_icp_dir, "genie_python_3")
genie_python3_dir = _get_latest_directory_path(genie_python3_build_dir, "BUILD-")

script_generator_build_dir = os.path.join(args.kits_icp_dir, "script_generator")
script_generator_source_dir = _get_latest_directory_path(script_generator_build_dir, "BUILD")

elif args.server_dir is not None and args.client_dir is not None and args.genie_python3_dir is not None and \
args.client_e4_dir is not None:
args.client_e4_dir is not None and args.script_generator_source_dir is not None:
server_dir = args.server_dir
client_dir = args.client_dir
client_e4_dir = args.client_e4_dir
genie_python3_dir = args.genie_python3_dir
script_generator_source_dir = args.script_generator_source_dir
else:
print("You must specify either the release directory or kits_icp_dir or "
"ALL of the server, client, client e4 and genie python 3 directories.")
"ALL of the server, client, client e4, genie python 3 and script generator directories.")
sys.exit(2)

try:
prompt = UserPrompt(args.quiet, args.confirm_step)
upgrade_instrument = UpgradeInstrument(prompt, server_dir, client_dir, client_e4_dir, genie_python3_dir)
upgrade_instrument = UpgradeInstrument(prompt, server_dir, client_dir, client_e4_dir, genie_python3_dir,
script_generator_source_dir)
upgrade_function = UPGRADE_TYPES[args.deployment_type][0]
upgrade_function(upgrade_instrument)

Expand Down
146 changes: 121 additions & 25 deletions installation_and_upgrade/ibex_install_utils/install_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
INSTRUMENT_BASE_DIR = os.path.join("C:\\", "Instrument")
APPS_BASE_DIR = os.path.join(INSTRUMENT_BASE_DIR, "Apps")
EPICS_PATH = os.path.join(APPS_BASE_DIR, "EPICS")
SCRIPT_GENERATOR_PATH = os.path.join(APPS_BASE_DIR, "script_generator")
SCRIPT_GENREATOR_CONFIG_PATH = os.path.join("C:\\", "ScriptGeneratorConfigs")

SYSTEM_SETUP_PATH = os.path.join(EPICS_PATH, "SystemSetup")
GUI_PATH = os.path.join(APPS_BASE_DIR, "Client")
Expand All @@ -40,11 +42,13 @@
PYTHON_3_PATH = os.path.join(APPS_BASE_DIR, "Python3")
CONFIG_UPGRADE_SCRIPT_DIR = os.path.join(EPICS_PATH, "misc", "upgrade", "master")
EPICS_UTILS_PATH = os.path.join(APPS_BASE_DIR, "EPICS_UTILS")
DESKTOP_TRAINING_FOLDER_PATH = os.path.join(os.environ["userprofile"], "desktop", "Mantid+IBEX training")
OLD_DESKTOP_TRAINING_FOLDER_PATH = os.path.join(os.environ["userprofile"], "desktop", "Mantid+IBEX training")
DESKTOP_TRAINING_FOLDER_PATH = os.path.join(os.environ["userprofile"], "desktop", "IBEX training")
SOURCE_DESKTOP_TRAINING_FOLDER_PATH = os.path.join(r"\\isis", "shares", "ISIS_Experimental_Controls_Public", "training", "2020-01-31")
SETTINGS_CONFIG_FOLDER = os.path.join("Settings", "config")
SETTINGS_CONFIG_PATH = os.path.join(INSTRUMENT_BASE_DIR, SETTINGS_CONFIG_FOLDER)
CALIBRATION_PATH = os.path.join(SETTINGS_CONFIG_PATH, "common")
SOURCE_FOLDER = os.path.join(os.path.dirname(os.path.realpath(__file__)), "resources")
SOURCE_FOLDER = os.path.join(os.path.dirname(os.path.realpath(__file__)), os.pardir, "resources")
SOURCE_MACHINE_SETTINGS_CONFIG_PATH = os.path.join(SOURCE_FOLDER, SETTINGS_CONFIG_FOLDER, "NDXOTHER")
SOURCE_MACHINE_SETTINGS_COMMON_PATH = os.path.join(SOURCE_FOLDER, SETTINGS_CONFIG_FOLDER, "common")

Expand All @@ -66,6 +70,7 @@
"vc_redist.x64.exe")

LABVIEW_DAE_DIR = os.path.join("C:\\", "LabVIEW modules", "DAE")
ICP_BINARIES_DAE=os.path.join(EPICS_PATH, "ICP_Binaries", "isisdae", "x64", "Release")

USER_START_MENU = os.path.join("C:\\", "users", "spudulike", "AppData", "Roaming", "Microsoft", "Windows", "Start Menu")
PC_START_MENU = os.path.join("C:\\", "ProgramData", "Microsoft", "Windows", "Start Menu")
Expand All @@ -77,7 +82,8 @@
STAGE_DELETED = os.path.join(INST_SHARE_AREA, "backups$", "stage-deleted")
SMALLEST_PERMISSIBLE_MYSQL_DUMP_FILE_IN_BYTES = 100

ALL_INSTALL_DIRECTORIES = (EPICS_PATH, PYTHON_PATH, PYTHON_3_PATH, GUI_PATH, GUI_PATH_E4, EPICS_UTILS_PATH)
ALL_INSTALL_DIRECTORIES = (EPICS_PATH, PYTHON_PATH, PYTHON_3_PATH, GUI_PATH, GUI_PATH_E4, EPICS_UTILS_PATH,
SCRIPT_GENERATOR_PATH)

GIGABYTE = 1024 ** 3

Expand All @@ -91,7 +97,7 @@ class UpgradeInstrument(object):
Class to upgrade the instrument installation to the given version of IBEX.
"""
def __init__(self, user_prompt, server_source_dir, client_source_dir, client_e4_source_dir, genie_python3_dir,
file_utils=FileUtils()):
script_generator_source_dir, file_utils=FileUtils()):
"""
Initializer.
Args:
Expand All @@ -100,10 +106,12 @@ def __init__(self, user_prompt, server_source_dir, client_source_dir, client_e4_
client_source_dir: directory to install ibex client from
client_e4_source_dir: directory to install ibex E4 client from
genie_python3_dir: directory to install genie_python 3 from
script_generator_source_dir: directory to install script generator from
file_utils : collection of file utilities
"""
self._upgrade_tasks = UpgradeTasks(
user_prompt, server_source_dir, client_source_dir, client_e4_source_dir, genie_python3_dir, file_utils)
user_prompt, server_source_dir, client_source_dir, client_e4_source_dir, genie_python3_dir,
script_generator_source_dir, file_utils=file_utils)

@staticmethod
def _should_install_utils():
Expand All @@ -114,19 +122,34 @@ def _should_install_utils():
"""
return not os.path.exists(LABVIEW_DAE_DIR)

def run_test_update(self):
def run_training_update(self):
"""
Run a complete test upgrade on the current system
Create a training machine on the current system
"""
self._upgrade_tasks.user_confirm_upgrade_type_on_machine('Training Machine')
self._upgrade_tasks.stop_ibex_server()

self._upgrade_tasks.remove_old_ibex()

self._upgrade_tasks.clean_up_desktop_ibex_training_folder()
self._upgrade_tasks.remove_settings()

self._upgrade_tasks.check_java_installation()

self._upgrade_tasks.create_desktop_ibex_training_material()

# settings include common directories which can not be got from the git repo on training machine
self._upgrade_tasks.install_settings()
self._upgrade_tasks.install_ibex_server(self._should_install_utils())
self._upgrade_tasks.install_ibex_server(True)
self._upgrade_tasks.register_isis_icp()
self._upgrade_tasks.install_genie_python3()
self._upgrade_tasks.install_script_generator()
self._upgrade_tasks.setup_script_generator_config()
self._upgrade_tasks.install_mysql(force_no_backup_data=True)
self._upgrade_tasks.install_ibex_client()

self._upgrade_tasks.update_kafka_topics()

self._upgrade_tasks.upgrade_notepad_pp()

def remove_all_and_install_client_and_server(self):
Expand Down Expand Up @@ -268,7 +291,7 @@ def run_force_upgrade_mysql(self):
# All possible upgrade tasks
UPGRADE_TYPES = {
'training_update': (
UpgradeInstrument.run_test_update,
UpgradeInstrument.run_training_update,
"update a training machine"),
'instrument_install': (
UpgradeInstrument.run_instrument_install,
Expand Down Expand Up @@ -306,7 +329,7 @@ class UpgradeTasks(object):
"""

def __init__(self, user_prompt, server_source_dir, client_source_dir, client_e4_source_dir, genie_python3_dir,
file_utils=FileUtils()):
script_generator_source_dir, file_utils=FileUtils()):
"""
Initializer.
Args:
Expand All @@ -315,13 +338,15 @@ def __init__(self, user_prompt, server_source_dir, client_source_dir, client_e4_
client_source_dir: directory to install ibex client from
client_e4_source_dir: directory to install ibex E4 client from
genie_python3_dir: directory to install genie python from
script_generator_source_dir: directory to install script generator from
file_utils : collection of file utilities
"""
self.prompt = user_prompt # This is needed to allow @tasks to work
self._server_source_dir = server_source_dir
self._client_source_dir = client_source_dir
self._client_e4_source_dir = client_e4_source_dir
self._genie_python_3_source_dir = genie_python3_dir
self._script_generator_source_dir = script_generator_source_dir
self._file_utils = file_utils

self._machine_name = self._get_machine_name()
Expand Down Expand Up @@ -391,8 +416,18 @@ def clean_up_desktop_ibex_training_folder(self):
Returns:

"""
self._file_utils.remove_tree(OLD_DESKTOP_TRAINING_FOLDER_PATH, self.prompt)
self._file_utils.remove_tree(DESKTOP_TRAINING_FOLDER_PATH, self.prompt)

@task("Creating training folder on desktop ...")
def create_desktop_ibex_training_material(self):
"""
Copy training folder to the desktop
Returns:

"""
shutil.copytree(SOURCE_DESKTOP_TRAINING_FOLDER_PATH, DESKTOP_TRAINING_FOLDER_PATH)

@task("Removing old settings file")
def remove_settings(self):
"""
Expand Down Expand Up @@ -459,6 +494,21 @@ def install_ibex_server(self, with_utils):
if with_utils and self.prompt.confirm_step("install icp binaries"):
RunProcess(EPICS_PATH, "create_icp_binaries.bat").run()

@task("Register ISIS ICP")
def register_isis_icp(self):
"""
register the isis icp program
"""
admin_commands = AdminCommandBuilder()
if os.path.exists(LABVIEW_DAE_DIR):
admin_commands.add_command("cd", LABVIEW_DAE_DIR)
admin_commands.add_command("register_programs.cmd", "")
else:
admin_commands.add_command("cd", ICP_BINARIES_DAE)
admin_commands.add_command("isisicp.exe", r"/RegServer")
admin_commands.add_command("isisdatasvr.exe", r"/RegServer")
admin_commands.run_all()

@task("Installing Genie Python 3")
def install_genie_python3(self):
"""
Expand All @@ -467,6 +517,16 @@ def install_genie_python3(self):
self._file_utils.mkdir_recursive(APPS_BASE_DIR)
RunProcess(self._genie_python_3_source_dir, "genie_python_install.bat").run()

@task("Installing Script Generator")
def install_script_generator(self):
"""
Install ibex server.
"""
self._file_utils.mkdir_recursive(APPS_BASE_DIR)
RunProcess(self._script_generator_source_dir, "install_script_generator.bat").run()



@task("Installing IBEX Client")
def install_ibex_client(self):
"""
Expand Down Expand Up @@ -525,6 +585,7 @@ def user_confirm_upgrade_type_on_machine(self, machine_type):
print(" Server source: {0}".format(self._server_source_dir))
print(" Client source: {0}".format(self._client_source_dir))
print(" Python 3 source: {0}".format(self._genie_python_3_source_dir))
print(" Script generator source: {0}".format(self._script_generator_source_dir))
answer = self.prompt.prompt("Continue? [Y/N]", ["Y", "N"], "Y")
if answer != "Y":
raise UserStop()
Expand Down Expand Up @@ -649,27 +710,56 @@ def setup_calibrations_repository(self):
"""
Set up the calibration repository
"""
if os.path.isdir(CALIBRATION_PATH):
if self.prompt.prompt("Calibrations directory already exists. Update calibrations repository?",
["Y", "N"], "N") == "Y":
self.update_calibrations_repository()
else:
exit_code = subprocess.call("git clone http://control-svcs.isis.cclrc.ac.uk/gitroot/instconfigs/common.git "
"C:\Instrument\Settings\config\common")
if exit_code is not 0:
raise ErrorInRun("Failed to set up common calibration directory.")

self._upgrade_or_create_git_dir(
"Calibration",
"http://control-svcs.isis.cclrc.ac.uk/gitroot/instconfigs/common.git",
CALIBRATION_PATH)

@task("Set up script generator config repository")
def setup_script_generator_config(self):
self._upgrade_or_create_git_dir(
"Script generator",
"https://github.com/ISISComputingGroup/ScriptGeneratorConfigs.git",
SCRIPT_GENREATOR_CONFIG_PATH)

@task("Updating calibrations repository")
def update_calibrations_repository(self):
"""
Update the calibration repository
"""
self._upgrade_git_repo("Calibration", CALIBRATION_PATH)

def _upgrade_or_create_git_dir(self, what, repo, destination):
"""
Create, or if exists update, the git repo at the given destination
Args:
what: what the repo is for messages
repo: the repo path
destination: where the repo should be cloned to
"""
if os.path.isdir(destination):
if self.prompt.prompt("{} directory already exists. Update calibrations repository?".format(what),
["Y", "N"], "N") == "Y":
self._upgrade_git_repo(what, destination)
else:
exit_code = subprocess.call("git clone {} {}".format(repo, destination))
if exit_code is not 0:
raise ErrorInRun("Failed to set up {} directory.".format(what))

def _upgrade_git_repo(self, what, destination):
"""
Updates an existing git repo
Args:
what: what the repo is for messages
destination: where the repo is cloned
"""
try:
repo = git.Repo(CALIBRATION_PATH)
repo = git.Repo(destination)
repo.git.pull()
except git.GitCommandError:
self.prompt.prompt_and_raise_if_not_yes("There was an error pulling the calibrations repo.\n"
"Manually pull it. Path='{}'".format(CALIBRATION_PATH))
self.prompt.prompt_and_raise_if_not_yes("There was an error pulling the {} repo.\n"
"Manually pull it. Path='{}'".format(what, destination))

@task("Install java")
def check_java_installation(self):
Expand Down Expand Up @@ -972,17 +1062,20 @@ def _install_vcruntime140(self):
"Install it from {} and confirm when complete".format(VCRUNTIME140_INSTALLER))

@task("Install latest MySQL")
def install_mysql(self, force=False):
def install_mysql(self, force=False, force_no_backup_data=False):
"""
Install mysql and the ibex database schemas
Args:
force: True delete old data and update
force_no_backup_data: If True even if the backuped data should be taken it isn't
"""
backup_data = False
clean_install = True
if os.path.exists(os.path.join(MYSQL57_INSTALL_DIR, "bin", "mysql.exe")):
self._backup_data()
backup_data = True

backup_data = not force_no_backup_data
if backup_data:
self._backup_data()
self.prompt.prompt_and_raise_if_not_yes("MySQL 5.7 detected. Please use the MySQL installer application"
"to remove MySQL 5.7. When it asks you whether to remove data"
"directories, answer yes. Type 'Y' when complete.")
Expand All @@ -997,6 +1090,9 @@ def install_mysql(self, force=False):
clean_install = force
self._remove_old_versions_of_mysql8(clean_install=clean_install)

if clean_install:
self._remove_old_mysql_data_dir()

self._install_vcruntime140()
self._install_latest_mysql8(clean_install=clean_install)
self._configure_mysql()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?xml version="1.0" ?>
<banner xmlns="http://epics.isis.rl.ac.uk/schema/banner/1.0" xmlns:ioc="http://www.w3.org/2001/XMLSchema-instance" xmlns:xi="http://www.w3.org/2001/XInclude">
<items>
<item>
<button>
<name>Stop All Motors</name>
<pv>CS:MOT:STOP:ALL</pv>
<local>true</local>
<pvValue>1</pvValue>
<textColour>#000000</textColour>
<buttonColour>#e0e0e0</buttonColour>
<fontSize>9</fontSize>
<width>100</width>
<height>25</height>
</button>
</item>
<item>
<display>
<name>Motors are</name>
<pv>CS:MOT:MOVING:STR</pv>
<local>true</local>
<width>170</width>
</display>
</item>
<item>
<display>
<name>Manager mode</name>
<pv>CS:MANAGER</pv>
<local>true</local>
<width>250</width>
</display>
</item>
<item>
<display>
<name>Config</name>
<pv>CS:BLOCKSERVER:CURR_CONFIG_NAME</pv>
<local>true</local>
<width>360</width>
</display>
</item>
</items>
</banner>
Loading