blob: 799afbcccd48b45e007d3b81789b206db36d2538 [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_postcheck(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 old_sw_version_in_db = ne_info.get("oldSwVersion", "")
21 current_sw_version_in_db = ne_info.get("currentSwVersion", "")
22
23 if old_sw_version != old_sw_version_in_db:
24 ret_value = {
25 "result": conf.RESULT_FAILURE,
26 "reason": "Old SW version %s in PNF is not matched with oldSwVersion %s" %
27 (old_sw_version_in_db, old_sw_version)
28 }
29 return ret_value
30
31 if target_sw_version != current_sw_version_in_db:
32 ret_value = {
33 "result": conf.RESULT_FAILURE,
34 "reason": "Current SW version %s in PNF is not matched with targetSwVersion %s" %
35 (current_sw_version_in_db, target_sw_version)
36 }
37 return ret_value
38
39 ne_info["checkStatus"] = conf.STATUS_POSTCHECKED
40 ems_util.update_ne_info(ne_info)
41
42 ret_value = {
43 "result": conf.RESULT_SUCCESS
44 }
45
46 return ret_value
47
48
49def main():
50 # {{pnfId}} {{oldSwVersion}} {{targetSwVersion}} {{ruleName}} /tmp/tmp-{{Id}}
51
52 if len(sys.argv) < 5:
53 ret_value = {
54 "result": conf.RESULT_FAILURE,
55 "reason": "Missing parameters"
56 }
57 print json.dumps(ret_value)
58 sys.exit(conf.RET_CODE_FAILURE)
59
60 if len(sys.argv) >= 5:
61 pnf_id = sys.argv[1]
62 old_sw_version = sys.argv[2]
63 target_sw_version = sys.argv[3]
64 rule_name = sys.argv[4]
65 tmp_file = None
66
67 if len(sys.argv) >= 6:
68 tmp_file = sys.argv[5]
69
70 ret_value = upgrade_postcheck(pnf_id, old_sw_version, target_sw_version, rule_name, tmp_file)
71 print json.dumps(ret_value)
72
73 if ret_value["result"] == conf.RESULT_SUCCESS:
74 sys.exit(conf.RET_CODE_SUCCESS)
75 else:
76 sys.exit(conf.RET_CODE_FAILURE)
77
78
79if __name__ == '__main__':
80 main()