def job_create(repo, branch, array_id): global jobs testlib.p("Running test for %s %s %s" % (repo, branch, array_id)) if any([x for x in config['ARRAYS'] if x['ID'] == array_id]): # Add a check to make sure we aren't already _running_ # a job for this array for k, v in jobs.items(): if v['ID'] == array_id: # Update status to make sure _update_state(k) if v['STATUS'] == 'RUNNING': return "", 412, "Job already running on array" # Run the job # Build the arguments for the script uri = "" password = "" plug = "" for a in config['ARRAYS']: if a['ID'] == array_id: uri = a['URI'] password = a['PASSWORD'] plug = a['PLUGIN'] break # When we add rpm builds we will need client to pass # which 'type' too incoming = ('git', repo, branch, uri, password) job_id = _rs(32) p = Process(target=_run_command, args=(job_id, incoming)) p.name = "|".join(incoming) p.start() jobs[job_id] = dict(STATUS='RUNNING', PROCESS=p, ID=array_id, PLUGIN=plug) return job_id, 201, "" else: return "", 400, "Invalid array specified!"
def job_create(repo, branch, array_id): global jobs testlib.p("Running test for %s %s %s" % (repo, branch, array_id)) if any([x for x in config["ARRAYS"] if x["ID"] == array_id]): # Add a check to make sure we aren't already _running_ # a job for this array for k, v in jobs.items(): if v["ID"] == array_id: # Update status to make sure _update_state(k) if v["STATUS"] == "RUNNING": return "", 412, "Job already running on array" # Run the job # Build the arguments for the script uri = "" password = "" plug = "" for a in config["ARRAYS"]: if a["ID"] == array_id: uri = a["URI"] password = a["PASSWORD"] plug = a["PLUGIN"] break # When we add rpm builds we will need client to pass # which 'type' too incoming = ("git", repo, branch, uri, password) job_id = _rs(32) p = Process(target=_run_command, args=(job_id, incoming)) p.name = "|".join(incoming) p.start() jobs[job_id] = dict(STATUS="RUNNING", PROCESS=p, ID=array_id, PLUGIN=plug) return job_id, 201, "" else: return "", 400, "Invalid array specified!"
if __name__ == "__main__": # Load the available test arrays from config file _load_config() # Connect to server while True: server = config["SERVER_IP"] port = config["SERVER_PORT"] proxy_is_ip = config["PROXY_IS_IP"] use_proxy = config["USE_PROXY"] proxy_host = config["PROXY_HOST"] proxy_port = config["PROXY_PORT"] testlib.p("Attempting connection to %s:%d" % (server, port)) node = testlib.TestNode( server, port, use_proxy=use_proxy, proxy_is_ip=proxy_is_ip, proxy_host=proxy_host, proxy_port=proxy_port ) if node.connect(): testlib.p("Connected!") # noinspection PyBroadException try: while True: request = node.wait_for_request() process_request(node, request) except KeyboardInterrupt: node.disconnect() sys.exit(0) except Exception:
n.return_response(testlib.Response(data, ec, error_msg)) else: # Bounce this back to the requester n.return_response(testlib.Response("", 404, "Command not found!")) if __name__ == "__main__": # Load the available test arrays from config file _load_config() # Connect to server while True: server = config['SERVER_IP'] port = config['SERVER_PORT'] testlib.p("Attempting connection to %s:%d" % (server, port)) node = testlib.TestNode(server, port) if node.connect(): # noinspection PyBroadException testlib.p("Connected!") try: while True: request = node.wait_for_request() process_request(node, request) except KeyboardInterrupt: node.disconnect() sys.exit(0) except Exception: testlib.p(str(traceback.format_exc())) pass