|
|
@@ -58,6 +58,7 @@ import sqlite3 |
|
|
|
import subprocess |
|
|
|
import sys |
|
|
|
import tempfile |
|
|
|
import ucl |
|
|
|
import unittest |
|
|
|
import urllib |
|
|
|
|
|
|
@@ -127,26 +128,36 @@ class BITEError(Exception): |
|
|
|
status_code: int |
|
|
|
|
|
|
|
class BoardManager(object): |
|
|
|
board_class_info = { |
|
|
|
'cora-z7s': { |
|
|
|
'clsname': 'cora-z7s', |
|
|
|
'arch': 'arm-armv7', |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
# Naming scheme: |
|
|
|
# <abbreviated class>-<num> |
|
|
|
# |
|
|
|
board_gen = [ |
|
|
|
dict(name='cora-1', brdclass='cora-z7s', options=[ |
|
|
|
SNMPPower(host='poe', port=2), |
|
|
|
]), |
|
|
|
] |
|
|
|
|
|
|
|
def __init__(self, settings): |
|
|
|
self._settings = settings |
|
|
|
_option_map = dict( |
|
|
|
snmppower=SNMPPower, |
|
|
|
) |
|
|
|
|
|
|
|
def __init__(self, cls_info, boards): |
|
|
|
# add the name to the classes |
|
|
|
classes = { k: dict(clsname=k, **cls_info[k]) for k in cls_info } |
|
|
|
self.board_class_info = classes |
|
|
|
|
|
|
|
self.boards = dict(**{ x.name: x for x in |
|
|
|
(BoardImpl(**y) for y in self.board_gen)}) |
|
|
|
(BoardImpl(**y) for y in boards)}) |
|
|
|
|
|
|
|
@classmethod |
|
|
|
def from_settings(cls, settings): |
|
|
|
return cls.from_ucl(settings.board_conf) |
|
|
|
|
|
|
|
@classmethod |
|
|
|
def from_ucl(cls, fname): |
|
|
|
with open(fname) as fp: |
|
|
|
conf = ucl.load(fp.read()) |
|
|
|
|
|
|
|
classes = conf['classes'] |
|
|
|
|
|
|
|
brds = conf['boards'] |
|
|
|
makeopt = lambda x: cls._option_map[x['cls']](**{ k: v for k, v in x.items() if k != 'cls' }) |
|
|
|
for i in brds: |
|
|
|
opt = i['options'] |
|
|
|
opt[:] = [ makeopt(x) for x in opt ] |
|
|
|
|
|
|
|
return cls(classes, brds) |
|
|
|
|
|
|
|
def classes(self): |
|
|
|
return self.board_class_info |
|
|
@@ -202,7 +213,7 @@ def get_data(settings: config.Settings = Depends(get_settings)): |
|
|
|
return d |
|
|
|
|
|
|
|
async def real_get_boardmanager(settings, data): |
|
|
|
brdmgr = BoardManager(settings) |
|
|
|
brdmgr = BoardManager.from_settings(settings) |
|
|
|
|
|
|
|
# Clean up the database |
|
|
|
# XXX - This isn't a complete fix, we need a better solution. |
|
|
@@ -496,9 +507,10 @@ class TestBiteLab(unittest.IsolatedAsyncioTestCase): |
|
|
|
# setup settings |
|
|
|
self.settings = config.Settings(db_file=self.dbtempfile.name, |
|
|
|
setup_script='somesetupscript', |
|
|
|
board_conf = os.path.join('fixtures', 'board_conf.ucl') |
|
|
|
) |
|
|
|
|
|
|
|
self.brdmgr = BoardManager(self.settings) |
|
|
|
self.brdmgr = BoardManager.from_settings(self.settings) |
|
|
|
|
|
|
|
self.app.dependency_overrides[get_settings] = \ |
|
|
|
self.get_settings_override |
|
|
|