コード例 #1
0
ファイル: isolate.py プロジェクト: xinghun61/infra
def GetIsolatedOuptputFileToHashMap(digest, name_space, isolated_server,
                                    http_client):
    """Gets the mapping of all files and their hashes and other info.

  Args:
    digest(str): Hash to file for retrieve request.
    name_space(str): Name space info for retrieve request.
    isolated_server(str): Host to isolate server.
    http_client(RetryHttpClient): Http client to send the request.

  Returns:
    (dict): Mapping from file names to hashes.
  """
    content, error = isolate_util.FetchFileFromIsolatedServer(
        digest, name_space, isolated_server, http_client)
    if not content:
        return None, error

    file_hash_mapping = {}
    content_json = json.loads(content)
    if not content_json.get('files'):
        return None, SwarmingTaskError.GenerateError(
            swarming_task_error.NO_ISOLATED_FILES)
    for file_name, info in content_json['files'].iteritems():
        file_hash_mapping[file_name] = info.get('h')
    return file_hash_mapping, None
コード例 #2
0
ファイル: isolate_util_test.py プロジェクト: xinghun61/infra
 def testFetchFileFromIsolatedServerError(self, *_):
     self.assertEqual(
         (None, {
             'code': 1
         }),
         isolate_util.FetchFileFromIsolatedServer('shard1_isolated',
                                                  'default-gzip',
                                                  'isolated_server', None))
コード例 #3
0
ファイル: isolate_util_test.py プロジェクト: xinghun61/infra
 def testFetchFileFromIsolatedServer(self, mock_fn):
     needed_content = json.dumps({'files': {'output.json': {'h': 'h'}}})
     content = json.dumps({
         'content':
         base64.b64encode(zlib.compress(needed_content)),
         'kind':
         'isolateservice#resourcesItem',
         'etag':
         '\'H_l3X6I4W5tDAoEMN5F54pK9RCg/teAVzABomW_XpYoLaFFl293qArc\''
     })
     mock_fn.return_value = (content, None)
     self.assertEqual(
         (needed_content, None),
         isolate_util.FetchFileFromIsolatedServer('shard1_isolated',
                                                  'default-gzip',
                                                  'isolated_server', None))
コード例 #4
0
ファイル: isolate_util_test.py プロジェクト: xinghun61/infra
    def testFetchFileFromIsolatedServerFromUrl(self, mock_request):
        content_with_url = json.dumps({
            'url':
            'url',
            'kind':
            'isolateservice#resourcesItem',
            'etag':
            '\'H_l3X6I4W5tDAoEMN5F54pK9RCg/teAVzABomW_XpYoLaFFl293qArc\''
        })
        content = zlib.compress('content')

        mock_request.side_effect = [(content_with_url, None), (content, None)]

        result, error = isolate_util.FetchFileFromIsolatedServer(
            'shard1_isolated', 'default-gzip', 'isolated_server', None)

        self.assertEqual('content', result)
        self.assertIsNone(error)
コード例 #5
0
ファイル: isolate.py プロジェクト: xinghun61/infra
def DownloadFileFromIsolatedServer(isolate_output_ref, http_client, file_name):
    """Downloads file and returns the json object.

  The basic steps to get test results are:
  1. Use isolate_output_ref to get hash to file,
  2. Use hash from step 1 to get the file.

  Args:
    isolate_output_ref(dict): Outputs ref to get mapping from files to hashes.
    http_client(FinditHttoClient): Http client to send requests.
    file_name(str): name of the file to get from isolate.
  """
    # First POST request to get hash for the file.
    file_hash_mapping, error = GetIsolatedOuptputFileToHashMap(
        isolate_output_ref['digest'], isolate_output_ref['namespace'],
        isolate_output_ref['isolatedserver'], http_client)
    file_hash = file_hash_mapping.get(file_name) if file_hash_mapping else None
    if not file_hash:
        return None, error

    # Second POST request to get the redirect url for the file.
    return isolate_util.FetchFileFromIsolatedServer(
        file_hash, isolate_output_ref['namespace'],
        isolate_output_ref['isolatedserver'], http_client)