Skip to content

Commit 988e81e

Browse files
tests/storage/linstor: Add test for forgetting and introducing Linstor SR
Introduced `test_forget_and_introduce_sr` in `test_linstor_sr.py` - Validates the ability to forget an SR and properly reintroduce it. - Ensures all PBD configurations are stored and restored correctly. - Checks that exceptions are raised when querying a forgotten SR. - Restores the SR and verifies successful reattachment of PBDs. Signed-off-by: Rushikesh Jadhav <[email protected]>
1 parent 567c583 commit 988e81e

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

Diff for: tests/storage/linstor/conftest.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def linstor_sr(pool_with_linstor, provisioning_type, storage_pool_name):
9393
'provisioning': provisioning_type
9494
}, shared=True)
9595
yield sr
96-
sr.destroy()
96+
sr.destroy(verify=True)
9797

9898
@pytest.fixture(scope='module')
9999
def vdi_on_linstor_sr(linstor_sr):

Diff for: tests/storage/linstor/test_linstor_sr.py

+52-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from .conftest import LINSTOR_PACKAGE
66
from lib.commands import SSHCommandFailed
7-
from lib.common import wait_for, vm_image
7+
from lib.common import wait_for, vm_image, safe_split
88
from tests.storage import vdi_is_open
99

1010
# Requirements:
@@ -78,6 +78,57 @@ def test_snapshot(self, vm_on_linstor_sr):
7878
finally:
7979
vm.shutdown(verify=True)
8080

81+
def test_forget_and_introduce_sr(self, linstor_sr):
82+
from lib.sr import SR
83+
84+
sr = linstor_sr
85+
sr_name = sr.param_get('name-label')
86+
all_pbds = sr.pbd_uuids()
87+
pbd_config_hosts = []
88+
pbd_config_devices = []
89+
# TBD: Move the pbd-param-get to either sr.py or introduce pbd.py
90+
for pbd in all_pbds:
91+
pbd_config_hosts.append(
92+
safe_split(sr.pool.master.xe('pbd-param-get', {'uuid': pbd, 'param-name': 'host-uuid'})))
93+
pbd_config_devices.append(
94+
safe_split(sr.pool.master.xe('pbd-param-get', {'uuid': pbd, 'param-name': 'device-config'})))
95+
96+
if sr.all_pbds_attached():
97+
sr.unplug_pbds()
98+
99+
sr.forget()
100+
logging.info(f"Forgot SR {sr.uuid} successfully.")
101+
102+
with pytest.raises(Exception):
103+
sr_type = sr.param_get('type') # Expecting exception as sr should not exist
104+
sr.plug_pbds() # Plug back pbds and let teardown handle SR destroy
105+
pytest.fail(f"SR still exists; returned type: {sr_type}")
106+
107+
logging.info(f"Introducing SR {sr.uuid} back.")
108+
new_sr = sr.introduce(type='linstor', shared='true', name_label=sr_name, uuid=sr.uuid)
109+
110+
# Example pbd_config_device
111+
# {provisioning: thin; redundancy: 3; group-name: linstor_group/thin_device}
112+
for pbd_config_host, pbd_config_device in zip(pbd_config_hosts, pbd_config_devices):
113+
pbd_config_dict = dict(
114+
(kv.split(": ")[0].strip(), kv.split(": ")[1].strip())
115+
for kv in pbd_config_device[0].split(";") if ": " in kv # Ensure key-value pair
116+
)
117+
device_config_entries = [('device-config:' + k, v) for k, v in pbd_config_dict.items()]
118+
119+
sr.pool.master.xe(
120+
'pbd-create',
121+
[
122+
('sr-uuid', new_sr),
123+
('host-uuid', pbd_config_host[0]),
124+
('content-type', 'user'),
125+
] + device_config_entries
126+
)
127+
128+
restored_sr = SR(new_sr, sr.pool)
129+
restored_sr.plug_pbds(verify=True)
130+
logging.info(f"Introduced SR {sr.uuid} successfully.")
131+
81132
# *** tests with reboots (longer tests).
82133

83134
@pytest.mark.reboot

0 commit comments

Comments
 (0)