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
44 def populate_e2t_instances_in_e2m_db_for_get_e2t_instances_tc():
45 r = getRedisClientDecodeResponse()
46 r.set("{e2Manager},E2TAddresses", "[\"e2t.att.com:38000\",\"e2t.att.com:38001\"]")
47 r.set("{e2Manager},E2TInstance:e2t.att.com:38000", "{\"address\":\"e2t.att.com:38000\",\"associatedRanList\":[\"test1\",\"test2\",\"test3\"],\"keepAliveTimestamp\":1577619310484022369,\"state\":\"ACTIVE\"}")
48 r.set("{e2Manager},E2TInstance:e2t.att.com:38001", "{\"address\":\"e2t.att.com:38001\",\"associatedRanList\":[],\"keepAliveTimestamp\":1577619310484022369,\"state\":\"ACTIVE\"}")
51 # def dissociate_ran_from_e2tInstance(ranName, e2tAddress):
52 # r = getRedisClientDecodeResponse()
53 # e2tInstanceJson = r.get("{e2Manager},E2TInstance:"+e2tAddress)
54 # e2tInstanceDic = json.loads(e2tInstanceJson)
55 # assocRanList = e2tInstanceDic.get("associatedRanList")
57 # assocRanList.remove(ranName)
58 # updatedE2tInstanceJson = json.dumps(e2tInstanceDic)
59 # print(updatedE2tInstanceJson)
60 # r.set("{e2Manager},E2TInstance:"+e2tAddress, updatedE2tInstanceJson)
61 # nodebBytes = r.get("{e2Manager},RAN:"+ranName)
62 # encoded = nodebBytes.decode().replace(e2tAddress,"").encode()
63 # r.set("{e2Manager},RAN:"+ranName, encoded)