Sync scripts with oslo-incubator

Sync all scripts with oslo-incubator (commit fed72f3).

Add scripts also to openstack-common.conf.

Change-Id: I4e595560e002f65d3a6d8e867c17eba04f0a8889
This commit is contained in:
Andreas Jaeger 2014-08-14 11:10:09 +02:00
parent 90fd87fdc9
commit 89fa0160a6
5 changed files with 77 additions and 69 deletions

View File

@ -28,5 +28,14 @@ module=timeutils
module=uuidutils module=uuidutils
module=versionutils module=versionutils
# The list of scripts to copy from oslo common code
script = tools/colorizer.py
script = tools/config/README
script = tools/config/check_uptodate.sh
script = tools/config/generate_sample.sh
script = tools/install_venv.py
script = tools/install_venv_common.py
script = tools/with_venv.sh
# The base module to hold the copy of openstack.common # The base module to hold the copy of openstack.common
base=manila base=manila

View File

@ -1,4 +1,5 @@
#!/usr/bin/env python #!/usr/bin/env python
# Copyright (c) 2013, Nebula, Inc. # Copyright (c) 2013, Nebula, Inc.
# Copyright 2010 United States Government as represented by the # Copyright 2010 United States Government as represented by the
# Administrator of the National Aeronautics and Space Administration. # Administrator of the National Aeronautics and Space Administration.
@ -44,14 +45,15 @@ import heapq
import sys import sys
import unittest import unittest
import six
import subunit import subunit
import testtools import testtools
class _AnsiColorizer(object): class _AnsiColorizer(object):
"""ANSI colorizer that wraps a stream object. """Colorizer allows callers to write text in a particular color.
colorizer is an object that loosely wraps around a stream, allowing A colorizer is an object that loosely wraps around a stream, allowing
callers to write text to the stream in a particular color. callers to write text to the stream in a particular color.
Colorizer classes must implement C{supported()} and C{write(text, color)}. Colorizer classes must implement C{supported()} and C{write(text, color)}.
@ -63,12 +65,10 @@ class _AnsiColorizer(object):
self.stream = stream self.stream = stream
def supported(cls, stream=sys.stdout): def supported(cls, stream=sys.stdout):
"""Check if platform is supported. """Check is the current platform supports coloring terminal output.
A class method that returns True if the current platform supports A class method that returns True if the current platform supports
coloring terminal output using this method. coloring terminal output using this method. Returns False otherwise.
Returns False otherwise.
""" """
if not stream.isatty(): if not stream.isatty():
return False # auto color only on TTYs return False # auto color only on TTYs
@ -118,7 +118,7 @@ class _Win32Colorizer(object):
'yellow': red | green | bold, 'yellow': red | green | bold,
'magenta': red | blue | bold, 'magenta': red | blue | bold,
'cyan': green | blue | bold, 'cyan': green | blue | bold,
'white': red | green | blue | bold 'white': red | green | blue | bold,
} }
def supported(cls, stream=sys.stdout): def supported(cls, stream=sys.stdout):
@ -169,9 +169,9 @@ def get_elapsed_time_color(elapsed_time):
return 'green' return 'green'
class ManilaTestResult(testtools.TestResult): class OpenStackTestResult(testtools.TestResult):
def __init__(self, stream, descriptions, verbosity): def __init__(self, stream, descriptions, verbosity):
super(ManilaTestResult, self).__init__() super(OpenStackTestResult, self).__init__()
self.stream = stream self.stream = stream
self.showAll = verbosity > 1 self.showAll = verbosity > 1
self.num_slow_tests = 10 self.num_slow_tests = 10
@ -225,26 +225,26 @@ class ManilaTestResult(testtools.TestResult):
self.colorizer.write(short_result, color) self.colorizer.write(short_result, color)
def addSuccess(self, test): def addSuccess(self, test):
super(ManilaTestResult, self).addSuccess(test) super(OpenStackTestResult, self).addSuccess(test)
self._addResult(test, 'OK', 'green', '.', True) self._addResult(test, 'OK', 'green', '.', True)
def addFailure(self, test, err): def addFailure(self, test, err):
if test.id() == 'process-returncode': if test.id() == 'process-returncode':
return return
super(ManilaTestResult, self).addFailure(test, err) super(OpenStackTestResult, self).addFailure(test, err)
self._addResult(test, 'FAIL', 'red', 'F', False) self._addResult(test, 'FAIL', 'red', 'F', False)
def addError(self, test, err): def addError(self, test, err):
super(ManilaTestResult, self).addFailure(test, err) super(OpenStackTestResult, self).addFailure(test, err)
self._addResult(test, 'ERROR', 'red', 'E', False) self._addResult(test, 'ERROR', 'red', 'E', False)
def addSkip(self, test, reason=None, details=None): def addSkip(self, test, reason=None, details=None):
super(ManilaTestResult, self).addSkip(test, reason, details) super(OpenStackTestResult, self).addSkip(test, reason, details)
self._addResult(test, 'SKIP', 'blue', 'S', True) self._addResult(test, 'SKIP', 'blue', 'S', True)
def startTest(self, test): def startTest(self, test):
self.start_time = self._now() self.start_time = self._now()
super(ManilaTestResult, self).startTest(test) super(OpenStackTestResult, self).startTest(test)
def writeTestCase(self, cls): def writeTestCase(self, cls):
if not self.results.get(cls): if not self.results.get(cls):
@ -274,7 +274,7 @@ class ManilaTestResult(testtools.TestResult):
self.stopTestRun() self.stopTestRun()
def stopTestRun(self): def stopTestRun(self):
for cls in list(self.results.iterkeys()): for cls in list(six.iterkeys(self.results)):
self.writeTestCase(cls) self.writeTestCase(cls)
self.stream.writeln() self.stream.writeln()
self.writeSlowTests() self.writeSlowTests()
@ -323,7 +323,8 @@ test = subunit.ProtocolTestCase(sys.stdin, passthrough=None)
if sys.version_info[0:2] <= (2, 6): if sys.version_info[0:2] <= (2, 6):
runner = unittest.TextTestRunner(verbosity=2) runner = unittest.TextTestRunner(verbosity=2)
else: else:
runner = unittest.TextTestRunner(verbosity=2, resultclass=ManilaTestResult) runner = unittest.TextTestRunner(verbosity=2,
resultclass=OpenStackTestResult)
if runner.run(test).wasSuccessful(): if runner.run(test).wasSuccessful():
exit_code = 0 exit_code = 0

View File

@ -1,10 +1,8 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2010 United States Government as represented by the # Copyright 2010 United States Government as represented by the
# Administrator of the National Aeronautics and Space Administration. # Administrator of the National Aeronautics and Space Administration.
# All Rights Reserved. # All Rights Reserved.
# #
# Copyright 2010 OpenStack, LLC # Copyright 2010 OpenStack Foundation
# Copyright 2013 IBM Corp. # Copyright 2013 IBM Corp.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may # Licensed under the Apache License, Version 2.0 (the "License"); you may
@ -19,47 +17,47 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
"""Installation script for Manila's development virtualenv."""
from __future__ import print_function
import optparse
import os import os
import subprocess
import sys import sys
import install_venv_common as install_venv import install_venv_common as install_venv # noqa
def print_help(): def print_help(venv, root):
help = """ help = """
Manila development environment setup is complete. OpenStack development environment setup is complete.
Manila development uses virtualenv to track and manage Python dependencies OpenStack development uses virtualenv to track and manage Python
while in development and testing. dependencies while in development and testing.
To activate the Manila virtualenv for the extent of your current shell To activate the OpenStack virtualenv for the extent of your current shell
session you can run: session you can run:
$ source .venv/bin/activate $ source %s/bin/activate
Or, if you prefer, you can run commands in the virtualenv on a case by case Or, if you prefer, you can run commands in the virtualenv on a case by case
basis by running: basis by running:
$ tools/with_venv.sh <your command> $ %s/tools/with_venv.sh <your command>
Also, make test will automatically use the virtualenv. Also, make test will automatically use the virtualenv.
""" """
print(help) print(help % (venv, root))
def main(argv): def main(argv):
root = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) root = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
if os.environ.get('tools_path'):
root = os.environ['tools_path']
venv = os.path.join(root, '.venv') venv = os.path.join(root, '.venv')
if os.environ.get('venv'):
venv = os.environ['venv']
pip_requires = os.path.join(root, 'requirements.txt') pip_requires = os.path.join(root, 'requirements.txt')
test_requires = os.path.join(root, 'test-requirements.txt') test_requires = os.path.join(root, 'test-requirements.txt')
project = 'Manila'
py_version = "python%s.%s" % (sys.version_info[0], sys.version_info[1]) py_version = "python%s.%s" % (sys.version_info[0], sys.version_info[1])
project = 'OpenStack'
install = install_venv.InstallVenv(root, venv, pip_requires, test_requires, install = install_venv.InstallVenv(root, venv, pip_requires, test_requires,
py_version, project) py_version, project)
options = install.parse_args(argv) options = install.parse_args(argv)
@ -67,7 +65,7 @@ def main(argv):
install.check_dependencies() install.check_dependencies()
install.create_virtualenv(no_site_packages=options.no_site_packages) install.create_virtualenv(no_site_packages=options.no_site_packages)
install.install_dependencies() install.install_dependencies()
print_help() print_help(venv, root)
if __name__ == '__main__': if __name__ == '__main__':
main(sys.argv) main(sys.argv)

View File

@ -1,5 +1,3 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2013 OpenStack Foundation # Copyright 2013 OpenStack Foundation
# Copyright 2013 IBM Corp. # Copyright 2013 IBM Corp.
# #
@ -18,12 +16,15 @@
"""Provides methods needed by installation script for OpenStack development """Provides methods needed by installation script for OpenStack development
virtual environments. virtual environments.
Since this script is used to bootstrap a virtualenv from the system's Python
environment, it should be kept strictly compatible with Python 2.6.
Synced in from openstack-common Synced in from openstack-common
""" """
from __future__ import print_function from __future__ import print_function
import argparse import optparse
import os import os
import subprocess import subprocess
import sys import sys
@ -31,12 +32,13 @@ import sys
class InstallVenv(object): class InstallVenv(object):
def __init__(self, root, venv, pip_requires, test_requires, py_version, def __init__(self, root, venv, requirements,
test_requirements, py_version,
project): project):
self.root = root self.root = root
self.venv = venv self.venv = venv
self.pip_requires = pip_requires self.requirements = requirements
self.test_requires = test_requires self.test_requirements = test_requirements
self.py_version = py_version self.py_version = py_version
self.project = project self.project = project
@ -72,11 +74,13 @@ class InstallVenv(object):
def get_distro(self): def get_distro(self):
if (os.path.exists('/etc/fedora-release') or if (os.path.exists('/etc/fedora-release') or
os.path.exists('/etc/redhat-release')): os.path.exists('/etc/redhat-release')):
return Fedora(self.root, self.venv, self.pip_requires, return Fedora(
self.test_requires, self.py_version, self.project) self.root, self.venv, self.requirements,
self.test_requirements, self.py_version, self.project)
else: else:
return Distro(self.root, self.venv, self.pip_requires, return Distro(
self.test_requires, self.py_version, self.project) self.root, self.venv, self.requirements,
self.test_requirements, self.py_version, self.project)
def check_dependencies(self): def check_dependencies(self):
self.get_distro().install_virtualenv() self.get_distro().install_virtualenv()
@ -95,11 +99,6 @@ class InstallVenv(object):
else: else:
self.run_command(['virtualenv', '-q', self.venv]) self.run_command(['virtualenv', '-q', self.venv])
print('done.') print('done.')
print('Installing pip in venv...', end=' ')
if not self.run_command(['tools/with_venv.sh', 'easy_install',
'pip>1.0']).strip():
self.die("Failed to install pip.")
print('done.')
else: else:
print("venv already exists...") print("venv already exists...")
pass pass
@ -111,18 +110,23 @@ class InstallVenv(object):
def install_dependencies(self): def install_dependencies(self):
print('Installing dependencies with pip (this can take a while)...') print('Installing dependencies with pip (this can take a while)...')
self.pip_install('pip>=1.3')
# First things first, make sure our venv has the latest pip and
# setuptools and pbr
self.pip_install('pip>=1.4')
self.pip_install('setuptools') self.pip_install('setuptools')
self.pip_install('-r', self.pip_requires, '-r', self.test_requires) self.pip_install('pbr')
self.pip_install('-r', self.requirements, '-r', self.test_requirements)
def parse_args(self, argv): def parse_args(self, argv):
"""Parses command-line arguments.""" """Parses command-line arguments."""
parser = argparse.ArgumentParser() parser = optparse.OptionParser()
parser.add_argument('-n', '--no-site-packages', parser.add_option('-n', '--no-site-packages',
action='store_true', action='store_true',
help="Do not inherit packages from global Python " help="Do not inherit packages from global Python "
"install") "install.")
return parser.parse_args(argv[1:]) return parser.parse_args(argv[1:])[0]
class Distro(InstallVenv): class Distro(InstallVenv):
@ -158,15 +162,11 @@ class Fedora(Distro):
return self.run_command_with_code(['rpm', '-q', pkg], return self.run_command_with_code(['rpm', '-q', pkg],
check_exit_code=False)[1] == 0 check_exit_code=False)[1] == 0
def yum_install(self, pkg, **kwargs):
print("Attempting to install '%s' via yum" % pkg)
self.run_command(['sudo', 'yum', 'install', '-y', pkg], **kwargs)
def install_virtualenv(self): def install_virtualenv(self):
if self.check_cmd('virtualenv'): if self.check_cmd('virtualenv'):
return return
if not self.check_pkg('python-virtualenv'): if not self.check_pkg('python-virtualenv'):
self.yum_install('python-virtualenv', check_exit_code=False) self.die("Please install 'python-virtualenv'.")
super(Fedora, self).install_virtualenv() super(Fedora, self).install_virtualenv()

View File

@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
tools_path=${tools_path:-$(dirname $0)} TOOLS_PATH=${TOOLS_PATH:-$(dirname $0)}
venv_path=${venv_path:-${tools_path}} VENV_PATH=${VENV_PATH:-${TOOLS_PATH}}
venv_dir=${venv_name:-/../.venv} VENV_DIR=${VENV_NAME:-/../.venv}
TOOLS=${tools_path} TOOLS=${TOOLS_PATH}
VENV=${venv:-${venv_path}/${venv_dir}} VENV=${VENV:-${VENV_PATH}/${VENV_DIR}}
source ${VENV}/bin/activate && "$@" source ${VENV}/bin/activate && "$@"