Skip to content

Commit

Permalink
Merge pull request #60 from Hui-Zhi/main
Browse files Browse the repository at this point in the history
Tag: 2.0.8
  • Loading branch information
Hui-Zhi committed Nov 21, 2022
2 parents 01b3a88 + 2cc1f6d commit 3a5187a
Show file tree
Hide file tree
Showing 8 changed files with 208 additions and 48 deletions.
2 changes: 1 addition & 1 deletion src/soliddriver_checks/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def check(dst):
"out_format",
type=click.Choice(FORMAT_TYPES),
default="json",
help="Specify output format",
help="Specify output format (PDF is in Beta)",
)
@click.option(
"--query",
Expand Down
3 changes: 3 additions & 0 deletions src/soliddriver_checks/config/soliddriver-checks.conf
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
{
"name":"GPLv2"
},
{
"name":"GPL v2 only"
},
{
"name":"GPL-2.0"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,15 @@
th.detail_6{
width:240px;
background-color:#90EBCD;
}th.detail_7{
}
th.detail_7{
width:240px;
background-color:#90EBCD;
}
th.detail_8{
width:240px;
background-color:#90EBCD;
}
td{
text-align:left;
vertical-align: top;
Expand Down
153 changes: 114 additions & 39 deletions src/soliddriver_checks/utils/data_exporter.py

Large diffs are not rendered by default.

80 changes: 78 additions & 2 deletions src/soliddriver_checks/utils/data_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import re
from collections import namedtuple
import tempfile
import fnmatch
import json
from scp import SCPClient
from paramiko.ssh_exception import NoValidConnectionsError, SSHException
Expand Down Expand Up @@ -90,8 +91,35 @@ def __init__(self, progress):
"sym-check",
"dv-licenses",
"is-signed",
"modalias",
]

def _get_driver_alias(self, driver):
alias = run_cmd("/usr/sbin/modinfo --field=alias %s | grep pci:" % driver)
return alias.splitlines()

def _get_rpm_modalias(self, rpm):
modalias = namedtuple("modalias", "kernel_flavor pci_re")
ml_pci_re = re.compile(r"modalias\((.*):(.*\:.*)\)") # example: modalias(kernel-default:pci:v000019A2d00000712sv*sd*bc*sc*i*)
ml_all_re = re.compile(r"modalias\((.*):(.*)\)") # example: packageand(kernel-default:primergy-be2iscsi)
raw_modalias = run_cmd("rpm -q --supplements %s" %rpm)

alias_re = []
for line in raw_modalias.splitlines():
line = str(line, "utf-8").strip()
pci_rst = ml_pci_re.match(line)
all_rst = ml_all_re.match(line)
if pci_rst:
ker_flavor, pci = pci_rst.groups()
if "pci:" in pci: # only check PCI devices
alias_re.append(pci)
elif all_rst: # match all (*) should not be allowed
ker_flavor, rst = all_rst.groups()
if rst == "*":
alias_re.append(rst)

return alias_re

def _driver_symbols_check(self, rpm_symbols, driver):
symvers = run_cmd("/usr/sbin/modprobe --dump-modversions %s" % driver)

Expand Down Expand Up @@ -147,7 +175,7 @@ def _get_driver_supported(self, driver):

if values[0].strip() == "supported":
if supported != "": # only allow appears once.
return "Multiple"
supported = supported + ", " + ":".join(values[1:]).strip()
else:
supported = ":".join(values[1:]).strip()

Expand Down Expand Up @@ -203,6 +231,50 @@ def _fmt_driver_symbol(self, drivers):
symbols[d] = d_info

return symbols

def _fmt_driver_modalias(self, kmp_alias, drivers):
key_match_all = 'match_all'
key_unmatched_km_alias = 'unmatched_km_alias'
key_unmatched_kmp_alias = 'unmatched_kmp_alias'
for a in kmp_alias:
if a == "*": # "use default-kernel:* to match all the devices is always a bad idea."
return {key_match_all:True,
key_unmatched_km_alias:[],
key_unmatched_kmp_alias:[]}

unmatched_ker_alias = []
unmatched_kmp_alias = kmp_alias.copy()

for d in drivers:
for ker_a in drivers[d]["alias"]:
ker_a = str(ker_a, "utf-8").strip()
found = False
for kmp_a in kmp_alias:
if fnmatch.fnmatch(ker_a.strip(), kmp_a.strip()):
found = True
for uk in unmatched_kmp_alias:
if uk.strip() == kmp_a.strip():
unmatched_kmp_alias.remove(uk)
break
break
if not found:
unmatched_ker_alias.append(ker_a)

# There has some packages have "%5" in the package but use "_" in the kernel module
# So we have to match it again, but equal is enough.
r_ukmpalias = [v.replace("_", "%5F").replace("-", "%2D").replace(".", "%2E") for v in unmatched_ker_alias]
for i in range(len(unmatched_kmp_alias) - 1, -1, -1):
found_match = False
for j in range(len(unmatched_ker_alias) - 1, -1, -1):
if r_ukmpalias[j] == unmatched_kmp_alias[i]:
unmatched_ker_alias.pop(j)
found_match = True
if found_match:
unmatched_kmp_alias.pop(i)

return {key_match_all:False,
key_unmatched_km_alias:unmatched_ker_alias,
key_unmatched_kmp_alias:unmatched_kmp_alias}

def _is_driver_signed(self, driver):
raw_info = run_cmd("/usr/sbin/modinfo %s" % driver)
Expand Down Expand Up @@ -242,6 +314,7 @@ def _driver_checks(self, rpm: str):
item["supported"] = self._get_driver_supported(driver)
item["license"] = self._get_driver_license(driver)
item["is_signed"] = self._is_driver_signed(driver)
item["alias"] = self._get_driver_alias(driver)

dpath = str(driver)
dpath = dpath[dpath.startswith(tmp.name) + len(tmp.name) - 1 :]
Expand Down Expand Up @@ -293,11 +366,13 @@ def _format_rpm_info(self, rpm_files, raw_output, row_handlers, query="all"):
symbols = dict()
d_licenses = dict()
is_signed = dict()
km_modalias = dict()
if driver_checks is not None:
supported = self._fmt_driver_supported(driver_checks)
symbols = self._fmt_driver_symbol(driver_checks)
d_licenses = self._fmt_driver_license(driver_checks)
is_signed = self._fmt_driver_is_signed(driver_checks)
km_modalias = self._fmt_driver_modalias(self._get_rpm_modalias(rpm), driver_checks)

if not self._query_filter(supported, query):
continue
Expand All @@ -315,7 +390,8 @@ def _format_rpm_info(self, rpm_files, raw_output, row_handlers, query="all"):
supported,
symbols,
d_licenses,
is_signed
is_signed,
km_modalias
]
)

Expand Down
2 changes: 1 addition & 1 deletion src/soliddriver_checks/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
Global version information used in soliddriver-checks and the package
"""

__VERSION__ = "2.0.7"
__VERSION__ = "2.0.8-beta"
7 changes: 4 additions & 3 deletions tests/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ FROM opensuse/leap:latest

WORKDIR /root

RUN zypper --non-interactive in python3-pip kmod
RUN zypper --non-interactive in python39 python39-pip kmod
RUN zypper --non-interactive dup

RUN pip3 install rich pdfkit pandas \
openpyxl click paramiko dominate
RUN pip3.9 install rich pdfkit pandas \
openpyxl click paramiko dominate build

2 changes: 1 addition & 1 deletion tests/create_container_mac.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
docker run \
-it --rm \
--mount type=bind,source=/Users/$USER/projects/github.com/SUSE/soliddriver-checks,target=/root/source_codes \
--mount type=bind,source=/Users/$USER/projects/Lenovo/SSDP/01-Apr-2022,target=/root/rpms \
--mount type=bind,source=/Users/$USER/projects/fujitsu/kmps-15-sp2,target=/root/rpms \
--mount type=bind,source=/Users/$USER/codes/tmp,target=/root/output_dir \
opensuse-leap-soliddriver-checks:latest /bin/bash

0 comments on commit 3a5187a

Please sign in to comment.