Esempio n. 1
0
    def testMultipleFragmentsInOneHttpSession(self):
        record = setup_and_get_record()
        conn = httplib.HTTPConnection(record['ip'], record['port'])

        expectedvdi = '\0' * (VDI_MB * M)
        try:
            for i in xrange(1, 6):
                data = ("xabcde"[i]) * M  # 1MB string of one character
                offset = i * M / 2
                rangeheader = http_test.content_range_header(
                    offset, offset + len(data), VDI_MB * M)
                record = do_test(
                    self,
                    packet_type='fragMENT',
                    session_id='{00000000-0000-0000-0000-000000000333}',
                    data=data,
                    headers={'Content-Range': rangeheader},
                    expected_status=200,
                    expected_session_id=
                    '{00000000-0000-0000-0000-000000000333}',
                    expected_headers={
                        'BITS-Received-Content-Range': str(offset + len(data)),
                        'BITS-Reply-URL': None
                    },
                    connection=conn,
                    record=record)

                # Do a local expected data write
                expectedvdi = expectedvdi[:offset] + data + expectedvdi[
                    offset + len(data):]
                assertVdiData(self, record, expectedvdi)
        finally:
            conn.close()
            clean_up()
Esempio n. 2
0
    def testMultipleFragmentsInOneHttpSession(self):
        record = setup_and_get_record()
        conn = httplib.HTTPConnection(record['ip'], record['port'])

        expectedvdi = '\0' * (VDI_MB*M)
        try:
            for i in xrange(1, 6):
                data = ("xabcde"[i]) * M  # 1MB string of one character
                offset = i * M / 2
                rangeheader = http_test.content_range_header(offset, offset + len(data), VDI_MB*M)
                record = do_test(self, packet_type='fragMENT',
                                       session_id='{00000000-0000-0000-0000-000000000333}',
                                       data=data,
                                       headers={'Content-Range': rangeheader},
                                       expected_status=200,
                                       expected_session_id='{00000000-0000-0000-0000-000000000333}',
                                       expected_headers={'BITS-Received-Content-Range': str(offset + len(data)),
                                                         'BITS-Reply-URL': None},
                                       connection=conn,
                                       record=record)

                # Do a local expected data write
                expectedvdi = expectedvdi[:offset] + data + expectedvdi[offset + len(data):]
                assertVdiData(self, record, expectedvdi)
        finally:
            conn.close()
            clean_up()
Esempio n. 3
0
    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()
Esempio n. 4
0
 def testInvalidContentRangeResultsIn400BadRequest(self):
     data = 'a' * (5*K)
     rangeheader = http_test.content_range_header(1*M, 1*M + len(data), 2 * VDI_MB*M)
     record = do_test(self, packet_type='FRAGMENT',
                            session_id='{00000000-0000-0000-0000-000000000222}',
                            data=data,
                            headers={'Content-Range': rangeheader},
                            expected_status=400,
                            expected_error_code=BITS_E_INVALIDARG,
                            expected_error_context=BITS_CONTEXT_SERVER)
     moreasserts.assertVdiIsZeroUsingHttpGet(self, record, VDI_MB)
     clean_up()
Esempio n. 5
0
 def test5KBFragment(self):
     data = 'a' * (5*K)
     rangeheader = http_test.content_range_header(1*M, 1*M + len(data), VDI_MB*M)
     record = do_test(self, packet_type='FRAgmENT',
                            session_id='{00000000-0000-0000-0000-000000000333}',
                            data=data,
                            headers={'Content-Range': rangeheader},
                            expected_status=200,
                            expected_session_id='{00000000-0000-0000-0000-000000000333}',
                            expected_headers={'BITS-Received-Content-Range': str(1*M + len(data)),
                                              'BITS-Reply-URL': None})
     assertVdiData(self, record, ('\0'*(1*M)) + data + ('\0'*(VDI_MB*M - 1*M - len(data))))
     clean_up()
Esempio n. 6
0
    def testMissingBitsSessionIdResultsIn400BadRequest(self):
        data = 'a' * (5*K)
        rangeheader = http_test.content_range_header(1*M, 1*M + len(data), VDI_MB*M)
        record = do_test(self, packet_type='FRAGMENT',
                               session_id=None,
                               data=data,
                               headers={'Content-Range': rangeheader},
                               expected_status=400,
                               expected_error_code=BITS_E_INVALIDARG,
                               expected_error_context=BITS_CONTEXT_SERVER)
        logging.debug('record')
	logging.debug(record)
	moreasserts.assertVdiIsZeroUsingHttpGet(self, record, VDI_MB)
        clean_up()
Esempio n. 7
0
 def testInvalidContentRangeResultsIn400BadRequest(self):
     data = 'a' * (5 * K)
     rangeheader = http_test.content_range_header(1 * M, 1 * M + len(data),
                                                  2 * VDI_MB * M)
     record = do_test(self,
                      packet_type='FRAGMENT',
                      session_id='{00000000-0000-0000-0000-000000000222}',
                      data=data,
                      headers={'Content-Range': rangeheader},
                      expected_status=400,
                      expected_error_code=BITS_E_INVALIDARG,
                      expected_error_context=BITS_CONTEXT_SERVER)
     moreasserts.assertVdiIsZeroUsingHttpGet(self, record, VDI_MB)
     clean_up()
Esempio n. 8
0
    def test4MBFragment(self):
	logging.debug('Begining test4MBFragment')
        data = 'a' * (4*M)
        rangeheader = http_test.content_range_header(1*M, 1*M + len(data), VDI_MB*M)
        record = do_test(self, packet_type='FRAGment',
                               session_id='{00000000-0000-0000-0000-000000000555}',
                               data=data,
                               headers={'Content-Range': rangeheader},
                               expected_status=200,
                               expected_session_id='{00000000-0000-0000-0000-000000000555}',
                               expected_headers={'BITS-Received-Content-Range': str(1*M + len(data)),
                                                 'BITS-Reply-URL': None})
        logging.debug('DEVICE NUMBER:')
	logging.debug(record['vdi_uuid'])
	assertVdiData(self, record, ('\0'*(1*M)) + data + ('\0'*(VDI_MB*M - 1*M - len(data))))
        clean_up()
Esempio n. 9
0
 def testMissingBitsSessionIdResultsIn400BadRequest(self):
     data = 'a' * (5 * K)
     rangeheader = http_test.content_range_header(1 * M, 1 * M + len(data),
                                                  VDI_MB * M)
     record = do_test(self,
                      packet_type='FRAGMENT',
                      session_id=None,
                      data=data,
                      headers={'Content-Range': rangeheader},
                      expected_status=400,
                      expected_error_code=BITS_E_INVALIDARG,
                      expected_error_context=BITS_CONTEXT_SERVER)
     logging.debug('record')
     logging.debug(record)
     moreasserts.assertVdiIsZeroUsingHttpGet(self, record, VDI_MB)
     clean_up()
Esempio n. 10
0
 def test5KBFragment(self):
     data = 'a' * (5 * K)
     rangeheader = http_test.content_range_header(1 * M, 1 * M + len(data),
                                                  VDI_MB * M)
     record = do_test(
         self,
         packet_type='FRAgmENT',
         session_id='{00000000-0000-0000-0000-000000000333}',
         data=data,
         headers={'Content-Range': rangeheader},
         expected_status=200,
         expected_session_id='{00000000-0000-0000-0000-000000000333}',
         expected_headers={
             'BITS-Received-Content-Range': str(1 * M + len(data)),
             'BITS-Reply-URL': None
         })
     assertVdiData(self, record, ('\0' * (1 * M)) + data +
                   ('\0' * (VDI_MB * M - 1 * M - len(data))))
     clean_up()
Esempio n. 11
0
 def test4MBFragment(self):
     logging.debug('Begining test4MBFragment')
     data = 'a' * (4 * M)
     rangeheader = http_test.content_range_header(1 * M, 1 * M + len(data),
                                                  VDI_MB * M)
     record = do_test(
         self,
         packet_type='FRAGment',
         session_id='{00000000-0000-0000-0000-000000000555}',
         data=data,
         headers={'Content-Range': rangeheader},
         expected_status=200,
         expected_session_id='{00000000-0000-0000-0000-000000000555}',
         expected_headers={
             'BITS-Received-Content-Range': str(1 * M + len(data)),
             'BITS-Reply-URL': None
         })
     logging.debug('DEVICE NUMBER:')
     logging.debug(record['vdi_uuid'])
     assertVdiData(self, record, ('\0' * (1 * M)) + data +
                   ('\0' * (VDI_MB * M - 1 * M - len(data))))
     clean_up()
Esempio n. 12
0
    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()