diff options
author | Enbo Wang <wangenbo@huawei.com> | 2019-04-23 13:42:21 +0000 |
---|---|---|
committer | Enbo Wang <wangenbo@huawei.com> | 2019-04-23 14:17:45 +0000 |
commit | 6ab8b62c35c6c850b95dbb3206de78a6ddb1206d (patch) | |
tree | 3d20b3abea69a298426e70e1fe68efa8015e7d13 /test/mocks/emssimulator/swm/ems_util.py | |
parent | ca2b87e4a1e01d1184b0793ea98ddd5385dec6a6 (diff) |
Add an EMS simulator
Change-Id: I4fedf9a812e19033e7f9a1bff55eae264bc5122f
Issue-ID: INT-1041
Signed-off-by: Enbo Wang <wangenbo@huawei.com>
Diffstat (limited to 'test/mocks/emssimulator/swm/ems_util.py')
-rw-r--r-- | test/mocks/emssimulator/swm/ems_util.py | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/test/mocks/emssimulator/swm/ems_util.py b/test/mocks/emssimulator/swm/ems_util.py new file mode 100644 index 000000000..6d0d3102b --- /dev/null +++ b/test/mocks/emssimulator/swm/ems_util.py @@ -0,0 +1,53 @@ +#!/usr/bin/python + +import time +import json +import jsonpath + +import conf + + +def get_ne_info_list_from_db(ne_filter): + with open(conf.NE_INFO_TABLE) as f_ne_info: + ne_info_table = json.load(f_ne_info) + + if ne_info_table: + ne_info_list = jsonpath.jsonpath(ne_info_table, ne_filter) + return ne_info_list if ne_info_list else [] + else: + return [] + + +def get_ne_info_from_db_by_id(ne_id): + ne_filter = '$..[?(@.nEIdentification == "%s")]' % ne_id + + ne_info_list = get_ne_info_list_from_db(ne_filter) + + return ne_info_list[0] if ne_info_list else None + + +def update_ne_info(ne_info): + with open(conf.NE_INFO_TABLE) as f_ne_info: + ne_info_table = json.load(f_ne_info) + + ne_info["updateTime"] = time.asctime() + + if ne_info_table: + for i in range(0, len(ne_info_table)): + if ne_info_table[i]["nEIdentification"] == ne_info["nEIdentification"]: + ne_info_table[i] = ne_info + break + else: + ne_info_table.append(ne_info) + else: + ne_info_table = [ne_info] + + with open(conf.NE_INFO_TABLE, 'w') as f_ne_info: + json.dump(ne_info_table, f_ne_info, indent=2) + + +def send_notification(notification, process_id): + notification_file = conf.NOTIFICATION_DIR + '/%s-%d' % (notification['notificationType'], process_id) + + with open(notification_file, 'w') as f_notification: + f_notification.write(json.dumps(notification)) |