Catch USBError during YubiKey location

https://fedorahosted.org/freeipa/ticket/4693

Reviewed-By: Martin Kosek <mkosek@redhat.com>
This commit is contained in:
Nathaniel McCallum
2014-11-07 10:47:43 -05:00
committed by Martin Kosek
parent c13862104a
commit b3a6701e73

View File

@@ -25,6 +25,7 @@ from ipalib.plugins.otptoken import otptoken
import os
import usb.core
import yubico
__doc__ = _("""
@@ -81,8 +82,10 @@ class otptoken_add_yubikey(Command):
# Open the YubiKey
try:
yk = yubico.find_yubikey()
except yubico.yubikey.YubiKeyError, e:
raise NotFound(reason=_('No YubiKey found'))
except usb.core.USBError as e:
raise NotFound(reason="No YubiKey found: %s" % e.strerror)
except yubico.yubikey.YubiKeyError as e:
raise NotFound(reason=e.reason)
assert yk.version_num() >= (2, 1)