]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Update to latest oslo-version code.
authorMonty Taylor <mordred@inaugust.com>
Sun, 3 Feb 2013 00:33:33 +0000 (11:33 +1100)
committerMonty Taylor <mordred@inaugust.com>
Thu, 7 Feb 2013 08:29:27 +0000 (02:29 -0600)
In prep for tag-based versioning, update to latest oslo-version code.

Change-Id: Ic5046006919e20247481fa1ddbde2dfd456b188a

bin/cinder-manage
cinder/openstack/common/setup.py
cinder/openstack/common/version.py [new file with mode: 0644]
cinder/service.py
cinder/tests/test_versions.py [deleted file]
cinder/version.py
doc/source/conf.py
openstack-common.conf
setup.py

index 671e2863384c25b26d376ab0e12fc91ca42f018d..fd98d33821eff77f6206aa0b976f8af95ea32750 100755 (executable)
@@ -226,10 +226,7 @@ class VersionCommands(object):
         pass
 
     def list(self):
-        print(
-            _("%(version)s (%(vcs)s)") %
-            {'version': version.version_string(),
-             'vcs': version.version_string_with_vcs()})
+        print(version.version_string())
 
     def __call__(self):
         self.list()
@@ -723,9 +720,8 @@ def main():
     FLAGS.register_cli_opt(category_opt)
     script_name = sys.argv[0]
     if len(sys.argv) < 2:
-        print _("\nOpenStack Cinder version: %(version)s (%(vcs)s)\n") %\
-            {'version': version.version_string(),
-             'vcs': version.version_string_with_vcs()}
+        print(_("\nOpenStack Cinder version: %(version)s\n") %
+              {'version': version.version_string()})
         print script_name + " category action [<args>]"
         print _("Available categories:")
         for category in CATEGORIES:
index cc8b99e3a8d0551526e39c178748915755514e4b..fb187fff465424ee7b677c8ed86c4aa01bf4eec8 100644 (file)
@@ -282,7 +282,7 @@ def get_version_from_git(pre_version):
     if os.path.isdir('.git'):
         if pre_version:
             try:
-                return  _run_shell_command(
+                return _run_shell_command(
                     "git describe --exact-match",
                     throw_on_error=True).replace('-', '.')
             except Exception:
diff --git a/cinder/openstack/common/version.py b/cinder/openstack/common/version.py
new file mode 100644 (file)
index 0000000..53e0c68
--- /dev/null
@@ -0,0 +1,86 @@
+
+#    Copyright 2012 OpenStack LLC
+#    Copyright 2012-2013 Hewlett-Packard Development Company, L.P.
+#
+#    Licensed under the Apache License, Version 2.0 (the "License"); you may
+#    not use this file except in compliance with the License. You may obtain
+#    a copy of the License at
+#
+#         http://www.apache.org/licenses/LICENSE-2.0
+#
+#    Unless required by applicable law or agreed to in writing, software
+#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+#    License for the specific language governing permissions and limitations
+#    under the License.
+
+"""
+Utilities for consuming the version from pkg_resources.
+"""
+
+import pkg_resources
+
+
+class VersionInfo(object):
+
+    def __init__(self, package):
+        """Object that understands versioning for a package
+        :param package: name of the python package, such as glance, or
+                        python-glanceclient
+        """
+        self.package = package
+        self.release = None
+        self.version = None
+        self._cached_version = None
+
+    def _get_version_from_pkg_resources(self):
+        """Get the version of the package from the pkg_resources record
+        associated with the package."""
+        try:
+            requirement = pkg_resources.Requirement.parse(self.package)
+            provider = pkg_resources.get_provider(requirement)
+            return provider.version
+        except pkg_resources.DistributionNotFound:
+            # The most likely cause for this is running tests in a tree with
+            # produced from a tarball where the package itself has not been
+            # installed into anything. Check for a PKG-INFO file.
+            from cinder.openstack.common import setup
+            return setup.get_version_from_pkg_info(self.package)
+
+    def release_string(self):
+        """Return the full version of the package including suffixes indicating
+        VCS status.
+        """
+        if self.release is None:
+            self.release = self._get_version_from_pkg_resources()
+
+        return self.release
+
+    def version_string(self):
+        """Return the short version minus any alpha/beta tags."""
+        if self.version is None:
+            parts = []
+            for part in self.release_string().split('.'):
+                if part[0].isdigit():
+                    parts.append(part)
+                else:
+                    break
+            self.version = ".".join(parts)
+
+        return self.version
+
+    # Compatibility functions
+    canonical_version_string = version_string
+    version_string_with_vcs = release_string
+
+    def cached_version_string(self, prefix=""):
+        """Generate an object which will expand in a string context to
+        the results of version_string(). We do this so that don't
+        call into pkg_resources every time we start up a program when
+        passing version information into the CONF constructor, but
+        rather only do the calculation when and if a version is requested
+        """
+        if not self._cached_version:
+            self._cached_version = "%s%s" % (prefix,
+                                             self.version_string())
+        return self._cached_version
index 8cbe0c252cfc2aaef20c2a4c0ea71847bc208116..7eebc37e4af1f197b694b76341da9817b8b96b23 100644 (file)
@@ -152,9 +152,9 @@ class Service(object):
         self.timers = []
 
     def start(self):
-        vcs_string = version.version_string_with_vcs()
-        LOG.audit(_('Starting %(topic)s node (version %(vcs_string)s)'),
-                  {'topic': self.topic, 'vcs_string': vcs_string})
+        version_string = version.version_string()
+        LOG.audit(_('Starting %(topic)s node (version %(version_string)s)'),
+                  {'topic': self.topic, 'version_string': version_string})
         self.manager.init_host()
         self.model_disconnected = False
         ctxt = context.get_admin_context()
diff --git a/cinder/tests/test_versions.py b/cinder/tests/test_versions.py
deleted file mode 100644 (file)
index 16aca26..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
-#    Copyright 2011 Ken Pepple
-#
-#    Licensed under the Apache License, Version 2.0 (the "License"); you may
-#    not use this file except in compliance with the License. You may obtain
-#    a copy of the License at
-#
-#         http://www.apache.org/licenses/LICENSE-2.0
-#
-#    Unless required by applicable law or agreed to in writing, software
-#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-#    License for the specific language governing permissions and limitations
-#    under the License.
-
-
-from cinder import test
-from cinder import version
-
-
-class VersionTestCase(test.TestCase):
-    """Test cases for Versions code."""
-    def setUp(self):
-        """Setup test with unchanging values."""
-        super(VersionTestCase, self).setUp()
-        self.version = version
-        self.version.FINAL = False
-        self.version.CINDER_VERSION = ['2012', '10']
-        self.version.YEAR, self.version.COUNT = self.version.CINDER_VERSION
-        self.version.version_info = {'branch_nick': u'LOCALBRANCH',
-                                     'revision_id': 'LOCALREVISION',
-                                     'revno': 0}
-
-    def test_version_string_is_good(self):
-        """Ensure version string works."""
-        self.assertEqual("2012.10-dev", self.version.version_string())
-
-    def test_canonical_version_string_is_good(self):
-        """Ensure canonical version works."""
-        self.assertEqual("2012.10", self.version.canonical_version_string())
-
-    def test_final_version_strings_are_identical(self):
-        """Ensure final version strings match only at release."""
-        self.assertNotEqual(self.version.canonical_version_string(),
-                            self.version.version_string())
-        self.version.FINAL = True
-        self.assertEqual(self.version.canonical_version_string(),
-                         self.version.version_string())
-
-    def test_vcs_version_string_is_good(self):
-        """Ensure uninstalled code generates local."""
-        self.assertEqual("LOCALBRANCH:LOCALREVISION",
-                         self.version.vcs_version_string())
-
-    def test_version_string_with_vcs_is_good(self):
-        """Ensure uninstalled code get version string."""
-        self.assertEqual("2012.10-LOCALBRANCH:LOCALREVISION",
-                         self.version.version_string_with_vcs())
index 3f50863fccc8e8da0869b86ebb83f58325dcc1b5..ef2caf1b8012b52191b983322ad252cab631cc66 100644 (file)
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
-CINDER_VERSION = ['2013', '1', None]
-YEAR, COUNT, REVISION = CINDER_VERSION
-FINAL = False   # This becomes true at Release Candidate time
+from cinder.openstack.common import version as common_version
 
+CINDER_VENDOR = "OpenStack Foundation"
+CINDER_PRODUCT = "OpenStack Cinder"
+CINDER_PACKAGE = None  # OS distro package version suffix
 
-def canonical_version_string():
-    return '.'.join(filter(None, CINDER_VERSION))
-
-
-def version_string():
-    if FINAL:
-        return canonical_version_string()
-    else:
-        return '%s-dev' % (canonical_version_string(),)
-
-
-def vcs_version_string():
-    return 'LOCALBRANCH:LOCALREVISION'
-
-
-def version_string_with_vcs():
-    return '%s-%s' % (canonical_version_string(), vcs_version_string())
+loaded = False
+version_info = common_version.VersionInfo('cinder')
+version_string = version_info.version_string
index 7436039e1a3c931adde0216b97360e276256b9d0..7fb1a7c83a41a698e5abe566dd8c7abd153831b2 100644 (file)
@@ -71,12 +71,11 @@ copyright = u'2010-present, OpenStack, LLC'
 # |version| and |release|, also used in various other places throughout the
 # built documents.
 #
-from cinder import version as cinder_version
-#import cinder.version
+from cinder.version import version_info
 # The full version, including alpha/beta/rc tags.
-release = cinder_version.version_string()
+release = version_info.release_string()
 # The short X.Y version.
-version = cinder_version.canonical_version_string()
+version = version_info.version_string()
 
 # The language for content autogenerated by Sphinx. Refer to documentation
 # for a list of supported languages.
index f00a3a9798e979840ac400f60d3a6438c47d453f..12d9bafb5117f1c9ff3bf54b0cbb1329d315355f 100644 (file)
@@ -1,7 +1,7 @@
 [DEFAULT]
 
 # The list of modules to copy from openstack-common
-modules=cfg,exception,excutils,gettextutils,importutils,iniparser,jsonutils,local,rootwrap,rpc,timeutils,log,setup,notifier,context,network_utils,policy,uuidutils,lockutils,fileutils,gettextutils,scheduler,scheduler.filters,scheduler.weights,install_venv_common,flakes
+modules=cfg,exception,excutils,gettextutils,importutils,iniparser,jsonutils,local,rootwrap,rpc,timeutils,log,setup,notifier,context,network_utils,policy,uuidutils,lockutils,fileutils,gettextutils,scheduler,scheduler.filters,scheduler.weights,install_venv_common,flakes,version
 
 # The base module to hold the copy of openstack.common
 base=cinder
index 6b7cccf3a0cce8e86b4b96f31d6cba89973f6506..2770d554fb01513ca35fcbbd8305945059beee87 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -19,9 +19,9 @@
 import setuptools
 
 from cinder.openstack.common import setup as common_setup
-from cinder import version
 
 requires = common_setup.parse_requirements()
+project = 'cinder'
 
 filters = [
     "AvailabilityZoneFilter = "
@@ -41,8 +41,8 @@ weights = [
 ]
 
 setuptools.setup(
-    name='cinder',
-    version=version.canonical_version_string(),
+    name=project,
+    version=common_setup.get_version(project, '2013.1'),
     description='block storage service',
     author='OpenStack',
     author_email='cinder@lists.launchpad.net',