[Asterisk-code-review] lib/python/asterisk/version: Handle Git tags/branches with p... (testsuite[master])

Mark Michelson asteriskteam at digium.com
Mon Jun 15 15:49:08 CDT 2015


Mark Michelson has submitted this change and it was merged.

Change subject: lib/python/asterisk/version: Handle Git tags/branches with prefixes
......................................................................


lib/python/asterisk/version: Handle Git tags/branches with prefixes

Some Git branches and tags are now prefixed with a descriptive modifier,
such as 'certified/'. These branches and tags currently aren't parsed
correctly, and will end up with strange versions assigned to them (such
as having a major version of '0').

This patch updates the version parsing to correctly handle said Git
branches/tags. The unit tests have been updated with examples that
caused the original failures.

Change-Id: Ib79901a8bd49c5c0d63773f8d908f12674702aab
---
M lib/python/asterisk/version.py
1 file changed, 47 insertions(+), 5 deletions(-)

Approvals:
  Mark Michelson: Looks good to me, approved; Verified
  Joshua Colp: Looks good to me, but someone else must approve



diff --git a/lib/python/asterisk/version.py b/lib/python/asterisk/version.py
index 520f5a0..0f33959 100644
--- a/lib/python/asterisk/version.py
+++ b/lib/python/asterisk/version.py
@@ -42,6 +42,9 @@
 def parse_version(version_string):
     """Parse a 'standard' Asterisk version"""
     parsed_numbers = [0, 0, 0]
+    if '/' in version_string:
+        # Strip off any prefix
+        version_string = version_string[version_string.index('/') + 1:]
     version_tokens = version_string.split('.')
     count = 0
     if not version_tokens[0].isdigit():
@@ -187,6 +190,10 @@
                         self.major = parsed_numbers[0]
                         self.minor = parsed_numbers[1]
                         self.patch = parsed_numbers[2]
+                    if not handled and '/' in token and not self.feature and not self.revision:
+                        # Strip off any prefix and update the version numbers
+                        token = token[token.index('/') + 1:]
+                        ((self.major, self.minor, self.patch), handled) = parse_version(token)
                     if not handled and not self.feature:
                         # If a feature returns back a number, its actually the
                         # 'patch' version number (e.g., 1.8.11-cert3)
@@ -197,13 +204,16 @@
                         (self.modifier,
                          self.iteration,
                          handled) = parse_version_modifier(token)
-                    if not handled and not self.revision:
-                        if not self.git:
-                            (self.revision, handled) = parse_revision(token)
+                    if not handled and not self.revision and not self.git:
+                        (self.revision, handled) = parse_revision(token)
+                    if not handled and not self.parent and not self.git:
+                        (self.parent, handled) = parse_parent_branch(token)
+                    if not handled and self.git:
+                        if self.revision:
+                            self.revision = '{0}-{1}'.format(self.revision, token)
                         else:
                             self.revision = token
-                    if not handled and not self.parent:
-                        (self.parent, handled) = parse_parent_branch(token)
+                        self.handled = True
                     if not handled:
                         LOGGER.error("Unable to parse token '%s' in version "
                                      "string '%s'" % (token, raw_version))
@@ -585,6 +595,38 @@
         self.assertEqual(version.name, None)
         self.assertEqual(version.revision, "a987f3")
 
+    def test_git_131_certified_branch(self):
+        """Test a Git checkout from certified/13.1 branch
+
+        Note that in this test, the last known tag is 13.1-cert3, but
+        modifications have been made since then on the branch
+        """
+        version = AsteriskVersion("Asterisk GIT-13-certified/13.1-cert3-1-hsd81h23")
+        self.assertFalse(version.svn)
+        self.assertTrue(version.git)
+        self.assertTrue(version.branch)
+        self.assertEqual(version.major, 13)
+        self.assertEqual(version.minor, 1)
+        self.assertEqual(version.patch, 3)
+        self.assertEqual(version.feature, 'cert')
+        self.assertEqual(version.name, None)
+        self.assertEqual(version.revision, '1-hsd81h23')
+
+    def test_git_131_certified_tag(self):
+        """Test a Git created tag from the certified/13.1 branch"""
+        version = AsteriskVersion("Asterisk certified/13.1-cert3-rc1")
+        self.assertFalse(version.svn)
+        # This is just a tag that happened to be made from git
+        self.assertFalse(version.git)
+        self.assertFalse(version.branch)
+        self.assertEqual(version.major, 13)
+        self.assertEqual(version.minor, 1)
+        self.assertEqual(version.patch, 3)
+        self.assertEqual(version.feature, 'cert')
+        self.assertEqual(version.name, None)
+        self.assertEqual(version.modifier, 'rc')
+        self.assertEqual(version.iteration, 1)
+
     def test_git_master(self):
         """Test a Git checkout from master"""
         version = AsteriskVersion("Asterisk GIT-master-a987f3")

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ib79901a8bd49c5c0d63773f8d908f12674702aab
Gerrit-PatchSet: 1
Gerrit-Project: testsuite
Gerrit-Branch: master
Gerrit-Owner: Matt Jordan <mjordan at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Mark Michelson <mmichelson at digium.com>



More information about the asterisk-code-review mailing list