Skip to content

Commit 68e5007

Browse files
authored
Merge pull request #279 from rushikeshjadhav/feat-storage-linstor-611
tests/storage/linstor: Add test for forgetting and introducing Linstor SR
2 parents 33246a0 + 934d625 commit 68e5007

3 files changed

Lines changed: 60 additions & 2 deletions

File tree

lib/host.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
XAPI_CONF_FILE = '/etc/xapi.conf'
4444
XAPI_CONF_DIR = '/etc/xapi.conf.d'
4545

46+
4647
def host_data(hostname_or_ip: str) -> dict[str, str]:
4748
# read from data.py
4849
from data import HOST_DEFAULT_PASSWORD, HOST_DEFAULT_USER, HOSTS
@@ -171,7 +172,7 @@ def xe(self, action: str, args: dict[str, str | bool | dict[str, str]] = {}, *,
171172

172173
def stringify(key: str, value: str | bool | dict[str, str]) -> str:
173174
if isinstance(value, bool):
174-
return "{}={}".format(key, to_xapi_bool(value))
175+
return f"{key}={to_xapi_bool(value)}"
175176
if isinstance(value, dict):
176177
ret = ""
177178
for key2, value2 in value.items():

lib/sr.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
)
2121
from lib.vdi import VDI, ImageFormat
2222

23-
from typing import TYPE_CHECKING, Literal, overload
23+
from typing import TYPE_CHECKING, Literal, Self, overload
2424

2525
if TYPE_CHECKING:
2626
from lib.host import Host
@@ -202,6 +202,16 @@ def param_clear(self, param_name: str) -> None:
202202
def content_type(self) -> str:
203203
return self.param_get('content-type')
204204

205+
@classmethod
206+
def introduce(cls, pool: Pool, type: str, shared: bool, name_label: str, sr_uuid: str) -> Self:
207+
return cls(
208+
pool.master.xe(
209+
'sr-introduce',
210+
{'uuid': sr_uuid, 'type': type, 'shared': shared, 'content-type': 'user', 'name-label': name_label},
211+
),
212+
pool,
213+
)
214+
205215
def is_shared(self) -> bool:
206216
if self._is_shared is None:
207217
self._is_shared = strtobool(self.param_get('shared'))

tests/storage/linstor/test_linstor_sr.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,53 @@ def test_resize_vdi(self, vm_on_linstor_sr: VM) -> None:
206206
vm.wait_for_os_booted()
207207
vm.shutdown(verify=True)
208208

209+
def test_forget_and_introduce_sr(self, linstor_sr: SR):
210+
sr = linstor_sr
211+
sr_name = sr.param_get('name-label')
212+
all_pbds = sr.pbd_uuids()
213+
pbd_config_hosts: list[list[str]] = []
214+
pbd_config_devices: list[list[str]] = []
215+
for pbd in all_pbds:
216+
pbd_config_hosts.append(
217+
safe_split(sr.pool.master.xe('pbd-param-get', {'uuid': pbd, 'param-name': 'host-uuid'}))
218+
)
219+
pbd_config_devices.append(
220+
safe_split(sr.pool.master.xe('pbd-param-get', {'uuid': pbd, 'param-name': 'device-config'}))
221+
)
222+
223+
sr.forget()
224+
logging.info(f"Forgot SR {sr.uuid} successfully")
225+
226+
with pytest.raises(Exception):
227+
sr_type = sr.param_get('type') # Expecting exception as sr should not exist
228+
sr.plug_pbds() # Plug back pbds and let teardown handle SR destroy
229+
pytest.fail(f"SR still exists; returned type: {sr_type}")
230+
231+
logging.info(f"Introducing SR {sr.uuid} back")
232+
new_sr = SR.introduce(sr.pool, type='linstor', shared=True, name_label=sr_name, sr_uuid=sr.uuid)
233+
234+
# Example pbd_config_device
235+
# {provisioning: thin; redundancy: 3; group-name: linstor_group/thin_device}
236+
for pbd_config_host, pbd_config_device in zip(pbd_config_hosts, pbd_config_devices):
237+
pbd_config_dict = dict(
238+
(kv.split(": ")[0].strip(), kv.split(": ")[1].strip())
239+
for kv in pbd_config_device[0].split(";")
240+
if ": " in kv # Ensure key-value pair
241+
)
242+
243+
sr.pool.master.xe(
244+
"pbd-create",
245+
{
246+
"sr-uuid": new_sr.uuid,
247+
"host-uuid": pbd_config_host[0],
248+
"content-type": "user",
249+
"device-config": pbd_config_dict,
250+
},
251+
)
252+
253+
new_sr.plug_pbds(verify=True)
254+
logging.info(f"Introduced SR {new_sr.uuid} successfully")
255+
209256
# *** tests with reboots (longer tests).
210257

211258
@pytest.mark.reboot

0 commit comments

Comments
 (0)