blob: 6bf867f489d8385165846e0c9c80817d9507cf5c [file] [log] [blame]
Enbo Wang6ab8b622019-04-23 13:42:21 +00001#!/usr/bin/python
2
3import sys
4import json
5
6import conf
7import ems_util
8
9
10def upgrade_precheck(pnf_id, old_sw_version, target_sw_version, rule_name, tmp_file=None):
11 ne_info = ems_util.get_ne_info_from_db_by_id(pnf_id)
12
13 if not ne_info:
14 ret_value = {
15 "result": conf.RESULT_FAILURE,
16 "reason": "Can not find NE %s" % pnf_id
17 }
18 return ret_value
19
20 current_sw_version_in_db = ne_info.get("currentSwVersion", "")
21
22 if old_sw_version != current_sw_version_in_db:
23 ret_value = {
24 "result": conf.RESULT_FAILURE,
25 "reason": "Current SW version %s in PNF is not matched with oldSwVersion %s" %
26 (current_sw_version_in_db, old_sw_version)
27 }
28 return ret_value
29
30 ne_info["checkStatus"] = conf.STATUS_PRECHECKED
31 ems_util.update_ne_info(ne_info)
32
33 ret_value = {
34 "result": conf.RESULT_SUCCESS
35 }
36
37 return ret_value
38
39
40def main():
41 # {{pnfId}} {{oldSwVersion}} {{targetSwVersion}} {{ruleName}} /tmp/tmp-{{Id}}
42
43 if len(sys.argv) < 5:
44 ret_value = {
45 "result": conf.RESULT_FAILURE,
46 "reason": "Missing parameters"
47 }
48 print json.dumps(ret_value)
49 sys.exit(conf.RET_CODE_FAILURE)
50
51 if len(sys.argv) >= 5:
52 pnf_id = sys.argv[1]
53 old_sw_version = sys.argv[2]
54 target_sw_version = sys.argv[3]
55 rule_name = sys.argv[4]
56 tmp_file = None
57
58 if len(sys.argv) >= 6:
59 tmp_file = sys.argv[5]
60
61 ret_value = upgrade_precheck(pnf_id, old_sw_version, target_sw_version, rule_name, tmp_file)
62 print json.dumps(ret_value)
63
64 if ret_value["result"] == conf.RESULT_SUCCESS:
65 sys.exit(conf.RET_CODE_SUCCESS)
66 else:
67 sys.exit(conf.RET_CODE_FAILURE)
68
69
70if __name__ == '__main__':
71 main()