コード例 #1
0
ファイル: utils_unittest.py プロジェクト: wkf31156/autotest
 def test_timeout_reset_after_call(self):
     old_timeout = socket.getdefaulttimeout()
     self.stub_urlopen_with_timeout_check(30, None, "url")
     try:
         socket.setdefaulttimeout(1234)
         utils.urlopen("url", timeout=30)
         self.assertEquals(1234, socket.getdefaulttimeout())
     finally:
         socket.setdefaulttimeout(old_timeout)
コード例 #2
0
ファイル: utils_unittest.py プロジェクト: autotest/autotest
 def test_timeout_reset_after_call(self):
     old_timeout = socket.getdefaulttimeout()
     self.stub_urlopen_with_timeout_check(30, None, "url")
     try:
         socket.setdefaulttimeout(1234)
         utils.urlopen("url", timeout=30)
         self.assertEquals(1234, socket.getdefaulttimeout())
     finally:
         socket.setdefaulttimeout(old_timeout)
コード例 #3
0
def get_results(results_files):
    """
    Download the results if needed.
    Return results of each run in a numerically-indexed dictionary
    of dictionaries keyed on testnames.
    Return dictionary keyed on unique testnames across all runs.
    """
    r = re.compile('(\S+\s+\S+)\s+(\S+)\s+:')
    i = 0
    runs = {}
    testnames = {}
    for file in results_files:
        runs[i] = {}
        try:
            fh = utils.urlopen(file)
            results = fh.readlines()
            fh.close()
        except Exception:
            print "ERROR: reading results resource [%s]" % (file)
            usage()
        for line in results:
            try:
                s = r.match(line)
                testname = s.group(1)
                status = s.group(2)
                runs[i][testname] = status
                testnames[testname] = 1
            except Exception:
                pass
        i += 1
    return (runs, testnames)
コード例 #4
0
ファイル: ltp-diff.py プロジェクト: uni-peter-zheng/autotest
def get_results(results_files):
    """
    Download the results if needed.
    Return results of each run in a numerically-indexed dictionary
    of dictionaries keyed on testnames.
    Return dictionary keyed on unique testnames across all runs.
    """
    r = re.compile('(\S+\s+\S+)\s+(\S+)\s+:')
    i = 0
    runs = {}
    testnames = {}
    for file in results_files:
        runs[i] = {}
        try:
            fh = utils.urlopen(file)
            results = fh.readlines()
            fh.close()
        except Exception:
            print "ERROR: reading results resource [%s]" % (file)
            usage()
        for line in results:
            try:
                s = r.match(line)
                testname = s.group(1)
                status = s.group(2)
                runs[i][testname] = status
                testnames[testname] = 1
            except Exception:
                pass
        i += 1
    return (runs, testnames)
コード例 #5
0
ファイル: bkr_proxy.py プロジェクト: andykobewu/autotest-1
def copy_remote(data, dest, use_put=None):
    """
    Copy data to a remote server using http calls POST or PUT

    Using http POST and PUT methods, copy data over http.  To use
    PUT method, provide a dictionary of values to be populated in
    the Content-Range and Content-Length headers.  Otherwise default
    is to use POST method.

    Traps on HTTPError 500 and 400

    :param data: encoded data string to copy remotely
    :param dest: remote server URL
    :param use_put: dictionary of items if using PUT method

    :return: html header info for post processing
    """

    ret = None
    req = urllib2.Request(dest, data=data)
    if use_put:
        req.add_header('Content-Type', 'application/octet-stream')
        end = use_put['start'] + use_put['size'] - 1
        req.add_header(
            'Content-Range',
            'bytes %s-%s/%s' % (use_put['start'], end, use_put['total']))
        req.add_header('Content-Length', '%s' % use_put['size'])
        req.get_method = lambda: 'PUT'

    try:
        res = utils.urlopen(req)
        ret = res.info()
        res.close()
    except urllib2.HTTPError as e:
        if e.code == 500:
            # the server aborted this recipe DIE DIE DIE
            raise BkrProxyException("We have been aborted!!!")
        elif e.code == 400 and use_put:
            log.error("Error(%s) failed to upload file %s" % (e.code, dest))
    return ret
コード例 #6
0
ファイル: bkr_proxy.py プロジェクト: Antique/autotest
def copy_remote(data, dest, use_put=None):
    """
    Copy data to a remote server using http calls POST or PUT

    Using http POST and PUT methods, copy data over http.  To use
    PUT method, provide a dictionary of values to be populated in
    the Content-Range and Content-Length headers.  Otherwise default
    is to use POST method.

    Traps on HTTPError 500 and 400

    @param data: encoded data string to copy remotely
    @param dest: remote server URL
    @param use_put: dictionary of items if using PUT method

    :return: html header info for post processing
    """

    ret = None
    req = urllib2.Request(dest, data=data)
    if use_put:
        req.add_header('Content-Type', 'application/octet-stream')
        end = use_put['start'] + use_put['size'] - 1
        req.add_header('Content-Range', 'bytes %s-%s/%s' % (use_put['start'],
                                                            end, use_put['total']))
        req.add_header('Content-Length', '%s' % use_put['size'])
        req.get_method = lambda: 'PUT'

    try:
        res = utils.urlopen(req)
        ret = res.info()
        res.close()
    except urllib2.HTTPError, e:
        if e.code == 500:
            # the server aborted this recipe DIE DIE DIE
            raise BkrProxyException("We have been aborted!!!")
        elif e.code == 400 and use_put:
            log.error("Error(%s) failed to upload file %s" % (e.code, dest))
コード例 #7
0
ファイル: utils_unittest.py プロジェクト: autotest/autotest
 def test_args_are_untouched(self):
     self.stub_urlopen_with_timeout_check(30, None, "http://url",
                                          "POST data")
     utils.urlopen("http://url", timeout=30, data="POST data")
コード例 #8
0
ファイル: utils_unittest.py プロジェクト: autotest/autotest
 def test_timeout_set_by_default(self):
     def test_func(timeout):
         self.assertTrue(timeout is not None)
     self.stub_urlopen_with_timeout_comparison(test_func, None, "url")
     utils.urlopen("url")
コード例 #9
0
ファイル: utils_unittest.py プロジェクト: autotest/autotest
 def test_timeout_set_during_call(self):
     self.stub_urlopen_with_timeout_check(30, "retval", "url")
     retval = utils.urlopen("url", timeout=30)
     self.assertEquals(retval, "retval")
コード例 #10
0
ファイル: utils_unittest.py プロジェクト: wkf31156/autotest
 def test_args_are_untouched(self):
     self.stub_urlopen_with_timeout_check(30, None, "http://url",
                                          "POST data")
     utils.urlopen("http://url", timeout=30, data="POST data")
コード例 #11
0
ファイル: utils_unittest.py プロジェクト: wkf31156/autotest
    def test_timeout_set_by_default(self):
        def test_func(timeout):
            self.assertTrue(timeout is not None)

        self.stub_urlopen_with_timeout_comparison(test_func, None, "url")
        utils.urlopen("url")
コード例 #12
0
ファイル: utils_unittest.py プロジェクト: wkf31156/autotest
 def test_timeout_set_during_call(self):
     self.stub_urlopen_with_timeout_check(30, "retval", "url")
     retval = utils.urlopen("url", timeout=30)
     self.assertEquals(retval, "retval")