-
Notifications
You must be signed in to change notification settings - Fork 491
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor out zvol create function and include wait_zvol check (#15046)
- Loading branch information
1 parent
3b9b1c7
commit feca45d
Showing
4 changed files
with
90 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import contextlib | ||
from time import sleep | ||
|
||
from middlewared.service_exception import InstanceNotFound | ||
from middlewared.test.integration.utils import call, ssh | ||
|
||
MB = 1024 * 1024 | ||
|
||
|
||
@contextlib.contextmanager | ||
def zvol(name, volsizeMB=512, pool=None, recursive=False, force=False, wait_zvol=True): | ||
payload = { | ||
'name': f'{pool}/{name}' if pool else name, | ||
'type': 'VOLUME', | ||
'volsize': volsizeMB * MB, | ||
'volblocksize': '16K' | ||
} | ||
config = call('pool.dataset.create', payload) | ||
try: | ||
if wait_zvol: | ||
# Ensure that the zvol has surfaced | ||
testpath = f'/dev/zvol/{config["name"]}' | ||
retries = 5 | ||
found = False | ||
while retries: | ||
result = ssh(f'ls -1 {testpath}', False, True) | ||
if result['stdout']: | ||
for line in result['stdout'].splitlines(): | ||
if line == testpath: | ||
found = True | ||
break | ||
if found: | ||
break | ||
sleep(1) | ||
retries -= 1 | ||
yield config | ||
finally: | ||
try: | ||
call('pool.dataset.delete', config['id'], {'recursive': recursive, 'force': force}) | ||
except InstanceNotFound: | ||
pass |
Oops, something went wrong.