예제 #1
0
파일: barsm_utils.py 프로젝트: ktj100/linux
def aacmToBarsmMsg(connsock): # B is 1 byte, H is 2 bytes, I is 4 bytes
    all_pids = [0,0]

    all_child = proc.findchild(barsm_pid)
    all_pids = [int(c['pid']) for c in all_child]

    byteLength = 2+2+4+2+4+4

    aacmToBarsmData = [CMD_AACM_TO_BARSM_MSG, (byteLength), int(barsm_pid), 2, all_pids[0], all_pids[1]]

    connsock.send(struct.pack(AACM_TO_BARSM_MSG_FMT, aacmToBarsmData[0], \
        aacmToBarsmData[1], aacmToBarsmData[2], aacmToBarsmData[3], aacmToBarsmData[4], aacmToBarsmData[5]))

    return all_child
예제 #2
0
파일: barsm_utils.py 프로젝트: ktj100/linux
def checkForRestart(appsToRestart):
    oldChildPid = []
    newChildPid = []
    oldChildName = []
    newChildName = []
    newChildState = []

    if appsToRestart == []:
        print('--Empty list')
        return False

    global barsm_pid
    childProc = proc.findchild(barsm_pid)

    for nc in childProc:
        newChildPid.append(nc['pid'])
        newChildName.append(nc['name'])
        newChildState.append(nc['state'])

    for oc in appsToRestart:
        oldChildPid.append(oc['pid'])
        oldChildName.append(oc['name'])

    #checks that the process exists
    for c in oldChildName:
        if (not(c in newChildName)):
            print('--process name not found')
            return False

    # checks the old one was stopped and the new one is running
    for oc in oldChildPid:
        index = 0
        for nc in newChildPid:
            #checks that it is not a zombie process
            if ((nc == oc) and ('Z' != newChildState[index])):
                print('-- matching process id found')
                return False

            index = index + 1

    return True
예제 #3
0
파일: barsm_utils.py 프로젝트: ktj100/linux
def aacm_setup():
    success = True
    aacmStarted = False
    global barsm_pid
    while False == aacmStarted:
        check_barsm_running()
        all_child = proc.findchild(barsm_pid)
        if 1 == len(all_child):
            aacmStarted = True

    global TCPconn, TCPserver, UDPsock
    TCPconn, TCPserver = TCPsetup()  # both return values are objects
    UDPsock = UDPsetup()

    success = barsmToAacmInit(TCPconn)
    if success:
        barsmToAacmInitAck(TCPconn)

    sysInit(UDPsock)

    return success
예제 #4
0
파일: barsm_utils.py 프로젝트: ktj100/linux
def waitForLaunch(log=None):
    notComplete = True

    disabled_pat = re.compile(r'NOTICE: Process for (?P<app>[A-Za-z0-9._]+) in (?P<path>[A-Za-z0-9._/]+) disabled permanently! \(0:Success\)')
    launched_pat = re.compile(r'SUCCESS: launched (?P<path>[A-Za-z0-9._/]+)/(?P<app>[A-Za-z0-9._]+) with name (?P<name>[a-z]{4}) with PID (?P<pid>\d+)')

    nameList = []
    while notComplete:
        check_barsm_running()
        logs = log.read('BARSM')

        msg_list = list(filter(lambda t: "COMPLETED: Launch sequence complete!" in t['message'], logs))
        launched_list = [p.groupdict() for p in [launched_pat.match(t['message']) for t in logs] if p]
        disabled_list = [p.groupdict() for p in [disabled_pat.match(t['message']) for t in logs] if p]

        if launched_list:
            for l in launched_list[:]:
                for n in nameList:
                    if n['app'] == l['app'] and n['path'] == l['path']:
                        n['pid'] = l['pid']
                        launched_list.remove(l)
            nameList.extend(launched_list)

        for d in disabled_list:
            for n in nameList[:]:
                if n['app'] == l['app'] and n['path'] == l['path']:
                    nameList.remove(n)

        if msg_list:
            print("Launch Complete message found!")
            notComplete = False

    global barsm_pid, barsm_spawned_pids
    print('BARSM: {}'.format(barsm_pid))
    all_child = proc.findchild(barsm_pid)

    child_pids = set([int(p['pid']) for p in all_child])
    barsm_spawned_pids = list(set(barsm_spawned_pids).union(child_pids))
    child_amount = len(all_child)
    return child_amount, nameList
예제 #5
0
def run():
    success = True
    # navigate to the end of the SYSLOG
    follow = log.logfollower()

    # clear out all app directories
    barsm_utils.remove()

    # add apps in directories
    subprocess.call('gcc '+apps_loc+'/infinite_sec.c -o /opt/rc360/system/aacm', shell=True)
    subprocess.call('gcc '+apps_loc+'/hundred_sec.c -o /opt/rc360/modules/GE/gemod', shell=True)

    # start barsm
    if success:
        print('-Starting BARSM')
        barsm_utils.start_barsm()
        logs = follow.read('BARSM')
        errors = sum(1 for d in logs if "ERROR" in d.get('message'))
        if 0 < errors:
            print('ERROR: SYSLOG errors while starting BARSM!')
            for d in logs:
                if "ERROR" in d.get('message'):
                    print (d.get('message'))
            success = False
        else:
            print('--BARSM started')

    # wait for AACM to start
    if success:
        print('-Waiting for AACM')
        barsm_pid = (proc.findproc("valgrind.bin"))[0]['pid']
        aacmStarted = False
        while False == aacmStarted and success:
            # check if AACM has started
            all_child = proc.findchild(barsm_pid)
            if 1 == len(all_child):
                aacmStarted = True
                aacm_pid = int(all_child[0]['pid'])
            # check for launch errors
            logs = follow.read('BARSM')
            errors = sum(1 for d in logs if "ERROR" in d.get('message'))
            if 0 < errors:
                print('ERROR: SYSLOG errors while waiting for AACM startup!')
                for d in logs:
                    if "ERROR" in d.get('message'):
                        print (d.get('message'))
                success = False
        if success:
            print('--AACM started')

    # setup TCP connection
    if success:
        print('-Setting up TCP connection')
        TCPconn, sVal = barsm_utils.TCPsetup()  # both return values are objects
        logs = follow.read('BARSM')
        errors = sum(1 for d in logs if "ERROR" in d.get('message'))
        if 0 < errors:
            print('ERROR: SYSLOG errors while initiating TCP connection!')
            for d in logs:
                if "ERROR" in d.get('message'):
                    print (d.get('message'))
            success = False
        else:
            print('--TCP connection setup successful')

    # receive BARSM to AACM init
    if success:
        print('-Waiting for BARSM to AACM init')
        success = barsm_utils.barsmToAacmInit(TCPconn)
        logs = follow.read('BARSM')
        errors = sum(1 for d in logs if "ERROR" in d.get('message'))
        if 0 < errors:
            print('ERROR: SYSLOG errors while receiving BARSM to AACM init!')
            for d in logs:
                if "ERROR" in d.get('message'):
                    print (d.get('message'))
            success = False
        else:
            print('--Init received')

    # send BARSM to AACM init ack
    if success:
        print('-Sending ACK')
        barsm_utils.barsmToAacmInitAck(TCPconn)
        logs = follow.read('BARSM')
        errors = sum(1 for d in logs if "ERROR" in d.get('message'))
        if 0 < errors:
            print('ERROR: SYSLOG errors while sending BARSM to AACM init ack!')
            for d in logs:
                if "ERROR" in d.get('message'):
                    print (d.get('message'))
            success = False
        else:
            print('--ACK sent')

    # wait for children to complete launching
    if success:
        print('-Waiting for launch completion')
        children, nameList = barsm_utils.waitForLaunch(follow)
        if 2 == children:
            print('--Launch complete!')
        else:
            print('ERROR: only {} child procs (should have 2)'.format(children))
            success = False

    # setup UDP connection
    if success:
        print('-Setting up UDP connection')
        UDPsock = barsm_utils.UDPsetup()
        logs = follow.read('BARSM')
        errors = sum(1 for d in logs if "ERROR" in d.get('message'))
        if 0 < errors:
            print('ERROR: SYSLOG errors while initiating UDP connection!')
            for d in logs:
                if "ERROR" in d.get('message'):
                    print (d.get('message'))
            success = False
        else:
            print('--UDP connection setup')

    # receive OPEN message
    if 0:#success:
        print('-Waiting to receive OPEN message from BARSM')
        SenderAddr = barsm_utils.udpOpen(UDPsock)
        logs = follow.read('BARSM')
        errors = sum(1 for d in logs if "ERROR" in d.get('message'))
        if 0 < errors:
            print('ERROR: SYSLOG errors while opening UDP connection!')
            for d in logs:
                if "ERROR" in d.get('message'):
                    print (d.get('message'))
            success = False
        else:
            print('--OPEN received')

    # send sysInit message
    if success:
        print('-Sending SYS_INIT message to BARSM')
        barsm_utils.sysInit(UDPsock)

    # receive barsm to aacm processes
    if success:
        print('-Receiving BARSM_TO_AACM_PROCESSES')

        expectedData = {}
        expectedData['numMsgBytes']  = 42
        expectedData['numMsgDataBytes']  = 38

        # expect number of processes + 1 for BARSM + 1 for AACM
        expectedData['unpackFMT'] = '=HHH' + 'I4sI' * (len(nameList) + 2)
        expectedData['numProcesses'] = len(nameList) + 2

        barsm_utils.barsmToAacmProcesses(TCPconn, expectedData, aacm_pid, nameList, follow)
        print('--BARSM_TO_AACM_PROCESSES message received')

    # Send for AACM_TO_BARSM_MSG
    if success:
        print('-Sending AACM_TO_BARSM_MSG')

        #send AACM_TO_BARSM_MSG
        appsToRestart = barsm_utils.aacmToBarsmMsg(TCPconn)
        logs = follow.read('BARSM')
        errors = sum(1 for d in logs if "ERROR" in d.get('message'))
        if 0 < errors:
            print('ERROR: SYSLOG errors while sending AACM_TO_BARSM_MSG!')
            for d in logs:
                if "ERROR" in d.get('message'):
                    print (d.get('message'))
            success = False
        if success:
            print('--AACM_TO_BARSM_MSG sent')

    # get AACM_TO_BARSM_MSG ack
    if success:
        print('-Receiving AACM_TO_BARSM_MSG ACK')
        msgNotReceived = True
        while True == msgNotReceived and success:
            expectedERR = 12
            msgNotReceived = barsm_utils.aacmToBarsmAck(TCPconn, expectedERR)
            logs = follow.read('BARSM')
            errors = sum(1 for d in logs if "ERROR" in d.get('message'))
            if 0 < errors:
                print('--ERROR: SYSLOG errors while receiving BARSM to AACM Msg ack!')
                for d in logs:
                    if "ERROR" in d.get('message'):
                        print (d.get('message'))
                success = False
        if success:
            print('--AACM_TO_BARSM_MSG ACK received')

    # verify restart of App(s)
    if success:
        print('-Checking for successful app restart(s)')
        success = barsm_utils.checkForRestart(appsToRestart)
        logs = follow.read('BARSM')
        errors = sum(1 for d in logs if "ERROR" in d.get('message'))
        if 0 < errors:
            print('--ERROR: SYSLOG error, App(s) not restarted!')
            for d in logs:
                if "ERROR" in d.get('message'):
                    print (d.get('message'))
            success = False
        if success:
            print('--App(s) restarted successfully')
            barsm_utils.populateChildren()
        else:
            print('--App(s) restart failure')

    if success:
        print('-Checking BARSM_TO_AACM_MSG')
        msgNotReceived = True
        if True == msgNotReceived and success:
            print('--Receiving BARSM_TO_AACM_MSG')
            expectedERR = 11

            appName = log.logfollower()
            names = []
            expectedName = ''

            while not names and expectedName == '':
                names = appName.read('BARSM')
                try:
                    expectedName = list(filter(lambda t: "DEBUG: Message sent with APP name:" in t['message'], names))[0]['message']
                except:
                    expectedName = ''
                    names = []

            expectedName = expectedName[-4:]

            msgNotReceived, failedPid = barsm_utils.receiveBarsmToAacm(TCPconn, expectedERR, expectedName)
            success = not msgNotReceived
            logs = follow.read('BARSM')
            errors = sum(1 for d in logs if "ERROR" in d.get('message'))
            #all of the errors less the one we are expecting
            errors = errors - sum(1 for d in logs if "ERROR: Process for /opt/rc360/modules/GE/gemod" in d.get('message'))
            if 0 < errors:
                print('--Error Receiving BARSM_TO_AACM_MSG')
        if success:
            print('--BARSM_TO_AACM_MSG received')

    #send ack back to barsm
    if success:
        appsToRestart = []
        restartData   = {}
        restartData['pid']  = failedPid
        restartData['name']  = list(filter(lambda t: "NOTICE: Restarting " in t['message'], logs))[-1]['message'].split(' ')[-1][:-3]
        appsToRestart.append(restartData)

        barsm_utils.sendBarsmToAacmAck(TCPconn, failedPid)
        logs = follow.read('BARSM')
        errors = sum(1 for d in logs if "ERROR" in d.get('message'))
        if 0 < errors:
            print('--ERROR: Sending ACK To BARSM!')
            for d in logs:
                if "ERROR" in d.get('message'):
                    print (d.get('message'))
            success = False

    if success:
        print('Checking for BARSM_TO_AACM_MSG process restart')
        success = barsm_utils.checkForRestart(appsToRestart)

        logs = follow.read('BARSM')
        errors = sum(1 for d in logs if "ERROR" in d.get('message'))
        if 0 < errors:
            print('--ERROR: SYSLOG error, App(s) not restarted!')
            for d in logs:
                if "ERROR" in d.get('message'):
                    print (d.get('message'))
            success = False
        if success:
            print('--BARSM_TO_AACM_MSG App(s) restarted successfully')
            barsm_utils.populateChildren()
        else:
            print('--BARSM_TO_AACM_MSG App(s) restart failure')

    # kill off all started processes
    barsm_utils.kill_procs()

    print('{}'.format('PASSED' if success else 'FAILED'))
    return success
예제 #6
0
def run():
    result = False
    success = False

    # clear out all app directories
    barsm_utils.remove()

    # compile needed applications and place in required directories
    subprocess.call('gcc '+barsm_utils.apps_loc+'/infinite_sec.c -o /opt/rc360/system/aacm', shell=True)
    subprocess.call('gcc '+barsm_utils.apps_loc+'/thirty_sec.c -o /opt/rc360/modules/TPA/thirty_sec', shell=True)

    # navigate to the end of the SYSLOG
    follow = log.logfollower()

    # start barsm

    print('-Starting BARSM')
    barsm_utils.start_barsm()
    logs = follow.read('BARSM')
    errors = sum(1 for d in logs if "ERROR" in d.get('message'))
    if 0 < errors:
        print('ERROR: SYSLOG errors while starting BARSM!')
        for d in logs:
            if "ERROR" in d.get('message'):
                print (d.get('message'))
        success = False
    else:
        print('--BARSM started')
        success = True

    # wait for AACM to start
    if success:
        print('-Waiting for AACM')
        barsm_pid = (proc.findproc("valgrind.bin"))[0]['pid']
        aacmStarted = False
        while False == aacmStarted and success:
            # check if AACM has started
            all_child = proc.findchild(barsm_pid)
            if 1 == len(all_child):
                aacmStarted = True
                aacm_pid = int(all_child[0]['pid'])
            # check for launch errors
            logs = follow.read('BARSM')
            errors = sum(1 for d in logs if "ERROR" in d.get('message'))
            if 0 < errors:
                print('ERROR: SYSLOG errors while waiting for AACM startup!')
                for d in logs:
                    if "ERROR" in d.get('message'):
                        print (d.get('message'))
                success = False
        if success:
            print('--AACM started')

    # setup TCP connection
    if success:
        print('-Setting up TCP connection')
        TCPconn, sVal = barsm_utils.TCPsetup()  # both return values are objects
        logs = follow.read('BARSM')
        errors = sum(1 for d in logs if "ERROR" in d.get('message'))
        if 0 < errors:
            print('ERROR: SYSLOG errors while initiating TCP connection!')
            for d in logs:
                if "ERROR" in d.get('message'):
                    print (d.get('message'))
            success = False
        else:
            print('--TCP connection setup successful')

    # receive BARSM to AACM init
    if success:
        print('-Waiting for BARSM to AACM init')
        success = barsm_utils.barsmToAacmInit(TCPconn)
        logs = follow.read('BARSM')
        errors = sum(1 for d in logs if "ERROR" in d.get('message'))
        if 0 < errors:
            print('ERROR: SYSLOG errors while receiving BARSM to AACM init!')
            for d in logs:
                if "ERROR" in d.get('message'):
                    print (d.get('message'))
            success = False
        else:
            print('--Init received')

    # send BARSM to AACM init ack
    if success:
        print('-Sending ACK')
        barsm_utils.barsmToAacmInitAck(TCPconn)
        logs = follow.read('BARSM')
        errors = sum(1 for d in logs if "ERROR" in d.get('message'))
        if 0 < errors:
            print('ERROR: SYSLOG errors while sending BARSM to AACM init ack!')
            for d in logs:
                if "ERROR" in d.get('message'):
                    print (d.get('message'))
            success = False
        else:
            print('--ACK sent')

    # wait for children to complete launching
    if success:
        print('-Waiting for launch completion')
        children, nameList = barsm_utils.waitForLaunch(follow)
        if 2 == children:
            print('--Launch complete!')
        else:
            print('ERROR: only {} child procs (should have 2)'.format(children))
            success = False

    # setup UDP connection
    if success:
        print('-Setting up UDP connection')
        UDPsock = barsm_utils.UDPsetup()
        logs = follow.read('BARSM')
        errors = sum(1 for d in logs if "ERROR" in d.get('message'))
        if 0 < errors:
            print('ERROR: SYSLOG errors while initiating UDP connection!')
            for d in logs:
                if "ERROR" in d.get('message'):
                    print (d.get('message'))
            success = False
        else:
            print('--UDP connection setup')

    # send sysInit message
    if success:
        print('-Waiting to receive OPEN message from BARSM')
        print('-Sending SYS_INIT message to BARSM')
        barsm_utils.sysInit(UDPsock)
        print('--OPEN received')

    # receive barsm to aacm processes
    if success:
        print('-Receiving BARSM_TO_AACM_PROCESSES')

        expectedData = {}
        expectedData['numMsgBytes']  = 42
        expectedData['numMsgDataBytes']  = 38
        # expect number of processes + 1 for BARSM + 1 for AACM
        expectedData['unpackFMT'] = '=HHH' + 'I4sI' * (len(nameList) + 2)
        expectedData['numProcesses'] = len(nameList) + 2

        barsm_utils.barsmToAacmProcesses(TCPconn, expectedData, aacm_pid, nameList, follow)
        print('--BARSM_TO_AACM_PROCESSES message received')

    # Default the time difference to a value that indicates failure
    dif = 0

    if success:
        #TODO: have a maximum time limit to look for the restart messages
        # capture the time of the first restart
        print("Waiting for first restart...")
        expectedERR = 11

        appName = log.logfollower()
        names = []
        expectedName = ''

        while not names and expectedName == '':
            names = appName.read('BARSM')
            try:
                expectedName = list(filter(lambda t: "DEBUG: Message sent with APP name:" in t['message'], names))[0]['message']
            except:
                expectedName = ''
                names = []

        expectedName = expectedName[-4:]

        barsm_utils.receiveBarsmToAacm(TCPconn, expectedERR, expectedName)
        logs = follow.read('BARSM')
        restart1_ts = list(filter(lambda t: "Restarting" in t['message'], logs))[0]['timestamp']
        #print('restart1_ts: {}'.format(restart1_ts))

        #update the children list after the restart
        barsm_utils.populateChildren()

        # capture the time of the second restart
        print("Waiting for second restart...")
        expectedERR = 11

        appName = log.logfollower()
        names = []
        expectedName = ''

        while not names and expectedName == '':
            names = appName.read('BARSM')
            try:
                expectedName = list(filter(lambda t: "DEBUG: Message sent with APP name:" in t['message'], names))[0]['message']
            except:
                expectedName = ''
                names = []

        expectedName = expectedName[-4:]

        barsm_utils.receiveBarsmToAacm(TCPconn, expectedERR, expectedName)
        logs = follow.read('BARSM')
        restart2_ts = list(filter(lambda t: "Restarting" in t['message'], logs))[0]['timestamp']
        #print('restart2_ts: {}'.format(restart2_ts))

        # compare timestamps
        dif = (restart2_ts - restart1_ts).total_seconds()
        #print('dif: {}'.format(dif))
        barsm_utils.populateChildren()

    # kill off all started processes
    barsm_utils.kill_procs()

    if success and 55 <= dif and 65 >= dif:
        result = True

    print('{}'.format('PASSED' if result else 'FAILED'))
    return result
예제 #7
0
def run():
    success = True
    zombies = 0
    # navigate to the end of the SYSLOG
    follow = log.logfollower()
    follow2 = log.logfollower()

    # clear out all app directories
    barsm_utils.remove()

    # compile needed applications and place in required directories
    barsm_utils.launch_bad()

    # start barsm
    if success:
        print('-Starting BARSM')
        barsm_utils.start_barsm()
        logs = follow.read('BARSM')
        errors = sum(1 for d in logs if "ERROR" in d.get('message'))
        if 0 < errors:
            print('ERROR: SYSLOG errors while starting BARSM!')
            for d in logs:
                if "ERROR" in d.get('message'):
                    print (d.get('message'))
            success = False
        else:
            print('--BARSM started')

    # wait for AACM to start
    if success:
        print('-Waiting for AACM')
        barsm_pid = (proc.findproc("valgrind.bin"))[0]['pid']
        aacmStarted = False
        while False == aacmStarted and success:
            # check if AACM has started
            all_child = proc.findchild(barsm_pid)
            if 1 == len(all_child):
                aacmStarted = True
                aacm_pid = int(all_child[0]['pid'])
            # check for launch errors
            logs = follow.read('BARSM')
            errors = sum(1 for d in logs if "ERROR" in d.get('message'))
            if 0 < errors:
                print('ERROR: SYSLOG errors while waiting for AACM startup!')
                for d in logs:
                    if "ERROR" in d.get('message'):
                        print (d.get('message'))
                success = False
        if success:
            print('--AACM started')

    # setup TCP connection
    if success:
        print('-Setting up TCP connection')
        TCPconn, sVal = barsm_utils.TCPsetup()  # both return values are objects
        logs = follow.read('BARSM')
        errors = sum(1 for d in logs if "ERROR" in d.get('message'))
        if 0 < errors:
            print('ERROR: SYSLOG errors while initiating TCP connection!')
            for d in logs:
                if "ERROR" in d.get('message'):
                    print (d.get('message'))
            success = False
        else:
            print('--TCP connection setup successful')

    # receive BARSM to AACM init
    if success:
        print('-Waiting for BARSM to AACM init')
        success = barsm_utils.barsmToAacmInit(TCPconn)
        logs = follow.read('BARSM')
        errors = sum(1 for d in logs if "ERROR" in d.get('message'))
        if 0 < errors:
            print('ERROR: SYSLOG errors while receiving BARSM to AACM init!')
            for d in logs:
                if "ERROR" in d.get('message'):
                    print (d.get('message'))
            success = False
        else:
            print('--Init received')

    # send BARSM to AACM init ack
    if success:
        print('-Sending ACK')
        barsm_utils.barsmToAacmInitAck(TCPconn)
        logs = follow.read('BARSM')
        errors = sum(1 for d in logs if "ERROR" in d.get('message'))
        if 0 < errors:
            print('ERROR: SYSLOG errors while sending BARSM to AACM init ack!')
            for d in logs:
                if "ERROR" in d.get('message'):
                    print (d.get('message'))
            success = False
        else:
            print('--ACK sent')

    # wait for children to complete launching
    if success:
        print('-Waiting for launch completion')
        children, nameList = barsm_utils.waitForLaunch(follow)
        if 9 == children:
            print('--Launch complete!')
        else:
            print('ERROR: only {} child procs (should have 9)'.format(children))
            success = False

    # setup UDP connection
    if success:
        print('-Setting up UDP connection')
        UDPsock = barsm_utils.UDPsetup()
        logs = follow.read('BARSM')
        errors = sum(1 for d in logs if "ERROR" in d.get('message'))
        if 0 < errors:
            print('ERROR: SYSLOG errors while initiating UDP connection!')
            for d in logs:
                if "ERROR" in d.get('message'):
                    print (d.get('message'))
            success = False
        else:
            print('--UDP connection setup')

    # send sysInit message
    if success:
        print('-Waiting to receive OPEN message from BARSM')
        print('-Sending SYS_INIT message to BARSM')
        barsm_utils.sysInit(UDPsock)
        print('--OPEN received')

    # receive barsm to aacm processes
    if success:
        print('-Receiving BARSM_TO_AACM_PROCESSES')

        expectedData = {}
        expectedData['numMsgBytes']  = 126
        expectedData['numMsgDataBytes']  = 122
        # expect number of processes + 1 for BARSM + 1 for AACM
        expectedData['unpackFMT'] = '=HHH' + 'I4sI' * (len(nameList) + 2)
        expectedData['numProcesses'] = len(nameList) + 2

        barsm_utils.barsmToAacmProcesses(TCPconn, expectedData, aacm_pid, nameList, follow)
        print('--BARSM_TO_AACM_PROCESSES message received')

    # wait for barsm to aacm messgae and reply back
    if success:


        print('-Waiting for and responding to BARSM TO ACCM message 1')
        appName = log.logfollower()
        names = []
        expectedName = ''

        while not names and expectedName == '':
            names = appName.read('BARSM')
            try:
                expectedName = list(filter(lambda t: "DEBUG: Message sent with APP name:" in t['message'], names))[0]['message']
            except:
                expectedName = ''
                names = []

        expectedName = expectedName[-4:]

        expectedERR = 11
        barsm_utils.receiveBarsmToAacm(TCPconn, expectedERR, expectedName)

        print('-Waiting for and responding to BARSM TO ACCM message 2')
        names = []
        expectedName = ''

        while not names and expectedName == '':
            names = appName.read('BARSM')
            try:
                expectedName = list(filter(lambda t: "DEBUG: Message sent with APP name:" in t['message'], names))[0]['message']
            except:
                expectedName = ''
                names = []

        expectedName = expectedName[-4:]

        expectedERR = 11
        barsm_utils.receiveBarsmToAacm(TCPconn, expectedERR, expectedName)

        print('-Waiting for and responding to BARSM TO ACCM message 3')
        names = []
        expectedName = ''

        while not names and expectedName == '':
            names = appName.read('BARSM')
            try:
                expectedName = list(filter(lambda t: "DEBUG: Message sent with APP name:" in t['message'], names))[0]['message']
            except:
                expectedName = ''
                names = []

        expectedName = expectedName[-4:]

        expectedERR = 11
        barsm_utils.receiveBarsmToAacm(TCPconn, expectedERR, expectedName)

        print('-Waiting for and responding to BARSM TO ACCM message 4')
        names = []
        expectedName = ''

        while not names and expectedName == '':
            names = appName.read('BARSM')
            try:
                expectedName = list(filter(lambda t: "DEBUG: Message sent with APP name:" in t['message'], names))[0]['message']
            except:
                expectedName = ''
                names = []

        expectedName = expectedName[-4:]

        expectedERR = 11
        barsm_utils.receiveBarsmToAacm(TCPconn, expectedERR, expectedName)

        print('-Waiting for and responding to BARSM TO ACCM message 5')
        names = []
        expectedName = ''

        while not names and expectedName == '':
            names = appName.read('BARSM')
            try:
                expectedName = list(filter(lambda t: "DEBUG: Message sent with APP name:" in t['message'], names))[0]['message']
            except:
                expectedName = ''
                names = []

        expectedName = expectedName[-4:]

        expectedERR = 11
        #barsm_utils.get_Message(TCPconn, expectedERR)
        barsm_utils.receiveBarsmToAacm(TCPconn, expectedERR, expectedName)


     # make sure all 5 stopped processes have logged errors to go with
     # get the time of the launch finish
    logs = follow2.read('BARSM')
    if list(filter(lambda t: "ERROR: Process for /opt/rc360/system/thirty_aacm" in t['message'], logs)) == []:
        print("SYSLOG error missing thirty_aacm")
        success = False
    if list(filter(lambda t: "ERROR: Process for /opt/rc360/modules/GE/thirty_gemod" in t['message'], logs)) == [] :
        print("SYSLOG error missing thirty_gemod")
        success = False
    if list(filter(lambda t: "ERROR: Process for /opt/rc360/modules/TPA/thirty_tpamod" in t['message'], logs)) == [] :
        print("SYSLOG error missing thirty_tpamod")
        success = False
    if list(filter(lambda t: "ERROR: Process for /opt/rc360/apps/GE/thirty_geapp" in t['message'], logs)) == [] :
        print("SYSLOG error missing thirty_geapp")
        success = False
    if list(filter(lambda t: "ERROR: Process for /opt/rc360/apps/TPA/thirty_tpaapp" in t['message'], logs)) == [] :
        print("SYSLOG error missing thirty_tpaapp")
        success = False

    #make sure all 5 apps that failed were restarted

    # make sure all apps get started back up
    child_info = barsm_utils.get_barsm_child_pids()
    if list(filter(lambda t: "NOTICE: Restarting thirty_aacm..." in t['message'], logs)) == []:
        print("SYSLOG error missing restart of thirty_aacm")
        success = False
    if list(filter(lambda t: "NOTICE: Restarting thirty_gemod..." in t['message'], logs)) == [] :
        print("SYSLOG error missing restart of thirty_gemod")
        success = False
    if list(filter(lambda t: "NOTICE: Restarting thirty_tpamod..." in t['message'], logs)) == [] :
        print("SYSLOG error missing restart of thirty_tpamod")
        success = False
    if list(filter(lambda t: "NOTICE: Restarting thirty_geapp..." in t['message'], logs)) == [] :
        print("SYSLOG error missing restart of thirty_geapp")
        success = False
    if list(filter(lambda t: "NOTICE: Restarting thirty_tpaapp..." in t['message'], logs)) == [] :
        print("SYSLOG error missing restart of thirty_tpaapp")
        success = False

    zombies = sum(1 for c in child_info if "Z" == c.get('state'))

    # kill off all started processes
    barsm_utils.populateChildren()
    barsm_utils.kill_procs()

    if not zombies and success:
        print('Test Passes')
        return True
    else:
        print('Test Failed')
        return False
예제 #8
0
파일: aacm_fail.py 프로젝트: ktj100/linux
def run():
    # navigate to the end of the SYSLOG
    follow = log.logfollower()
    logError = log.logfollower()

    result = False
    success = True

    # clear out all app directories
    barsm_utils.remove()

    # compile needed applications and place in required directories
    random.seed()
    r = random.randint(1, 2)

    print(r)
    if 1 == r:
        subprocess.call("gcc " + barsm_utils.apps_loc + "/zero_sec.c -o /opt/rc360/system/zero_sec_aacm", shell=True)
    else:
        subprocess.call("cp " + barsm_utils.apps_loc + "/non_exec.c /opt/rc360/system/", shell=True)

    print("-Starting BARSM")
    barsm_utils.start_barsm()
    logs = follow.read("BARSM")
    errors = sum(1 for d in logs if "ERROR" in d.get("message"))
    if 0 < errors:
        print("ERROR: SYSLOG errors while starting BARSM!")
        for d in logs:
            if "ERROR" in d.get("message"):
                print(d.get("message"))
        success = False
    else:
        print("--BARSM started")
        success = True

    # wait for AACM to start
    if success:
        print("-Waiting for AACM")
        barsm_pid = (proc.findproc("valgrind.bin"))[0]["pid"]
        aacmStarted = False
        # time.sleep(1)
        while False == aacmStarted and success:

            # the c is moving faster than the python and is getting to the restarting before we can
            # break out of this loop, so the check for errors needs to come before the check if done
            logs = follow.read("BARSM")
            errors = sum(1 for d in logs if "ERROR" in d.get("message"))
            if 0 < errors:
                print("ERROR: SYSLOG errors while waiting for AACM startup!")
                for d in logs:
                    if "ERROR" in d.get("message"):
                        print(d.get("message"))
                success = False

            # check if AACM has started
            all_child = proc.findchild(barsm_pid)
            if 1 == len(all_child):
                aacmStarted = True
            # check for launch errors

        if success:
            print("--AACM start attempt finished")

    if success:
        # takes about 20 seconds to restart 5 times
        time.sleep(25)

        # check logs to see if five errors were logged for each launch failure
        logs = logError.read("BARSM")
        # print('logs : {}'.format(logs))
        launch_errors = sum(
            1 for d in logs if "File launch failed!" in d.get("message") and "/opt/rc360/" in d.get("message")
        )

        if 5 == launch_errors:
            result = True

    # kill off all started processes
    barsm_utils.kill_procs()

    print("{}".format("PASSED" if result else "FAILED"))
    return result
예제 #9
0
파일: barsm_utils.py 프로젝트: ktj100/linux
def populateChildren():
    global barsm_pid, barsm_spawned_pids

    all_child = proc.findchild(barsm_pid)
    child_pids = set([int(p['pid']) for p in all_child])
    barsm_spawned_pids = list(set(barsm_spawned_pids).union(child_pids))
예제 #10
0
파일: barsm_utils.py 프로젝트: ktj100/linux
def get_barsm_child_pids():
    global barsm_pid
    info = proc.findchild(barsm_pid)
    return info