def data_download_test_xml(self, xml_file_name, uuids, client_options='', server_options='', check_sha1=True): server = None # delete the bams so we can download them for uuid in uuids: if os.path.isfile(self.client_bam(uuid)): os.remove(self.client_bam(uuid)) if TestConfig.MOCKHUB: # prepare server server = GeneTorrentInstance( '-s server%sroot -q server%sworkdir -c %s ' \ '--security-api %s %s' \ % ( os.path.sep, os.path.sep, self.cred_filename, TestConfig.SECURITY_API, server_options, ), instance_type=InstanceType.GT_SERVER) # add new download GTO to server work queue # add gt_download_mode flag to server gto for uuid in uuids: gtodict = read_gto(self.client_gto(uuid)) gtodict['gt_download_mode'] = 'true' expiry = time.time() + (1 * 3600 * 24) # expire in 1 day set_key(gtodict, 'expires on', int(expiry)) emit_gto(gtodict, self.server_gto(uuid), True) else: self.upload_sleep(3) # prepare download client client = GeneTorrentInstance('-d %s ' \ '-p client2 -c %s %s' \ % ( xml_file_name, self.cred_filename, client_options, ), instance_type=InstanceType.GT_DOWNLOAD) # wait for download client to exit client_sout, client_serr = client.communicate() if server: self.terminate_server(server) # check download client return code self.assertEqual(client.returncode, 0) self.assertTrue('Downloaded' in client_serr) self.assertTrue('state changed to: finished' in client_sout) # check file hashes on both sides of transfer for uuid in uuids: if check_sha1 and TestConfig.MOCKHUB: self.assertTrue(self.compare_hashes( self.client_bam2(uuid), self.server_bam(uuid))) return client.returncode
def test_server_peer_verify(self): '''Test server client curl SSL peer verification behavior.''' uuid = uuid4() self.generate_bam_data(uuid, 1024) self.create_gto_only(uuid) # now, test server without --ssl-no-verify-ca server = GeneTorrentInstance( \ '-s %s -q %s -c %s --security-api ' \ '%s ' \ '--foreground -l stdout:full -R .' \ % ('server' + os.path.sep + 'root', 'server' + os.path.sep + 'workdir', self.cred_filename, TestConfig.SECURITY_API ), ssl_no_verify_ca=False, instance_type=InstanceType.GT_SERVER, add_defaults=False) # copy gto to server client_gto = self.client_gto(uuid) server_gto = self.server_gto(uuid) gtodict = read_gto(client_gto) gtodict['gto_download_mode'] = 'true' emit_gto(gtodict, server_gto, True) time.sleep(10) # kill server server.kill() # check for SSL signing error server.stdout_buffer.seek(0) server_sout = server.stdout_buffer.read() print server_sout self.assertTrue('while attempting a CSR signing transaction' in \ server_sout)
def data_download_test_uuid(self, uuid, client_options='', server_options='', check_sha1=True, assert_rc=0, assert_serr='', server_ct=1): # delete the bam so we can download it if os.path.isfile(self.client_bam(uuid)): os.remove(self.client_bam(uuid)) servers = [] if TestConfig.MOCKHUB: # prepare server(s) for i in range(0, server_ct): server = GeneTorrentInstance( '-s server%sroot -q server%sworkdir -c %s ' \ '--security-api %s %s' \ % ( os.path.sep, os.path.sep, self.cred_filename, TestConfig.SECURITY_API, server_options, ), instance_type=InstanceType.GT_SERVER, client_num=i) servers.append(server) # add new download GTO to server work queue # add gt_download_mode flag to server gto gtodict = read_gto(self.client_gto(uuid)) gtodict['gt_download_mode'] = 'true' expiry = time.time() + (1 * 3600 * 24) # expire in 1 day set_key(gtodict, 'expires on', int(expiry)) emit_gto(gtodict, self.server_gto(uuid), True) else: self.upload_sleep(3) # prepare download client client = GeneTorrentInstance('-d %s/cghub/data/analysis/download/%s ' \ '-p client2 %s %s' \ % ( TestConfig.HUB_SERVER, str(uuid), '-c ' + self.cred_filename if not '-c ' in client_options else '', client_options, ), instance_type=InstanceType.GT_DOWNLOAD) # wait for download client to exit client_sout, client_serr = client.communicate() if servers: for server in servers: self.terminate_server(server) # check download client return code self.assertEqual(client.returncode, assert_rc) # caller-passed client_serr contains assert if assert_serr: self.assertTrue(assert_serr in client_serr) # only continue checking if assert_rc == 0 if assert_rc == 0: # check download client self.assertTrue('Downloaded' in client_serr) self.assertTrue('state changed to: finished' in client_sout) # check file hashes on both sides of transfer if servers and check_sha1: self.assertTrue(self.compare_hashes( self.client_bam2(uuid), self.server_bam(uuid))) return client.returncode
def data_upload_test(self, size, data_generator=DataGenRandom, ssl=True, client_options='', server_options='', check_sha1=True): server = None uuid = uuid4() self.generate_bam_data(uuid, size, data_generator) if TestConfig.MOCKHUB: # prepare server server = GeneTorrentInstance( '-s server%sroot -q server%sworkdir -c %s ' \ '--security-api %s %s' \ % ( os.path.sep, os.path.sep, self.cred_filename, TestConfig.SECURITY_API, server_options ), instance_type=InstanceType.GT_SERVER) else: # submit via cgsubmit cgsubmit_process = Popen(['python', '../cgsubmit', '-s', TestConfig.HUB_SERVER, '-c', TestConfig.CREDENTIAL, '-u', str(uuid)], stdout=PIPE, stderr=PIPE, cwd='client') cgout, cgerr = cgsubmit_process.communicate() if TestConfig.VERBOSE: logger.info('cgsubmit stdout: ' + cgout) logger.info('cgsubmit stderr: ' + cgerr) self.assertEqual(cgsubmit_process.returncode, 0) # prepare upload client client_manifest = os.path.join( 'client', str(uuid), 'manifest-generated.xml', ) # modify manifest for nossl, if necessary if not ssl: manifest_file = open(client_manifest, 'r+') try: manifest_text = manifest_file.read() manifest_text = manifest_text.replace('/analysis/', '/analysis-nossl/') manifest_file.seek(0) manifest_file.truncate() manifest_file.write(manifest_text) finally: manifest_file.close() client = GeneTorrentInstance('-u %s -p client -c %s %s' \ % ( client_manifest, self.cred_filename, client_options, ), instance_type=InstanceType.GT_UPLOAD) # add new upload GTO to server work queue gto_file = False ssl_cert = False while not gto_file or (not ssl_cert and ssl): # check for premature exits of GT programs # subprocess.poll() returns return code, nonzero is True if client.poll(): self.fail('Client exited prematurely') if server and server.poll(): self.fail('Server exited prematurely') try: os.stat(self.client_gto(uuid)) gto_file = True gtodata = read_gto(self.client_gto(uuid)) ssl_cert = True if 'ssl-cert' in gtodata['info'] else False except: time.sleep(1) copy2(self.client_gto(uuid), os.path.join( 'server', 'workdir', )) # wait for upload client to exit client_sout, client_serr = client.communicate() if server: self.terminate_server(server) # check upload client return code self.assertEqual(client.returncode, 0) # check upload client stderr complete message (100.000%) self.assertTrue('100.000% complete' in client_serr) # check file hashes on both sides of transfer if server and check_sha1: self.assertTrue(self.compare_hashes( self.client_bam(uuid), self.server_bam(uuid))) return uuid