#95 Update branch detection for c10s
Merged 2 months ago by tdawson. Opened 2 months ago by sgallagh.
centos/ sgallagh/centpkg c10s-prep  into  develop

file modified
+39 -30
@@ -158,27 +158,33 @@ 

              stream_version = self.cmd.target.split('-')[0]

              rhel_version = centpkg.utils.stream_mapping(stream_version)

              try:

-                 active_y, in_stabilization = centpkg.utils.determine_active_y_version(rhel_version, pp_api_url)

+                 x_version, active_y, is_beta, in_stabilization = centpkg.utils.determine_active_y_version(rhel_version, pp_api_url)

              except AssertionError as e:

                  self.log.error("  Error: centpkg cannot determine the development phase.")

                  self.log.error("         Please file an issue at https://git.centos.org/centos/centpkg")

                  self.log.error("  Workaround: Use the --rhel-target option")

                  self.log.error("Exiting")

                  raise SystemExit(1)

-             divergent_branch = centpkg.utils.does_divergent_branch_exist(

-                                     self.cmd.repo_name,

-                                     rhel_version,

-                                     active_y,

-                                     rhel_dist_git,

-                                     pp_api_url,

-                                     "rpms")

+             if is_beta:

+                 # Special case: for X.0 betas, there will never be a prior branch

+                 # In this case, always work on the active branch.

+                 divergent_branch = True

+             else:

+                 divergent_branch = centpkg.utils.does_divergent_branch_exist(

+                                         self.cmd.repo_name,

+                                         x_version,

+                                         active_y,

+                                         rhel_dist_git,

+                                         "rpms")

              # Good to know

              if in_stabilization :

                  self.log.info("    we are in stabilization mode.")

              else:

                  self.log.info("    we are not in stabilization mode.")

-             if divergent_branch :

+             if divergent_branch and not is_beta:

                  self.log.info("    a divergent branch was found.")

+             elif divergent_branch and is_beta:

+                 self.log.info("    we are working on a beta release.")

              else:

                  self.log.info("    a divergent branch was not found.")

          else:
@@ -253,35 +259,38 @@ 

                      stream_version = self.cmd.target.split('-')[0]

                      rhel_version = centpkg.utils.stream_mapping(stream_version)

  

-                     # Until RHEL 10.1 is starting, set 10 to latest, by setting divergent_branch to True

-                     if stream_version == "c10s" or rhel_version == "rhel-10":

+                     try:

+                         x_version, active_y, is_beta, in_stabilization = centpkg.utils.determine_active_y_version(rhel_version, pp_api_url)

+                     except AssertionError as e:

+                         self.log.error("  Error: centpkg cannot determine the development phase.")

+                         self.log.error("         Please file an issue at https://git.centos.org/centos/centpkg")

+                         self.log.error("  Workaround: Use the --rhel-target option")

+                         self.log.error("Exiting")

+                         raise SystemExit(1)

+ 

+                     if is_beta:

+                         # Special case: for X.0 betas, there will never be a prior branch

+                         # In this case, always work on the active branch.

                          divergent_branch = True

                      else:

-                         try:

-                             active_y, in_stabilization = centpkg.utils.determine_active_y_version(rhel_version, pp_api_url)

-                         except AssertionError as e:

-                             self.log.error("  Error: centpkg cannot determine the development phase.")

-                             self.log.error("         Please file an issue at https://git.centos.org/centos/centpkg")

-                             self.log.error("  Workaround: Use the --rhel-target option")

-                             self.log.error("Exiting")

-                             raise SystemExit(1)

                          divergent_branch = centpkg.utils.does_divergent_branch_exist(

                                                  self.cmd.repo_name,

-                                                 rhel_version,

+                                                 x_version,

                                                  active_y,

                                                  rhel_dist_git,

-                                                 pp_api_url,

                                                  "rpms")

  

-                         # Good to know

-                         if divergent_branch :

-                             self.log.info("    a divergent branch was found.")

-                         else:

-                             self.log.info("    a divergent branch was not found.")

-                         if in_stabilization :

-                             self.log.info("    we are in stabilization mode.")

-                         else:

-                             self.log.info("    we are not in stabilization mode.")

+                     # Good to know

+                     if divergent_branch and not is_beta:

+                         self.log.info("    a divergent branch was found.")

+                     elif divergent_branch and is_beta:

+                         self.log.info("    we are working on a beta release.")

+                     else:

+                         self.log.info("    a divergent branch was not found.")

+                     if in_stabilization :

+                         self.log.info("    we are in stabilization mode.")

+                     else:

+                         self.log.info("    we are not in stabilization mode.")

  

                      # Update args.custom_user_metadata

                      if hasattr(self.args, 'custom_user_metadata') and self.args.custom_user_metadata:

file modified
+61 -24
@@ -285,14 +285,22 @@ 

          return "rhel-11"

      return None

  

- def does_divergent_branch_exist(repo_name, rhel_version, active_y, rhel_dist_git, pp_api_url, namespace):

+ def does_divergent_branch_exist(repo_name, x_version, active_y, rhel_dist_git, namespace):

      logger = logging.getLogger(__name__)

  

      # Determine if the Y-1 branch exists for this repo

  

-     divergent_branch = "{}.{}.0".format(rhel_version, active_y - 1)

+     if x_version >= 10 and active_y <= 0:

+         # For 10.0 and later X.0 releases, check for a rhel-X.0-beta branch

+         divergent_branch = "rhel-{}.0-beta".format(x_version)

+     elif x_version <= 9:

+         divergent_branch = "rhel-{}.{}.0".format(x_version, active_y - 1)

+     else:

+         # Starting with RHEL 10, the branch names have dropped the extra .0

+         divergent_branch = "rhel-{}.{}".format(x_version, active_y - 1)

+ 

      logger.debug("Divergent branch: {}".format(divergent_branch))

-     

+ 

      g = gitpython.cmd.Git()

      try:

          g.ls_remote(
@@ -316,56 +324,85 @@ 

      return [ int(x) for x in date_string_tuple ]

  

  

- def determine_active_y_version(rhel_version, pp_api_url):

+ def parse_rhel_shortname(shortname):

+     # The shortname is in the form rhel-9-1.0 or rhel-10.0[.beta]

+     m = re.match(

+         "rhel-(?P<major>[0-9]+)[.-](?P<minor>[0-9]+)([.]0|[.](?P<extra>.*))?", shortname

+     )

+     if not m:

+         raise RuntimeError("Could not parse version from {}".format(shortname))

+ 

+     major_version = int(m.group("major"))

+     minor_version = int(m.group("minor"))

+     extra_version = m.group("extra") or None

+ 

+     return major_version, minor_version, extra_version

+ 

+ 

+ def determine_active_y_version(rhel_version, api_url):

      """

-     Returns: A 2-tuple of the active Y-stream version(int) and whether we are

-     in the Exception Phase(bool)

+     Returns: A 4-tuple containing:

+       0. The major release version(int)

+       1. The active Y-stream version(int)

+       2. Whether the active release is the pre-X.0 beta

+       3. Whether we are in the Exception Phase(bool)

      """

      logger = logging.getLogger(__name__)

  

-     # Query the "package pages" API for the current active Y-stream release

+     # Phase Identifiers

      # Phase 230 is "Planning / Development / Testing" (AKA DevTestDoc)

      # Phase 450 is "Stabilization"

+     phase_devtestdoc = 230

+     phase_stabilization = 450

+ 

+     # Query the "package pages" API for the current active Y-stream release

      request_params = {

-         "phase__in": "230,450",

+         "phase__in": "{},{}".format(phase_devtestdoc, phase_stabilization),

          "product__shortname": "rhel",

          "relgroup__shortname": rhel_version,

          "format": "json",

      }

  

      res = requests.get(

-         os.path.join(pp_api_url, "latest", "releases"),

+         os.path.join(api_url, "latest", "releases"),

          params=request_params,

          timeout=60,

      )

      res.raise_for_status()

      payload = json.loads(res.text)

-     logger.debug(

-         "Response from PP API: {}".format(json.dumps(payload, indent=2))

-     )

+     logger.debug("Response from PP API: {}".format(json.dumps(payload, indent=2)))

      if len(payload) < 1:

-         raise RuntimeError("Received zero potential release matches")

+         # Received zero potential release matches

+         logger.warning("Didn't match any active releases. Assuming pre-Beta.")

+ 

+         # Fake up a Beta payload

+         payload = [

+             {

+                 "shortname": "{}.0.beta".format(rhel_version),

+                 "phase": phase_devtestdoc,

+             }

+         ]

  

-     release_id = -1

      active_y_version = -1

+     beta = False

      for entry in payload:

          shortname = entry["shortname"]

  

-         # The shortname is in the form rhel-9-1.0

+         # The shortname is in the form rhel-9-1.0 or rhel-10.0[.beta]

          # Extract the active Y-stream version

-         m = re.search("(?<={}-)\d+(?=\.0)".format(rhel_version), shortname)

-         if not m:

-             raise RuntimeError(

-                 "Could not determine active Y-stream version from shortname"

-             )

-         y_version = int(m.group(0))

+         x_version, y_version, extra_version = parse_rhel_shortname(shortname)

+ 

          if y_version > active_y_version:

              active_y_version = y_version

-             release_id = entry["id"]

+             beta = bool(extra_version and "beta" in extra_version)

  

          in_exception_phase = entry["phase"] == 450

  

-     logger.debug("Active Y-stream: {}, Enforcing: {}".format(active_y_version, in_exception_phase))

+     logger.debug(

+         "Active Y-stream: {}, Enforcing: {}, Beta: {}".format(

+             active_y_version, in_exception_phase, beta

+         )

+     )

  

-     return active_y_version, in_exception_phase

+     return x_version, active_y_version, beta, in_exception_phase

  

In RHEL 10, the internal branch names have dropped the extra .0

Additionally, there will now also be a rhel-X.0-beta branch.

Signed-off-by: Stephen Gallagher sgallagh@redhat.com

The code looks good.

It is currently showing c10s is NOT in beta. It is currently getting "zstream"
c9s is also getting "zstream"
c8s shows that we are in stabilization and thus forcing "--rhel-target" to be used.

Is this expected?
Last I looked c10s was supposed to be "latest"

I tried doing a "centpkg build" on c10s, c9s, and c8s branches. This is what I got.

(c8s) $ centpkg build
Checking rhel-target information:
    a divergent branch was not found.
    we are in stabilization mode.
We are currently in Stabalization mode
You must either set the rhel-target (--rhel-target)
or branch for the previous version.
Exiting
(c9s) $ centpkg build
Checking rhel-target information:
    a divergent branch was not found.
    we are not in stabilization mode.
    rhel-target: zstream
(c10s) $ centpkg build
Checking rhel-target information:
    a divergent branch was not found.
    we are not in stabilization mode.
    rhel-target: zstream

Okay, that's definitely wrong for c10s. I'm not sure about c9s at the moment. c8s is correct, as it's now in "permanent zstream".

I found the bug in c10s. I need to use if "beta" in extra_version" rather than extra_version.find("beta"). The latter worked when it was going to be .public_beta, but if it's the exact phrase, it ends up returning index 0 which is interpreted as False.

For c9s, it depends on the package you were testing against. Does it have a rhel-9.4.0 branch? If not, it should be zstream. If it does, it should be latest.

rebased onto 3c9d74b

2 months ago

Looks good.
c10s

(c10s) $ centpkg build
Checking rhel-target information:
    we are working on a beta release.
    we are not in stabilization mode.
    rhel-target: latest

c9s with divergent branch

(c9s)]$ centpkg build
Checking rhel-target information:
    a divergent branch was found.
    we are not in stabilization mode.
    rhel-target: latest

c8s with divergent branch

(c8s) $ centpkg build
Checking rhel-target information:
    a divergent branch was found.
    we are in stabilization mode.
    rhel-target: latest

c9s without divergent branch

(c9s) $ centpkg build
Checking rhel-target information:
    a divergent branch was not found.
    we are not in stabilization mode.
    rhel-target: zstream

c8s without divergent branch

(c8s) $ centpkg build
Checking rhel-target information:
    a divergent branch was not found.
    we are in stabilization mode.
We are currently in Stabalization mode
You must either set the rhel-target (--rhel-target)
or branch for the previous version.
Exiting

It looks correct to me. If it looks correct to you, let's merge this in.

Yes, this all looks correct now. Thanks!

Pull-Request has been merged by tdawson

2 months ago