Ejemplo n.º 1
0
def create_pr_symlink_s3(args):
    """Create a 'symlink' in S3 pointing at the results for a PR.
    This is a null op if PROW environment variables indicate this is not a PR
    job.
    """
    s3 = boto3.resource("s3")
    # S3 layout is defined here:
    # https://github.com/kubernetes/test-infra/tree/master/gubernator#job-artifact-gcs-layout
    pull_number = os.getenv("PULL_NUMBER")
    if not pull_number:
        # Symlinks are only created for pull requests.
        return

    path = "pr-logs/directory/{job}/{build}.txt".format(
        job=os.getenv("JOB_NAME"), build=os.getenv("BUILD_NUMBER"))

    pull_number = os.getenv("PULL_NUMBER")

    source = aws_util.to_s3_uri(args.bucket, path)
    target = get_s3_dir(args.bucket)
    logging.info("Creating symlink %s pointing to %s", source, target)

    file_name = "{build}.txt".format(build=os.getenv("BUILD_NUMBER"))
    with open(file_name, "w+") as data:
        data.write(target)
    s3.meta.client.upload_file(file_name, args.bucket, path)
Ejemplo n.º 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
Ejemplo n.º 3
0
    def test_to_s3_uri(self):
        bucket = "fakeBucket"
        path = "fakePath/folder1/folder2/hello.txt"

        self.assertEqual(
            "s3://fakeBucket/fakePath/folder1/folder2/hello.txt",
            util.to_s3_uri(bucket, path),
        )