blob: 90794488db30dfa082e2430a5dd98c31543a2adc [file] [log] [blame]
Enbo Wang818f76a2020-03-04 00:42:31 +08001#!/usr/bin/python3
2# ============LICENSE_START=======================================================
3# ONAP - SO
4# ================================================================================
5# Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved.
6# ================================================================================
7# Licensed under the Apache License, Version 2.0 (the "License");
8# you may not use this file except in compliance with the License.
9# You may obtain a copy of the License at
10#
11# http://www.apache.org/licenses/LICENSE-2.0
12#
13# Unless required by applicable law or agreed to in writing, software
14# distributed under the License is distributed on an "AS IS" BASIS,
15# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16# See the License for the specific language governing permissions and
17# limitations under the License.
18# ============LICENSE_END=========================================================
Enbo Wang6ab8b622019-04-23 13:42:21 +000019
20import sys
21import argparse
22import json
Enbo Wang6ab8b622019-04-23 13:42:21 +000023
24import conf
Enbo Wang818f76a2020-03-04 00:42:31 +080025import download_n_e_sw
26import install_n_e_sw
Enbo Wang6ab8b622019-04-23 13:42:21 +000027
28
29def main():
30 parser = argparse.ArgumentParser()
31
32 parser.add_argument("--swToBeDownloaded", help="The NE software to be downloaded", required=True)
33 parser.add_argument("--neIdentifier", help="The NE where the software can be downloaded", required=True)
34
35 args = parser.parse_args()
36
37 sw_to_be_downloaded = json.loads(args.swToBeDownloaded)
38
Enbo Wang818f76a2020-03-04 00:42:31 +080039 all_installed_ne_sw_list = []
40 all_failed_sw_info = []
Enbo Wang6ab8b622019-04-23 13:42:21 +000041
Enbo Wang818f76a2020-03-04 00:42:31 +080042 download_notification, download_ret_value = download_n_e_sw.download(sw_to_be_downloaded, args.neIdentifier)
43
44 downloaded_ne_sw_list = download_notification.get("downloadedNESwInfo", [])
45 failed_downloaded_sw_list = download_notification.get("failedSwInfo", [])
46 all_failed_sw_info.extend(failed_downloaded_sw_list)
47
48 for downloaded_ne_sw in downloaded_ne_sw_list:
49 install_notification, _ = install_n_e_sw.install(downloaded_ne_sw, args.neIdentifier)
50 installed_ne_sw_list = install_notification.get("installedNESwInfo", [])
51 failed_installed_sw_list = install_notification.get("failedSwInfo", [])
52
53 all_installed_ne_sw_list.extend(installed_ne_sw_list)
54 all_failed_sw_info.extend(failed_installed_sw_list)
55
56 num_all_installed_ne_sw_list = len(all_installed_ne_sw_list)
57 num_sw_to_be_downloaded = len(sw_to_be_downloaded)
58
59 if num_all_installed_ne_sw_list == num_sw_to_be_downloaded:
60 download_ret_value["result"] = conf.REQ_SUCCESS
61 else:
62 download_ret_value["result"] = conf.REQ_FAILURE
63 download_ret_value["reason"] = "Failed downloaded or installed SW: %s" % json.dumps(all_failed_sw_info)
64
65 print(json.dumps(download_ret_value))
66
67 if download_ret_value["result"] == conf.REQ_SUCCESS:
Enbo Wang6ab8b622019-04-23 13:42:21 +000068 sys.exit(conf.RET_CODE_SUCCESS)
69 else:
70 sys.exit(conf.RET_CODE_FAILURE)
71
72
73if __name__ == '__main__':
74 main()