def check_heartbeat(): global sent_email heartbeats = [] with open("heartbeats.txt", "r") as infile: lines = infile.readlines() for line in lines: timestamp = line.strip().split(".")[0] date_str, time_str = timestamp.split("T") year_str, mon_str, day_str = date_str.split("-") year, mon, day = int(year_str), int(mon_str), int(day_str) hour_str, min_str, sec_str = time_str.split(":") hour, min, sec = int(hour_str), int(min_str), int(sec_str) heartbeat = datetime.datetime(year, mon, day, hour, min, sec) heartbeats.append(heartbeat) print "heartbeats len:", len(heartbeats) for index in range(1, len(heartbeats)): delta = (heartbeats[index] - heartbeats[index - 1]).seconds if delta < 250: print "heartbeat_interval:", str(delta / 60) + " min, ", str(delta % 60) + " sec" if delta < 60: if not sent_email: print "Sending email..." DLCLibs.send_mail( subject="heartbeat less than 60 sec...", body="heartbeat lessn than 60 sec... at {0}".format(cur_time), ) sent_email = True
with open(os.devnull, "w") as nullfile: global sent_email while True: print "\n" * 3 cur_time = time.strftime("%Y:%m:%d %H:%M:%S") print "current time: {0}".format(cur_time) ret = subprocess.call(["grep", search_str, "dlc_1.log"], stdout=nullfile) # if there is search string, ret = 0 if not ret: print "Found search str:{0}".format(search_str) # if email was not sent already, send now... if not sent_email: print "Sending email..." DLCLibs.send_mail(subject="wifi reset occured...", body="wifi reset happened at {0}".format(cur_time)) sent_email = True else: print "No trouble found" """ timestamp = datetime.datetime.now().time() if heartbeat_start < timestamp and heartbeat_end > timestamp: print 'Send heartbeat...' DLCLibs.send_mail(subject='wifi heartbeat', body = 'heartbeat') """ time.sleep(1) with open("heartbeats.txt", "w") as heartbeatfile: subprocess.call(["grep", "HeartBeat response received", "dlc_1.log"], stdout=heartbeatfile)
Initial Release: v0.1 by Inzoo Lee([email protected]) This module has DLC Test Cases which will be tested in DLCXXX_UnitTest.py file. It leverages libs from DLCLibs.py file to interact with DLCXXX for test execution. For monitoring log in real time, 'tail -f logs/DLC200_TestCases.log' convention for function name: 'uut'_'component'_'action'_'target' ex: dlc_3g_check_status, dlc_firmware_upgrade_dla, dlc_dlaopmode_check_normal, dla_webui_start_discovery Note: these are functions, and don't determine pass or fail. """ import DLCLibs import DLC200_CFGs import re, sys, time, datetime logger = DLCLibs.createLogger('TestFunctions ') def dlc_upgrade_dlc_firmware(dlc=None, dlc_firmware=None): """ func to upgrade dlc_firmware. dlc: dlc instance from DLCLibs.DLC() dlc_firmware: dlc_firmware name including path. """ if not dlc or not dlc_firmware: logger.error('Trying to upgrade DLC firmware but no dlc or dlc_firmware given') raise DLCLibs.ExceptionDLC('Trying to upgrade DLC firmware but no dlc or dlc_firmware given') try: logger.info('Upgrading DLC firmware: {0}'.format(dlc_firmware)) if dlc.upgrade_dlc(dlc_firmware): logger.info('Upgrading DLC firmware: {0} successful'.format(dlc_firmware))