Simulator can recycle keys
Rather than always generating a new key, let's sometimes recycle a key value to test caching. Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
This commit is contained in:
parent
787d9b4a7b
commit
238da432fb
|
@ -5,22 +5,35 @@ import string
|
||||||
|
|
||||||
class Serial:
|
class Serial:
|
||||||
def __init__(self, path, baudrate, timeout):
|
def __init__(self, path, baudrate, timeout):
|
||||||
self.path = path
|
self.path = path
|
||||||
self.baudrate = baudrate
|
self.baudrate = baudrate
|
||||||
self.timeout = timeout
|
self.timeout = timeout
|
||||||
|
self.generated = set()
|
||||||
|
self.exceptions = True
|
||||||
|
|
||||||
def gen_key(self, count):
|
def gen_key(self, count):
|
||||||
lst = [random.choice(string.hexdigits) for n in range(count - 2)]
|
lst = [random.choice(string.hexdigits) for n in range(count - 2)]
|
||||||
return "A" + "".join(lst) + "D"
|
ret = "A" + "".join(lst) + "D"
|
||||||
|
print("> Serial generated key: %s" % ret)
|
||||||
|
self.generated.add(ret)
|
||||||
|
return ret
|
||||||
|
|
||||||
|
def old_key(self, count):
|
||||||
|
if len(self.generated) == 0:
|
||||||
|
return self.gen_key(count)
|
||||||
|
index = random.randint(0, len(self.generated) - 1)
|
||||||
|
ret = list(self.generated)[index]
|
||||||
|
print("> Serial using old key: %s" % ret)
|
||||||
|
return ret;
|
||||||
|
|
||||||
def read(self, count):
|
def read(self, count):
|
||||||
val = random.randint(0, 4)
|
val = random.randint(0, 5)
|
||||||
if val == 0 or val == 1:
|
if val == 0:
|
||||||
|
return self.gen_key(count).encode()
|
||||||
|
elif val in {1, 2}:
|
||||||
|
return self.old_key(count).encode()
|
||||||
|
elif val in {3, 4} or self.exceptions == False:
|
||||||
return "".encode()
|
return "".encode()
|
||||||
elif val == 2 or val == 3:
|
|
||||||
ret = self.gen_key(count)
|
|
||||||
print("> Serial generating key: %s" % ret)
|
|
||||||
return ret.encode()
|
|
||||||
raise Exception("Test Serial Exception")
|
raise Exception("Test Serial Exception")
|
||||||
|
|
||||||
def flushInput(self):
|
def flushInput(self):
|
||||||
|
|
|
@ -13,11 +13,11 @@ class Request:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def read(self):
|
def read(self):
|
||||||
val = random.randint(0, 4)
|
val = random.randint(0, 5)
|
||||||
if val == 0 or val == 1:
|
if val == 0:
|
||||||
return "OK".encode()
|
|
||||||
elif val == 2 or val == 3:
|
|
||||||
return "ERROR".encode()
|
return "ERROR".encode()
|
||||||
|
elif val < 4:
|
||||||
|
return "OK".encode()
|
||||||
raise Exception("Test Network Exception")
|
raise Exception("Test Network Exception")
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue