Skip to content

Commit

Permalink
fix tests and a regression found after API test run
Browse files Browse the repository at this point in the history
  • Loading branch information
yocalebo committed May 11, 2024
1 parent af2f55b commit 06dab03
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 40 deletions.
2 changes: 1 addition & 1 deletion src/middlewared/middlewared/plugins/pool_/replace_disk.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ async def replace(self, job, oid, options):
await self.middleware.call('pool.format_disks', job, {
disk['devname']: {
'vdev': vdev,
'size': min_size,
'size': None, # pool.format_disks checks size of disk
'create_swap': False,
},
})
Expand Down
5 changes: 2 additions & 3 deletions tests/api2/test_disk_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ def test_disk_format_removes_existing_partition_table(unused_disk):
partitions = call('disk.list_partitions', disk['name'])
assert len(partitions) == 1

# format removes existing partition labels
call('disk.format', disk['name'], 0)
# We should now have one partition: data
# format removes existing partition labels and creates a new (data) partition
call('disk.format', disk['name'], NO_SWAP)
partitions = call('disk.list_partitions', disk['name'])
assert len(partitions) == 1
12 changes: 5 additions & 7 deletions tests/api2/test_disk_wipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,18 @@ def test_disk_wipe_partition_clean():

disk = call("disk.get_unused")[0]["name"]

# Create 1 GiB swap and a data partition
call('disk.format', disk, 1)
# Create a data partition
call('disk.format', disk, 0)
parts = call('disk.list_partitions', disk)
seek_blk = parts[1]['start_sector']
seek_blk = parts[0]['start_sector']
blk_size = int(parts[0]['start'] / parts[0]['start_sector'])

# Write some private data into the start of the data partition
cmd = (
ssh(
f"echo '{signal_msg}' > junk;"
f"dd if=junk bs={blk_size} count=1 oseek={seek_blk} of=/dev/{disk};"
"rm -f junk"
)
ssh(cmd)

# Confirm presence
readback_presence = ssh(f"dd if=/dev/{disk} bs={blk_size} iseek={seek_blk} count=1").splitlines()[0]
Expand All @@ -64,8 +63,7 @@ def test_disk_wipe_partition_clean():
proc_partitions = str(ssh('cat /proc/partitions'))
# If the wipe is truly successful /proc/partitions should have a singular
# entry for 'disk' in the table
disk_entries = [line for line in proc_partitions.splitlines() if disk in line]
assert len(disk_entries) == 1
assert len([line for line in proc_partitions.splitlines() if disk in line]) == 1


@pytest.mark.parametrize('dev_name', ['BOOT', 'UNUSED', 'bogus', ''])
Expand Down
4 changes: 2 additions & 2 deletions tests/api2/test_pool_expand.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ def test_expand_pool():

# Transform this pool into a pool on a vdev with a partition that is only 2 GiB
ssh(f"zpool export {pool['name']}")
ssh(f"sgdisk -d 2 /dev/{disk}")
ssh(f"sgdisk -n 2:0:+2GiB -t 2:BF01 /dev/{disk}")
ssh(f"sgdisk -d 1 /dev/{disk}")
ssh(f"sgdisk -n 1:0:+2GiB -t 1:BF01 /dev/{disk}")
small_partition = call("disk.list_partitions", disk)[-1]
assert small_partition["size"] < 2147483648 * 1.01
device = "disk/by-partuuid/" + small_partition["partition_uuid"]
Expand Down
28 changes: 1 addition & 27 deletions tests/api2/test_pool_replace_disk.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest

from time import sleep
from middlewared.test.integration.assets.pool import mirror_topology, another_pool_topologies, another_pool
from middlewared.test.integration.assets.pool import another_pool_topologies, another_pool
from middlewared.test.integration.utils import call
from auto_config import ha
pytestmark = [
Expand Down Expand Up @@ -49,29 +49,3 @@ def test_pool_replace_disk(topology, i):

assert call("disk.get_instance", new_disk["identifier"], {"extra": {"pools": True}})["pool"] == pool["name"]
assert call("disk.get_instance", to_replace_disk["identifier"], {"extra": {"pools": True}})["pool"] is None


@pytest.mark.parametrize("swaps", [[0, 0], [2, 2], [2, 4]])
def test_pool_replace_disk_swap(swaps):
unused = call("disk.get_unused")
if len(unused) < 3:
raise RuntimeError(f"At least 3 unused disks required to run this test")

test_disks = unused[:3]

sizes = {disk["name"]: disk["size"] for disk in test_disks}
assert len(set(sizes.values())) == 1, sizes

call("system.advanced.update", {"swapondrive": swaps[0]})
try:
with another_pool(topology=mirror_topology) as pool:
to_replace_vdev = disks(pool["topology"])[0]

call("system.advanced.update", {"swapondrive": swaps[1]})
call("pool.replace", pool["id"], {
"label": to_replace_vdev["guid"],
"disk": test_disks[2]["identifier"],
"force": True,
}, job=True)
finally:
call("system.advanced.update", {"swapondrive": 2})

0 comments on commit 06dab03

Please sign in to comment.