<p>George Joseph <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/8291">View Change</a></p><div style="white-space:pre-wrap">Approvals:
Joshua Colp: Looks good to me, but someone else must approve; Verified
George Joseph: Looks good to me, approved; Approved for Submit
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">testsuite: Added a testsuite repo module<br><br>The new testsuite modules adds functionality to add and delete branches, and<br>add tags to the Asterisk testsuite repository.<br><br>By calling the update_testsuite function a new branch will be created for a<br>given version if the version is the first pre-release version. If the version<br>is the first branch release version then it tags the old release branch, and<br>deletes it.<br><br>Change-Id: I626cc8eb3290503d213047ffa6c3eddad8ef72b4<br>---<br>M mkrelease.py<br>A testsuite.py<br>2 files changed, 176 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/mkrelease.py b/mkrelease.py<br>index b70030e..1a71067 100755<br>--- a/mkrelease.py<br>+++ b/mkrelease.py<br>@@ -22,6 +22,7 @@<br> from version_parser import AsteriskVersion<br> from release_summary import ReleaseSummary, ReleaseSummaryOptions<br> from alembic_creator import create_db_script<br>+from testsuite import update_testsuite<br> <br> LOGGER = logging.getLogger(__name__)<br> <br>@@ -686,6 +687,11 @@<br> prompt_to_continue("Tag created, pushing changes to remote.")<br> repo.push_changes()<br> <br>+ if options.project.lower() == 'asterisk':<br>+ # Tags created and pushed to Asterisk remote, so update the testsuite<br>+ update_testsuite(version_object, options.local_root,<br>+ options.remote_url, repo)<br>+<br> prompt_to_continue("Proceeding to tarball.")<br> create_patch_archive(options, repo)<br> tag_archive = create_tag_archive(repo)<br>diff --git a/testsuite.py b/testsuite.py<br>new file mode 100644<br>index 0000000..e60e24a<br>--- /dev/null<br>+++ b/testsuite.py<br>@@ -0,0 +1,170 @@<br>+#!/usr/bin/env python<br>+"""Asterisk testsuite wrapper<br>+<br>+Functions, methods, and/or classes used to manipulate the Asterisk testsuite<br>+<br>+Copyright (C) 2018, Digium, Inc.<br>+Kevin Harwell <kharwell@digium.com><br>+"""<br>+<br>+import logging<br>+import os<br>+<br>+import digium_git<br>+<br>+from version_parser import AsteriskVersion<br>+<br>+<br>+LOGGER = logging.getLogger(__name__)<br>+<br>+<br>+def update_testsuite(version, local_root=None,<br>+ remote_url=None, asterisk=None):<br>+ """Create a branch for a new release if needed. Also, if it's a first<br>+ release then create a tag for the previous release branch and then delete<br>+ that branch.<br>+<br>+ Keyword Arguments:<br>+ version - The version number or object to use<br>+ local_root - The local root directory where the repository will be<br>+ checked out under.<br>+ remote_url - The remote url for the repository<br>+ asterisk - An asterisk repo object<br>+ """<br>+<br>+ if isinstance(version, str):<br>+ version = AsteriskVersion.create_from_string(version)<br>+<br>+ LOGGER.info("Updating testsuite for version '{0}'".format(version))<br>+<br>+ if version.is_first_pre():<br>+ # If this is the first pre release version then all we need to do<br>+ # is make sure the appropriate branch(es) gets created<br>+ LOGGER.info("Creating branch '{0}'".format(version.branch_name()))<br>+<br>+ testsuite = Testsuite(local_root, remote_url)<br>+ testsuite.checkout(version)<br>+ testsuite.push_changes()<br>+ return<br>+<br>+ if not version.is_first():<br>+ # Nothing to do if it's not the first release<br>+ LOGGER.info("Nothing to do for version '{0}'".format(version))<br>+ return<br>+<br>+ # If it is the first release we need to tag the previous release<br>+ # and then delete the previous release's branch.<br>+ #<br>+ # Usually there is only a single active branch in the Testsuite for a<br>+ # release type. But around release time two exist for a while. One being<br>+ # for this new release, the other for the old/last release. We need<br>+ # to find the old one, tag it and then delete it.<br>+ asterisk = asterisk or digium_git.get_repo(<br>+ 'asterisk', local_root, remote_url)<br>+<br>+ prev = asterisk.find_last_tag(version)<br>+ if not prev:<br>+ LOGGER.info("Nothing to do. No prior tag found for version '{0}' on "<br>+ "branch {1}".format(version, version.major))<br>+ return<br>+<br>+ LOGGER.info("Creating tag '{0}' and deleting branch '{1}'".format(<br>+ prev, prev.branch_name()))<br>+<br>+ testsuite = Testsuite(local_root, remote_url)<br>+ testsuite.checkout(prev)<br>+ testsuite.create_tag(prev)<br>+<br>+ # Switch branches since we can't delete a branch we're on<br>+ testsuite.checkout(version)<br>+ testsuite.delete_branch(prev.branch_name())<br>+ testsuite.push_changes()<br>+<br>+<br>+class Testsuite(digium_git.DigiumGitRepo):<br>+ """An Asterisk testsuite wrapper"""<br>+<br>+ def __init__(self, local_root=None, remote_url=None):<br>+ """Constructor<br>+<br>+ Keyword Arguments:<br>+ local_root - The local root directory where the repository will be<br>+ checked out under.<br>+ remote_url - The remote url for the repository<br>+ """<br>+<br>+ log_level = logging.getLogger().getEffectiveLevel()<br>+<br>+ project = "testsuite"<br>+ local_root = local_root or digium_git.DEFAULT_LOCAL_ROOT<br>+ remote_url = remote_url or digium_git.GERRIT<br>+<br>+ path = os.path.join(local_root, project)<br>+ repo_url = '{0}/{1}'.format(remote_url, project)<br>+<br>+ super(Testsuite, self).__init__(<br>+ path, repo_url, log_level == logging.DEBUG)<br>+<br>+ def checkout(self, version):<br>+ """Checkout a given version of the testsuite.<br>+<br>+ Keyword Arguments:<br>+ version - A version object of the version to use<br>+ """<br>+<br>+ # The branch to checkout coincides with an Asterisk release branch.<br>+ branch = version.branch_name()<br>+<br>+ LOGGER.debug("Checking out branch '{0}'".format(branch))<br>+<br>+ if self.branch_exists(branch):<br>+ super(Testsuite, self).checkout(branch)<br>+ return<br>+<br>+ # If that branch does not exist a base branch is checked out first.<br>+<br>+ if version.prefix:<br>+ # If there is a prefix then the branch to checkout is based off the<br>+ # Asterisk release branch. As the regular Asterisk release branch<br>+ # is always created prior to a prefixed branch, the branch and/or<br>+ # tag(s) should already exist.<br>+ base = version.branch_name(prefix=False)<br>+<br>+ if not self.branch_exists(base):<br>+ # If for some reason the base branch doesn't exist (release<br>+ # branch was deleted prior to creating the prefixed branch)<br>+ # then use the latest tag instead.<br>+ try:<br>+ base = self.find_tags(base)[-1].name<br>+ except:<br>+ raise IndexError("No release tags available for '{0}'. "<br>+ "Nothing to base branch '{1}' on".format(base, branch))<br>+ else:<br>+ # We're dealing with a regular Asterisk release. The branch to<br>+ # checkout is always based off the major branch.<br>+ base = str(version.major)<br>+<br>+ if not self.branch_exists(base):<br>+ # Must be a new major version. Create it off of master.<br>+ super(Testsuite, self).checkout('master')<br>+<br>+ # Switch to the base branch first that way the new release branch is<br>+ # created off of that one.<br>+ super(Testsuite, self).checkout(base)<br>+ super(Testsuite, self).checkout(branch)<br>+<br>+ def create_tag(self, version):<br>+ """Create a new version tag in the local repository.<br>+<br>+ Keyword Arguments:<br>+ version - The version object of the tag to create<br>+ """<br>+<br>+ # Do not create a tag for alpha, beta, or RC releases<br>+ if version.has_modifier(['rc', 'alpha', 'beta']):<br>+ return<br>+<br>+ try:<br>+ super(Testsuite, self).create_tag(str(version))<br>+ except ValueError as e:<br>+ LOGGER.debug("{0} Skipping tag creation.".format(e))<br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/8291">change 8291</a>. To unsubscribe, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/8291"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: repotools </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: merged </div>
<div style="display:none"> Gerrit-Change-Id: I626cc8eb3290503d213047ffa6c3eddad8ef72b4 </div>
<div style="display:none"> Gerrit-Change-Number: 8291 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Kevin Harwell <kharwell@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@digium.com> </div>