python脚本:1.启动机器, 检查BIOS POST过程输出信息,获取CPU信息 2. 进入BIOS配置界面, 读取CPU版本信息 3. OS 下通过lscpu检查cpu的信息 4. 运行以下命令检查CPU possible, online和offline信息 cat /sys/devices/system/cpu/possible cat /sys/devices/system/cpu/online cat /sys/devices/system/cpu/offline 输出以上信息和日志,并和已经写入的CPU的配置文件.xlsx与1-4进行比较,结果一致为pass ,结果不一致为fail。
时间: 2023-08-16 12:08:10 浏览: 175
以下是一个简单的Python脚本,可以实现您所述的功能:
```python
import subprocess
import os
import pandas as pd
# 获取CPU信息
def get_cpu_info():
output = subprocess.check_output('lscpu').decode()
cpu_info = {}
for line in output.split('\n'):
if ':' in line:
key, value = line.split(':')
cpu_info[key.strip()] = value.strip()
return cpu_info
# 获取BIOS中的CPU版本信息
def get_bios_cpu_version():
# 进入BIOS配置界面,读取CPU版本信息
# 这里假设使用了ipmitool工具来远程访问BIOS,具体操作可能因系统不同而异
os.system('ipmitool -I lanplus -H <BIOS IP> -U <username> -P <password> chassis bootdev disk')
output = subprocess.check_output('ipmitool -I lanplus -H <BIOS IP> -U <username> -P <password> chassis info').decode()
for line in output.split('\n'):
if 'Processor Version' in line:
cpu_version = line.split(':')[1].strip()
return cpu_version
# 获取CPU possible, online和offline信息
def get_cpu_status():
with open('/sys/devices/system/cpu/possible', 'r') as f:
possible = f.read().strip()
with open('/sys/devices/system/cpu/online', 'r') as f:
online = f.read().strip()
with open('/sys/devices/system/cpu/offline', 'r') as f:
offline = f.read().strip()
return possible, online, offline
# 检查CPU信息是否与配置文件一致
def check_cpu_config():
cpu_info = get_cpu_info()
bios_cpu_version = get_bios_cpu_version()
possible, online, offline = get_cpu_status()
# 读取已经写入的CPU配置文件
cpu_config = pd.read_excel('CPU配置文件.xlsx')
# 比较CPU信息
if (cpu_info['Model name'] == cpu_config['CPU型号'][0]
and cpu_info['Architecture'] == cpu_config['CPU架构'][0]
and cpu_info['CPU(s)'] == cpu_config['CPU核心数'][0]
and cpu_info['Thread(s) per core'] == cpu_config['CPU线程数'][0]
and bios_cpu_version == cpu_config['BIOS CPU版本信息'][0]
and possible == cpu_config['CPU possible信息'][0]
and online == cpu_config['CPU online信息'][0]
and offline == cpu_config['CPU offline信息'][0]):
print('Pass')
else:
print('Fail')
if __name__ == '__main__':
check_cpu_config()
```
请注意,此脚本仅作为示例,具体实现可能需要进行适当修改以适应您的系统环境和需求。
阅读全文