Files
cyborg/cyborg/accelerator/accelerator.py
T
Shaohe Feng 709f79ce6d 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
2018-02-08 09:31:23 +00:00

37 lines
1.3 KiB
Python

# -*- coding: utf-8 -*-
# Copyright 2016-2017 OpenStack Foundation
#
# 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.
from sqlalchemy import Column, Integer, String
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
# A common internal acclerator object for internal use.
class Accelerator(Base):
__tablename__ = 'accelerators'
accelerator_id = Column(String, primary_key=True)
device_type = Column(String)
remoteable = Column(Integer)
vender_id = Column(String)
product_id = Column(String)
def __init__(self, **kwargs):
self.accelerator_id = kwargs['accelerator_id']
self.device_type = kwargs['device_type']
self.remoteable = kwargs['remoteable']
self.vendor_id = kwargs['vendor_id']
self.product_id = kwargs['product_id']