[Asterisk-code-review] testsuite: Added a testsuite repo module (repotools[master])

George Joseph asteriskteam at digium.com
Wed Mar 14 10:28:09 CDT 2018


George Joseph has submitted this change and it was merged. ( https://gerrit.asterisk.org/8291 )

Change subject: testsuite: Added a testsuite repo module
......................................................................

testsuite: Added a testsuite repo module

The new testsuite modules adds functionality to add and delete branches, and
add tags to the Asterisk testsuite repository.

By calling the update_testsuite function a new branch will be created for a
given version if the version is the first pre-release version. If the version
is the first branch release version then it tags the old release branch, and
deletes it.

Change-Id: I626cc8eb3290503d213047ffa6c3eddad8ef72b4
---
M mkrelease.py
A testsuite.py
2 files changed, 176 insertions(+), 0 deletions(-)

Approvals:
  Joshua Colp: Looks good to me, but someone else must approve; Verified
  George Joseph: Looks good to me, approved; Approved for Submit



diff --git a/mkrelease.py b/mkrelease.py
index b70030e..1a71067 100755
--- a/mkrelease.py
+++ b/mkrelease.py
@@ -22,6 +22,7 @@
 from version_parser import AsteriskVersion
 from release_summary import ReleaseSummary, ReleaseSummaryOptions
 from alembic_creator import create_db_script
+from testsuite import update_testsuite
 
 LOGGER = logging.getLogger(__name__)
 
@@ -686,6 +687,11 @@
     prompt_to_continue("Tag created, pushing changes to remote.")
     repo.push_changes()
 
+    if options.project.lower() == 'asterisk':
+        # Tags created and pushed to Asterisk remote, so update the testsuite
+        update_testsuite(version_object, options.local_root,
+                         options.remote_url, repo)
+
     prompt_to_continue("Proceeding to tarball.")
     create_patch_archive(options, repo)
     tag_archive = create_tag_archive(repo)
diff --git a/testsuite.py b/testsuite.py
new file mode 100644
index 0000000..e60e24a
--- /dev/null
+++ b/testsuite.py
@@ -0,0 +1,170 @@
+#!/usr/bin/env python
+"""Asterisk testsuite wrapper
+
+Functions, methods, and/or classes used to manipulate the Asterisk testsuite
+
+Copyright (C) 2018, Digium, Inc.
+Kevin Harwell <kharwell at digium.com>
+"""
+
+import logging
+import os
+
+import digium_git
+
+from version_parser import AsteriskVersion
+
+
+LOGGER = logging.getLogger(__name__)
+
+
+def update_testsuite(version, local_root=None,
+                      remote_url=None, asterisk=None):
+    """Create a branch for a new release if needed. Also, if it's a first
+    release then create a tag for the previous release branch and then delete
+    that branch.
+
+    Keyword Arguments:
+    version - The version number or object to use
+    local_root - The local root directory where the repository will be
+        checked out under.
+    remote_url - The remote url for the repository
+    asterisk - An asterisk repo object
+    """
+
+    if isinstance(version, str):
+        version = AsteriskVersion.create_from_string(version)
+
+    LOGGER.info("Updating testsuite for version '{0}'".format(version))
+
+    if version.is_first_pre():
+        # If this is the first pre release version then all we need to do
+        # is make sure the appropriate branch(es) gets created
+        LOGGER.info("Creating branch '{0}'".format(version.branch_name()))
+
+        testsuite = Testsuite(local_root, remote_url)
+        testsuite.checkout(version)
+        testsuite.push_changes()
+        return
+
+    if not version.is_first():
+        # Nothing to do if it's not the first release
+        LOGGER.info("Nothing to do for version '{0}'".format(version))
+        return
+
+    # If it is the first release we need to tag the previous release
+    # and then delete the previous release's branch.
+    #
+    # Usually there is only a single active branch in the Testsuite for a
+    # release type. But around release time two exist for a while. One being
+    # for this new release, the other for the old/last release. We need
+    # to find the old one, tag it and then delete it.
+    asterisk = asterisk or digium_git.get_repo(
+        'asterisk', local_root, remote_url)
+
+    prev = asterisk.find_last_tag(version)
+    if not prev:
+        LOGGER.info("Nothing to do. No prior tag found for version '{0}' on "
+                    "branch {1}".format(version, version.major))
+        return
+
+    LOGGER.info("Creating tag '{0}' and deleting branch '{1}'".format(
+        prev, prev.branch_name()))
+
+    testsuite = Testsuite(local_root, remote_url)
+    testsuite.checkout(prev)
+    testsuite.create_tag(prev)
+
+    # Switch branches since we can't delete a branch we're on
+    testsuite.checkout(version)
+    testsuite.delete_branch(prev.branch_name())
+    testsuite.push_changes()
+
+
+class Testsuite(digium_git.DigiumGitRepo):
+    """An Asterisk testsuite wrapper"""
+
+    def __init__(self, local_root=None, remote_url=None):
+        """Constructor
+
+        Keyword Arguments:
+        local_root - The local root directory where the repository will be
+            checked out under.
+        remote_url - The remote url for the repository
+        """
+
+        log_level = logging.getLogger().getEffectiveLevel()
+
+        project = "testsuite"
+        local_root = local_root or digium_git.DEFAULT_LOCAL_ROOT
+        remote_url = remote_url or digium_git.GERRIT
+
+        path = os.path.join(local_root, project)
+        repo_url = '{0}/{1}'.format(remote_url, project)
+
+        super(Testsuite, self).__init__(
+            path, repo_url, log_level == logging.DEBUG)
+
+    def checkout(self, version):
+        """Checkout a given version of the testsuite.
+
+        Keyword Arguments:
+        version - A version object of the version to use
+        """
+
+        # The branch to checkout coincides with an Asterisk release branch.
+        branch = version.branch_name()
+
+        LOGGER.debug("Checking out branch '{0}'".format(branch))
+
+        if self.branch_exists(branch):
+            super(Testsuite, self).checkout(branch)
+            return
+
+        # If that branch does not exist a base branch is checked out first.
+
+        if version.prefix:
+            # If there is a prefix then the branch to checkout is based off the
+            # Asterisk release branch. As the regular Asterisk release branch
+            # is always created prior to a prefixed branch, the branch and/or
+            # tag(s) should already exist.
+            base = version.branch_name(prefix=False)
+
+            if not self.branch_exists(base):
+                # If for some reason the base branch doesn't exist (release
+                # branch was deleted prior to creating the prefixed branch)
+                # then use the latest tag instead.
+                try:
+                    base = self.find_tags(base)[-1].name
+                except:
+                    raise IndexError("No release tags available for '{0}'. "
+                        "Nothing to base branch '{1}' on".format(base, branch))
+        else:
+            # We're dealing with a regular Asterisk release. The branch to
+            # checkout is always based off the major branch.
+            base = str(version.major)
+
+            if not self.branch_exists(base):
+                # Must be a new major version. Create it off of master.
+                super(Testsuite, self).checkout('master')
+
+        # Switch to the base branch first that way the new release branch is
+        # created off of that one.
+        super(Testsuite, self).checkout(base)
+        super(Testsuite, self).checkout(branch)
+
+    def create_tag(self, version):
+        """Create a new version tag in the local repository.
+
+        Keyword Arguments:
+        version - The version object of the tag to create
+        """
+
+        # Do not create a tag for alpha, beta, or RC releases
+        if version.has_modifier(['rc', 'alpha', 'beta']):
+            return
+
+        try:
+            super(Testsuite, self).create_tag(str(version))
+        except ValueError as e:
+            LOGGER.debug("{0} Skipping tag creation.".format(e))

-- 
To view, visit https://gerrit.asterisk.org/8291
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-Project: repotools
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I626cc8eb3290503d213047ffa6c3eddad8ef72b4
Gerrit-Change-Number: 8291
Gerrit-PatchSet: 1
Gerrit-Owner: Kevin Harwell <kharwell at digium.com>
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20180314/0a6818a5/attachment.html>


More information about the asterisk-code-review mailing list