Add R5 content to master
[ric-plt/e2mgr.git] / Automation / Tests / Scripts / e2mdbscripts.py
1 ##############################################################################
2 #
3 #   Copyright (c) 2019 AT&T Intellectual Property.
4 #
5 #   Licensed under the Apache License, Version 2.0 (the "License");
6 #   you may not use this file except in compliance with the License.
7 #   You may obtain a copy of the License at
8 #
9 #       http://www.apache.org/licenses/LICENSE-2.0
10 #
11 #   Unless required by applicable law or agreed to in writing, software
12 #   distributed under the License is distributed on an "AS IS" BASIS,
13 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 #   See the License for the specific language governing permissions and
15 #   limitations under the License.
16 #
17 ##############################################################################
18
19 import config
20 import json
21 import redis
22
23
24 def getRedisClientDecodeResponse():
25     c = config.redis_ip_address
26     p = config.redis_ip_port
27     return redis.Redis(host=c, port=p, db=0, decode_responses=True)
28
29
30 def verify_ran_is_associated_with_e2t_instance(ranName, e2tAddress):
31     r = getRedisClientDecodeResponse()
32     e2tInstanceJson = r.get("{e2Manager},E2TInstance:" + e2tAddress)
33     e2tInstanceDic = json.loads(e2tInstanceJson)
34     assocRanList = e2tInstanceDic.get("associatedRanList")
35     return ranName in assocRanList
36
37
38 def verify_e2t_instance_has_no_associated_rans(e2tAddress):
39     r = getRedisClientDecodeResponse()
40     e2tInstanceJson = r.get("{e2Manager},E2TInstance:" + e2tAddress)
41     e2tInstanceDic = json.loads(e2tInstanceJson)
42     assocRanList = e2tInstanceDic.get("associatedRanList")
43     return not assocRanList
44
45
46 def verify_e2t_instance_exists_in_addresses(e2tAddress):
47     r = getRedisClientDecodeResponse()
48     e2tAddressesJson = r.get("{e2Manager},E2TAddresses")
49     e2tAddresses = json.loads(e2tAddressesJson)
50     return e2tAddress in e2tAddresses
51
52
53 def verify_e2t_instance_key_exists(e2tAddress):
54     r = getRedisClientDecodeResponse()
55     return r.exists("{e2Manager},E2TInstance:" + e2tAddress)
56
57
58 def populate_e2t_instances_in_e2m_db_for_get_e2t_instances_tc():
59     r = getRedisClientDecodeResponse()
60     r.set("{e2Manager},E2TAddresses", "[\"e2t.att.com:38000\"]")
61     r.set("{e2Manager},E2TInstance:e2t.att.com:38000",
62           "{\"address\":\"e2t.att.com:38000\",\"associatedRanList\":[\"test1\",\"test2\",\"test3\"],\"keepAliveTimestamp\":1577619310484022369,\"state\":\"ACTIVE\"}")
63     return True
64
65
66 def set_enable_ric_false():
67     r = getRedisClientDecodeResponse()
68     r.set("{e2Manager},GENERAL", "{\"enableRic\":false}")
69     return True