bug fix: rename accelerator to Accelerator

When run:
$ python -m unittest cyborg.tests.unit.accelerator.drivers.modules.test_generic

It will report the follow error:
  File "cyborg/tests/unit/accelerator/drivers/modules/test_generic.py", line 20, in <module>
    from cyborg.accelerator.drivers.generic_driver import GenericDriver as generic
  File "cyborg/accelerator/drivers/generic_driver.py", line 24, in <module>
    from cyborg.accelerator import accelerator
  File "cyborg/accelerator/accelerator.py", line 23, in <module>
    class accelerator(Base):
  File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/ext/declarative/api.py", line 64, in __init__
    _as_declarative(cls, classname, cls.__dict__)
  File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/ext/declarative/base.py", line 88, in _as_declarative
    _MapperConfig.setup_mapping(cls, classname, dict_)
  File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/ext/declarative/base.py", line 103, in setup_mapping
    cfg_cls(cls_, classname, dict_)
  File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/ext/declarative/base.py", line 125, in __init__
    clsregistry.add_class(self.classname, self.cls)
  File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/ext/declarative/clsregistry.py", line 65, in add_class
    module.add_class(classname, cls)
  File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/ext/declarative/clsregistry.py", line 172, in add_class
    existing.add_item(cls)
AttributeError: '_ModuleMarker' object has no attribute 'add_item'

That's because:
_ModuleMarker will add the module name and class name in to same contents dict.
_MultipleClassMarker refers to multiple classes of the same name within _decl_class_registry.
It has add_item attribute.
_ModuleMarker refers to a module name within _decl_class_registry.
It does not have add_item attribute.

So the class name should be different with module name.

REF:
https://github.com/zzzeek/sqlalchemy/blob/master/lib/sqlalchemy/ext/declarative/clsregistry.py

Change-Id: I8d8aa8809f6afd5b9eaace832a06ba7f3770e652
This commit is contained in:
Shaohe Feng 2018-02-08 09:21:28 +00:00
parent 2e78e10e5a
commit 709f79ce6d
2 changed files with 2 additions and 2 deletions

View File

@ -20,7 +20,7 @@ Base = declarative_base()
# A common internal acclerator object for internal use.
class accelerator(Base):
class Accelerator(Base):
__tablename__ = 'accelerators'
accelerator_id = Column(String, primary_key=True)
device_type = Column(String)

View File

@ -44,7 +44,7 @@ class GenericDriver(generic.GENERICDRIVER):
def do_setup(self, context):
"""Any initialization the generic driver does while starting."""
super(GenericDriver, self).do_setup(context)
self.acc = accelerator.accelerator()
self.acc = accelerator.Accelerator()
def create_accelerator(self, context):
"""Creates accelerator."""