[Mellanox] Added patchwork link to commit message (#15301)

- Why I did it
Add the patchwork link to the commit description for non-upstream patches if present

- How I did it
Parse the patchwork/<patch_name>.txt file from hw-mgmt
This commit is contained in:
Vivek 2023-06-08 08:51:58 -07:00 committed by mssonicbld
parent 36f1c8c972
commit a416372e04
6 changed files with 63 additions and 23 deletions

View File

@ -199,6 +199,7 @@ def build_commit_description(changes):
content = content + f"* {key} : {value}\n" content = content + f"* {key} : {value}\n"
return content return content
def parse_id(id_): def parse_id(id_):
if id_ and id_ != "N/A": if id_ and id_ != "N/A":
id_ = "https://github.com/torvalds/linux/commit/" + id_ id_ = "https://github.com/torvalds/linux/commit/" + id_

View File

@ -28,11 +28,18 @@ from helper import *
COMMIT_TITLE = "Intgerate HW-MGMT {} Changes" COMMIT_TITLE = "Intgerate HW-MGMT {} Changes"
PATCH_TABLE_LOC = "platform/mellanox/hw-management/hw-mgmt/recipes-kernel/linux/" PATCH_TABLE_LOC = "platform/mellanox/hw-management/hw-mgmt/recipes-kernel/linux/"
PATCHWORK_LOC = "linux-{}/patchwork"
PATCH_TABLE_NAME = "Patch_Status_Table.txt" PATCH_TABLE_NAME = "Patch_Status_Table.txt"
PATCH_TABLE_DELIMITER = "----------------------" PATCH_TABLE_DELIMITER = "----------------------"
PATCH_NAME = "patch name" PATCH_NAME = "patch name"
COMMIT_ID = "Upstream commit id" COMMIT_ID = "Upstream commit id"
# Strips the subversion
def get_kver(k_version):
major, minor, subversion = k_version.split(".")
k_ver = "{}.{}".format(major, minor)
return k_ver
def trim_array_str(str_list): def trim_array_str(str_list):
ret = [elem.strip() for elem in str_list] ret = [elem.strip() for elem in str_list]
return ret return ret
@ -46,12 +53,8 @@ def get_line_elements(line):
columns = trim_array_str(columns_raw) columns = trim_array_str(columns_raw)
return columns return columns
def load_patch_table(path, k_version): def load_patch_table(path, k_ver):
patch_table_filename = os.path.join(path, PATCH_TABLE_NAME) patch_table_filename = os.path.join(path, PATCH_TABLE_NAME)
major, minor, subversion = k_version.split(".")
k_ver = "{}.{}".format(major, minor)
print("Loading patch table {} kver:{}".format(patch_table_filename, k_ver)) print("Loading patch table {} kver:{}".format(patch_table_filename, k_ver))
if not os.path.isfile(patch_table_filename): if not os.path.isfile(patch_table_filename):
@ -140,6 +143,8 @@ class Data:
current_kcfg = list(tuple()) current_kcfg = list(tuple())
# current raw kconfig exclude data # current raw kconfig exclude data
kcfg_exclude = list() kcfg_exclude = list()
# kernel version
k_ver = ""
class HwMgmtAction(Action): class HwMgmtAction(Action):
@ -247,6 +252,7 @@ class PostProcess(HwMgmtAction):
print("-> FATAL: Patch {} not found either in upstream or non-upstream list".format(patch)) print("-> FATAL: Patch {} not found either in upstream or non-upstream list".format(patch))
if not self.args.is_test: if not self.args.is_test:
sys.exit(1) sys.exit(1)
Data.k_ver = get_kver(self.args.kernel_version)
def find_mlnx_hw_mgmt_markers(self): def find_mlnx_hw_mgmt_markers(self):
""" Find the indexes where the current mlnx patches sits in SLK_SERIES file """ """ Find the indexes where the current mlnx patches sits in SLK_SERIES file """
@ -386,13 +392,45 @@ class PostProcess(HwMgmtAction):
old_non_up_patches = [ptch.strip() for ptch in Data.old_non_up] old_non_up_patches = [ptch.strip() for ptch in Data.old_non_up]
return old_up_patches, old_non_up_patches return old_up_patches, old_non_up_patches
def _get_patchwork(self, patch_name):
root_p = os.path.join(self.args.build_root, PATCH_TABLE_LOC)
patchwork_loc = PATCHWORK_LOC.format(Data.k_ver)
file_dir = os.path.join(root_p, patchwork_loc)
file_loc = os.path.join(file_dir, f"{patch_name}.txt")
if not os.path.exists(file_loc):
return ""
print(f"-> INFO: Patchwork file {file_loc} is present")
lines = FileHandler.read_strip(file_loc)
for line in lines:
if "patchwork_link" not in line:
continue
tokens = line.split(":")
if len(tokens) < 2:
print(f"-> WARN: Invalid entry {line}, did not follow <key>:<value>")
continue
key = tokens[0]
values = tokens[1:]
if key == "patchwork_link":
desc = ":".join(values)
desc = desc.strip()
print(f"-> INFO: Patch work link for patch {patch_name} : {desc}")
return desc
return ""
def _fetch_description(self, patch, id_):
desc = parse_id(id_)
if not desc:
# not an upstream patch, check if the patchwork link is present and fetch it
desc = self._get_patchwork(patch)
return desc
def create_commit_msg(self, table): def create_commit_msg(self, table):
title = COMMIT_TITLE.format(self.args.hw_mgmt_ver) title = COMMIT_TITLE.format(self.args.hw_mgmt_ver)
changes_slk, changes_sb = {}, {} changes_slk, changes_sb = {}, {}
old_up_patches, old_non_up_patches = self.list_patches() old_up_patches, old_non_up_patches = self.list_patches()
for patch in table: for patch in table:
id_ = parse_id(patch.get(COMMIT_ID, ""))
patch_ = patch.get(PATCH_NAME) patch_ = patch.get(PATCH_NAME)
id_ = self._fetch_description(patch_, patch.get(COMMIT_ID, ""))
if patch_ in Data.new_up and patch_ not in old_up_patches: if patch_ in Data.new_up and patch_ not in old_up_patches:
changes_slk[patch_] = id_ changes_slk[patch_] = id_
print(f"-> INFO: Patch: {patch_}, Commit: {id_}, added to linux-kernel description") print(f"-> INFO: Patch: {patch_}, Commit: {id_}, added to linux-kernel description")
@ -432,7 +470,7 @@ class PostProcess(HwMgmtAction):
self.write_series_diff() self.write_series_diff()
path = os.path.join(self.args.build_root, PATCH_TABLE_LOC) path = os.path.join(self.args.build_root, PATCH_TABLE_LOC)
patch_table = load_patch_table(path, self.args.kernel_version) patch_table = load_patch_table(path, Data.k_ver)
sb_msg, slk_msg = self.create_commit_msg(patch_table) sb_msg, slk_msg = self.create_commit_msg(patch_table)
@ -470,4 +508,3 @@ if __name__ == '__main__':
parser = create_parser() parser = create_parser()
action = HwMgmtAction.get(parser.parse_args()) action = HwMgmtAction.get(parser.parse_args())
action.perform() action.perform()

View File

@ -48,10 +48,10 @@ Kernel-5.10
|0044-platform-mellanox-mlxreg-io-Fix-read-access-of-n-byt.patch | 5fd56f11838d | Bugfix upstream | 5.10.75 | | |0044-platform-mellanox-mlxreg-io-Fix-read-access-of-n-byt.patch | 5fd56f11838d | Bugfix upstream | 5.10.75 | |
|0045-i2c-mlxcpld-Fix-criteria-for-frequency-setting.patch | 52f57396c75a | Feature upstream | | | |0045-i2c-mlxcpld-Fix-criteria-for-frequency-setting.patch | 52f57396c75a | Feature upstream | | |
|0046-i2c-mlxcpld-Reduce-polling-time-for-performance-impr.patch | 669b2e4aa1a8 | Feature upstream | | (5.16) | |0046-i2c-mlxcpld-Reduce-polling-time-for-performance-impr.patch | 669b2e4aa1a8 | Feature upstream | | (5.16) |
|0047-i2c-mlxcpld-Allow-flexible-polling-time-setting-for-.patch | 712d6617d0a2 | Feature upstream | | (5.16) |
|0048-hwmon-pmbus-mp2975-Add-missed-POUT-attribute-for-pag.patch | 2292e2f685cd | Bugfix upstream | 5.10.71 | | |0048-hwmon-pmbus-mp2975-Add-missed-POUT-attribute-for-pag.patch | 2292e2f685cd | Bugfix upstream | 5.10.71 | |
|0049-leds-mlxreg-Provide-conversion-for-hardware-LED-colo.patch | | Rejected; take[ALL] | |Need to check patch apply. Can break patch apply| |0049-leds-mlxreg-Provide-conversion-for-hardware-LED-colo.patch | | Rejected; take[ALL] | |Need to check patch apply. Can break patch apply|
|0050-leds-mlxreg-Skip-setting-LED-color-during-initializa.patch | | Downstream | | | |0050-leds-mlxreg-Skip-setting-LED-color-during-initializa.patch | | Downstream | | |
|0051-leds-mlxreg-Allow-multi-instantiation-of-same-name-L.patch | | Downstream | | Modular SN4800 | |0051-leds-mlxreg-Allow-multi-instantiation-of-same-name-L.patch | | Downstream | | Modular SN4800 |
|0188-i2c-mux-Add-register-map-based-mux-driver.patch | | Feature pending | | BF3-COME |
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

View File

@ -51,6 +51,7 @@
0105-mlxsw-reg-Extend-MTBR-register-with-new-slot-number-.patch 0105-mlxsw-reg-Extend-MTBR-register-with-new-slot-number-.patch
0106-mlxsw-reg-Extend-MCIA-register-with-new-slot-number-.patch 0106-mlxsw-reg-Extend-MCIA-register-with-new-slot-number-.patch
0107-mlxsw-reg-Extend-MCION-register-with-new-slot-number.patch 0107-mlxsw-reg-Extend-MCION-register-with-new-slot-number.patch
0188-i2c-mux-Add-register-map-based-mux-driver.patch
###-> mellanox_hw_mgmt-end ###-> mellanox_hw_mgmt-end
# Cisco patches for 5.10 kernel # Cisco patches for 5.10 kernel

View File

@ -8,6 +8,7 @@
+0169-TMP-mlxsw-i2c-Prevent-transaction-execution-for-spec.patch +0169-TMP-mlxsw-i2c-Prevent-transaction-execution-for-spec.patch
+0172-DS-platform-mlx-platform-Add-SPI-path-for-rack-switc.patch +0172-DS-platform-mlx-platform-Add-SPI-path-for-rack-switc.patch
+0174-DS-mlxsw-core_linecards-Skip-devlink-and-provisionin.patch +0174-DS-mlxsw-core_linecards-Skip-devlink-and-provisionin.patch
0188-i2c-mux-Add-register-map-based-mux-driver.patch
###-> mellanox_hw_mgmt-end ###-> mellanox_hw_mgmt-end
# Cisco patches for 5.10 kernel # Cisco patches for 5.10 kernel

View File

@ -18,6 +18,7 @@
import sys import sys
import shutil import shutil
from unittest import mock, TestCase from unittest import mock, TestCase
from pyfakefs.fake_filesystem_unittest import Patcher
sys.path.append('../') sys.path.append('../')
from hwmgmt_kernel_patches import * from hwmgmt_kernel_patches import *
@ -49,6 +50,7 @@ NEW_UP_LIST = """\
0105-mlxsw-reg-Extend-MTBR-register-with-new-slot-number-.patch 0105-mlxsw-reg-Extend-MTBR-register-with-new-slot-number-.patch
0106-mlxsw-reg-Extend-MCIA-register-with-new-slot-number-.patch 0106-mlxsw-reg-Extend-MCIA-register-with-new-slot-number-.patch
0107-mlxsw-reg-Extend-MCION-register-with-new-slot-number.patch 0107-mlxsw-reg-Extend-MCION-register-with-new-slot-number.patch
0188-i2c-mux-Add-register-map-based-mux-driver.patch
""" """
TEST_SLK_COMMIT = """\ TEST_SLK_COMMIT = """\
@ -63,10 +65,9 @@ Intgerate HW-MGMT 7.0030.0937 Changes
* 0009-i2c-mux-mlxcpld-Extend-driver-to-support-word-addres.patch : https://github.com/torvalds/linux/commit/c52a1c5f5db5 * 0009-i2c-mux-mlxcpld-Extend-driver-to-support-word-addres.patch : https://github.com/torvalds/linux/commit/c52a1c5f5db5
* 0010-i2c-mux-mlxcpld-Extend-supported-mux-number.patch : https://github.com/torvalds/linux/commit/699c0506543e * 0010-i2c-mux-mlxcpld-Extend-supported-mux-number.patch : https://github.com/torvalds/linux/commit/699c0506543e
* 0011-i2c-mux-mlxcpld-Add-callback-to-notify-mux-creation-.patch : https://github.com/torvalds/linux/commit/a39bd92e92b9 * 0011-i2c-mux-mlxcpld-Add-callback-to-notify-mux-creation-.patch : https://github.com/torvalds/linux/commit/a39bd92e92b9
* 0188-i2c-mux-Add-register-map-based-mux-driver.patch : https://patchwork.ozlabs.org/project/linux-i2c/patch/20230215195322.21955-1-vadimp@nvidia.com/
""" """
TEST_SB_COMMIT = """\ TEST_SB_COMMIT = """\
Intgerate HW-MGMT 7.0030.0937 Changes Intgerate HW-MGMT 7.0030.0937 Changes
@ -128,12 +129,6 @@ class TestHwMgmtPostAction(TestCase):
Data.current_kcfg = KCFG.parse_opts_strs(Data.current_kcfg) Data.current_kcfg = KCFG.parse_opts_strs(Data.current_kcfg)
Data.kcfg_exclude = FileHandler.read_raw(MOCK_INPUTS_DIR+"/kconfig-exclusions") Data.kcfg_exclude = FileHandler.read_raw(MOCK_INPUTS_DIR+"/kconfig-exclusions")
def tearDown(self):
try:
os.remove(MOCK_WRITE_FILE)
except:
pass
def test_find_mlnx_hw_mgmt_markers(self): def test_find_mlnx_hw_mgmt_markers(self):
self.action.find_mlnx_hw_mgmt_markers() self.action.find_mlnx_hw_mgmt_markers()
print(Data.i_mlnx_start, Data.i_mlnx_end) print(Data.i_mlnx_start, Data.i_mlnx_end)
@ -186,10 +181,15 @@ class TestHwMgmtPostAction(TestCase):
assert check_file_content(MOCK_INPUTS_DIR+"expected_data/series.patch") assert check_file_content(MOCK_INPUTS_DIR+"expected_data/series.patch")
def test_commit_msg(self): def test_commit_msg(self):
table = load_patch_table(MOCK_INPUTS_DIR, "5.10.140") root_dir = "/sonic/" + PATCH_TABLE_LOC + PATCHWORK_LOC.format("5.10")
sb, slk = self.action.create_commit_msg(table) content = "patchwork_link: https://patchwork.ozlabs.org/project/linux-i2c/patch/20230215195322.21955-1-vadimp@nvidia.com/\n"
print(slk) file = "0188-i2c-mux-Add-register-map-based-mux-driver.patch.txt"
print(TEST_SLK_COMMIT) table = load_patch_table(MOCK_INPUTS_DIR, "5.10")
assert slk.split() == TEST_SLK_COMMIT.split() with Patcher() as patcher:
assert sb.split() == TEST_SB_COMMIT.split() patcher.fs.create_file(os.path.join(root_dir, file), contents=content)
sb, slk = self.action.create_commit_msg(table)
print(slk)
print(TEST_SLK_COMMIT)
assert slk.split() == TEST_SLK_COMMIT.split()
assert sb.split() == TEST_SB_COMMIT.split()