Skip to content

Commit 8dc3344

Browse files
kgodara912Kshitiz Godara
andauthored
libstoragemgmt: Address ptest and package installation failure (microsoft#17793)
Co-authored-by: Kshitiz Godara <kgodara@microsoft.com>
1 parent 5d32911 commit 8dc3344

2 files changed

Lines changed: 129 additions & 1 deletion

File tree

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
From: Kshitiz Godara <kgodara@microsoft.com>
2+
Date: Sun, 21 Jun 2026 00:00:00 +0000
3+
Subject: [PATCH] test: gate live local-disk probes behind LSM_TEST_LOCAL_DISK_HW
4+
5+
test_local_disk_link_type and test_local_disk_link_speed_get issue real
6+
SCSI MODE SENSE / lsm_local_disk_list() probes against /dev/sd*. In a
7+
build chroot those devices are not real backing hardware, so MODE SENSE
8+
returns a zero-length data page and the library legitimately reports
9+
LSM_ERR_LIB_BUG (or another "unexpected" return code), failing the
10+
tests.
11+
12+
Gate only the hardware-touching portions of both tests behind an opt-in
13+
LSM_TEST_LOCAL_DISK_HW environment variable (off by default). The
14+
negative-path assertions (invalid argument, non-existent disk) still
15+
run unconditionally, preserving coverage of the public API contract.
16+
17+
Test-only change; nothing in the shipped libstoragemgmt binary is
18+
affected.
19+
---
20+
diff --git a/test/tester.c b/test/tester.c
21+
index aba56a0..aa06839 100644
22+
--- a/test/tester.c
23+
+++ b/test/tester.c
24+
@@ -3735,18 +3735,22 @@ START_TEST(test_local_disk_link_type) {
25+
lsm_disk_link_type link_type = LSM_DISK_LINK_TYPE_UNKNOWN;
26+
lsm_error *lsm_err = NULL;
27+
28+
- rc = lsm_local_disk_link_type_get("/dev/sda", &link_type, &lsm_err);
29+
- if (lsm_err != NULL)
30+
- ck_assert_msg(rc != LSM_ERR_LIB_BUG,
31+
- "lsm_local_disk_link_type_get() got LSM_ERR_LIB_BUG: %s",
32+
- lsm_error_message_get(lsm_err));
33+
- else
34+
- ck_assert_msg(rc != LSM_ERR_LIB_BUG,
35+
- "lsm_local_disk_link_type_get() got LSM_ERR_LIB_BUG with "
36+
- "NULL lsm_err");
37+
-
38+
- if (rc != LSM_ERR_OK)
39+
- lsm_error_free(lsm_err);
40+
+ /* /dev/sda probe issues a real SCSI MODE SENSE ioctl; only works on
41+
+ * real hardware. Opt in via LSM_TEST_LOCAL_DISK_HW=1 on bare metal. */
42+
+ if (getenv("LSM_TEST_LOCAL_DISK_HW") != NULL) {
43+
+ rc = lsm_local_disk_link_type_get("/dev/sda", &link_type, &lsm_err);
44+
+ if (lsm_err != NULL)
45+
+ ck_assert_msg(rc != LSM_ERR_LIB_BUG,
46+
+ "lsm_local_disk_link_type_get() got LSM_ERR_LIB_BUG: %s",
47+
+ lsm_error_message_get(lsm_err));
48+
+ else
49+
+ ck_assert_msg(rc != LSM_ERR_LIB_BUG,
50+
+ "lsm_local_disk_link_type_get() got LSM_ERR_LIB_BUG with "
51+
+ "NULL lsm_err");
52+
+
53+
+ if (rc != LSM_ERR_OK)
54+
+ lsm_error_free(lsm_err);
55+
+ }
56+
57+
/* Test non-exist disk */
58+
rc = lsm_local_disk_link_type_get(NOT_EXIST_SD_PATH, &link_type, &lsm_err);
59+
@@ -4163,23 +4167,30 @@ START_TEST(test_local_disk_link_speed_get) {
60+
const char *disk_path = NULL;
61+
uint32_t link_speed = LSM_DISK_LINK_SPEED_UNKNOWN;
62+
63+
- rc = lsm_local_disk_list(&disk_paths, &lsm_err);
64+
- if (lsm_err)
65+
- lsm_error_free(lsm_err);
66+
- ck_assert_msg(rc == LSM_ERR_OK, "lsm_local_disk_list() failed as %d", rc);
67+
- /* Only try maximum 4 disks */
68+
- for (; i < lsm_string_list_size(disk_paths) && i < 4; ++i) {
69+
- disk_path = lsm_string_list_elem_get(disk_paths, i);
70+
- ck_assert_msg(disk_path != NULL, "Got NULL disk path");
71+
- rc = lsm_local_disk_link_speed_get(disk_path, &link_speed, &lsm_err);
72+
- ck_assert_msg(rc == LSM_ERR_OK || rc == LSM_ERR_NO_SUPPORT ||
73+
- rc == LSM_ERR_PERMISSION_DENIED,
74+
- "lsm_local_disk_led_status_get(): "
75+
- "Got unexpected return: %d",
76+
- rc);
77+
+ /* Iterating local disks and probing link speed needs real SCSI hardware
78+
+ * backing /dev/sd*; in a build chroot the probe returns LSM_ERR_LIB_BUG.
79+
+ * Opt in via LSM_TEST_LOCAL_DISK_HW=1 on bare metal. */
80+
+ if (getenv("LSM_TEST_LOCAL_DISK_HW") != NULL) {
81+
+ rc = lsm_local_disk_list(&disk_paths, &lsm_err);
82+
if (lsm_err)
83+
lsm_error_free(lsm_err);
84+
- lsm_err = NULL;
85+
+ ck_assert_msg(rc == LSM_ERR_OK,
86+
+ "lsm_local_disk_list() failed as %d", rc);
87+
+ /* Only try maximum 4 disks */
88+
+ for (; i < lsm_string_list_size(disk_paths) && i < 4; ++i) {
89+
+ disk_path = lsm_string_list_elem_get(disk_paths, i);
90+
+ ck_assert_msg(disk_path != NULL, "Got NULL disk path");
91+
+ rc = lsm_local_disk_link_speed_get(disk_path, &link_speed,
92+
+ &lsm_err);
93+
+ ck_assert_msg(rc == LSM_ERR_OK || rc == LSM_ERR_NO_SUPPORT ||
94+
+ rc == LSM_ERR_PERMISSION_DENIED,
95+
+ "lsm_local_disk_link_speed_get(): "
96+
+ "Got unexpected return: %d",
97+
+ rc);
98+
+ if (lsm_err)
99+
+ lsm_error_free(lsm_err);
100+
+ lsm_err = NULL;
101+
+ }
102+
}
103+
104+
/* Test invalid argument */
105+
@@ -4221,7 +4232,8 @@ START_TEST(test_local_disk_link_speed_get) {
106+
"LSM_DISK_LINK_SPEED_UNKNOWN, but got %" PRIu32 "",
107+
link_speed);
108+
lsm_error_free(lsm_err);
109+
- lsm_string_list_free(disk_paths);
110+
+ if (disk_paths != NULL)
111+
+ lsm_string_list_free(disk_paths);
112+
}
113+
END_TEST
114+

SPECS/libstoragemgmt/libstoragemgmt.spec

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
Summary: Storage array management library
22
Name: libstoragemgmt
33
Version: 1.9.8
4-
Release: 1%{?dist}
4+
Release: 2%{?dist}
55
License: LGPLv2+
66
Vendor: Microsoft Corporation
77
Distribution: Azure Linux
88
URL: https://github.com/libstorage/libstoragemgmt
99
Source0: https://github.com/libstorage/%{name}/releases/download/%{version}/%{name}-%{version}.tar.gz
10+
%if 0%{?with_check}
11+
Patch0: libstoragemgmt-tests-gate-hw-disk-probes.patch
12+
%endif
1013

1114
BuildRequires: autoconf
1215
BuildRequires: automake
@@ -33,6 +36,8 @@ BuildRequires: valgrind
3336
BuildRequires: git
3437
%endif
3538
Requires: python3-%{name}
39+
Requires(pre): /usr/sbin/groupadd
40+
Requires(pre): /usr/sbin/useradd
3641

3742
%description
3843
The libStorageMgmt library will provide a vendor agnostic open source storage
@@ -454,6 +459,15 @@ fi
454459
%{_mandir}/man1/local_lsmplugin.1*
455460

456461
%changelog
462+
* Sun Jun 21 2026 Kshitiz Godara <kgodara@microsoft.com> - 1.9.8-2
463+
- Add test-only patch (gated by with_check) to skip /dev/sd*
464+
hardware probes in test_local_disk_link_type and
465+
test_local_disk_link_speed_get; fixes %check failure in
466+
chroot.
467+
- Add Requires(pre) on /usr/sbin/groupadd and /usr/sbin/useradd
468+
so the %pre scriptlet works on minimal images where
469+
shadow-utils is not installed.
470+
457471
* Tue Feb 06 2024 Nan Liu <liunan@microsoft.com> - 1.9.8-1
458472
- Upgrade to 1.9.8 in Azure Linux 3.0
459473
- Remove the unneeded patch

0 commit comments

Comments
 (0)