Skip to content

Commit

Permalink
Add unit tests for blktap2.TapCtl
Browse files Browse the repository at this point in the history
Signed-off-by: Mark Syms <mark.syms@citrix.com>
  • Loading branch information
MarkSymsCtx committed Jun 1, 2020
1 parent dd36c65 commit f434164
Show file tree
Hide file tree
Showing 2 changed files with 650 additions and 6 deletions.
21 changes: 17 additions & 4 deletions drivers/blktap2.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,14 @@ def __getattr__(self, key):
if self.info.has_key(key): return self.info[key]
return object.__getattribute__(self, key)

@property
def has_status(self):
return 'status' in self.info

@property
def has_signal(self):
return 'signal' in self.info

# Retrieves the error code returned by the command. If the error code
# was not supplied at object-construction time, zero is returned.
def get_error_code(self):
Expand Down Expand Up @@ -351,7 +359,7 @@ def list(cls, **args):

except cls.CommandFailure, e:
transient = [ errno.EPROTO, errno.ENOENT ]
if e.status in transient:
if e.has_status and e.status in transient:
raise RetryLoop.TransientFailure(e)
raise

Expand Down Expand Up @@ -389,6 +397,12 @@ def detach(cls, pid, minor):
args = [ "detach", "-p", pid, "-m", minor ]
cls._pread(args)

@classmethod
def _load_key(cls, key_hash, vdi_uuid):
import plugins

return plugins.load_key(key_hash, vdi_uuid)

@classmethod
def open(cls, pid, minor, _type, _file, options):
params = Tapdisk.Arg(_type, _file)
Expand All @@ -414,11 +428,10 @@ def open(cls, pid, minor, _type, _file, options):
if options.get('cbtlog'):
args.extend(['-C', options['cbtlog']])
if options.get('key_hash'):
import plugins

key_hash = options['key_hash']
vdi_uuid = options['vdi_uuid']
key = plugins.load_key(key_hash, vdi_uuid)
key = cls._load_key(key_hash, vdi_uuid)

if not key:
raise util.SMException("No key found with key hash {}".format(key_hash))
input = key
Expand Down

0 comments on commit f434164

Please sign in to comment.