def create_server(cls): if cls._process is None: #check if no other server is running. if so, kill them Tools.kill_process("harness_soap_server") args = ["python3", application.__file__] my_env = os.environ.copy() my_env["PYTHONPATH"] = os.environ.get( "PYTHONPATH", "") + ":" + "/".join( webservice.__path__[0].split('/')[:-1]) cls._process = subprocess.Popen(args, env=my_env) sleep(3) print("Soap server started")
def setUp(self): # Configuring repertories file_sender.sender.DEBUG = False self.tmpdir = mkdtemp(prefix='harnais_') os.environ["TMPDIR"] = self.tmpdir self.difmet_deposit = join(self.tmpdir, "difmet_deposit") os.mkdir(self.difmet_deposit) self.ack_dir = join(self.tmpdir, "ack_dir") os.mkdir(self.ack_dir) #killing ftpserver in case one exists Tools.kill_process("diffmet_test_ftp_server") # start FTP server FTPserver.create_server("/")
def test_complet(self): """ This is a full test. The SOAP server receives 3 requests, 2 mails and 1 ftp The manager is then started to process the three json files created by the previous step When the files are correctly packaed, the sender sends them by FTP to local deposit. Finally, a ack is simulated and ack_receiver processes it. """ SettingsManager.load_settings() # start the SOAP server SoapServer.create_server() # connect to the WSDL client = Client(self.soap_url) factory = client.type_factory('http://dissemination.harness.openwis.org/') # create a dummy request MailDiffusion test_diffusion = factory.MailDiffusion(address="*****@*****.**", headerLine="dummyHeaderLine", subject= "dummySubject", dispatchMode = "TO", attachmentMode="AS_ATTACHMENT") info = factory.DisseminationInfo(priority=5,SLA=6,dataPolicy="dummyDataPolicy", diffusion=test_diffusion) # send the mail requests result1 = client.service.disseminate(requestId="123456", fileURI=self.staging_post, disseminationInfo=info) result2 = client.service.disseminate(requestId="654321", fileURI=self.staging_post, disseminationInfo=info) # create a dummy request FTPDiffusion test_diffusion = factory.FTPDiffusion(host="dummyHost", port="dummyPort", user="******", password="******", passive="False", remotePath="dummyPath", checkFileSize="True", encrypted="False") info = factory.DisseminationInfo(priority=5,SLA=6, dataPolicy="dummyDataPolicy", diffusion=test_diffusion) # send the ftp requests result3 = client.service.disseminate(requestId="111111", fileURI=self.staging_post, disseminationInfo=info) print(result1) print(result2) print(result3) #stop the SOAP SoapServer.stop_server() # create the SFTP server SFTPserver.create_server(self.staging_post) # SettingsManager.update(dict(openwisStagingPath=gettempdir(), # openwisHost="localhost", # openwisSftpUser="******", # openwisSftpPassword="******", # openwisSftpPort = 3373 # ), # testing=True) # Start the manager for 1 loop thr = Thread(target=FileManager.process, kwargs={"max_loops":1}) try: thr.start() thr.join() # STOP sftp server when the FileManager is done # processing SFTPserver.stop_server() print("Manager finished") except KeyboardInterrupt: SFTPserver.stop_server() sleep(10) # create the ftp server Tools.kill_process("diffmet_test_ftp_server") FTPserver.create_server("/") # send the files thr = Thread(target=DifmetSender.process, kwargs={"max_loops":3}) try: thr.start() thr.join() print("DifMet finished") # STOP sftp server when the DifmetSender is done # processing FTPserver.stop_server() except KeyboardInterrupt: FTPserver.stop_server() # get the diff_external_id in the database required for to simulate an ack with Database.get_app().app_context(): records = Diffusion.query.filter(Diffusion.fullrequestId.contains("123456")).all() print(records[0].fullrequestId) ext_id1 = records[0].diff_externalid ext_id2 = records[1].diff_externalid #simulate an ack difmet file with open(join(self.ack_dir, "ack_file.acqdifmet.xml"),"w") as file_: file_.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" "<acquittements>\n" "<acquittement>\n" "<date>2018-10-01T12:31:46Z</date>\n" "<type>RECEIVED</type>\n" "<status>OK</status>\n" "<productid>fr-met,SNFR30LFPW011000LFPW,00000-wiss,20181001100000</productid>\n" "<product_internalid>66180_20181001123146</product_internalid>\n" "<send2>0</send2>\n" "<diffusion_externalid>{ext_id1}</diffusion_externalid>\n" "<diffusion_internalid>66181_20181001123146</diffusion_internalid>\n" "<channel>EMAIL</channel>\n" "<media>EMAIL</media>\n" "<use_standby>0</use_standby>\n" "<email_adress>[email protected]</email_adress>\n" "</acquittement>\n" "<acquittement>\n" "<date>2018-10-01T12:31:46Z</date>\n" "<type>SEND</type>\n" "<status>OK</status>\n" "<productid>fr-met,SNFR30LFPW011000LFPW,00001-wiss,20181001100000</productid>\n" "<product_internalid>66180_20181001123146</product_internalid>\n" "<send2>0</send2>\n" "<diffusion_externalid>{ext_id2}</diffusion_externalid>\n" "<diffusion_internalid>66181_20181001123146</diffusion_internalid>\n" "<channel>EMAIL</channel>\n" "<media>EMAIL</media>\n" "<use_standby>0</use_standby>\n" "<try_number>1</try_number>\n" "<email_adress>[email protected]</email_adress>\n" "<comment>nom de fichier en attachement au courriel: machin</comment>\n" "</acquittement>\n" "<acquittement>\n" "<date>2018-10-01T12:31:46Z</date>\n" "<type>SEND</type>\n" "<status>OK</status>\n" "<productid>fr-met,SNFR30LFPW011000LFPW,00000-wiss,20181001100000</productid>\n" "<product_internalid>66180_20181001123146</product_internalid>\n" "<send2>0</send2>\n" "<diffusion_externalid>{ext_id1}</diffusion_externalid>\n" "<diffusion_internalid>66181_20181001123146</diffusion_internalid>\n" "<channel>EMAIL</channel>\n" "<media>EMAIL</media>\n" "<use_standby>0</use_standby>\n" "<try_number>1</try_number>\n" "<email_adress>[email protected]</email_adress>\n" "<comment>nom de fichier en attachement au courriel: machin</comment>\n" "</acquittement>\n" "<acquittementnumber>3</acquittementnumber>\n" "</acquittements>".format(ext_id1=ext_id1, ext_id2=ext_id2)) # start the ack_receiver to process the ack file generated thr = Thread(target=AckReceiver.process, kwargs={"max_loops":2}) thr.start() thr.join() print("Ack_receiver finished") # check acquittement SoapServer.create_server() client = Client(self.soap_url) factory = client.type_factory('http://dissemination.harness.openwis.org/') result = client.service.monitorDissemination(requestId="123456") print(result) result = client.service.monitorDissemination(requestId="654321") print(result) SoapServer.stop_server() error_log = join(self.tmpdir, "harnais/errors.log") # if no errors, test is successful. with open(error_log, "r") as file_: self.assertEqual(file_.read(),"")
proc.__qualname__) # sleep to avoid concurrent access to database at startup sleep(1) # we wait until an exception arises wait(process_status, return_when=FIRST_EXCEPTION) if __name__ == '__main__': # prevent launching two harness_service_launcher res = Tools.get_pid("harness_service_launcher") if len(res) > 1: raise RuntimeError("harness_service_launcher already running.") # Set the process name to harness_service_launcher setproctitle("harness_service_launcher") logger = get_logger() # kill pid of already existing process for process in [ "harness_difmet_sender", "harness_file_manager", "harness_ack_receiver" ]: pid_killed = Tools.kill_process(process) for pid in pid_killed: logger.info("Killed process %s with pid %i", process, pid) # launch the harness launch(launch_logger=logger, debug=DEBUG)