示例#1
0
    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
示例#2
0
    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