update/software/scripts/controllers-software-sync
Cristian Mondo 240d17802d Update script to call software_sync api
This commit updates the script which calls
software_sync api, this script can be called by
prestaging. This will help sync the /opt/software
directory between controllers.

TestPlan:
PASS: Verify the script calls software_sync api

Story: 2010676
Task: 51001

Change-Id: I7d76c8877c1239d0ed2bfa514b99d494f7029e62
Signed-off-by: Cristian Mondo <cristian.mondo@windriver.com>
2024-09-20 17:08:23 -03:00

56 lines
1.5 KiB
Python
Executable File

#!/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
#
"""
software sync between duplex controllers to be called
after prestaging
"""
import os
import six.moves.configparser as configparser
import software.constants as constants
import sys
import upgrade_utils
KEYSTONE_CONFIG_SECTION = "keystone_authtoken"
CONF = configparser.ConfigParser(interpolation=None)
CONF.optionxform = str
def main():
try:
if not os.path.exists(constants.SOFTWARE_CONFIG_FILE_LOCAL):
raise Exception("Software config file is not found!")
CONF.read(constants.SOFTWARE_CONFIG_FILE_LOCAL)
if not CONF.has_section(KEYSTONE_CONFIG_SECTION):
raise Exception(f"ERROR: {KEYSTONE_CONFIG_SECTION} section does not exist!")
config = dict(CONF.items(KEYSTONE_CONFIG_SECTION))
usm_token, usm_endpoint = \
upgrade_utils.get_token_endpoint(config, service_type="usm")
api_cmd = usm_endpoint + "/deploy/software_sync"
method = 'POST'
output = upgrade_utils.call_api(usm_token, method, api_cmd)
result = output.get("result")
if not result:
raise Exception(f"ERROR: Unable to sync subclouds controllers!")
print(result)
except Exception as ex:
print(f"Exception: {str(ex)}")
return -1
if __name__ == "__main__":
sys.exit(main())