Use pbr entry_points to setup the cinder scripts

The following patch changes how cinder scripts are
installed and unit tested. This patch moves all the
cinder scripts from bin into cinder/cmd and creates
entry_points for those scripts in setup.cfg. When
cinder is installed, these scripts will be installed
under /usr/local/bin by pbr.

DocImpact: 'host' config option for multiple-storage backends
in cinder.conf is renamed to 'backend_host' in order to avoid
a naming conflict with the 'host' to locate redis
Change-Id: If82cf0c58d765bf79dbf721ca95c10a468940cab
Implements: blueprint unit-test-cases-for-cinder-scripts
This commit is contained in:
Thang Pham 2014-06-20 00:30:36 -04:00
parent 83bc931790
commit 5fb266a0da
14 changed files with 1383 additions and 89 deletions

0
cinder/cmd/__init__.py Normal file
View File

View File

@ -25,12 +25,9 @@ continue attempting to launch the rest of the services.
"""
import eventlet
eventlet.monkey_patch()
import os
import sys
import warnings
@ -38,12 +35,6 @@ warnings.simplefilter('once', DeprecationWarning)
from oslo.config import cfg
possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]),
os.pardir,
os.pardir))
if os.path.exists(os.path.join(possible_topdir, "cinder", "__init__.py")):
sys.path.insert(0, possible_topdir)
from cinder import i18n
i18n.enable_lazy()
@ -59,7 +50,7 @@ from cinder import version
CONF = cfg.CONF
if __name__ == '__main__':
def main():
CONF(sys.argv[1:], project='cinder',
version=version.version_string())
logging.setup("cinder")

View File

@ -20,7 +20,6 @@
import eventlet
eventlet.monkey_patch()
import os
import sys
import warnings
@ -28,12 +27,6 @@ warnings.simplefilter('once', DeprecationWarning)
from oslo.config import cfg
possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]),
os.pardir,
os.pardir))
if os.path.exists(os.path.join(possible_topdir, "cinder", "__init__.py")):
sys.path.insert(0, possible_topdir)
from cinder import i18n
i18n.enable_lazy()
@ -49,7 +42,7 @@ from cinder import version
CONF = cfg.CONF
if __name__ == '__main__':
def main():
CONF(sys.argv[1:], project='cinder',
version=version.version_string())
logging.setup("cinder")

View File

@ -17,8 +17,6 @@
"""Starter script for Cinder Volume Backup."""
import os
import sys
import warnings
@ -29,14 +27,6 @@ from oslo.config import cfg
eventlet.monkey_patch()
# If ../cinder/__init__.py exists, add ../ to Python search path, so that
# it will override what happens to be installed in /usr/(local/)lib/python...
possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]),
os.pardir,
os.pardir))
if os.path.exists(os.path.join(possible_topdir, 'cinder', '__init__.py')):
sys.path.insert(0, possible_topdir)
from cinder import i18n
i18n.enable_lazy()
@ -51,7 +41,7 @@ from cinder import version
CONF = cfg.CONF
if __name__ == '__main__':
def main():
CONF(sys.argv[1:], project='cinder',
version=version.version_string())
logging.setup("cinder")

View File

@ -64,14 +64,6 @@ warnings.simplefilter('once', DeprecationWarning)
from oslo.config import cfg
from oslo import messaging
# If ../cinder/__init__.py exists, add ../ to Python search path, so that
# it will override what happens to be installed in /usr/(local/)lib/python...
POSSIBLE_TOPDIR = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]),
os.pardir,
os.pardir))
if os.path.exists(os.path.join(POSSIBLE_TOPDIR, 'cinder', '__init__.py')):
sys.path.insert(0, POSSIBLE_TOPDIR)
from cinder import i18n
i18n.enable_lazy()
@ -546,6 +538,3 @@ def main():
fn = CONF.category.action_fn
fn_args = fetch_func_args(fn)
fn(*fn_args)
if __name__ == '__main__':
main()

View File

@ -231,6 +231,3 @@ def main(argv=None):
usage()
return 0
if __name__ == '__main__':
sys.exit(main())

View File

@ -17,12 +17,9 @@
"""Starter script for Cinder Scheduler."""
import eventlet
eventlet.monkey_patch()
import os
import sys
import warnings
@ -30,14 +27,6 @@ warnings.simplefilter('once', DeprecationWarning)
from oslo.config import cfg
# If ../cinder/__init__.py exists, add ../ to Python search path, so that
# it will override what happens to be installed in /usr/(local/)lib/python...
possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]),
os.pardir,
os.pardir))
if os.path.exists(os.path.join(possible_topdir, 'cinder', '__init__.py')):
sys.path.insert(0, possible_topdir)
from cinder import i18n
i18n.enable_lazy()
@ -52,7 +41,7 @@ from cinder import version
CONF = cfg.CONF
if __name__ == '__main__':
def main():
CONF(sys.argv[1:], project='cinder',
version=version.version_string())
logging.setup("cinder")

View File

@ -35,14 +35,6 @@ warnings.simplefilter('once', DeprecationWarning)
from oslo.config import cfg
# If ../cinder/__init__.py exists, add ../ to Python search path, so that
# it will override what happens to be installed in /usr/(local/)lib/python...
possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]),
os.pardir,
os.pardir))
if os.path.exists(os.path.join(possible_topdir, 'cinder', '__init__.py')):
sys.path.insert(0, possible_topdir)
from cinder import i18n
i18n.enable_lazy()
@ -54,12 +46,14 @@ from cinder import utils
from cinder import version
host_opt = cfg.StrOpt('host',
help='Backend override of host value.')
deprecated_host_opt = cfg.DeprecatedOpt('host')
host_opt = cfg.StrOpt('backend_host', help='Backend override of host value.',
deprecated_opts=[deprecated_host_opt])
cfg.CONF.register_cli_opt(host_opt)
CONF = cfg.CONF
if __name__ == '__main__':
def main():
CONF(sys.argv[1:], project='cinder',
version=version.version_string())
logging.setup("cinder")
@ -67,8 +61,8 @@ if __name__ == '__main__':
launcher = service.get_launcher()
if CONF.enabled_backends:
for backend in CONF.enabled_backends:
CONF.register_opts([host_opt], group=backend)
backend_host = getattr(CONF, backend).host
CONF.register_opt(host_opt, group=backend)
backend_host = getattr(CONF, backend).backend_host
host = "%s@%s" % (backend_host or CONF.host, backend)
server = service.Service.create(host=host,
service_name=backend,

View File

@ -35,7 +35,6 @@
from __future__ import print_function
from datetime import datetime
import os
import sys
import traceback
import warnings
@ -44,14 +43,6 @@ warnings.simplefilter('once', DeprecationWarning)
from oslo.config import cfg
# If ../cinder/__init__.py exists, add ../ to Python search path, so that
# it will override what happens to be installed in /usr/(local/)lib/python...
POSSIBLE_TOPDIR = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]),
os.pardir,
os.pardir))
if os.path.exists(os.path.join(POSSIBLE_TOPDIR, 'cinder', '__init__.py')):
sys.path.insert(0, POSSIBLE_TOPDIR)
from cinder import i18n
i18n.enable_lazy()
from cinder import context
@ -84,7 +75,7 @@ script_opts = [
CONF.register_cli_opts(script_opts)
if __name__ == '__main__':
def main():
admin_context = context.get_admin_context()
CONF(sys.argv[1:], project='cinder',
version=version.version_string())

View File

@ -32,6 +32,7 @@ import mox
from oslo.concurrency import lockutils
from oslo.config import cfg
from oslo.config import fixture as config_fixture
from oslo.i18n import _lazy
from oslo.messaging import conffixture as messaging_conffixture
from oslo.utils import strutils
from oslo.utils import timeutils
@ -112,6 +113,9 @@ class TestCase(testtools.TestCase):
"""Run before each test method to initialize test environment."""
super(TestCase, self).setUp()
# Unit tests do not need to use lazy gettext
_lazy.enable_lazy(enable=False)
test_timeout = os.environ.get('OS_TEST_TIMEOUT', 0)
try:
test_timeout = int(test_timeout)

1358
cinder/tests/test_cmd.py Executable file

File diff suppressed because it is too large Load Diff

View File

@ -190,7 +190,7 @@ function warn_on_flake8_without_venv {
function run_pep8 {
echo "Running flake8 ..."
warn_on_flake8_without_venv
bash -c "${wrapper} flake8 cinder* bin/*"
bash -c "${wrapper} flake8"
}

View File

@ -24,15 +24,6 @@ setup-hooks =
[files]
packages =
cinder
scripts =
bin/cinder-all
bin/cinder-api
bin/cinder-backup
bin/cinder-manage
bin/cinder-rtstool
bin/cinder-scheduler
bin/cinder-volume
bin/cinder-volume-usage-audit
[entry_points]
cinder.scheduler.filters =
@ -49,7 +40,15 @@ cinder.scheduler.weights =
ChanceWeigher = cinder.scheduler.weights.chance:ChanceWeigher
VolumeNumberWeigher = cinder.scheduler.weights.volume_number:VolumeNumberWeigher
console_scripts =
cinder-all = cinder.cmd.all:main
cinder-api = cinder.cmd.api:main
cinder-backup = cinder.cmd.backup:main
cinder-manage = cinder.cmd.manage:main
cinder-rootwrap = oslo.rootwrap.cmd:main
cinder-rtstool = cinder.cmd.rtstool:main
cinder-scheduler = cinder.cmd.scheduler:main
cinder-volume = cinder.cmd.volume:main
cinder-volume-usage-audit = cinder.cmd.volume_usage_audit:main
# These are for backwards compat with Havana notification_driver configuration values
oslo.messaging.notify.drivers =
cinder.openstack.common.notifier.log_notifier = oslo.messaging.notify._impl_log:LogDriver

View File

@ -23,7 +23,6 @@ downloadcache = ~/cache/pip
[testenv:pep8]
commands =
flake8 {posargs} . cinder/common
flake8 --filename=cinder* bin
# Check that .po and .pot files are valid:
bash -c "find cinder -type f -regex '.*\.pot?' -print0|xargs -0 -n 1 msgfmt --check-format -o /dev/null"