Skip to content

Commit

Permalink
Update tests.py
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewc12 committed Aug 3, 2023
1 parent d0811ff commit 495e2c2
Showing 1 changed file with 47 additions and 25 deletions.
72 changes: 47 additions & 25 deletions contrib/windows/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@


def parse_arguments():
parser = argparse.ArgumentParser(description='Process command line arguments.')
parser = argparse.ArgumentParser(description='Process command line ' + \
'arguments.')
parser.add_argument('-path', type=dir_path, required=True)
return parser.parse_args()

Expand All @@ -29,7 +30,8 @@ def dir_path(path):
if os.path.isdir(path):
return path
else:
raise argparse.ArgumentTypeError(f"readable_dir:{path} is not a valid path")
raise argparse.ArgumentTypeError(f"readable_dir:{path} is not a valid"
"path")


def get_DeviceId():
Expand All @@ -42,7 +44,8 @@ def get_DeviceId():
#https://github.com/sir-ragna/dddddd
#get DeviceId

a=magic_number_process.stdout.decode(encoding='UTF-8',errors='strict').replace("\r\r\n", "\r\n")
a=magic_number_process.stdout.decode(encoding='UTF-8',errors='strict')
b = a.replace("\r\r\n", "\r\n")

c = a.splitlines()

Expand All @@ -52,17 +55,17 @@ def get_DeviceId():

e.sort()

#print(e)
# print(e)

#print([x.encode(encoding='UTF-8') for x in e])
# print([x.encode(encoding='UTF-8') for x in e])

#import csv
# import csv

#with open('csv_file.csv', 'w', encoding='UTF8') as f:
# writer = csv.writer(f, dialect='excel', quoting=csv.QUOTE_ALL)
#
# for row in e:
# writer.writerow([row])
# with open('csv_file.csv', 'w', encoding='UTF8') as f:
# writer = csv.writer(f, dialect='excel', quoting=csv.QUOTE_ALL)
#
# for row in e:
# writer.writerow([row])

return e

Expand Down Expand Up @@ -109,19 +112,25 @@ def get_driveletters():

def create_pool(name, file):
magic_number_process = subprocess.run(
["C:\\Program Files\\OpenZFS On Windows\\zpool.exe", "create", "-f", name, file],
["C:\\Program Files\\OpenZFS On Windows\\zpool.exe", "create", "-f", \
name, file],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
)

return magic_number_process


def destroy_pool(name):
magic_number_process = subprocess.run(
["C:\\Program Files\\OpenZFS On Windows\\zpool.exe", "destroy", "-f", name],
["C:\\Program Files\\OpenZFS On Windows\\zpool.exe", "destroy", \
"-f", name],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
)

return magic_number_process


def zpool(*args):
magic_number_process = subprocess.run(
Expand All @@ -144,7 +153,8 @@ def zfs(*args):


def run(args):
d = {"zfs": "C:\\Program Files\\OpenZFS On Windows\\zfs.exe", "zpool": "C:\\Program Files\\OpenZFS On Windows\\zpool.exe"}
d = {"zfs": "C:\\Program Files\\OpenZFS On Windows\\zfs.exe", \
"zpool": "C:\\Program Files\\OpenZFS On Windows\\zpool.exe"}
l = list(args)
cmd = d[l[0]]
result = subprocess.run(
Expand Down Expand Up @@ -172,7 +182,7 @@ def runWithPrint(cmd):
return ret


def preTest(testName = None):
def preTest(testName=None):
print("=" * 20)
if testName is not None:
print("Name:", testName)
Expand Down Expand Up @@ -216,7 +226,8 @@ def main():
postTest()

preTest()
ret = runWithPrint(["zpool", "create", "-f", "test02", tounc(f1), tounc(f2)])
ret = runWithPrint(["zpool", "create", "-f", "test02", tounc(f1), \
tounc(f2)])
if ret.returncode != 0:
print("FAIL")
time.sleep(10)
Expand All @@ -226,7 +237,8 @@ def main():
postTest()

preTest()
ret = runWithPrint(["zpool", "create", "-f", "test03", tounc(f1), tounc(f2), tounc(f3)])
ret = runWithPrint(["zpool", "create", "-f", "test03", tounc(f1), \
tounc(f2), tounc(f3)])
if ret.returncode != 0:
print("FAIL")
time.sleep(10)
Expand All @@ -236,7 +248,8 @@ def main():
postTest()

preTest()
ret = runWithPrint(["zpool", "create", "-f", "test04", "mirror", tounc(f1), tounc(f2)])
ret = runWithPrint(["zpool", "create", "-f", "test04", "mirror", \
tounc(f1), tounc(f2)])
if ret.returncode != 0:
print("FAIL")
time.sleep(10)
Expand All @@ -246,7 +259,8 @@ def main():
postTest()

preTest()
ret = runWithPrint(["zpool", "create", "-f", "test05", "mirror", tounc(f1), tounc(f2), tounc(f3)])
ret = runWithPrint(["zpool", "create", "-f", "test05", "mirror", \
tounc(f1), tounc(f2), tounc(f3)])
time.sleep(10)
if ret.returncode != 0:
print("FAIL")
Expand All @@ -256,7 +270,8 @@ def main():
postTest()

preTest()
ret = runWithPrint(["zpool", "create", "-f", "test06", "raidz", tounc(f1), tounc(f2), tounc(f3)])
ret = runWithPrint(["zpool", "create", "-f", "test06", "raidz", \
tounc(f1), tounc(f2), tounc(f3)])
if ret.returncode != 0:
print("FAIL")
time.sleep(10)
Expand All @@ -266,7 +281,8 @@ def main():
postTest()

preTest()
ret = runWithPrint(["zpool", "create", "-f", "test07", "raidz1", tounc(f1), tounc(f2), tounc(f3)])
ret = runWithPrint(["zpool", "create", "-f", "test07", "raidz1", \
tounc(f1), tounc(f2), tounc(f3)])
if ret.returncode != 0:
print("FAIL")
time.sleep(10)
Expand Down Expand Up @@ -345,10 +361,12 @@ def main():
with open(key01, 'wb') as f:
f.write(random_bytearray)

nx ="file://" + tounc(key01).replace("\\", "/")
nx = "file://" + tounc(key01).replace("\\", "/")
print(nx)

ret = runWithPrint(["zpool", "create", "-f", "-O", "encryption=aes-256-ccm", "-O", "keylocation=" + nx, "-O", "keyformat=raw", "tank", tounc(f1)])
ret = runWithPrint(["zpool", "create", "-f", "-O", \
"encryption=aes-256-ccm", "-O", "keylocation=" + nx, "-O", \
"keyformat=raw", "tank", tounc(f1)])
if ret.returncode != 0:
print("FAIL")
time.sleep(10)
Expand All @@ -364,7 +382,9 @@ def main():
time.sleep(10)

print("Drive letters before pool create:", get_driveletters())
ret = runWithPrint(["zpool", "import", "-f", "-l", "-O", "encryption=aes-256-ccm", "-O", "keylocation=" + nx, "-O", "keyformat=raw", tounc(f1)])
ret = runWithPrint(["zpool", "import", "-f", "-l", "-O", \
"encryption=aes-256-ccm", "-O", "keylocation=" + nx, "-O", \
"keyformat=raw", tounc(f1)])
if ret.returncode != 0:
print("FAIL")
time.sleep(10)
Expand All @@ -377,7 +397,8 @@ def main():
preTest("run out of drive letters")

for i in range(1, 26):
ret = runWithPrint(["zpool", "create", "-f", "tank" + str(i), tounc(f1)])
ret = runWithPrint(["zpool", "create", "-f", "tank" + str(i), \
tounc(f1)])
if ret.returncode != 0:
print("FAIL")
time.sleep(10)
Expand All @@ -399,5 +420,6 @@ def main():
delete_file(f2)
delete_file(f3)


if __name__ == "__main__":
main()

0 comments on commit 495e2c2

Please sign in to comment.