Ejemplo n.º 1
0
  def upload_test_run(self, testrun):
    """Uploads the TestRun at a particular file.

    Args:
      testrun: TestRun proto or filepath.
    """
    http = httplib2.Http()
    # if self.credentials.access_token_expired:
    #   self.credentials.refresh(http)
    # self.credentials.authorize(http)

    if isinstance(testrun, test_runs_pb2.TestRun):
      serialized_run = testrun.SerializeToString()
    elif os.path.isfile(testrun):
      with open(testrun) as testrun_file:
        serialized_run = testrun_file.read()
    else:
      InvalidTestRunError('Invalid test run data')

    test_run_envelope = guzzle_pb2.TestRunEnvelope()
    test_run_envelope.payload = zlib.compress(serialized_run)
    test_run_envelope.payload_type = guzzle_pb2.COMPRESSED_TEST_RUN
    serialized_envelope = test_run_envelope.SerializeToString()

    resp, content = http.request(self.destination_url, 'POST',
                                 serialized_envelope)
Ejemplo n.º 2
0
def send_mfg_inspector_data(inspector_proto, credentials, destination_url):
    """Upload MfgEvent to steam_engine."""
    envelope = guzzle_pb2.TestRunEnvelope()
    envelope.payload = zlib.compress(inspector_proto.SerializeToString())
    envelope.payload_type = guzzle_pb2.COMPRESSED_TEST_RUN
    envelope_data = envelope.SerializeToString()

    for _ in range(5):
        try:
            result = _send_mfg_inspector_request(envelope_data, credentials,
                                                 destination_url)
            return result
        except UploadFailedError:
            time.sleep(1)

    logging.critical(
        'Could not upload to mfg-inspector after 5 attempts. Giving up.')

    return {}
Ejemplo n.º 3
0
    def upload_test_run(self, testrun):
        """Uploads the TestRun at a particular file.

    Args:
      testrun: TestRun proto or filepath.
    """
        http = httplib2.Http()
        if self.credentials.access_token_expired:
            self.credentials.refresh(http)
        self.credentials.authorize(http)

        if isinstance(testrun, test_runs_pb2.TestRun):
            serialized_run = testrun.SerializeToString()
        elif os.path.isfile(testrun):
            with open(testrun) as testrun_file:
                serialized_run = testrun_file.read()
        else:
            InvalidTestRunError('Invalid test run data')

        test_run_envelope = guzzle_pb2.TestRunEnvelope()
        test_run_envelope.payload = zlib.compress(serialized_run)
        test_run_envelope.payload_type = guzzle_pb2.COMPRESSED_TEST_RUN
        serialized_envelope = test_run_envelope.SerializeToString()

        resp, content = http.request(self.destination_url, 'POST',
                                     serialized_envelope)
        if resp.status != 200:
            try:
                results = json.loads(content)
            except Exception:
                raise UploadFailedError(resp, content)
            else:
                raise UploadFailedError(results['error'], results)

        result = json.loads(content)
        return result['key']