Skip to content

Commit 0c2ef10

Browse files
committed
Address some comments
lib/vdi.py: Renamed `size` to `get_virtual_size` Renamed `readonly` to `is_readonly` tests/storage/ext/test_ext_sr.py: Changed to use `vdi.get_virtual_size()` Fix Exception type in `test_failing_resize` tests/storage/lvm/test_lvm_sr.py: Changed to use `vdi.get_virtual_size()` Changed Exception handling to use `pytest.raises()` Signed-off-by: Damien Thenot <[email protected]>
1 parent 2359991 commit 0c2ef10

File tree

3 files changed

+13
-21
lines changed

3 files changed

+13
-21
lines changed

lib/vdi.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ def clone(self):
4444
uuid = self.sr.pool.master.xe('vdi-clone', {'uuid': self.uuid})
4545
return VDI(uuid, sr=self.sr)
4646

47-
def readonly(self) -> bool:
47+
def is_readonly(self) -> bool:
4848
return strtobool(self.param_get("read-only"))
4949

50-
def size(self) -> int:
50+
def get_virtual_size(self) -> int:
5151
return int(self.param_get("virtual-size"))
5252

5353
def resize(self, new_size: int) -> None:

tests/storage/ext/test_ext_sr.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,29 +74,29 @@ def test_blktap_activate_failure(self, vm_on_ext_sr):
7474
def test_resize(self, vm_on_ext_sr):
7575
vm = vm_on_ext_sr
7676
vdi = VDI(vm.vdi_uuids()[0], host=vm.host)
77-
old_size = vdi.size()
77+
old_size = vdi.get_virtual_size()
7878
new_size = old_size + (1 * 1024 * 1024 * 1024) # Adding a 1GiB to size
7979

8080
vdi.resize(new_size)
8181

82-
assert vdi.size() == new_size
82+
assert vdi.get_virtual_size() == new_size
8383

8484
@pytest.mark.small_vm
8585
@pytest.mark.big_vm
8686
def test_failing_resize(self, host, ext_sr, vm_on_ext_sr, exit_on_fistpoint):
8787
vm = vm_on_ext_sr
8888
vdi = VDI(vm.vdi_uuids()[0], host=vm.host)
89-
old_size = vdi.size()
89+
old_size = vdi.get_virtual_size()
9090
new_size = old_size + (1 * 1024 * 1024 * 1024) # Adding a 1GiB to size
9191

9292
with FistPoint(vm.host, "LVHDRT_inflate_after_setSize"):
9393
try:
9494
vdi.resize(new_size)
95-
except Exception:
95+
except SSHCommandFailed:
9696
logging.info(f"Launching SR scan for {ext_sr} after failure")
9797
host.xe("sr-scan", {"uuid": ext_sr})
9898

99-
assert vdi.size() == new_size
99+
assert vdi.get_virtual_size() == new_size
100100

101101
@pytest.mark.reboot
102102
@pytest.mark.small_vm

tests/storage/lvm/test_lvm_sr.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,14 @@ def test_snapshot(self, vm_on_lvm_sr):
6363
def test_failing_resize_on_inflate_after_setSize(self, host, lvm_sr, vm_on_lvm_sr, exit_on_fistpoint):
6464
vm = vm_on_lvm_sr
6565
lvinflate = ""
66-
need_rescan = False
6766
vdi = VDI(vm.vdi_uuids()[0], host=vm.host)
68-
new_size = vdi.size() + (1 * 1024 * 1024 * 1024) # Adding a 1GiB to size
67+
new_size = vdi.get_virtual_size() + (1 * 1024 * 1024 * 1024) # Adding a 1GiB to size
6968

7069
with FistPoint(vm.host, "LVHDRT_inflate_after_setSize"):
71-
try:
70+
with pytest.raises(SSHCommandFailed) as exc_info:
7271
vdi.resize(new_size)
73-
except SSHCommandFailed as e:
74-
logging.info(e)
75-
need_rescan = True
72+
logging.info(exc_info)
7673

77-
assert need_rescan, "Resize did not make an error"
7874
lvlist = host.lvs(f"VG_XenStorage-{lvm_sr.uuid}")
7975
for lv in lvlist:
8076
if lv.startswith("inflate_"):
@@ -94,18 +90,14 @@ def test_failing_resize_on_inflate_after_setSize(self, host, lvm_sr, vm_on_lvm_s
9490
def test_failing_resize_on_inflate_after_setSizePhys(self, host, lvm_sr, vm_on_lvm_sr, exit_on_fistpoint):
9591
vm = vm_on_lvm_sr
9692
lvinflate = ""
97-
need_rescan = False
9893
vdi = VDI(vm.vdi_uuids()[0], host=vm.host)
99-
new_size = vdi.size() + (1 * 1024 * 1024 * 1024) # Adding a 1GiB to size
94+
new_size = vdi.get_virtual_size() + (1 * 1024 * 1024 * 1024) # Adding a 1GiB to size
10095

10196
with FistPoint(vm.host, "LVHDRT_inflate_after_setSizePhys"):
102-
try:
97+
with pytest.raises(SSHCommandFailed) as exc_info:
10398
vdi.resize(new_size)
104-
except SSHCommandFailed as e:
105-
logging.info(e)
106-
need_rescan = True
99+
logging.info(exc_info)
107100

108-
assert need_rescan, "Resize did not make an error"
109101
lvlist = host.lvs(f"VG_XenStorage-{lvm_sr.uuid}")
110102
for lv in lvlist:
111103
if lv.startswith("inflate_"):

0 commit comments

Comments
 (0)