aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSzczepan Zalega <szczepan@nitrokey.com>2019-01-26 20:59:36 +0100
committerSzczepan Zalega <szczepan@nitrokey.com>2019-01-26 21:13:21 +0100
commit909a2c3c30fc56e42c0193ab528ae86cde31ea7c (patch)
treeb0757100a6cb43bcf1c0696f7d89f6be075eba6a
parentc9b07f6adea66d1edc20acfee759880743e6a5db (diff)
downloadlibnitrokey-909a2c3c30fc56e42c0193ab528ae86cde31ea7c.tar.gz
libnitrokey-909a2c3c30fc56e42c0193ab528ae86cde31ea7c.tar.bz2
Detect UV's block device on Fedora automatically
Signed-off-by: Szczepan Zalega <szczepan@nitrokey.com>
-rw-r--r--unittest/test_storage.py32
1 files changed, 27 insertions, 5 deletions
diff --git a/unittest/test_storage.py b/unittest/test_storage.py
index 73dae9d..55671ae 100644
--- a/unittest/test_storage.py
+++ b/unittest/test_storage.py
@@ -409,14 +409,36 @@ def test_export_firmware_extended_fedora29(C):
skip_if_device_version_lower_than({'S': 43})
skip_if_not_fedora('Fedora specific test, due to the mount path. Could be suited for Debian.')
- import pexpect
from time import sleep
import os
from os.path import exists as exist
+ import re
+ try:
+ import pyudev as pu
+ import pexpect
+ except:
+ pytest.skip('Skipping due to missing required packages: pyudev and pexpect.')
+
+ ctx = pu.Context()
+ devices = ctx.list_devices(subsystem='block', ID_VENDOR='Nitrokey')
+ device = None
+ for d in devices:
+ if d.device_type == 'partition':
+ device = '/dev/{}'.format(d.sys_name)
+ break
+ assert device, 'Device could not be found'
+
+ pexpect.run(f'udisksctl unmount -b {device}').decode()
+ sleep(1)
+ _res = pexpect.run(f'udisksctl mount -b {device}').decode()
+ firmware_abs_path = re.findall('at (/.*)\.', _res)
+ assert firmware_abs_path, 'Cannot get mount point'
+ firmware_abs_path = firmware_abs_path[0]
+
+ print('path: {}, device: {}'.format(firmware_abs_path, device))
+ assert firmware_abs_path, 'Cannot get mount point'
+ firmware_abs_path = firmware_abs_path + '/firmware.bin'
- device = '/dev/sde1' # FIXME autodetect the block device with udev
- firmware_abs_path = '/run/media/sz/Nitrokey/firmware.bin' # FIXME use the actual user name in mount path
- pexpect.run(f'udisksctl mount -b {device}')
checks = 0
checks_add = 0
@@ -428,7 +450,7 @@ def test_export_firmware_extended_fedora29(C):
ATTEMPTS = 20
for i in range(ATTEMPTS):
# if umount is disabled, success rate is 3/10, enabled: 10/10
- # pexpect.run(f'udisksctl unmount -b {device}')
+ pexpect.run(f'udisksctl unmount -b {device}')
assert C.NK_export_firmware(DefaultPasswords.ADMIN) == DeviceErrorCode.STATUS_OK
pexpect.run(f'udisksctl mount -b {device}')
sleep(1)