diff options
author | Enbo Wang <wangenbo@huawei.com> | 2020-03-04 00:42:31 +0800 |
---|---|---|
committer | Morgan Richomme <morgan.richomme@orange.com> | 2020-03-05 10:59:35 +0000 |
commit | 818f76a0173c5d6cef483425042b4f0651ee793b (patch) | |
tree | f5055f9841e51f4b68423d1c6e4bbf5731dbac34 /test/mocks/emssimulator/swm/swFallback | |
parent | 5da05c576855c0e9b0f7a3c5934da41b91615f33 (diff) |
EMS simulator extension for PNF SW Upgrade
Change-Id: I3a8c706373f4004850c2403f4aee0d1f28aad464
Issue-ID: INT-1208
Signed-off-by: Enbo Wang <wangenbo@huawei.com>
Diffstat (limited to 'test/mocks/emssimulator/swm/swFallback')
-rwxr-xr-x | test/mocks/emssimulator/swm/swFallback | 123 |
1 files changed, 22 insertions, 101 deletions
diff --git a/test/mocks/emssimulator/swm/swFallback b/test/mocks/emssimulator/swm/swFallback index 9d6608c23..506eee0d4 100755 --- a/test/mocks/emssimulator/swm/swFallback +++ b/test/mocks/emssimulator/swm/swFallback @@ -1,108 +1,29 @@ -#!/usr/bin/python +#!/usr/bin/python3 +# ============LICENSE_START======================================================= +# ONAP - SO +# ================================================================================ +# Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +import sys import argparse import json -import sys -import os -import shutil import conf import ems_util - - -def sw_fallback(ne_info_list): - ne_list = [] - num_failure = 0 - - for ne_info in ne_info_list: - if ne_info.get("status") == conf.STATUS_DOWNLOADING: - ne_info["status"] = conf.STATUS_ACTIVATED - ems_util.update_ne_info(ne_info) - - ne_entry = { - "nEIdentification": ne_info["nEIdentification"], - "swFallbackStatus": "fallbackSuccessful" - } - ne_list.append(ne_entry) - continue - - sw_install_dir_in_ne = conf.PNF_SIMULATORS_DIR + '/' + ne_info['omIP'] + conf.PNF_SW_INSTALL_DIR - - if ne_info.get("status") == conf.STATUS_INSTALLING: - old_sw_version = ne_info.get("currentSwVersion", "") - current_sw_version = ne_info.get("targetSwVersion", "") - else: - old_sw_version = ne_info.get("oldSwVersion", "") - current_sw_version = ne_info.get("currentSwVersion", "") - - old_sw_dir = sw_install_dir_in_ne + '/' + old_sw_version - - if not old_sw_version or not os.path.isdir(old_sw_dir): - ne_entry = { - "nEIdentification": ne_info["nEIdentification"], - "swFallbackStatus": "fallbackUnsuccessful" - } - ne_list.append(ne_entry) - - num_failure += 1 - continue - - current_sw_dir = sw_install_dir_in_ne + '/' + current_sw_version - - if current_sw_version and os.path.isdir(current_sw_dir) and current_sw_dir != old_sw_dir: - shutil.rmtree(current_sw_dir, ignore_errors=True) - - old_cwd = os.getcwd() - os.chdir(sw_install_dir_in_ne) - if os.path.islink(conf.CURRENT_VERSION_DIR): - os.remove(conf.CURRENT_VERSION_DIR) - os.symlink(old_sw_version, conf.CURRENT_VERSION_DIR) - os.chdir(old_cwd) - - installed_sw_db = old_sw_dir + '/' + conf.INSTALLED_SW - if os.path.isfile(installed_sw_db): - with open(installed_sw_db) as f_installed_sw: - installed_sw_table = json.load(f_installed_sw) - if not installed_sw_table: - installed_sw_table = {} - else: - installed_sw_table = {} - - ne_info["installedSw"] = installed_sw_table - if "oldSwVersion" in ne_info: - ne_info["currentSwVersion"] = ne_info["oldSwVersion"] - del ne_info["oldSwVersion"] - - if "targetSwVersion" in ne_info: - del ne_info["targetSwVersion"] - - if "downloadedSwLocation" in ne_info: - if os.path.isdir(ne_info["downloadedSwLocation"]): - shutil.rmtree(ne_info["downloadedSwLocation"], ignore_errors=True) - del ne_info["downloadedSwLocation"] - - ne_info["status"] = conf.STATUS_ACTIVATED - ems_util.update_ne_info(ne_info) - - ne_entry = { - "nEIdentification": ne_info["nEIdentification"], - "swFallbackStatus": "fallbackSuccessful" - } - ne_list.append(ne_entry) - - if num_failure == 0: - result = conf.RESULT_SUCCESS - elif num_failure == len(ne_info_list): - result = conf.RESULT_FAILURE - else: - result = conf.RESULT_PARTLY - - ret_value = { - "nEList": ne_list, - "result": result - } - - return ret_value +import sw_fallback def main(): @@ -114,8 +35,8 @@ def main(): ne_info_list = ems_util.get_ne_info_list_from_db(args.filter) - ret_value = sw_fallback(ne_info_list) - print json.dumps(ret_value) + ret_value = sw_fallback.fallback(ne_info_list) + print(json.dumps(ret_value)) if ret_value["result"] == conf.RESULT_SUCCESS: sys.exit(conf.RET_CODE_SUCCESS) |