
This commit changes all deploy start upgrade scripts to python, improve them by removing duplicated/needless code and add more logging. The summary of the changes are: - All shell scripts were converted to python code - Some scripts were renamed to follow a naming convention and as a symlink with the old name was added to them for backwards compatibility - Improved error logging and exception try/except blocks - Removed from deploy start script the unnecessary initial step to initialize a temporary ostree_repo, changing it to checkout the ostree_repo directly from the feed Test Plan: PASS: AIO-SX stx-10 to stx-11 e2e upgrade PASS: AIO-DX stx-10 to stx-11 e2e upgrade Story: 2011357 Task: 51892 Change-Id: I63c324b169883c6e9007bc99fd67b5f5b2880668 Signed-off-by: Heitor Matsui <heitorvieira.matsui@windriver.com>
101 lines
2.7 KiB
Python
101 lines
2.7 KiB
Python
#!/usr/bin/python3
|
|
# -*- encoding: utf-8 -*-
|
|
#
|
|
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
|
#
|
|
# Copyright (c) 2023-2024 Wind River Systems, Inc.
|
|
#
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
#
|
|
|
|
"""
|
|
Run feed synchronization between controllers
|
|
"""
|
|
|
|
import logging as LOG
|
|
import os
|
|
import socket
|
|
import subprocess
|
|
import sys
|
|
import upgrade_utils
|
|
|
|
CONTROLLER_0_HOSTNAME = "controller-0"
|
|
CONTROLLER_1_HOSTNAME = "controller-1"
|
|
SYSTEM_MODE_SIMPLEX = "simplex"
|
|
|
|
def sync_controllers(feed):
|
|
controller = socket.gethostname()
|
|
controller = CONTROLLER_1_HOSTNAME if \
|
|
controller == CONTROLLER_0_HOSTNAME else CONTROLLER_0_HOSTNAME
|
|
|
|
LOG.info(f"Synchronizing feed with {controller}...")
|
|
cmd = [
|
|
"rsync",
|
|
"-ac",
|
|
"--delete",
|
|
"--exclude", "tmp",
|
|
feed,
|
|
f"rsync://{controller}/feed"
|
|
]
|
|
subprocess.run(cmd, check=True, text=True, capture_output=True)
|
|
|
|
def print_usage(sys_argv):
|
|
script_name = sys_argv[0]
|
|
print("Usage: %s --feed=<feed>" % script_name)
|
|
|
|
def get_system_mode():
|
|
system_mode=None
|
|
with open(os.devnull, "w") as fnull:
|
|
cmd = "bash -c 'grep system_mode /etc/platform/platform.conf'"
|
|
process = subprocess.Popen(cmd, stdout=subprocess.PIPE,
|
|
stderr=subprocess.PIPE,
|
|
shell=True,
|
|
executable='/bin/bash')
|
|
|
|
stdout, stderr = process.communicate()
|
|
|
|
output = stdout.decode("utf-8").strip()
|
|
error_output = stderr.decode("utf-8").strip()
|
|
|
|
if process.returncode == 0:
|
|
system_mode = output.split('=')[1]
|
|
else:
|
|
LOG.error(f"Error: {error_output}")
|
|
|
|
return system_mode
|
|
|
|
def main(sys_argv):
|
|
args = upgrade_utils.parse_arguments(sys_argv)
|
|
try:
|
|
feed = args["feed"]
|
|
|
|
system_mode = get_system_mode()
|
|
if system_mode is None:
|
|
LOG.error("Unable to get the system mode.")
|
|
return 1
|
|
elif system_mode == SYSTEM_MODE_SIMPLEX:
|
|
LOG.info("System mode is simplex. Skipping sync controllers feed.")
|
|
return 0
|
|
|
|
sync_controllers(feed)
|
|
LOG.info("Feed synchronized between controllers.")
|
|
|
|
except KeyError as e:
|
|
msg = "%s is not provided" % str(e)
|
|
LOG.error(msg)
|
|
print(msg)
|
|
print_usage(sys_argv)
|
|
return 1
|
|
|
|
except subprocess.CalledProcessError as e:
|
|
LOG.exception("Feed synchronization command failed. Error: %s", e.stderr)
|
|
return 1
|
|
|
|
except Exception as e:
|
|
LOG.exception("Feed synchronization failed. Error: %s", e)
|
|
return 1
|
|
|
|
if __name__ == "__main__":
|
|
upgrade_utils.configure_logging('/var/log/software.log', log_level=LOG.INFO)
|
|
sys.exit(main(sys.argv))
|