コード例 #1
0
ファイル: vhd_tests.py プロジェクト: 2xyo/transfervm
def generate_vhd(vdi_mb, pattern, vhd_name="tmp.vhd"):
    REFERENCE_FILE = "reference.tmp"
    logging.debug("Creating VHD...")
    vhd.create(vhd_name, vdi_mb)
    logging.debug("Filling VHD...")
    vhd.fill(vhd_name, REFERENCE_FILE, vdi_mb, pattern)
    logging.debug("Generated %s" % vhd_name)
    return vhd_name
コード例 #2
0
ファイル: vhd_tests.py プロジェクト: xueqingz/transfervm
def generate_vhd(vdi_mb, pattern, vhd_name="tmp.vhd"):
    REFERENCE_FILE = "reference.tmp"
    logging.debug("Creating VHD...")
    vhd.create(vhd_name, vdi_mb)
    logging.debug("Filling VHD...")
    vhd.fill(vhd_name, REFERENCE_FILE, vdi_mb, pattern)
    logging.debug("Generated %s" % vhd_name)
    return vhd_name
コード例 #3
0
ファイル: bits_test.py プロジェクト: 2xyo/transfervm
    def _testFragment(self, pattern, frag_size):
        TMP_RAW_RESPONSE_FILE = "response.tmp"
        TMP_VHD_RESPONSE_FILE = "response.vhd"
        REFERENCE_FILE = "reference.tmp"
        VHD_FILE = "tmp.vhd"
        VDI_MB = 16
        frag_variable = False

        if not frag_size:
            frag_variable = True
            frag_size = random.randint(1, 100*K)

        vdi_mb = VDI_MB
        vhd.create(VHD_FILE, vdi_mb)
        vhd.fill(VHD_FILE, REFERENCE_FILE, vdi_mb, pattern)
        f = open(VHD_FILE, 'r')
        data = f.read()
        f.close()

        record, resp = do_test(self, packet_type='CREATE-SESSION',
                      headers={'BITS-Supported-Protocols': BITS_PROTOCOL},
                      expected_status=200,
                      expected_headers={'BITS-Protocol': BITS_PROTOCOL.lower(),
                                        'BITS-Host-ID': None,
                                        'BITS-Host-Id-Fallback-Timeout': None},
                      vhd=True, vdi_raw=self.VDI_RAW, ret_headers=True)

        session_id = resp['bits-session-id']
        
        range_start = 0
        range_end = frag_size
        total = len(data)
        while (range_start < total):
            if range_end > total:
                range_end = total
            rangeheader = http_test.content_range_header(range_start, range_end, total)
            record = do_test(self, packet_type='FRAGMENT',
                                   session_id=session_id,
                                   data=data[range_start:range_end],
                                   headers={'Content-Range': rangeheader},
                                   expected_status=200,
                                   expected_headers={'BITS-Received-Content-Range': str(range_end),
                                                     'BITS-Reply-URL': None},
                                   record=record, vhd=True)
            range_start = range_end
            if frag_variable:
                frag_size = random.randint(1, 100*K)
            range_end += frag_size

        f = open(REFERENCE_FILE, 'r')
        data = f.read()
        f.close()
        assertVdiData(self, record, data)
        clean_up()
コード例 #4
0
ファイル: http_test.py プロジェクト: 2xyo/transfervm
def do_vhd_put_get_test(self, vdi_mb, vdi_raw, pattern, blocks = None):
    MAX_FRAG_SIZE = 100*K
    TMP_RAW_RESPONSE_FILE = "response.tmp"
    TMP_VHD_RESPONSE_FILE = "response.vhd"
    REFERENCE_FILE = "reference.tmp"
    VHD_FILE = "tmp.vhd"
    bitmap = None

    vhd.create(VHD_FILE, vdi_mb)
    vhd.fill(VHD_FILE, REFERENCE_FILE, vdi_mb, pattern)
    hostname, network, vdi = testsetup.setup_host_and_network(templates=1, vdi_mb=vdi_mb, vdi_raw=vdi_raw)
    args = {'vdi_uuid': vdi, 'network_uuid': network, 'transfer_mode': 'http'}
    if blocks:
        bitmap = vhd.to_bitmap(blocks, vdi_mb * M)
        args['vhd_blocks'] = base64.b64encode(zlib.compress(bitmap))
	args['vhd_uuid'] = vdi #vhd uuid needed for get - using vdi value for test purposes
    transferclient.expose(hostname, **args)
    record = transferclient.get_record(hostname, vdi_uuid=vdi)
    url_path = record['url_path']

    # test "put"
    f = open(VHD_FILE, 'r')
    put_data = f.read()
    f.close()

    record['url_path'] = url_path + ".vhd"
    put_status, put_headers = http_put(record, put_data, None, vdi_mb * M)
    self.assertEqual(put_status, 200)

    record['url_path'] = url_path
    get_status, get_headers, get_respdata = http_get(record)
    if len(get_respdata) > vdi_mb * M:
        # raw VDIs can be larger than requested size
        get_respdata = get_respdata[:vdi_mb * M]
    f = open(TMP_RAW_RESPONSE_FILE, 'w')
    f.write(get_respdata)
    f.close()

    cmd = "diff %s %s" % (TMP_RAW_RESPONSE_FILE, REFERENCE_FILE)
    util.doexec(cmd, 0)

    # test "get"
    record['url_path'] = url_path + ".vhd"
    frag_size = random.randint(1, MAX_FRAG_SIZE)
    range_start = 0
    range_end = frag_size
    head_status, head_headers = http_head(record)
    vhd_size = int(head_headers['content-length'])
    total = vhd_size 
    total_received = 0
    total_chunks = 0
    f = open(TMP_VHD_RESPONSE_FILE, 'w')
    while range_start < total:
        if range_end > total:
            range_end = total
        
        #print "Getting range %d-%d" % (range_start, range_end)
        get_status, get_headers, get_respdata = http_get(record, content_range=(range_start, range_end, total))
        self.assertEquals(get_status, 200)
        #print "Got response of length %d" % len(get_respdata)
        total_received += len(get_respdata)
        total_chunks += 1
        f.write(get_respdata)

        range_start = range_end
        frag_size = random.randint(1, MAX_FRAG_SIZE)
        range_end += frag_size

    f.close()
    #print "Got total length %d in %d chunks" % (total_received, total_chunks)

    if blocks:
        vhd.mask(REFERENCE_FILE, vdi_mb * M, blocks)
        vhd.extract(TMP_VHD_RESPONSE_FILE, TMP_RAW_RESPONSE_FILE)
        cmd = "diff %s %s" % (TMP_RAW_RESPONSE_FILE, REFERENCE_FILE)
        util.doexec(cmd, 0)
    else:
        vhd.diff(TMP_VHD_RESPONSE_FILE, VHD_FILE)

    clean_up()
コード例 #5
0
ファイル: bits_test.py プロジェクト: xueqingz/transfervm
    def _testFragment(self, pattern, frag_size):
        TMP_RAW_RESPONSE_FILE = "response.tmp"
        TMP_VHD_RESPONSE_FILE = "response.vhd"
        REFERENCE_FILE = "reference.tmp"
        VHD_FILE = "tmp.vhd"
        VDI_MB = 16
        frag_variable = False

        if not frag_size:
            frag_variable = True
            frag_size = random.randint(1, 100 * K)

        vdi_mb = VDI_MB
        vhd.create(VHD_FILE, vdi_mb)
        vhd.fill(VHD_FILE, REFERENCE_FILE, vdi_mb, pattern)
        f = open(VHD_FILE, 'r')
        data = f.read()
        f.close()

        record, resp = do_test(
            self,
            packet_type='CREATE-SESSION',
            headers={'BITS-Supported-Protocols': BITS_PROTOCOL},
            expected_status=200,
            expected_headers={
                'BITS-Protocol': BITS_PROTOCOL.lower(),
                'BITS-Host-ID': None,
                'BITS-Host-Id-Fallback-Timeout': None
            },
            vhd=True,
            vdi_raw=self.VDI_RAW,
            ret_headers=True)

        session_id = resp['bits-session-id']

        range_start = 0
        range_end = frag_size
        total = len(data)
        while (range_start < total):
            if range_end > total:
                range_end = total
            rangeheader = http_test.content_range_header(
                range_start, range_end, total)
            record = do_test(self,
                             packet_type='FRAGMENT',
                             session_id=session_id,
                             data=data[range_start:range_end],
                             headers={'Content-Range': rangeheader},
                             expected_status=200,
                             expected_headers={
                                 'BITS-Received-Content-Range': str(range_end),
                                 'BITS-Reply-URL': None
                             },
                             record=record,
                             vhd=True)
            range_start = range_end
            if frag_variable:
                frag_size = random.randint(1, 100 * K)
            range_end += frag_size

        f = open(REFERENCE_FILE, 'r')
        data = f.read()
        f.close()
        assertVdiData(self, record, data)
        clean_up()
コード例 #6
0
def do_vhd_put_get_test(self, vdi_mb, vdi_raw, pattern, blocks=None):
    MAX_FRAG_SIZE = 100 * K
    TMP_RAW_RESPONSE_FILE = "response.tmp"
    TMP_VHD_RESPONSE_FILE = "response.vhd"
    REFERENCE_FILE = "reference.tmp"
    VHD_FILE = "tmp.vhd"
    bitmap = None

    vhd.create(VHD_FILE, vdi_mb)
    vhd.fill(VHD_FILE, REFERENCE_FILE, vdi_mb, pattern)
    hostname, network, vdi = testsetup.setup_host_and_network(templates=1,
                                                              vdi_mb=vdi_mb,
                                                              vdi_raw=vdi_raw)
    args = {'vdi_uuid': vdi, 'network_uuid': network, 'transfer_mode': 'http'}
    if blocks:
        bitmap = vhd.to_bitmap(blocks, vdi_mb * M)
        args['vhd_blocks'] = base64.b64encode(zlib.compress(bitmap))
        args[
            'vhd_uuid'] = vdi  #vhd uuid needed for get - using vdi value for test purposes
    transferclient.expose(hostname, **args)
    record = transferclient.get_record(hostname, vdi_uuid=vdi)
    url_path = record['url_path']

    # test "put"
    f = open(VHD_FILE, 'r')
    put_data = f.read()
    f.close()

    record['url_path'] = url_path + ".vhd"
    put_status, put_headers = http_put(record, put_data, None, vdi_mb * M)
    self.assertEqual(put_status, 200)

    record['url_path'] = url_path
    get_status, get_headers, get_respdata = http_get(record)
    if len(get_respdata) > vdi_mb * M:
        # raw VDIs can be larger than requested size
        get_respdata = get_respdata[:vdi_mb * M]
    f = open(TMP_RAW_RESPONSE_FILE, 'w')
    f.write(get_respdata)
    f.close()

    cmd = "diff %s %s" % (TMP_RAW_RESPONSE_FILE, REFERENCE_FILE)
    util.doexec(cmd, 0)

    # test "get"
    record['url_path'] = url_path + ".vhd"
    frag_size = random.randint(1, MAX_FRAG_SIZE)
    range_start = 0
    range_end = frag_size
    head_status, head_headers = http_head(record)
    vhd_size = int(head_headers['content-length'])
    total = vhd_size
    total_received = 0
    total_chunks = 0
    f = open(TMP_VHD_RESPONSE_FILE, 'w')
    while range_start < total:
        if range_end > total:
            range_end = total

        #print "Getting range %d-%d" % (range_start, range_end)
        get_status, get_headers, get_respdata = http_get(
            record, content_range=(range_start, range_end, total))
        self.assertEquals(get_status, 200)
        #print "Got response of length %d" % len(get_respdata)
        total_received += len(get_respdata)
        total_chunks += 1
        f.write(get_respdata)

        range_start = range_end
        frag_size = random.randint(1, MAX_FRAG_SIZE)
        range_end += frag_size

    f.close()
    #print "Got total length %d in %d chunks" % (total_received, total_chunks)

    if blocks:
        vhd.mask(REFERENCE_FILE, vdi_mb * M, blocks)
        vhd.extract(TMP_VHD_RESPONSE_FILE, TMP_RAW_RESPONSE_FILE)
        cmd = "diff %s %s" % (TMP_RAW_RESPONSE_FILE, REFERENCE_FILE)
        util.doexec(cmd, 0)
    else:
        vhd.diff(TMP_VHD_RESPONSE_FILE, VHD_FILE)

    clean_up()