def run_schedule(obj, cron, ssid, scan): global count count += 1 print("Main reached", count) print("NOW: %s" % time.ctime(time.time())) print("TASK: ", str(obj["name"])) if not scan: print("SSID: ", str(ssid["name"])) print("Result URL: ") rest_api.main(obj["TASK"])
def run_pscheduler(main_obj, dest, bssid): if main_obj["throughput"] and "dest" not in main_obj["TASK"]["test"][ "spec"].keys(): main_obj["TASK"]["test"]["spec"]["dest"] = dest main_obj["TASK"]["archives"] = transform(main_obj, bssid) pSched_task = main_obj["TASK"] try: rest_api.main(pSched_task) except: print(time.ctime(time.time())) print("ERROR in running test with pscheduler", main_obj["name"], bssid["ssid"]) print(traceback.print_exc())
def loop_forever(): global child_exited global DEBUG pid_child = 0 connect_ttl = 20 task_ttl = 0 computed_TTL = 0 interface = {} scanned_table = [] bssid_list = {} next_task = schedule.get_queue[0] schedule.pop(next_task) main_obj, cron, ssid, scan = retrieve(next_task) if DEBUG: print("Next Task: ") print_task = time.ctime(next_task.time) + \ " main_obj: " + main_obj["name"] print(print_task) old_sig = signal.signal(signal.SIGCHLD, sigh) while True: if scan: if next_task.time > time.time(): sleep_time = next_task.time - time.time() if DEBUG: print("Waiting: ", sleep_time) time.sleep(sleep_time) ssid_list = main_obj["profiles"] scanned_table, scan_duration = ssid_scan.get_all_bssids( main_obj["interface"]) checked_bssid, qualified_per_ssid = scan_qualify( scanned_table, ssid_list, main_obj["unknown_SSID_warning"]) bssid_list["meta"] = main_obj["meta"] bssid_list["operation"] = "scan" bssid_list["duration"] = scan_duration bssid_list["SSID_bad_coverage"] = [] for j in ssid_list: if qualified_per_ssid[j["SSID"]] < j["min_qualifying"]: obj = {} obj["SSID"] = j["SSID"] obj["min_qualifying_BSSID"] = j["min_qualifying"] obj["min_signal"] = j["min_signal"] obj["qualified_BSSIDs"] = qualified_per_ssid[j["SSID"]] bssid_list["SSID_bad_coverage"].append(obj) bssid_list[main_obj["name"]] = checked_bssid interface[main_obj["name"]] = main_obj["interface"] message = json.dumps(bssid_list) rabbitmqQueue(message, "pSSID", "pSSID") schedule.reschedule(main_obj, cron, ssid, scan=True) next_task = schedule.get_queue[0] schedule.pop(next_task) main_obj, cron, ssid, scan = retrieve(next_task) if DEBUG: print("Next Task: ") print_task = time.ctime(next_task.time) + \ " main_obj: " + main_obj["name"] print(print_task) child_exited = False continue if pid_child != 0: waittime = time.time() + computed_TTL while not child_exited and time.time() < waittime: continue elif next_task.time > time.time(): sleep_time = next_task.time - time.time() if DEBUG: print("Waiting: ", sleep_time) time.sleep(sleep_time) if (pid_child != 0): if not child_exited: if DEBUG: print("***kill child***", pid_child) os.kill(pid_child, signal.SIGKILL) try: os.wait() except: if args.debug: print("CHILD DEAD") else: child_exited = False pid_child = 0 schedule.reschedule(main_obj, cron, ssid) if DEBUG: print("NEW QUEUE:") schedule.print_queue() next_task = schedule.get_queue[0] schedule.pop(next_task) main_obj, cron, ssid, scan = retrieve(next_task) if schedule.empty(): print("ERROR: this should never reach") continue task_ttl = main_obj["ttl"] + connect_ttl num_bssids = BSSID_qualify(scanned_table, ssid) #Compute task time to live if num_bssids: computed_TTL = num_bssids * task_ttl if DEBUG: print("TTL", computed_TTL, num_bssids) else: schedule.reschedule(main_obj, cron, ssid) if DEBUG: print("NEW QUEUE:") schedule.print_queue() next_task = schedule.get_queue[0] schedule.pop(next_task) main_obj, cron, ssid, scan = retrieve(next_task) continue pid_child = os.fork() if pid_child == 0: signal.signal(signal.SIGCHLD, old_sig) if DEBUG: print("CHILD") for item in bssid_list[main_obj["BSSIDs"]]: bssid = item["BSSID"] if single_BSSID_qualify(bssid, ssid): if DEBUG: print("Connect") # Connect to bssid connection_info = connect_bssid.prepare_connection( bssid['ssid'], bssid['address'], interface[main_obj["BSSIDs"]], ssid["AuthMethod"]) connection_info["bssid_info"] = bssid connection_info["meta"] = main_obj["meta"] connection_string = json.dumps(connection_info) rabbitmqQueue(connection_string, "pSSID", "pSSID") #if connection fails, it won't run any test if not connection_info["connected"]: if DEBUG: print("Connection Failed") continue if "dest" not in main_obj["TASK"]["test"]["spec"].keys(): main_obj["TASK"]["test"]["spec"][ "dest"] = connection_info["new_ip"] main_obj["TASK"]["archives"] = transform(main_obj, bssid) pSched_task = main_obj["TASK"] rest_api.main(pSched_task) exit(0)
#!/usr/bin/env python3 # Copyright 2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # ------------------------------------------------------------------------------ from rest_api import main if __name__ == '__main__': main()