From c3c2b3b52c9eda37dcd97b1468cf65f4db5b2c1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=95=E6=B1=82?= Date: Sun, 13 Feb 2022 23:47:45 +0800 Subject: [PATCH] fail test when some controller dose not have drvier --- ancert | 4 ++++ lib/component.py | 12 +++++++++++- lib/device.py | 6 ++++++ lib/expection.py | 2 ++ 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/ancert b/ancert index 469aead..f9f2c0c 100755 --- a/ancert +++ b/ancert @@ -91,6 +91,10 @@ def main(args): if not args.list_hardware: print(e) return 1 + except NonDriverAttached as e: + if args.category == 'System': + print(e) + return 1 else: save_device_info(selected_components, dstree, logdir) diff --git a/lib/component.py b/lib/component.py index e92bc01..026cad8 100644 --- a/lib/component.py +++ b/lib/component.py @@ -61,7 +61,8 @@ class Component(): if self.unavailable and self.output: print('Unavailable %ss:' % msg) for ctr in self.unavailable: - print('\t%s [%s]' % (ctr.devinfo.split('|')[0], ctr.driver)) + print('\t%s %s' % (ctr.devinfo.split('|')[0], '[%s]' % ctr.driver \ + if ctr.driver else '[* No Driver *]')) logging.info('Available %ss:' % msg) for ctr in self.available: logging.info('%s [%s]' % (ctr.devinfo, ctr.driver)) @@ -92,6 +93,13 @@ class Component(): info['unavailable'].append({self.name: ctr.properties}) return info + def check_controller_state(self): + for ctr in self.unavailable: + if not ctr.get_property('DRIVER'): + raise NonDriverAttached('\nTest *FAILED* since following Controller was not claimed ' + 'any driver, please manually attach driver or ask help from ' + 'OpenAnolis community:\n %s' % ctr.name) + class FakeComponent(Component): def __init__(self, logdir, cases, category, args): @@ -251,6 +259,7 @@ class Network(Component): raise NonAvaliableController('No available network controller to test! Please config at least ' 'a port with dhcp IP address for unavailable network controllers.') self.build_works() + self.check_controller_state() def mapping(self, ctr, dstree): for dev in dstree.devices: @@ -350,6 +359,7 @@ class Storage(Component): raise NonAvaliableController('No available {0} controller to test! Please config at least ' 'a free disk for above unavailable {0} controllers.'.format(self.name)) self.build_works() + self.check_controller_state() def mapping(self, ctr, dstree): for dev in dstree.devices: diff --git a/lib/device.py b/lib/device.py index 3ea089b..8bf6e25 100644 --- a/lib/device.py +++ b/lib/device.py @@ -157,6 +157,12 @@ class Controller(): if not self.device_inst.name: if self.component.name not in ['cpu', 'memory']: self.device_inst.name = get_device_name_from_hwdb(self) + if not self.device_inst.name: + self.device_inst.name = '%s' % self.device_inst.get_property('PCI_ID') + if self.device_inst.get_property('PCI_SUBSYS_ID'): + self.device_inst.name += '[%s]' % self.device_inst.get_property('PCI_SUBSYS_ID') + if self.device_inst.get_property('PCI_CLASS'): + self.device_inst.name += '[%s]' % self.device_inst.get_property('PCI_CLASS') def __getattr__(self, name): try: diff --git a/lib/expection.py b/lib/expection.py index 0e2cfef..736c661 100644 --- a/lib/expection.py +++ b/lib/expection.py @@ -1,3 +1,5 @@ +class NonDriverAttached(RuntimeError): + pass class NonAvaliableController(RuntimeError): -- Gitee