From b390454b6d26b5dc4b26e115aecbcfa0bcca2bdc Mon Sep 17 00:00:00 2001 From: Monty Taylor Date: Sun, 3 Feb 2013 11:33:33 +1100 Subject: [PATCH] Update to latest oslo-version code. In prep for tag-based versioning, update to latest oslo-version code. Change-Id: Ic5046006919e20247481fa1ddbde2dfd456b188a --- bin/cinder-manage | 10 ++-- cinder/openstack/common/setup.py | 2 +- cinder/openstack/common/version.py | 86 ++++++++++++++++++++++++++++++ cinder/service.py | 6 +-- cinder/tests/test_versions.py | 59 -------------------- cinder/version.py | 27 +++------- doc/source/conf.py | 7 ++- openstack-common.conf | 2 +- setup.py | 6 +-- 9 files changed, 107 insertions(+), 98 deletions(-) create mode 100644 cinder/openstack/common/version.py delete mode 100644 cinder/tests/test_versions.py diff --git a/bin/cinder-manage b/bin/cinder-manage index 671e2863384..fd98d33821e 100755 --- a/bin/cinder-manage +++ b/bin/cinder-manage @@ -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 []" print _("Available categories:") for category in CATEGORIES: diff --git a/cinder/openstack/common/setup.py b/cinder/openstack/common/setup.py index cc8b99e3a8d..fb187fff465 100644 --- a/cinder/openstack/common/setup.py +++ b/cinder/openstack/common/setup.py @@ -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 index 00000000000..53e0c68a200 --- /dev/null +++ b/cinder/openstack/common/version.py @@ -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 diff --git a/cinder/service.py b/cinder/service.py index 8cbe0c252cf..7eebc37e4af 100644 --- a/cinder/service.py +++ b/cinder/service.py @@ -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 index 16aca269f44..00000000000 --- a/cinder/tests/test_versions.py +++ /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()) diff --git a/cinder/version.py b/cinder/version.py index 3f50863fccc..ef2caf1b801 100644 --- a/cinder/version.py +++ b/cinder/version.py @@ -14,25 +14,12 @@ # 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 diff --git a/doc/source/conf.py b/doc/source/conf.py index 7436039e1a3..7fb1a7c83a4 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -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. diff --git a/openstack-common.conf b/openstack-common.conf index f00a3a9798e..12d9bafb511 100644 --- a/openstack-common.conf +++ b/openstack-common.conf @@ -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 diff --git a/setup.py b/setup.py index 6b7cccf3a0c..2770d554fb0 100644 --- 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',