From 9c87cadc317e974332239daf5d6fc6f8cb184138 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=95=E6=B1=82?= Date: Thu, 17 Feb 2022 18:13:51 +0800 Subject: [PATCH] feature: collect detail information of tested disk --- ancert | 1 + ancert.spec | 2 +- lib/component.py | 4 +- lib/device.py | 10 ++++- lib/utils.py | 85 ++++++++++++++++++++++++++++++++------ lib/worker.py | 2 +- tests/lib/shell/common.sh | 6 ++- tests/storage/storage.yaml | 4 +- utils/collect_host_info.sh | 8 ++++ utils/get_disk_info.sh | 23 +++++++++++ 10 files changed, 125 insertions(+), 20 deletions(-) create mode 100644 utils/get_disk_info.sh diff --git a/ancert b/ancert index 74fc7ca..ba31ff4 100755 --- a/ancert +++ b/ancert @@ -156,6 +156,7 @@ def main(args): global RESULT if total_finished_tasks: + logging.info('all tests finished') print('') print('Results Summary:') print('{:<12}{:22}{:<12}{:<52}'.format('Category:', 'Case:', 'Result:', 'Device name:')) diff --git a/ancert.spec b/ancert.spec index 3bf15e4..bd9f9a0 100644 --- a/ancert.spec +++ b/ancert.spec @@ -28,7 +28,7 @@ ExclusiveArch: %(arch) Vendor: Alibaba BuildRequires: make, gcc, gcc-c++ Requires: fio, nvme-cli, glx-utils, python3, rpm-build, bc -Requires: alsa-lib, alsa-utils, virt-what +Requires: alsa-lib, alsa-utils, virt-what, smartmontools, hdparm Requires: xorg-x11-utils, xorg-x11-server-utils, xorg-x11-apps %description diff --git a/lib/component.py b/lib/component.py index 324a7ab..dade168 100644 --- a/lib/component.py +++ b/lib/component.py @@ -406,12 +406,12 @@ class Storage(Component): drive_name = '' if dk.get_property('ID_VENDOR'): drive_name += dk.get_property('ID_VENDOR') + ' ' - if dk.get_property('ID_MODEL') in ['Virtual_disk']: + if dk.get_property('ID_MODEL') in ['Virtual_disk']: # raid drive_name += dk.get_property('ID_MODEL') + ' ' if dk.get_property('ID_SERIAL'): drive_name += dk.get_property('ID_SERIAL').replace('_', ' ') if not drive_name.strip() and self.is_virtual_platform: - drive_name = 'Virtual Disk' + drive_name = 'Virtual Disk' # qemu dk.properties.update({'DRIVE_FULL_NAME': drive_name}) if not dk.is_partition: ctr.devices.append(dk) diff --git a/lib/device.py b/lib/device.py index 46eed3e..74fa97e 100644 --- a/lib/device.py +++ b/lib/device.py @@ -82,9 +82,16 @@ class Disk(): self.is_boot_disk = stor_inst.boot_disk.startswith(self.dev_path) if self.is_boot_disk: ctr_inst.is_boot_controller = True + self.properties.update({'IS_BOOT_DISK': 'yes'}) self.is_pvs_disk = is_pvs_disk(self.dev_path, stor_inst.pvs_disk) self.check_mount_point() + self.properties.update({'DISK_TYPE': get_disk_type(self.dev_path)}) self.properties.update({'IS_RAW_DISK': 'false'}) + if not self.is_partition: + self.properties.update({'DISK_TRANSPORT': get_disk_transport(self.dev_path)}) + if stor_inst.name not in ['nvme']: + self.properties.update({'DISK_DRIVER': get_disk_driver(self.dev_path)}) + self.properties.update({'DISK_VENDOR': get_disk_vendor(self.syspath)}) def __getattr__(self, name): try: @@ -152,7 +159,7 @@ class Controller(): self.available_devices = list() self.bus_device = self.syspath.rsplit('.', 1)[0] self.bdf = self.syspath.rsplit('/')[-1] - self.device_inst.properties.update({'PCI_BDF': self.bdf}) + self.device_inst.properties.update({'PCI_BDF': self.bdf.split(':', 1)[-1]}) self.test_mode = self.component.env.get('ANCERT_SYSTEM_TEST_MODE', '') self.is_raid = is_sub_class_code(['000104'], self.classcode) self.is_boot_ctr = False @@ -227,6 +234,7 @@ class StorageController(Controller): def pickup_device(self, index=0): logging.debug('select index %s for testing from available list' % index) dk = self.available_devices[index] + dk.properties.update({'STORAGE_TESTED_DISK': 'yes'}) if dk.partition_inst: logging.debug('partition %s was selected for storage testing' % dk.partition_inst[0].dev_path) return dk.partition_inst[0] diff --git a/lib/utils.py b/lib/utils.py index c72a4cc..f7af93a 100644 --- a/lib/utils.py +++ b/lib/utils.py @@ -42,7 +42,7 @@ def run_task(gname, tasks): to_run_futures = [] with ThreadPoolExecutor(max_workers=POOL_MAX_WORKERS) as pool: for task in tasks: - logging.debug('starting to run task %s' % task.name) + logging.debug('starting to run task %s on %s' % (task.name, task.test.controller.name.strip())) future = pool.submit(task.run) to_run_futures.append(future) th.start() @@ -548,7 +548,7 @@ def save_test_result(comp_insts, args, logdir, result): info['test_info'] = {} info['test_info']['all_test_result'] = 'PASS' if result else 'FAIL' info['test_info']['detail'] = detail - logging.info('current test info: %s' % info) + logging.info('total test result: %s' % info['test_info']['all_test_result']) for cpt in comp_insts: if cpt.name not in detail: detail[cpt.name] = [] @@ -560,8 +560,28 @@ def save_test_result(comp_insts, args, logdir, result): 'ctr_name': t.test.controller.name.strip(), 'ctr_bdf': t.test.controller.bdf, 'ctr_syspath': t.test.controller.syspath} + if hasattr(cpt, 'boot_disk'): # sub class of Storage + for dk in t.test.controller.available_devices: + if dk.get_property('STORAGE_TESTED_DISK') == 'yes': + if 'tested_disk' not in t_info: + t_info['tested_disk'] = [] + model, serial = dk.get_property('ID_MODEL').replace('_', ' '), dk.get_property('ID_SERIAL_SHORT') + id_serial = dk.get_property('ID_SERIAL') + id_serial_short = dk.get_property('ID_SERIAL_SHORT') + if id_serial and id_serial_short: + model = id_serial.replace(id_serial_short, '').replace('_', ' ').strip() + serial = dk.get_property('ID_SERIAL_SHORT') + t_info['tested_disk'].append({'devname': dk.dev_path, + 'size': dk.get_property('DISK_SIZE'), + 'revision': dk.get_property('ID_REVISION'), + 'model': model, + 'serial': serial, + 'vendor': dk.get_property('DISK_VENDOR'), + 'driver': dk.get_property('DISK_DRIVER'), + 'transport': dk.get_property('DISK_TRANSPORT'), + 'disk_type': dk.get_property('DISK_TYPE'), + 'name': dk.get_property('DRIVE_FULL_NAME')}) detail[cpt.name].append(t_info) - all_info = {} info_file = os.path.join(logdir, ALL_DEVICE_INFO) with open(info_file, 'r') as fd: @@ -585,6 +605,53 @@ def get_int_value_from_file(filepath): return int(ret) +def get_disk_type(dev_path): + devname = dev_path.split('/')[-1] + rotational = '/sys/block/%s/queue/rotational' % devname + if os.path.exists(rotational): + val = get_int_value_from_file(rotational) + if int(val) == 0: + return 'SSD' + elif int(val) == 1: + return 'HDD' + else: + logging.warning('Get unexpect value %s from %s' % (val, rotational)) + return '' + + +def get_disk_vendor(sys_path): + vendor_path = '/sys/%s/device/vendor' % sys_path + cmd = 'cat %s' % vendor_path + if os.path.exists(vendor_path): + rc, ret = run_local_cmd(cmd, shell=True) + if rc: + logging.warning('failed to get %s vendor, error %s' % (sys_path, ret)) + return '' + return ret.strip() + return '' + + +def get_disk_transport(dev_path): + cmd = 'lsblk -idno TRAN %s' % dev_path + rc, ret = run_local_cmd(cmd, shell=True) + if rc: + logging.warning('failed to get %s transport, error: %s' % (dev_path, ret)) + return '' + return ret.strip() + + +def get_disk_driver(dev_path): + devname = dev_path.split('/')[-1] + block_path = '/sys/block/%s/device/driver' % devname + if not os.path.exists(block_path): + return '' + driver_path = os.path.realpath(block_path) + logging.debug('%s driver path %s' % (dev_path, driver_path)) + if driver_path: + return driver_path.split('/')[-1] + return '' + + def get_boot_disk_hw_info(dk, ctr, dstree): disk_name = '' for dev in dstree.devices: @@ -597,16 +664,10 @@ def get_boot_disk_hw_info(dk, ctr, dstree): return disk_name if dev.get_property('ID_SERIAL'): disk_name += dev.get_property('ID_SERIAL').replace('_', ' ') + disk_type = get_disk_type(dev.get_property('DEVNAME')) + if disk_type: + disk_name += ' %s' % disk_type devname = dev.get_property('DEVNAME').split('/')[-1] - rotational = '/sys/block/%s/queue/rotational' % devname - if os.path.exists(rotational): - val = get_int_value_from_file(rotational) - if int(val) == 0: - disk_name += ' SSD' - elif int(val) == 1: - disk_name += ' HDD' - else: - logging.warning('Get unexpect value %s from %s' % (val, rotational)) logical_block_size = '/sys/block/%s/queue/logical_block_size' % devname size = '/sys/block/%s/size' % devname if os.path.exists(logical_block_size) and os.path.exists(size): diff --git a/lib/worker.py b/lib/worker.py index 98a699a..eae5b32 100644 --- a/lib/worker.py +++ b/lib/worker.py @@ -46,7 +46,7 @@ class Worker(object): time.sleep(5) if time.time() - start_time > self.timeout: self.kill() - logging.error('testcase %s timeout, killed it...' % self.name) + logging.error('testcase %s does not finish in %s secs, killed it...' % (self.name, self.timeout)) break if self.is_subprocess_alive(): continue diff --git a/tests/lib/shell/common.sh b/tests/lib/shell/common.sh index a661a57..9f35966 100644 --- a/tests/lib/shell/common.sh +++ b/tests/lib/shell/common.sh @@ -160,7 +160,7 @@ ioengine=sync iodepth=4 numjobs=1 group_reporting -size=256M +size=128M direct=1 runtime=120 timeout=900 @@ -268,7 +268,11 @@ function run_fio_test() { echo generate_fio_config_file "$fio_config_file" "$test_dir" echo + echo "change work dir to $TESTLOG_DIR" + cd $TESTLOG_DIR run_cmd "fio $fio_config_file" + cd - + echo "current work dir `pwd`" if $IS_RAW_DISK; then umount $test_dir diff --git a/tests/storage/storage.yaml b/tests/storage/storage.yaml index 5eff8de..586bb4e 100644 --- a/tests/storage/storage.yaml +++ b/tests/storage/storage.yaml @@ -7,9 +7,9 @@ cases: - name: raw_disk_rw description: run dd read/write test filepath: raw_disk_rw.sh - runtime: 300 + runtime: 900 required: [raw] - name: fs_rw description: run fio read/write test filepath: fs_rw.sh - runtime: 300 + runtime: 1200 diff --git a/utils/collect_host_info.sh b/utils/collect_host_info.sh index 260c773..1dffea3 100644 --- a/utils/collect_host_info.sh +++ b/utils/collect_host_info.sh @@ -56,3 +56,11 @@ run_cmd "mount" "mount" echo "collect df information" run_cmd "bash df -P" "df_P" +echo "collect disk smart information" +run_cmd "bash utils/get_disk_info.sh smartctl" "smartctl_x_dev" + +echo "collect disk hdparm information" +run_cmd "bash utils/get_disk_info.sh hdparm" "hdparm_I_dev" + +echo "collect /proc/scsi/scsi information" +run_cmd "cat /proc/scsi/scsi" "proc_scsi_scsi" diff --git a/utils/get_disk_info.sh b/utils/get_disk_info.sh new file mode 100644 index 0000000..fb8cab6 --- /dev/null +++ b/utils/get_disk_info.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +cmd=$1 + +if [ "$cmd" == "smartctl" ]; then + cmd_prefix="smartctl -x" +elif [ "$cmd" == "hdparm" ]; then + cmd_prefix="hdparm -I" +else + echo "does not support command $cmd" + exit 1 +fi + +echo "[root@localhost]# lsblk -nido NAME" +output=`lsblk -nido NAME` +echo "$output" + +echo "$output" | while read line; do + echo;echo;echo; + dev_path="/dev/$line" + echo "[root@localhost]# $cmd_prefix $dev_path" + $cmd_prefix $dev_path +done -- Gitee