aboutsummaryrefslogtreecommitdiffstats
path: root/test/csit/tests/dcaegen2/prh-testcases/resources/PrhLibrary.py
blob: e12816a2e4c172a02750652b032f6772cdb31477 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import json

import docker


class PrhLibrary(object):

    def __init__(self):
        pass

    def check_for_log(self, search_for):
        client = docker.from_env()
        container = client.containers.get('prh')
        for line in container.logs(stream=True):
            if search_for in line.strip():
                return True
        else:
            return False

    def create_pnf_ready_notification(self, json_file):
        jsonToPython = json.loads(json_file)
        ipv4 = jsonToPython["event"]["otherFields"]["pnfOamIpv4Address"]
        ipv6 = jsonToPython["event"]["otherFields"]["pnfOamIpv6Address"]
        pnfName = _create_pnf_name(json_file)
        strJson = '{"pnf-name":"' + pnfName + '","ipaddress-v4-oam":"' + ipv4 + '","ipaddress-v6-oam":"' + ipv6 +'"}'
        pythonToJson = json.dumps(strJson)
        return pythonToJson.replace("\\", "")[1:-1]

    def create_pnf_name(self, json_file):
        return _create_pnf_name(json_file)

def _create_pnf_name(json_file):
    jsonToPython = json.loads(json_file)
    vendor = jsonToPython["event"]["otherFields"]["pnfVendorName"]
    serialNumber = jsonToPython["event"]["otherFields"]["pnfSerialNumber"]
    return vendor[:3].upper() + serialNumber