|
4 | 4 |
|
5 | 5 | from .conftest import LINSTOR_PACKAGE
|
6 | 6 | 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 |
8 | 8 | from tests.storage import vdi_is_open
|
9 | 9 |
|
10 | 10 | # Requirements:
|
@@ -78,6 +78,57 @@ def test_snapshot(self, vm_on_linstor_sr):
|
78 | 78 | finally:
|
79 | 79 | vm.shutdown(verify=True)
|
80 | 80 |
|
| 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 | + |
81 | 132 | # *** tests with reboots (longer tests).
|
82 | 133 |
|
83 | 134 | @pytest.mark.reboot
|
|
0 commit comments