def test_dispatcher(): c = command.factory(["BEGIN", True, ['whatever', 'end']]) agentFiles = "" params = "" update = Procedure("UPDATE", ["REVERT", "START_VM", "RELOG", "STOP_VM"]) dispatch = Procedure("DISPATCH", ["REVERT", "START_VM", ("PUSH", None, agentFiles)]) scout = Procedure("SCOUT", [ ("CALL", None, "dispatch"), ("PUSH", None, agentFiles), ]) assert update assert dispatch assert scout
def test_procedure_insert(): c = command.factory(["BEGIN", True, ['whatever', 'end']]) agentFiles = "" params = "" p1 = Procedure("UPDATE", ["REVERT", "START_VM", "RELOG", "STOP_VM"]) p2 = Procedure("DISPATCH", ["REVERT", "START_VM", ("PUSH", None, agentFiles)]) lp1= len(p1) lp2= len(p2) p1.insert(p2) assert p1 assert p2 assert len(p1) == lp1 + lp2
def notest_ProtocolEval(): host = "localhost" mq = MQStar(host) mq.clean() c = "client1" mq.add_client(c) commands = [ "BEGIN", ("EVAL_SERVER", "dir()"), ("EVAL_SERVER", "locals()"), ("EVAL_SERVER", "__import__('os').getcwd()"), ("END", None, None) ] procedure = Procedure("PROC", commands) p = Protocol(mq, c, procedure) while p.send_next_command(): logging.debug("sent command") exit = False while not exit: rec = mq.receive_server(blocking=True, timeout=10) if rec is not None: logging.debug("- SERVER RECEIVED %s %s" % (rec, type(rec))) c, msg = rec answer = p.receive_answer(c, msg) logging.debug("- SERVER RECEIVED ANSWER: ", answer.success) if answer.name == "END" or not answer.success: logging.debug("- SERVER RECEIVE END") #if answer.success: a = """('client1', ('EVAL_SERVER', True, {'self': <Command_EVAL_SERVER.Command_EVAL_SERVER object at 0x10931f810>, 'args': 'locals()'}))""" # p.send_next_command() else: logging.debug("- SERVER RECEIVED empty") exit = True
def test_dispatcher_server(): host = "localhost" vms = ["noav", "zenovm"] host = "localhost" mq = MQStar(host) mq.clean() #istanzia n client e manda delle procedure. vm_manager.vm_conf_file = "../AVMaster/conf/vms.cfg" dispatcher = Dispatcher(mq, vms) test = Procedure("TEST", [("EVAL_SERVER", None, 'vm'), ("SLEEP", None, 10)]) dispatcher.dispatch(test)
def execute(vm, protocol, mon_args): """ client side, returns (bool,*) """ logging.debug(" SET %s" % str(mon_args)) assert vm, "null vm" assert command.context is not None assert isinstance(mon_args, list), "VM expects a list" assert protocol assert protocol.procedure logging.debug("insert report init") command_list = [] command_list.append("REPORT_INIT") for proc_token in mon_args: report_args = [] if isinstance(proc_token, basestring): proc_name = proc_token elif isinstance(proc_token, dict): assert len(proc_token.keys()) == 1 proc_name = proc_token.keys()[0] report_args = proc_token[proc_name] else: return False, "Error parsing" logging.debug("insert report kind: %s args: %s" % (proc_name, report_args)) command_list.append(["REPORT_KIND_INIT", None, (proc_name)]) command_list.append(["CALL", None, (proc_name)]) command_list.append( ["REPORT_KIND_END", None, (proc_name, report_args)]) command_list.append("REPORT_END") proc = Procedure("_REPORT", command_list) protocol.procedure.insert(proc) #logging.debug("procedure: %s" % (protocol.procedure.command_list)) #logging.debug("report items: %s" % (command.context)) return True, "REPORT"