Update to latest oslo-version code.

In prep for tag-based versioning, update to latest oslo-version code.

Change-Id: Ic5046006919e20247481fa1ddbde2dfd456b188a
This commit is contained in:
Monty Taylor 2013-02-03 11:33:33 +11:00
parent 5d33cf07c7
commit b390454b6d
9 changed files with 107 additions and 98 deletions

View File

@ -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:

View 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:

View File

@ -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

View 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()

View File

@ -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())

View File

@ -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

View 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.

View 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

View File

@ -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',