コード例 #1
0
ファイル: prow_artifacts.py プロジェクト: svalleru/testing
def check_no_errors(gcs_client, artifacts_dir):
    """Check that all the XML files exist and there were no errors.
  Args:
    gcs_client: The GCS client.
    artifacts_dir: The directory where artifacts should be stored.
  Returns:
    True if there were no errors and false otherwise.
  """
    bucket_name, prefix = util.split_gcs_uri(artifacts_dir)
    bucket = gcs_client.get_bucket(bucket_name)
    no_errors = True

    # Get a list of actual junit files.
    actual_junit = _get_actual_junit_files(bucket, prefix)

    for f in actual_junit:
        full_path = os.path.join(artifacts_dir, f)
        logging.info("Checking %s", full_path)
        b = bucket.blob(os.path.join(prefix, f))

        xml_contents = b.download_as_string()

        if test_util.get_num_failures(xml_contents) > 0:
            logging.info("Test failures in %s", full_path)
            no_errors = False

    return no_errors
コード例 #2
0
def check_no_errors_s3(s3_client, artifacts_dir):
    """Check that all the XML files exist and there were no errors.
    Args:
      s3_client: The S3 client.
      artifacts_dir: The directory where artifacts should be stored.
    Returns:
      True if there were no errors and false otherwise.
    """
    bucket, prefix = aws_util.split_s3_uri(artifacts_dir)
    no_errors = True

    junit_objects = s3_client.list_objects(Bucket=bucket,
                                           Prefix=os.path.join(
                                               prefix, "junit"))

    if "Contents" not in junit_objects.keys():
        return no_errors

    for b in junit_objects["Contents"]:
        full_path = aws_util.to_s3_uri(bucket, b["Key"])
        if not os.path.splitext(b["Key"])[-1] == ".xml":
            logging.info("Skipping %s; not an xml file", full_path)
            continue
        logging.info("Checking %s", full_path)
        tmp_file = "/tmp/junit.xml"
        s3_client.download_file(bucket, b["Key"], tmp_file)
        with open(tmp_file) as f:
            xml_contents = f.read()

        if test_util.get_num_failures(xml_contents) > 0:
            logging.info("Test failures in %s", full_path)
            no_errors = False

    return no_errors
コード例 #3
0
ファイル: prow_artifacts.py プロジェクト: subodh101/testing
def check_no_errors(gcs_client, artifacts_dir):
    """Check that all the XML files exist and there were no errors.
  Args:
    gcs_client: The GCS client.
    artifacts_dir: The directory where artifacts should be stored.
  Returns:
    True if there were no errors and false otherwise.
  """
    bucket_name, prefix = util.split_gcs_uri(artifacts_dir)
    bucket = gcs_client.get_bucket(bucket_name)
    no_errors = True

    for b in bucket.list_blobs(prefix=os.path.join(prefix, "junit")):
        full_path = util.to_gcs_uri(b.bucket, b.path)
        if not os.path.splitext(b.path)[-1] == ".xml":
            logging.info("Skipping %s; not an xml file", full_path)
            continue
        logging.info("Checking %s", full_path)
        xml_contents = b.download_as_string()

        if test_util.get_num_failures(xml_contents) > 0:
            logging.info("Test failures in %s", full_path)
            no_errors = False

    return no_errors
コード例 #4
0
  def test_get_num_failures_success(self):
    success = test_util.TestCase()
    success.class_name = "some_test"
    success.name = "first"
    success.time = 10

    e = test_util.create_xml([success])
    s = StringIO.StringIO()
    e.write(s)
    xml_value = s.getvalue()
    self.assertEqual(0, test_util.get_num_failures(xml_value))
コード例 #5
0
  def test_get_num_failures(self):
    failure = test_util.TestCase()
    failure.class_name = "some_test"
    failure.name = "first"
    failure.time = 10
    failure.failure = "failed for some reason."

    e = test_util.create_xml([failure])
    s = StringIO.StringIO()
    e.write(s)
    xml_value = s.getvalue()
    self.assertEqual(1, test_util.get_num_failures(xml_value))