Fixup pyflakes, pep8 and broken things

Change-Id: Ia1878234632ef57cf5e74072d42ff8aa526583ff
This commit is contained in:
Endre Karlson 2012-11-16 11:44:57 +01:00
parent 29c4dde737
commit 0e9834636b
22 changed files with 88 additions and 56 deletions

View File

@ -25,13 +25,13 @@ from bufunfa.api import service as api_service
eventlet.monkey_patch()
config_files = cfg.find_config_files(project='bufunfa',
prog='bufunfa-api')
prog='bufunfa-api')
if os.path.exists('./etc/bufunfa-api.conf'):
config_files.append('./etc/bufunfa-api.conf')
cfg.CONF(sys.argv[1:], project='bufunfa', prog='bufunfa-api',
default_config_files=config_files)
default_config_files=config_files)
logging.setup('bufunfa')

View File

@ -16,7 +16,7 @@ if os.path.exists('./etc/bufunfa-central.conf'):
config_files.append('./etc/bufunfa-central.conf')
cfg.CONF(sys.argv[1:], project="bufunfa", prog="bufunfa-central",
default_config_files=config_files)
default_config_files=config_files)
log.setup("bufunfa")

View File

@ -25,13 +25,14 @@ from bufunfa.recorder.service import Service
eventlet.monkey_patch()
config_files = cfg.find_config_files(project="bufunfa", prog="bufunfa-recorder-sync")
config_files = cfg.find_config_files(project="bufunfa",
prog="bufunfa-recorder-sync")
if os.path.exists('./etc/bufunfa-recorder.conf'):
config_files.append('./etc/bufunfa-recorder.conf')
cfg.CONF(sys.argv[1:], project="bufunfa", prog="bufunfa-recorder-sync",
default_config_files=config_files)
default_config_files=config_files)
log.setup('bufunfa')

View File

@ -17,7 +17,6 @@
import flask
from bufunfa.openstack.common import cfg
from bufunfa.openstack.common import jsonutils
from bufunfa.api.v1 import blueprint as bp_v1
# Replace the json module used by flask with the one from

View File

@ -21,6 +21,9 @@ from bufunfa.openstack.common import cfg
from bufunfa import utils
LOG = logging.getLogger(__name__)
class Service(wsgi.Service):
def __init__(self, backlog=128, threads=1000):
super(Service, self).__init__(threads)
@ -29,8 +32,7 @@ class Service(wsgi.Service):
self.port = cfg.CONF.api_port
self.backlog = backlog
config_path = cfg.CONF.api_paste_config
config_path = utils.find_config(config_path)
config_path = utils.find_config(cfg.CONF.api_paste_config)
self.application = deploy.loadapp("config:%s" % config_path,
name='osapi_billing')

View File

@ -13,8 +13,6 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import datetime
import flask
from bufunfa.openstack.common import log

View File

@ -110,7 +110,7 @@ def update_account(context, account_id, values):
return RPC.call(context, msg)
def delete_account(context, rate_id):
def delete_account(context, account_id):
msg = {
"method": "delete_account",
"args": {

View File

@ -20,7 +20,6 @@ from bufunfa.openstack.common import timeutils
from bufunfa.openstack.common.rpc import service as rpc_service
from bufunfa import exceptions
from bufunfa import storage
from bufunfa import utils
LOG = log.getLogger(__name__)

View File

@ -34,7 +34,7 @@ class RecordEngine(Plugin):
def get_opts(cls):
return [
cfg.IntOpt('poll_age', default=86400,
help='How far back to pull data from the source service'),
help='How far back to pull data from'),
cfg.BoolOpt('record_audit_logging', default=False,
help='Logs individual records pr get_records()')]

View File

@ -14,15 +14,13 @@
# License for the specific language governing permissions and limitations
# under the License.
# NOTE(zykes): Copied verbatim from ceilometerclient
from datetime import datetime, timedelta
from datetime import datetime
import ceilometerclient
from bufunfa.openstack.common import cfg
from bufunfa.openstack.common import log
from bufunfa.openstack.common import timeutils
from bufunfa.openstack.common.rpc.common import RemoteError
from bufunfa import exceptions
from bufunfa.central import api as central_api
from bufunfa.recorder.openstack import OpenstackEngine

View File

@ -47,12 +47,10 @@ SQL_OPTS = [
class SQLAlchemyStorage(base.StorageEngine):
__plugin_name__ = 'sqlalchemy'
OPTIONS = []
@classmethod
def get_opts(cls):
opts = super(SQLAlchemyStorage, cls).get_opts()
opts.extend(cls.OPTIONS + SQL_OPTS)
opts.extend(SQL_OPTS)
return opts
def get_connection(self, conf):

View File

@ -14,21 +14,18 @@
# License for the specific language governing permissions and limitations
# under the License.
# NOTE(zykes): Copied verbatim from Moniker
import copy
from uuid import uuid4
from urlparse import urlparse
from sqlalchemy import Column, DateTime, Unicode, Float, Integer, ForeignKey
from sqlalchemy import Column, DateTime, Unicode, Float, ForeignKey
from sqlalchemy.exc import IntegrityError
from sqlalchemy.orm import relationship, backref, object_mapper
from sqlalchemy.orm import relationship, object_mapper
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.ext.hybrid import hybrid_property
from bufunfa import exceptions
import bufunfa.openstack.common.cfg as cfg
from bufunfa.openstack.common import log
from bufunfa.openstack.common import timeutils
from bufunfa.storage.impl_sqlalchemy.session import get_session
from bufunfa.storage.impl_sqlalchemy.types import JSONBlob, UUID
LOG = log.getLogger(__name__)

View File

@ -26,6 +26,7 @@ from sqlalchemy.pool import NullPool, StaticPool
from bufunfa.openstack.common import cfg
from bufunfa.openstack.common import log as logging
from bufunfa.openstack.common.gettextutils import _
LOG = logging.getLogger(__name__)
@ -181,3 +182,44 @@ def get_maker(engine, autocommit=True, expire_on_commit=False, autoflush=True):
autocommit=autocommit,
autoflush=autoflush,
expire_on_commit=expire_on_commit)
def debug_mysql_do_query():
"""Return a debug version of MySQLdb.cursors._do_query"""
import MySQLdb.cursors
import traceback
old_mysql_do_query = MySQLdb.cursors.BaseCursor._do_query
def _do_query(self, q):
stack = ''
for file, line, method, function in traceback.extract_stack():
# exclude various common things from trace
if file.endswith('session.py') and method == '_do_query':
continue
if file.endswith('api.py') and method == 'wrapper':
continue
if file.endswith('utils.py') and method == '_inner':
continue
if file.endswith('exception.py') and method == '_wrap':
continue
# nova/db/api is just a wrapper around nova/db/sqlalchemy/api
if file.endswith('nova/db/api.py'):
continue
# only trace inside nova
index = file.rfind('nova')
if index == -1:
continue
stack += "File:%s:%s Method:%s() Line:%s | " \
% (file[index:], line, method, function)
# strip trailing " | " from stack
if stack:
stack = stack[:-3]
qq = "%s /* %s */" % (q, stack)
else:
qq = q
old_mysql_do_query(self, qq)
# return the new _do_query method
return _do_query

View File

@ -16,9 +16,9 @@
# License for the specific language governing permissions and limitations
# under the License.
# NOTE(zykes): Copied UUID from Moniker
from sqlalchemy.types import TypeDecorator, CHAR, VARCHAR, Text
from sqlalchemy.types import TypeDecorator, CHAR, Text
from sqlalchemy.dialects.postgresql import UUID as pgUUID
import simplejson as json
from bufunfa.openstack.common import jsonutils as json
import uuid

View File

@ -23,6 +23,7 @@
import sqlalchemy
from bufunfa.openstack.common import log as logging
from bufunfa.openstack.common.gettextutils import _
from bufunfa import exceptions

View File

@ -15,6 +15,7 @@
# under the License.
from bufunfa.central import service as central_service
from bufunfa.tests import TestCase
from bufunfa.api import service as api_service
class CentralTestCase(TestCase):
@ -22,3 +23,6 @@ class CentralTestCase(TestCase):
def get_central_service(self):
return central_service.Service()
def get_api_service(self):
return api_service.Service()

View File

@ -50,7 +50,6 @@ class ServiceTest(CentralTestCase):
def setUp(self):
super(ServiceTest, self).setUp()
self.config(rpc_backend='bufunfa.openstack.common.rpc.impl_fake')
self.service = self.get_central_service()
self.admin_context = self.get_admin_context()

View File

@ -14,7 +14,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import copy
from nose import SkipTest
from bufunfa.openstack.common import cfg
from bufunfa.openstack.common import log as logging
from bufunfa.tests import TestCase

View File

@ -1,14 +0,0 @@
#!/bin/sh
# Wrap tox to force it to enable global site-packages until
# https://bitbucket.org/hpk42/tox/issue/32 is released.
set -x
rm -rf cover
if [ ! -z "$VIRTUAL_ENV" ]
then
rm -f $VIRTUAL_ENV/lib/python*/no-global-site-packages.txt
fi
nosetests "$@"

View File

@ -1,14 +1,10 @@
Flask==0.9
eventlet
jsonschema>=0.6
sqlalchemy>=0.7
PasteDeploy
stevedore
# From OpenStack Common
routes>=1.12.3
iso8601>=0.1.4
WebOb>=1.0.8
# Needed for Keystone Middleware
https://launchpad.net/keystone/folsom/2012.2/+download/keystone-2012.2.tar.gz#egg=keystone
python-keystoneclient

View File

@ -1,9 +1,7 @@
unittest2
nose
nosexcover
openstack.nose_plugin
nosehtmloutput
mox
coverage
pep8==1.3.3
sphinx
sphinxcontrib-httpdomain

27
tox.ini
View File

@ -1,8 +1,13 @@
[tox]
envlist = py26,py27,pep8
envlist = py26,py27,pep8,pyflakes
minversion = 1.4.0
[tox:jenkins]
downloadcache = ~/cache/pip
[testenv]
deps = -r{toxinidir}/tools/test-requires
-r{toxinidir}/tools/pip-options
-r{toxinidir}/tools/pip-requires
setenv = VIRTUAL_ENV={envdir}
NOSE_WITH_OPENSTACK=1
@ -10,15 +15,25 @@ setenv = VIRTUAL_ENV={envdir}
NOSE_OPENSTACK_RED=0.05
NOSE_OPENSTACK_YELLOW=0.025
NOSE_OPENSTACK_SHOW_ELAPSED=1
commands = {toxinidir}/run_tests.sh --no-path-adjustment []
sitepackages = True
commands = nosetests {posargs}
sitepackages = False
[testenv:cover]
commands = {toxinidir}/run_tests.sh --no-path-adjustment --with-coverage --cover-erase --cover-package=bufunfa --cover-inclusive []
deps = {[testenv]deps}
coverage
nosexcover
setenv = {[testenv]setenv}
NOSE_WITH_COVERAGE=1
[testenv:pep8]
deps = pep8==1.1
commands = pep8 --repeat --show-source bufunfa setup.py bin/bufunfa-central bin/bufunfa-api bin/bufunfa-recorder
deps = {[testenv]deps}
pep8==1.3.3
commands = pep8 --repeat --show-source --exclude=.venv,.tox,dist,doc,openstack bufunfa setup.py bin/bufunfa-api bin/bufunfa-central bin/bufunfa-recorder
[testenv:pyflakes]
deps = {[testenv]deps}
pyflakes==0.5.0
commands = pyflakes bufunfa bin setup.py
[testenv:venv]
commands = {posargs}