Convert scripts to entry points
The executable programs used by Glance have historically been scripts in the ./bin directory. This patch converts all of the scripts to entry_points. This change makes these programs python modules. Thus they can be imported and methods in them can be called just like any other module. This will allow the tests to call into these programs directly instead of having to fork out a process. The conf.py file in the doc tree was causing a name collision with the python module cmd. The glance/glance directory was being added to sys.path which made glance.cmd import with the name cmd. This patch also fixes that problem. blueprint: refactoring-better-faster-stronger-functional-tests Change-Id: I67ae14b7403af31a5944befcd2ec27a690e81f15
This commit is contained in:
parent
3acd2a58d2
commit
039f3d8a59
@ -33,7 +33,7 @@ import sys
|
||||
# If extensions (or modules to document with autodoc) are in another directory,
|
||||
# add these directories to sys.path here. If the directory is relative to the
|
||||
# documentation root, use os.path.abspath to make it absolute, like shown here.
|
||||
sys.path = [os.path.abspath('../../glance'),
|
||||
sys.path = [
|
||||
os.path.abspath('../..'),
|
||||
os.path.abspath('../../bin')
|
||||
] + sys.path
|
||||
|
16
glance/cmd/__init__.py
Normal file
16
glance/cmd/__init__.py
Normal file
@ -0,0 +1,16 @@
|
||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||
|
||||
# Copyright 2013 OpenStack LLC.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# 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.
|
@ -52,7 +52,7 @@ def fail(returncode, e):
|
||||
sys.exit(returncode)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
def main():
|
||||
try:
|
||||
config.parse_args()
|
||||
log.setup('glance')
|
@ -55,7 +55,7 @@ from glance.openstack.common import log
|
||||
CONF = cfg.CONF
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
def main():
|
||||
try:
|
||||
config.parse_cache_args()
|
||||
log.setup('glance')
|
@ -473,7 +473,7 @@ def user_confirm(prompt, default=False):
|
||||
return answer.lower() in ("yes", "y")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
def main():
|
||||
usage = """
|
||||
%prog <command> [options] [args]
|
||||
|
@ -47,7 +47,7 @@ import glance.store
|
||||
CONF = cfg.CONF
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
def main():
|
||||
try:
|
||||
config.parse_cache_args()
|
||||
log.setup('glance')
|
@ -47,7 +47,7 @@ from glance.openstack.common import log
|
||||
CONF = cfg.CONF
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
def main():
|
||||
try:
|
||||
config.parse_cache_args()
|
||||
log.setup('glance')
|
@ -70,6 +70,8 @@ And command is one of:
|
||||
|
||||
And CONFPATH is the optional configuration file to use."""
|
||||
|
||||
exitcode = 0
|
||||
|
||||
|
||||
def gated_by(predicate):
|
||||
def wrap(f):
|
||||
@ -281,8 +283,8 @@ def add_command_parsers(subparsers):
|
||||
parser.set_defaults(servers=['glance-' + s for s in ALL_SERVERS])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
exitcode = 0
|
||||
def main():
|
||||
global exitcode
|
||||
|
||||
opts = [
|
||||
cfg.SubCommandOpt('server',
|
@ -130,7 +130,3 @@ def main():
|
||||
CONF.command.func()
|
||||
except exception.GlanceException as e:
|
||||
sys.exit("ERROR: %s" % e)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
@ -45,7 +45,7 @@ from glance.common import wsgi
|
||||
from glance.openstack.common import log
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
def main():
|
||||
try:
|
||||
config.parse_args()
|
||||
log.setup('glance')
|
@ -670,7 +670,7 @@ def lookup_command(parser, command_name):
|
||||
return command
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
def main():
|
||||
usage = """
|
||||
%%prog <command> [options] [args]
|
||||
|
@ -39,12 +39,12 @@ from oslo.config import cfg
|
||||
from glance.common import config
|
||||
from glance.openstack.common import log
|
||||
import glance.store
|
||||
from glance.store import scrubber
|
||||
import glance.store.scrubber
|
||||
|
||||
CONF = cfg.CONF
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
def main():
|
||||
CONF.register_cli_opt(
|
||||
cfg.BoolOpt('daemon',
|
||||
short='D',
|
||||
@ -64,10 +64,10 @@ if __name__ == '__main__':
|
||||
glance.store.create_stores()
|
||||
glance.store.verify_default_store()
|
||||
|
||||
app = scrubber.Scrubber()
|
||||
app = glance.store.scrubber.Scrubber()
|
||||
|
||||
if CONF.daemon:
|
||||
server = scrubber.Daemon(CONF.wakeup_time)
|
||||
server = glance.store.scrubber.Daemon(CONF.wakeup_time)
|
||||
server.start(app)
|
||||
server.wait()
|
||||
else:
|
@ -68,7 +68,7 @@ class Server(object):
|
||||
self.conf_file_name = None
|
||||
self.conf_base = None
|
||||
self.paste_conf_base = None
|
||||
self.server_control = './bin/glance-control'
|
||||
self.server_control = 'glance-control'
|
||||
self.exec_env = None
|
||||
self.deployment_flavor = ''
|
||||
self.show_image_direct_url = False
|
||||
@ -205,7 +205,7 @@ class Server(object):
|
||||
os.system('cp %s %s/tests.sqlite'
|
||||
% (db_location, self.test_dir))
|
||||
else:
|
||||
cmd = ('bin/glance-manage --config-file %s db_sync'
|
||||
cmd = ('glance-manage --config-file %s db_sync'
|
||||
% conf_filepath)
|
||||
execute(cmd, no_venv=self.no_venv, exec_env=self.exec_env,
|
||||
expect_exit=True)
|
||||
@ -696,8 +696,9 @@ class FunctionalTest(test_utils.BaseTestCase):
|
||||
|
||||
def start_servers(self, **kwargs):
|
||||
"""
|
||||
Starts the API and Registry servers (bin/glance-control api start
|
||||
& bin/glance-control registry start) on unused ports.
|
||||
Starts the API and Registry servers (glance-control api start
|
||||
& glance-control registry start) on unused ports. glance-control
|
||||
should be installed into the python path
|
||||
|
||||
Any kwargs passed to this method will override the configuration
|
||||
value in the conf file used in starting the servers.
|
||||
|
@ -70,7 +70,7 @@ class TestBinGlanceCacheManage(functional.FunctionalTest):
|
||||
"""
|
||||
Return True if supplied image ID is cached, False otherwise
|
||||
"""
|
||||
cmd = "bin/glance-cache-manage --port=%d list-cached" % self.api_port
|
||||
cmd = "glance-cache-manage --port=%d list-cached" % self.api_port
|
||||
|
||||
exitcode, out, err = execute(cmd)
|
||||
|
||||
@ -81,7 +81,7 @@ class TestBinGlanceCacheManage(functional.FunctionalTest):
|
||||
"""
|
||||
Return True if supplied image ID is cached, False otherwise
|
||||
"""
|
||||
cmd = "bin/glance-cache-manage --port=%d list-cached" % self.api_port
|
||||
cmd = "glance-cache-manage --port=%d list-cached" % self.api_port
|
||||
|
||||
exitcode, out, err = execute(cmd)
|
||||
|
||||
@ -99,7 +99,7 @@ class TestBinGlanceCacheManage(functional.FunctionalTest):
|
||||
registry_port = self.registry_port
|
||||
|
||||
# Verify decent error message returned
|
||||
cmd = "bin/glance-cache-manage --port=%d list-cached" % api_port
|
||||
cmd = "glance-cache-manage --port=%d list-cached" % api_port
|
||||
|
||||
exitcode, out, err = execute(cmd, raise_error=False)
|
||||
|
||||
@ -120,7 +120,7 @@ class TestBinGlanceCacheManage(functional.FunctionalTest):
|
||||
registry_port = self.registry_port
|
||||
|
||||
# Verify no cached images
|
||||
cmd = "bin/glance-cache-manage --port=%d list-cached" % api_port
|
||||
cmd = "glance-cache-manage --port=%d list-cached" % api_port
|
||||
|
||||
exitcode, out, err = execute(cmd)
|
||||
|
||||
@ -159,7 +159,7 @@ class TestBinGlanceCacheManage(functional.FunctionalTest):
|
||||
registry_port = self.registry_port
|
||||
|
||||
# Verify no cached images
|
||||
cmd = "bin/glance-cache-manage --port=%d list-cached" % api_port
|
||||
cmd = "glance-cache-manage --port=%d list-cached" % api_port
|
||||
|
||||
exitcode, out, err = execute(cmd)
|
||||
|
||||
@ -167,7 +167,7 @@ class TestBinGlanceCacheManage(functional.FunctionalTest):
|
||||
self.assertTrue('No cached images' in out.strip())
|
||||
|
||||
# Verify no queued images
|
||||
cmd = "bin/glance-cache-manage --port=%d list-queued" % api_port
|
||||
cmd = "glance-cache-manage --port=%d list-queued" % api_port
|
||||
|
||||
exitcode, out, err = execute(cmd)
|
||||
|
||||
@ -182,7 +182,7 @@ class TestBinGlanceCacheManage(functional.FunctionalTest):
|
||||
ids[x] = self.add_image("Image%s" % x)
|
||||
|
||||
# Queue second image and then cache it
|
||||
cmd = "bin/glance-cache-manage --port=%d --force queue-image %s" % (
|
||||
cmd = "glance-cache-manage --port=%d --force queue-image %s" % (
|
||||
api_port, ids[1])
|
||||
|
||||
exitcode, out, err = execute(cmd)
|
||||
@ -190,7 +190,7 @@ class TestBinGlanceCacheManage(functional.FunctionalTest):
|
||||
self.assertEqual(0, exitcode)
|
||||
|
||||
# Verify queued second image
|
||||
cmd = "bin/glance-cache-manage --port=%d list-queued" % api_port
|
||||
cmd = "glance-cache-manage --port=%d list-queued" % api_port
|
||||
|
||||
exitcode, out, err = execute(cmd)
|
||||
|
||||
@ -219,7 +219,7 @@ metadata_encryption_key = %(metadata_encryption_key)s
|
||||
log_file = %(log_file)s
|
||||
""" % cache_file_options)
|
||||
|
||||
cmd = ("bin/glance-cache-prefetcher --config-file %s" %
|
||||
cmd = ("glance-cache-prefetcher --config-file %s" %
|
||||
cache_config_filepath)
|
||||
|
||||
exitcode, out, err = execute(cmd)
|
||||
@ -228,7 +228,7 @@ log_file = %(log_file)s
|
||||
self.assertEqual('', out.strip(), out)
|
||||
|
||||
# Verify no queued images
|
||||
cmd = "bin/glance-cache-manage --port=%d list-queued" % api_port
|
||||
cmd = "glance-cache-manage --port=%d list-queued" % api_port
|
||||
|
||||
exitcode, out, err = execute(cmd)
|
||||
|
||||
@ -236,7 +236,7 @@ log_file = %(log_file)s
|
||||
self.assertTrue('No queued images' in out.strip())
|
||||
|
||||
# Verify second image now cached
|
||||
cmd = "bin/glance-cache-manage --port=%d list-cached" % api_port
|
||||
cmd = "glance-cache-manage --port=%d list-cached" % api_port
|
||||
|
||||
exitcode, out, err = execute(cmd)
|
||||
|
||||
@ -244,7 +244,7 @@ log_file = %(log_file)s
|
||||
self.assertTrue(ids[1] in out, 'Image %s was not cached!' % ids[1])
|
||||
|
||||
# Queue third image and then delete it from queue
|
||||
cmd = "bin/glance-cache-manage --port=%d --force queue-image %s" % (
|
||||
cmd = "glance-cache-manage --port=%d --force queue-image %s" % (
|
||||
api_port, ids[2])
|
||||
|
||||
exitcode, out, err = execute(cmd)
|
||||
@ -252,7 +252,7 @@ log_file = %(log_file)s
|
||||
self.assertEqual(0, exitcode)
|
||||
|
||||
# Verify queued third image
|
||||
cmd = "bin/glance-cache-manage --port=%d list-queued" % api_port
|
||||
cmd = "glance-cache-manage --port=%d list-queued" % api_port
|
||||
|
||||
exitcode, out, err = execute(cmd)
|
||||
|
||||
@ -260,7 +260,7 @@ log_file = %(log_file)s
|
||||
self.assertTrue(ids[2] in out, 'Image %s was not queued!' % ids[2])
|
||||
|
||||
# Delete the image from the queue
|
||||
cmd = ("bin/glance-cache-manage --port=%d --force "
|
||||
cmd = ("glance-cache-manage --port=%d --force "
|
||||
"delete-queued-image %s") % (api_port, ids[2])
|
||||
|
||||
exitcode, out, err = execute(cmd)
|
||||
@ -268,7 +268,7 @@ log_file = %(log_file)s
|
||||
self.assertEqual(0, exitcode)
|
||||
|
||||
# Verify no queued images
|
||||
cmd = "bin/glance-cache-manage --port=%d list-queued" % api_port
|
||||
cmd = "glance-cache-manage --port=%d list-queued" % api_port
|
||||
|
||||
exitcode, out, err = execute(cmd)
|
||||
|
||||
@ -277,7 +277,7 @@ log_file = %(log_file)s
|
||||
|
||||
# Queue all images
|
||||
for x in xrange(0, 4):
|
||||
cmd = ("bin/glance-cache-manage --port=%d --force "
|
||||
cmd = ("glance-cache-manage --port=%d --force "
|
||||
"queue-image %s") % (api_port, ids[x])
|
||||
|
||||
exitcode, out, err = execute(cmd)
|
||||
@ -285,7 +285,7 @@ log_file = %(log_file)s
|
||||
self.assertEqual(0, exitcode)
|
||||
|
||||
# Verify queued third image
|
||||
cmd = "bin/glance-cache-manage --port=%d list-queued" % api_port
|
||||
cmd = "glance-cache-manage --port=%d list-queued" % api_port
|
||||
|
||||
exitcode, out, err = execute(cmd)
|
||||
|
||||
@ -293,7 +293,7 @@ log_file = %(log_file)s
|
||||
self.assertTrue('Found 3 queued images' in out)
|
||||
|
||||
# Delete the image from the queue
|
||||
cmd = ("bin/glance-cache-manage --port=%d --force "
|
||||
cmd = ("glance-cache-manage --port=%d --force "
|
||||
"delete-all-queued-images") % (api_port)
|
||||
|
||||
exitcode, out, err = execute(cmd)
|
||||
@ -301,7 +301,7 @@ log_file = %(log_file)s
|
||||
self.assertEqual(0, exitcode)
|
||||
|
||||
# Verify nothing in queue anymore
|
||||
cmd = "bin/glance-cache-manage --port=%d list-queued" % api_port
|
||||
cmd = "glance-cache-manage --port=%d list-queued" % api_port
|
||||
|
||||
exitcode, out, err = execute(cmd)
|
||||
|
||||
|
@ -535,7 +535,7 @@ log_file = %(log_file)s
|
||||
|
||||
self.verify_no_cached_images()
|
||||
|
||||
cmd = ("bin/glance-cache-prefetcher --config-file %s" %
|
||||
cmd = ("glance-cache-prefetcher --config-file %s" %
|
||||
cache_config_filepath)
|
||||
|
||||
exitcode, out, err = execute(cmd)
|
||||
|
@ -43,7 +43,7 @@ class TestGlanceManage(functional.FunctionalTest):
|
||||
conf_file.write(self.connection)
|
||||
conf_file.flush()
|
||||
|
||||
cmd = ('bin/glance-manage --config-file %s db_sync' %
|
||||
cmd = ('glance-manage --config-file %s db_sync' %
|
||||
self.conf_filepath)
|
||||
execute(cmd, raise_error=True)
|
||||
|
||||
|
@ -120,7 +120,7 @@ class TestScrubber(functional.FunctionalTest):
|
||||
time.sleep(self.api_server.scrub_time)
|
||||
|
||||
# scrub images and make sure they get deleted
|
||||
cmd = ("bin/glance-scrubber --config-file %s" %
|
||||
cmd = ("glance-scrubber --config-file %s" %
|
||||
self.scrubber_daemon.conf_file_name)
|
||||
exitcode, out, err = execute(cmd, raise_error=False)
|
||||
self.assertEqual(0, exitcode)
|
||||
@ -180,7 +180,7 @@ class TestScrubber(functional.FunctionalTest):
|
||||
time.sleep(self.api_server.scrub_time)
|
||||
|
||||
# call the scrubber to scrub images
|
||||
cmd = ("bin/glance-scrubber --config-file %s" %
|
||||
cmd = ("glance-scrubber --config-file %s" %
|
||||
self.scrubber_daemon.conf_file_name)
|
||||
exitcode, out, err = execute(cmd, raise_error=False)
|
||||
self.assertEqual(0, exitcode)
|
||||
@ -318,7 +318,7 @@ class TestScrubber(functional.FunctionalTest):
|
||||
time.sleep(self.api_server.scrub_time)
|
||||
|
||||
# run the scrubber app, and ensure it doesn't fall over
|
||||
cmd = ("bin/glance-scrubber --config-file %s" %
|
||||
cmd = ("glance-scrubber --config-file %s" %
|
||||
self.scrubber_daemon.conf_file_name)
|
||||
exitcode, out, err = execute(cmd, raise_error=False)
|
||||
self.assertEqual(0, exitcode)
|
||||
|
@ -15,7 +15,6 @@
|
||||
# under the License.
|
||||
|
||||
import copy
|
||||
import imp
|
||||
import json
|
||||
import os
|
||||
import StringIO
|
||||
@ -26,19 +25,7 @@ import uuid
|
||||
import fixtures
|
||||
|
||||
from glance.tests import utils as test_utils
|
||||
|
||||
|
||||
TOPDIR = os.path.normpath(os.path.join(
|
||||
os.path.dirname(os.path.abspath(__file__)),
|
||||
os.pardir,
|
||||
os.pardir,
|
||||
os.pardir))
|
||||
GLANCE_REPLICATOR_PATH = os.path.join(TOPDIR, 'bin', 'glance-replicator')
|
||||
|
||||
sys.dont_write_bytecode = True
|
||||
glance_replicator = imp.load_source('glance_replicator',
|
||||
GLANCE_REPLICATOR_PATH)
|
||||
sys.dont_write_bytecode = False
|
||||
from glance.cmd import replicator as glance_replicator
|
||||
|
||||
|
||||
IMG_RESPONSE_ACTIVE = {
|
||||
|
@ -71,7 +71,7 @@ function run_pep8 {
|
||||
PEP8_EXCLUDE=".venv,.tox,dist,doc,openstack"
|
||||
PEP8_OPTIONS="--exclude=$PEP8_EXCLUDE --repeat"
|
||||
PEP8_IGNORE="--ignore=E125,E126,E711,E712"
|
||||
PEP8_INCLUDE=". bin/*"
|
||||
PEP8_INCLUDE="."
|
||||
|
||||
${wrapper} pep8 $PEP8_OPTIONS $PEP8_INCLUDE $PEP8_IGNORE
|
||||
}
|
||||
|
21
setup.py
21
setup.py
@ -45,14 +45,15 @@ setuptools.setup(
|
||||
'Environment :: No Input/Output (Daemon)',
|
||||
'Environment :: OpenStack',
|
||||
],
|
||||
scripts=['bin/glance-api',
|
||||
'bin/glance-cache-prefetcher',
|
||||
'bin/glance-cache-pruner',
|
||||
'bin/glance-cache-manage',
|
||||
'bin/glance-cache-cleaner',
|
||||
'bin/glance-control',
|
||||
'bin/glance-manage',
|
||||
'bin/glance-registry',
|
||||
'bin/glance-replicator',
|
||||
'bin/glance-scrubber'],
|
||||
entry_points={'console_scripts':
|
||||
['glance-api=glance.cmd.api:main',
|
||||
'glance-cache-prefetcher=glance.cmd.cache_prefetcher:main',
|
||||
'glance-cache-pruner = glance.cmd.cache_pruner:main',
|
||||
'glance-cache-manage = glance.cmd.cache_manage:main',
|
||||
'glance-cache-cleaner = glance.cmd.cache_cleaner:main',
|
||||
'glance-control = glance.cmd.control:main',
|
||||
'glance-manage = glance.cmd.manage:main',
|
||||
'glance-registry = glance.cmd.registry:main',
|
||||
'glance-replicator = glance.cmd.replicator:main',
|
||||
'glance-scrubber = glance.cmd.scrubber:main']},
|
||||
py_modules=[])
|
||||
|
1
tox.ini
1
tox.ini
@ -19,7 +19,6 @@ downloadcache = ~/cache/pip
|
||||
[testenv:pep8]
|
||||
commands =
|
||||
pep8 --ignore=E125,E126,E711,E712 --repeat --show-source --exclude=.venv,.tox,dist,doc,openstack .
|
||||
pep8 --ignore=E125,E126,E711,E712 --repeat --show-source --filename=glance* bin
|
||||
|
||||
[testenv:cover]
|
||||
setenv = NOSE_WITH_COVERAGE=1
|
||||
|
Loading…
x
Reference in New Issue
Block a user