def test_report_meta(): yaml = """ P1: - SLEEP: 1 P2: - SLEEP P3: - SLEEP: 2 P4: - SLEEP TEST_REPORT: - VM: [noav,zenoav] - SET_SERVER: mail_recipients: [[email protected]] - REPORT: - P1: ["AVtest", "MyCase"] - P2: ["AVtest", "MyOtherCase", INVERSE ] - P3 - P4 """ procedures = Procedure.load_from_yaml(yaml) vms = ["noav", "zenovm"] # vms = ["noav"] redis_host = "localhost" mq = MQStar(redis_host) mq.clean() vm_manager.vm_conf_file = "../AVMaster/conf/vms.cfg" dispatcher = Dispatcher(mq, vms) logging.info("STARTING TEST REPORT") dispatcher.dispatch(procedures["TEST_REPORT"]) logging.info("STOPPING TEST REPORT") r = report.Report() # report.finish() assert r assert len(r.c_received) == len(vms) assert len(r.c_sent) == len(vms) assert len(r.current_procedure) == len(vms) assert len(r.c_received) == len(vms), len(r.c_received) for vm in vms: assert vm in r.c_received assert len(r.c_received[vm]) >= 18
def test_report_meta(): yaml = """ P1: - SLEEP: 1 P2: - SLEEP P3: - SLEEP: 2 P4: - SLEEP TEST_REPORT: - VM: [noav,zenoav] - SET_SERVER: mail_recipients: [[email protected]] - REPORT: - P1: ["AVtest", "MyCase"] - P2: ["AVtest", "MyOtherCase", INVERSE ] - P3 - P4 """ procedures = Procedure.load_from_yaml(yaml) vms = ["noav", "zenovm"] #vms = ["noav"] redis_host = "localhost" mq = MQStar(redis_host) mq.clean() vm_manager.vm_conf_file = "../AVMaster/conf/vms.cfg" dispatcher = Dispatcher(mq, vms) logging.info("STARTING TEST REPORT") dispatcher.dispatch(procedures["TEST_REPORT"]) logging.info("STOPPING TEST REPORT") r = report.Report() #report.finish() assert r assert len(r.c_received) == len(vms) assert len(r.c_sent) == len(vms) assert len(r.current_procedure) == len(vms) assert len(r.c_received) == len(vms), len(r.c_received) for vm in vms: assert vm in r.c_received assert len(r.c_received[vm]) >= 18
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 test_avagent_pull(): host = "localhost" vms = ["testvm_%d" % i for i in range(1)] #command_client={ 'COMMAND_CLIENT': [{ 'SET': [ 'windows' 'whatever']}]} procedure = """ TEST: - START_AGENT - SET: - [backend, 192.168.100.201] - [frontend, 172.20.100.204] - [redis, 10.0.20.1] - BUILD: [ pull, windows, silent] - STOP_AGENT """ test = Procedure.load_from_yaml(procedure) host = "localhost" mq = MQStar(host) mq.clean() logging.debug("MQ session: %s" % mq.session) #istanzia n client e manda delle procedure. vm_manager.vm_conf_file = "../AVMaster/conf/vms.cfg" report = Report() # dispatcher, inoltra e riceve i comandi della procedura test sulle vm dispatcher = Dispatcher(mq, vms, report) thread = threading.Thread(target=dispatcher.dispatch, args=(test["TEST"], )) thread.start() #p = Process(target=dispatcher.dispatch, args=(test["TEST"],)) #p.start() # i client vengono eseguiti asincronicamente e comunicano tramite redis al server pool = Pool(len(vms)) r = pool.map_async(av_agent.start_agent, ((v, host, mq.session) for v in vms)) r.get( ) #notare che i results dei client non ci interessano, viaggia tutto su channel/command. # chiusura del server #p.join() thread.join() logging.debug(dispatcher.report) logging.debug("sent: %s" % dispatcher.report.c_sent) logging.debug("received: %s" % Report.c_received)
def test_vm_commands(): yaml = """ TEST1: - START_VM TEST2: - EXECUTE_VM: c:\\users\\avtest\\desktop\\pubsub\\started.bat - PUSH: - [/tmp/gggg] - c:\\users\\avtest\\desktop - SCREENSHOT: /tmp/maggic_path.png TEST3: - PUSH: - [gggg, jojojo] - /tmp - c:\\users\\avtest\\desktop - PUSH: - [AVAgent/av_agent.py, AVAgent/build.py, AVAgent/package.py, AVAgent/rcs_client.py, AVCommon/commands/START_AGENT.py, AVCommon/commands/STOP_AGENT.py, AVCommon/commands/BUILD.py, AVCommon/commands/GET.py, AVCommon/commands/SET.py] - /home/olli/AVTest - c:\\AVTest - PULL: - [gggg, jojojo] - c:\\users\\avtest\\desktop - /tmp/cpl TEST4: - START_VM - SCREENSHOT: /tmp/magic_img_path.png - STOP_VM TEST5: - PUSH: - [AVCommon/commands/client/*.py] - /home/olli/AVTest - C:\\AVTest - PUSH: - [AVAgent/*.py] - /home/olli/AVTest - C:\\AVTest UPLOAD_AGENT: - PUSH: - [AVAgent/av_agent.py, AVAgent/build.py, AVAgent/package.py, AVAgent/rcs_client.py, AVCommon/commands/*.py] - /home/olli/AVTest - c:\\AVTest UPDATE: - REVERT - START_VM - SLEEP: 180 - CALL: UPLOAD_AGENT - INTERNET: True - SLEEP: 120 - INTERNET: False - STOP_VM - START_VM - SLEEP: 180 - STOP_VM - REFRESH_SNAPSHOT ZLEEP: - SLEEP: 120 T_IS: - CHECK_INFECTION - SLEEP: - 10 - 20 - CHECK_SHUTDOWN - SLEEP: 5 TEST_INTERNET: - INTERNET: True - SLEEP: 15 - INTERNET: False TEST_DIR: - PUSH: - [gigi/gggg] - /tmp - C:/Users/avtest/Desktop/gigi - SLEEP: 10 - DELETE_DIR: C:/Users/avtest/Desktop/gigi TEST_DIR_KO: - DELETE_DIR: C:/Users/avtest/Desktop/gigiol TEST_STOP1: - STOP_VM: 60 TEST_STOP: - STOP_VM """ procedures = Procedure.load_from_yaml(yaml) #vms = ["noav", "zenovm"] vms = ["zenoav"] redis_host = "localhost" mq = MQStar(redis_host) mq.clean() vm_manager.vm_conf_file = "../AVMaster/conf/vms.cfg" dispatcher = Dispatcher(mq, vms) ''' logging.info("STARTING TEST 1") dispatcher.dispatch(procedures["TEST1"]) import time time.sleep(200) logging.info("STARTING TEST 2") dispatcher.dispatch(procedures["TEST2"]) time.sleep(30) dispatcher.dispatch(procedures["TEST3"]) time.sleep(30) logging.info("STARTING TEST UPDATE PROCEDURE") dispatcher.dispatch(procedures["UPDATE"]) ''' logging.info("STARTING TEST 5") dispatcher.dispatch(procedures["TEST_STOP"])