Skip to content

Commit

Permalink
Dry run testing
Browse files Browse the repository at this point in the history
  • Loading branch information
kwk committed Mar 22, 2024
1 parent 5285f02 commit a9590b9
Show file tree
Hide file tree
Showing 5 changed files with 215 additions and 47 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/check-todays-snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ jobs:
shell: bash -e {0}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TESTING_FARM_API_TOKEN_PUBLIC_RANCH: ${{ secrets.TESTING_FARM_API_TOKEN_PUBLIC_RANCH }}
TESTING_FARM_API_TOKEN_REDHAT_RANCH: ${{ secrets.TESTING_FARM_API_TOKEN_REDHAT_RANCH }}
run: |
extra_args=""
Expand Down
48 changes: 2 additions & 46 deletions snapshot_manager/snapshot_manager/build_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,55 +141,11 @@ def success(self) -> bool:

@property
def os(self):
"""Get the os part of a chroot string
Args:
chroot (str): A string like "fedora-rawhide-x86_64
Returns:
str: The OS part of the chroot string.
Examples:
>>> BuildState(chroot="fedora-rawhide-x86_64").os
'fedora-rawhide'
>>> BuildState(chroot="fedora-40-ppc64le").os
'fedora-40'
>>> BuildState(chroot="fedora-rawhide-NEWARCH").os
'fedora-rawhide'
"""
match = re.search(pattern=r"[^-]+-[0-9,rawhide]+", string=self.chroot)
if match:
return str(match[0])
return ""
return util.chroot_os(self.chroot)

@property
def arch(self):
"""Get architecture part of a chroot string
Args:
chroot (str): A string like "fedora-rawhide-x86_64
Returns:
str: The architecture part of the chroot string.
Example:
>>> BuildState(chroot="fedora-rawhide-x86_64").arch
'x86_64'
>>> BuildState(chroot="fedora-40-ppc64le").arch
'ppc64le'
>>> BuildState(chroot="fedora-rawhide-NEWARCH").arch
'NEWARCH'
"""
match = regex.search(pattern=r"[^-]+-[^-]+-\K[^\s]+", string=self.chroot)
if match:
return str(match[0])
return ""
return util.chroot_arch(self.chroot)

@property
def source_build_url(self) -> str:
Expand Down
8 changes: 8 additions & 0 deletions snapshot_manager/snapshot_manager/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ class Config:
)
"""URL to the Copr monitor page. We'll use this in the issue comment's body, not for querying Copr."""

test_repo_url: str = "https://github.com/fedora-llvm-team/llvm-snapshots"
"""TBD"""

@property
def copr_projectname(self) -> str:
"""Takes the copr_project_tpl and replaces the YYYYMMDD placeholder (if any) with a date.
Expand All @@ -71,6 +74,11 @@ def copr_projectname(self) -> str:
"""
return self.copr_project_tpl.replace("YYYYMMDD", self.yyyymmdd)

@property
def copr_project(self) -> str:
"""Returns the owner/project string for the current date."""
return f"{self.config.copr_ownername}/{self.config.copr_projectname}"

@property
def copr_monitor_url(self) -> str:
"""Takes the copr_monitor_tpl and replaces the YYYYMMDD placeholder (if any) with a date.
Expand Down
30 changes: 29 additions & 1 deletion snapshot_manager/snapshot_manager/snapshot_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@

import datetime
import logging
import os

import snapshot_manager.build_status as build_status
import snapshot_manager.copr_util as copr_util
import snapshot_manager.github_util as github_util
import snapshot_manager.config as config
import snapshot_manager.util as util


class SnapshotManager:
Expand Down Expand Up @@ -169,7 +171,33 @@ def check_todays_builds(self):
logging.info(f"Kicking off new tests for chroot {chroot}.")
all_tests_succeeded = False
issue.add_to_labels(f"in_testing/{chroot}")
# TODO(kwk): Add testing-farm code here.
# TODO(kwk): Add testing-farm code here, something like this:
# TODO(kwk): Decide how if we want to wait for test results (probably not) and if not how we can check for the results later.
ranch = util.pick_testing_farm_ranch(chroot)
logging.info(f"Using testing-farm ranch: {ranch}")
if ranch == "public":
os.environ["TESTING_FARM_API_TOKEN"] = os.getenv(
"TESTING_FARM_API_TOKEN_PUBLIC_RANCH"
)
if ranch == "redhat":
os.environ["TESTING_FARM_API_TOKEN"] = os.getenv(
"TESTING_FARM_API_TOKEN_REDHAT_RANCH"
)
cmd = f"""testing-farm \
request \
--compose {util.chroot_os(chroot).upper()} \
--git-url {self.config.test_repo_url} \
--arch {util.chroot_arch(chroot)} \
--plan /tests/snapshot-gating \
--environment COPR_PROJECT={self.config.copr_project} \
--context distro={util.chroot_os(chroot)} \
--context arch=${util.chroot_arch(chroot)} \
--user-webpage{issue.html_url} \
--no-wait \
--dry-run \
--context snapshot={self.config.yyyymmdd}"""
exit_code, stdout, stderr = util._run_cmd(cmd, timeout_secs=None)
# if exit_code == 0:

logging.info("Checking if issue can be closed")
building_is_done = num_builds_to_succeed == 0
Expand Down
174 changes: 174 additions & 0 deletions snapshot_manager/snapshot_manager/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
import shlex
import subprocess
import os
import re

import requests
import regex

import snapshot_manager.file_access as file_access
import snapshot_manager.build_status as build_status
Expand Down Expand Up @@ -167,3 +169,175 @@ def golden_file_path(basename: str, extension: str = ".golden.txt") -> pathlib.P
f"{basename}{extension}",
)
return pathlib.Path(path)


def expect_chroot(chroot: str) -> None:
"""Raises an exception if passes string is not a chroot
Args:
chroot (str): Any chroot string
Raises:
ValueError: if chroot argument is not a chroot string
Examples:
>>> expect_chroot("fedora-rawhide-x86_64")
>>> expect_chroot("fedora-rawhide-")
Traceback (most recent call last):
...
ValueError: invalid chroot fedora-rawhide-
"""
if not re.search(pattern=r"^[^-]+-[^-]+-[^-]+$", string=chroot):
raise ValueError(f"invalid chroot {chroot}")


def chroot_name(chroot: str) -> str:
"""Get the name part of a chroot string
Args:
chroot (str): A string like "fedora-rawhide-x86_64
Returns:
str: The Name part of the chroot string.
Examples:
>>> chroot_name(chroot="fedora-rawhide-x86_64")
'fedora'
>>> chroot_name(chroot="fedora-40-ppc64le")
'fedora'
>>> chroot_name(chroot="fedora-rawhide-NEWARCH")
'fedora'
>>> chroot_name(chroot="rhel-9-x86_64")
'rhel'
"""
expect_chroot(chroot)
match = re.search(pattern=r"^[^-]+", string=chroot)
return str(match[0])


def chroot_version(chroot: str) -> str:
"""Get the version part of a chroot string
Args:
chroot (str): A string like "fedora-rawhide-x86_64
Returns:
str: The Name part of the chroot string.
Examples:
>>> chroot_version(chroot="fedora-rawhide-x86_64")
'rawhide'
>>> chroot_version(chroot="fedora-40-ppc64le")
'40'
>>> chroot_version(chroot="fedora-rawhide-NEWARCH")
'rawhide'
>>> chroot_version(chroot="rhel-9-x86_64")
'9'
"""
expect_chroot(chroot)
match = re.search(pattern=r"(-)([^-]+)(-)", string=chroot)
return str(match.groups()[1])


def chroot_os(chroot: str) -> str:
"""Get the os part of a chroot string
Args:
chroot (str): A string like "fedora-rawhide-x86_64
Raises:
ValueError: if chroot argument is not a chroot string
Returns:
str: The OS part of the chroot string.
Examples:
>>> chroot_os(chroot="fedora-rawhide-x86_64")
'fedora-rawhide'
>>> chroot_os(chroot="fedora-40-ppc64le")
'fedora-40'
>>> chroot_os(chroot="fedora-rawhide-NEWARCH")
'fedora-rawhide'
"""
expect_chroot(chroot)
match = re.search(pattern=r"[^-]+-[0-9,rawhide]+", string=chroot)
return str(match[0])


def pick_testing_farm_ranch(chroot: str) -> str:
"""Depending on the chroot, we decide if we build in the public or redhat testing ranch
Args:
chroot (str): chroot to use for determination of ranch
Returns:
str: "public", "private" or None
Examples:
>>> pick_testing_farm_ranch("fedora-rawhide-x86_64")
'public'
>>> pick_testing_farm_ranch("fedora-40-aarch64")
'public'
>>> pick_testing_farm_ranch("rhel-9-x86_64")
'redhat'
>>> pick_testing_farm_ranch("fedora-rawhide-s390x")
'redhat'
>>> pick_testing_farm_ranch("fedora-rawhide-ppc64le")
'redhat'
>>> pick_testing_farm_ranch("fedora-rawhide-i386")
'redhat'
"""
expect_chroot(chroot)
ranch = None
if re.search(r"(x86_64|aarch64)$", chroot):
ranch = "public"
if re.search(r"(^rhel|(ppc64le|s390x|i386)$)", chroot):
ranch = "redhat"
return ranch


def chroot_arch(chroot: str) -> str:
"""Get architecture part of a chroot string
Args:
chroot (str): A string like "fedora-rawhide-x86_64
Raises:
ValueError: if chroot argument is not a chroot string
Returns:
str: The architecture part of the chroot string.
Example:
>>> chroot_arch(chroot="fedora-rawhide-x86_64")
'x86_64'
>>> chroot_arch(chroot="fedora-40-ppc64le")
'ppc64le'
>>> chroot_arch(chroot="fedora-rawhide-NEWARCH")
'NEWARCH'
"""
expect_chroot(chroot)
match = regex.search(pattern=r"[^-]+-[^-]+-\K[^\s]+", string=chroot)
return str(match[0])

0 comments on commit a9590b9

Please sign in to comment.