1 ##############################################################################
3 # Copyright (c) 2019 AT&T Intellectual Property.
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
9 # http://www.apache.org/licenses/LICENSE-2.0
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.
17 ##############################################################################
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)
29 def verify_ran_is_associated_with_e2t_instance(ranName, e2tAddress):
30 r = getRedisClientDecodeResponse()
31 e2tInstanceJson = r.get("{e2Manager},E2TInstance:"+e2tAddress)
32 e2tInstanceDic = json.loads(e2tInstanceJson)
33 assocRanList = e2tInstanceDic.get("associatedRanList")
34 return ranName in assocRanList
36 def verify_e2t_instance_has_no_associated_rans(e2tAddress):
37 r = getRedisClientDecodeResponse()
38 e2tInstanceJson = r.get("{e2Manager},E2TInstance:"+e2tAddress)
39 e2tInstanceDic = json.loads(e2tInstanceJson)
40 assocRanList = e2tInstanceDic.get("associatedRanList")
41 return not assocRanList
43 def verify_e2t_instance_exists_in_addresses(e2tAddress):
44 r = getRedisClientDecodeResponse()
45 e2tAddressesJson = r.get("{e2Manager},E2TAddresses")
46 e2tAddresses = json.loads(e2tAddressesJson)
47 return e2tAddress in e2tAddresses
49 def verify_e2t_instance_key_exists(e2tAddress):
50 r = getRedisClientDecodeResponse()
51 return r.exists("{e2Manager},E2TInstance:"+e2tAddress)
53 def populate_e2t_instances_in_e2m_db_for_get_e2t_instances_tc():
54 r = getRedisClientDecodeResponse()
55 r.set("{e2Manager},E2TAddresses", "[\"e2t.att.com:38000\"]")
56 r.set("{e2Manager},E2TInstance:e2t.att.com:38000", "{\"address\":\"e2t.att.com:38000\",\"associatedRanList\":[\"test1\",\"test2\",\"test3\"],\"keepAliveTimestamp\":1577619310484022369,\"state\":\"ACTIVE\"}")
59 # def dissociate_ran_from_e2tInstance(ranName, e2tAddress):
60 # r = getRedisClientDecodeResponse()
61 # e2tInstanceJson = r.get("{e2Manager},E2TInstance:"+e2tAddress)
62 # e2tInstanceDic = json.loads(e2tInstanceJson)
63 # assocRanList = e2tInstanceDic.get("associatedRanList")
65 # assocRanList.remove(ranName)
66 # updatedE2tInstanceJson = json.dumps(e2tInstanceDic)
67 # print(updatedE2tInstanceJson)
68 # r.set("{e2Manager},E2TInstance:"+e2tAddress, updatedE2tInstanceJson)
69 # nodebBytes = r.get("{e2Manager},RAN:"+ranName)
70 # encoded = nodebBytes.decode().replace(e2tAddress,"").encode()
71 # r.set("{e2Manager},RAN:"+ranName, encoded)