Beispiel #1
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()
Beispiel #2
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()
Beispiel #3
0
def get_encoded_bitmap_from_file(fn):
    vdi_mb = vhd.get_virtual_size(fn)
    blocks = vhd.get_allocated_blocks(fn)
    bitmap = vhd.to_bitmap(blocks, vdi_mb * M)
    return base64.b64encode(zlib.compress(bitmap))
Beispiel #4
0
def get_encoded_bitmap_from_file(fn):
    vdi_mb = vhd.get_virtual_size(fn)
    blocks = vhd.get_allocated_blocks(fn)
    bitmap = vhd.to_bitmap(blocks, vdi_mb * M)
    return base64.b64encode(zlib.compress(bitmap))