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

Ticket3492 update upgrade script #32

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 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
101 changes: 53 additions & 48 deletions installation_and_upgrade/ibex_install_utils/install_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import socket
import subprocess
from datetime import date, datetime
from os.path import isfile, join

import psutil
import git

Expand Down Expand Up @@ -43,6 +45,9 @@
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")

THIRD_PARTY_INSTALLERS_REL_DIR = "..\\..\\third_party_installers"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use os.path.join

THIRD_PARTY_LATEST = os.path.join(THIRD_PARTY_INSTALLERS_REL_DIR, "latest_versions")

VAR_DIR = os.path.join(INSTRUMENT_BASE_DIR, "var")
MYSQL_FILES_DIR = os.path.join(VAR_DIR, "mysql")
PV_BACKUPS_DIR = os.path.join(VAR_DIR, "deployment_pv_backups")
Expand All @@ -60,6 +65,9 @@
STAGE_DELETED = os.path.join(r"\\isis", "inst$", "backups$", "stage-deleted")
SMALLEST_PERMISSIBLE_MYSQL_DUMP_FILE_IN_BYTES = 100

GIT_INSTALL_ARGS = ["/SILENT", "/CLOSEAPPLICATIONS"]
JRE_INSTALL_ARGS = ["/s"]

RAM_MIN = 8e+9
FREE_DISK_MIN = 3e+10

Expand Down Expand Up @@ -137,7 +145,6 @@ def run_instrument_install(self):

self._upgrade_tasks.check_resources()

self._upgrade_tasks.check_java_installation()
self._upgrade_tasks.install_mysql()
self._upgrade_tasks.remove_seci_shortcuts()
self._upgrade_tasks.remove_seci_one()
Expand All @@ -158,7 +165,6 @@ def run_instrument_install(self):
self._upgrade_tasks.configure_motion()
self._upgrade_tasks.add_nagios_checks()
self._upgrade_tasks.update_instlist()
self._upgrade_tasks.update_web_dashboard()
self._upgrade_tasks.put_autostart_script_in_startup_area()

def run_instrument_deploy(self):
Expand Down Expand Up @@ -194,7 +200,8 @@ def run_instrument_deploy_main(self):

Current the server can not be started or stopped in this python script.
"""
self._upgrade_tasks.check_java_installation()
self._upgrade_tasks.copy_third_party_installs()
self._upgrade_tasks.configure_git()
self._upgrade_tasks.backup_old_directories()
self._upgrade_tasks.backup_database()
self._upgrade_tasks.truncate_database()
Expand Down Expand Up @@ -453,15 +460,7 @@ def setup_config_repository(self):

"""
inst_name = self._machine_name

subprocess.call("git config --global core.autocrlf true")
subprocess.call("git config --global credential.helper wincred")
subprocess.call("git config --global user.name spudulike")
set_user_email = "git config --global user.email spudulike@{}.isis.cclrc.ac.uk"
subprocess.call(set_user_email.format(inst_name.lower()))

if not os.path.exists(SETTINGS_CONFIG_PATH):
os.makedirs(SETTINGS_CONFIG_PATH)
self.git_configs(inst_name)

subprocess.call(
"git clone http://[email protected]/gitroot/instconfigs/inst.git {}".format(
Expand Down Expand Up @@ -577,25 +576,47 @@ def update_calibrations_repository(self):
self.prompt.prompt_and_raise_if_not_yes("There was an error pulling the calibrations repo.\n"
"Manually pull it. Path='{}'".format(CALIBRATION_PATH))

@task("Install java")
def check_java_installation(self):
"""
Checks Java installation
"""
java_url = "/<Public Share>/third_party_installers/"
try:
subprocess.call(["java", "-version"])
self.prompt.prompt_and_raise_if_not_yes(
"Confirm that the java version above is the desired version or that you have "
"upgraded to the desired 64-bit version from {}".format(java_url))
except (subprocess.CalledProcessError, WindowsError):
self.prompt.prompt_and_raise_if_not_yes(
"No installation of Java found on this machine. You can find an installer for the java"
"version used in the current release in {}.".format(java_url))
@task("Copy third party installs")
def copy_third_party_installs(self):
"""
Reminds the user to copy the third party installs from the share
"""
print("This is a new feature. If you find problems, add them to #3492, or open a new one and reference #3492")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this line is needed (if bugs are found, we'll find the appropriate ticket anyway)

# enumerate files in directory
installers = [f for f in os.listdir(THIRD_PARTY_LATEST) if isfile(join(THIRD_PARTY_LATEST, f))]
# for each file
for installer in installers:
if "Git" in installer:
RunProcess(working_dir=THIRD_PARTY_LATEST, executable_file=installer, prog_args=GIT_INSTALL_ARGS).run()
# TODO update git config
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Surely this is just a call to git_configs() which you've defined below?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I forgot to remove the TODO comment

elif "jre" in installer:
# TODO uninstall old java and install latest version
RunProcess(working_dir=THIRD_PARTY_LATEST, executable_file=installer, prog_args=JRE_INSTALL_ARGS).run(shell_option=True)
elif "Npadm" in installer:
if os.path.isdir("C:\\Program Files\\NPortAdminSuite"):
print("NPort already installed")
else:
# Note that there is apparently no way to do a quiet install of NPort
RunProcess(working_dir=THIRD_PARTY_LATEST, executable_file=installer).run(shell_option=True)

def git_configs(self, machine_name):
inst_name = machine_name

subprocess.call("git config --global core.autocrlf true")
subprocess.call("git config --global credential.helper wincred")
subprocess.call("git config --global core.autocrlf input")
subprocess.call("git config --global push.recurseSubmodules check")
subprocess.call("git config --global user.name spudulike")
set_user_email = "git config --global user.email spudulike@{}.isis.cclrc.ac.uk"
subprocess.call(set_user_email.format(inst_name.lower()))

if not os.path.exists(SETTINGS_CONFIG_PATH):
os.makedirs(SETTINGS_CONFIG_PATH)

@task("Configure git")
def configure_git(self):
self.git_configs(self._machine_name)

self.prompt.prompt_and_raise_if_not_yes(
"Is auto-update turned off? This can be checked from the Java control panel in "
"C:\\Program Files\\Java\\jre\\bin\\javacpl.exe")

@task("Configure COM ports")
def configure_com_ports(self):
Expand Down Expand Up @@ -834,7 +855,7 @@ def perform_server_tests(self):
repo.git.fetch()
status = repo.git.status()
print("Current repository status is: {}".format(status))
if "up-to-date with 'origin/{}".format(self._get_machine_name()) in status:
if "up to date with 'origin/{}".format(self._get_machine_name()) in status:
print("Configurations updating correctly")
else:
self.prompt.prompt_and_raise_if_not_yes(
Expand All @@ -854,22 +875,6 @@ def update_instlist(self):
self.prompt.prompt_and_raise_if_not_yes(
"Add the host name of the instrument to the list saved in the CS:INSTLIST PV")

@task("Update web dashboard")
def update_web_dashboard(self):
"""
Prompt user to add the instrument to the web dashboard
"""
redirect_page = os.path.join("C:", "inetpub", "wwwroot", "DataWeb", "Dashboards", "redirect.html")
self.prompt.prompt_and_raise_if_not_yes(
"Add the host name of the instrument to NDX_INSTS or ALL_INSTS in webserver.py in the JSON_bourne "
"repository.")
self.prompt.prompt_and_raise_if_not_yes(
"On NDAEXTWEB1, pull the updated code and add a link to the instrument dashboard on the main "
"dataweb page under {}".format(redirect_page))
self.prompt.prompt_and_raise_if_not_yes(
"Restart JSON_bourne on NDAEXTWEB1 when appropriate. "
"(WARNING: This will kill all existing sessions!)")

@task("Install wiring tables")
def install_wiring_tables(self):
"""
Expand Down Expand Up @@ -1039,7 +1044,7 @@ def put_autostart_script_in_startup_area(self):
autostart_script_name = "ibex_system_boot.bat"

from_path = os.path.join(EPICS_PATH, autostart_script_name)
to_path = os.path.join(PC_START_MENU, "Programs", "Startup", autostart_script_name)
to_path = os.path.join(USER_START_MENU, "Programs", "Startup", autostart_script_name)

# Remove old version if exists
if os.path.exists(to_path):
Expand Down
11 changes: 7 additions & 4 deletions installation_and_upgrade/ibex_install_utils/run_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def __init__(self, working_dir, executable_file, executable_directory=None, pres
else:
self._full_path_to_process_file = os.path.join(executable_directory, executable_file)

def run(self):
def run(self, shell_option=False):
"""
Run the process

Expand All @@ -51,21 +51,24 @@ def run(self):
command_line.extend(self._prog_args)

if not self._capture_pipes:
error_code = subprocess.call(command_line, cwd=self._working_dir)
error_code = subprocess.call(command_line, cwd=self._working_dir, shell=shell_option)
if error_code != 0:
raise ErrorInRun("Command failed with error code: {0}".format(error_code))
output_lines = ""
elif self._press_any_key:
output = subprocess.Popen(command_line, cwd=self._working_dir,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT, stdin=subprocess.PIPE)
stderr=subprocess.STDOUT,
stdin=subprocess.PIPE,
shell=shell_option)
output_lines, err = output.communicate(" ")
else:
output_lines = subprocess.check_output(
command_line,
cwd=self._working_dir,
stderr=subprocess.STDOUT,
stdin=subprocess.PIPE)
stdin=subprocess.PIPE,
shell=shell_option)

for line in output_lines.splitlines():
print(" > {line}".format(line=line))
Expand Down