-
Notifications
You must be signed in to change notification settings - Fork 2
/
TestConfig.py
80 lines (71 loc) · 3.11 KB
/
TestConfig.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import os
import sys
import subprocess
import Configs
import ZfsApi
# This class will quickly test if your machine is properly configured for
# these perf tests.
# TODO check that zfs is installed, perhaps get version
def check_all():
permissions_check()
check_pool_exists()
check_filesystems()
def permissions_check():
# Check that the calling user has permissions to run zfs commands this is
# established by having read permissions on the /dev/zfs device
if not os.access('/dev/zfs' ,os.R_OK):
print("You do not have read permissions to /dev/zfs, can you run zfs"
+ " commands?")
sys.exit(1)
def check_pool_exists():
"""The config file specifies a pool that the testing will be happening on,
make sure that the pool exists"""
if not ZfsApi.zpool_exists(Configs.main_pool):
print("The main pool in config.cfg is " + Configs.main_pool +
" however no pool by that name was found. Is your pool setup?")
sys.exit(1)
def check_filesystems():
# Check that the area we are going to be working in exists. If it does not
# offer to set it up for the user.
if not os.path.isdir(Configs.mount_point):
print("Could not find the pref_tests directory " +
Configs.mount_point)
result = raw_input("Create it? [Y/n] ")
if result == "Y":
setup_system()
else:
print("Exiting tests")
sys.exit(1)
def setup_system():
# This function will setup the zfs filesystems, it does not perform
# any checks, call it when you know this machine needs to be set up
subprocess.check_call(['zfs', 'create', '-p',
Configs.test_filesystem_path,
'-o', "mountpoint=" + Configs.mount_point])
# Create the corpus directory, currently setting primarycahce=none
# since not doing so results in abnormalities in test timing. I
# think this will become especially useful when this process
# becomes multithreaded.
subprocess.check_call(['zfs', 'create',
Configs.test_filesystem_path + '/corpus',
'-o', 'primarycache=none'])
# Create the area for test runs to go. I keep this in a separate
# area to ensure that cleanup is easy
ZfsApi.create_filesystem(Configs.test_filesystem_path + '/runs')
# Create the log directory, and its two sub directories
ZfsApi.create_filesystem(Configs.test_filesystem_path + '/logs')
# The two sub directories are not zfs filesystems
os.mkdir(Configs.results_directory)
os.mkdir(Configs.stats_directory)
def check_testfile():
'''Perfomr tests to ensure the test file will be usable'''
# Check that the specified test file exists
if not os.path.isfile(Configs.test_file_full_path):
print("The test file does not exits. It is set to " +
Configs.test_file_full_path + " please check config.cfg")
sys.exit(1)
# Check that the specified test file is readable
if not os.access(Configs.test_file_full_path, os.R_OK):
print("Cannot read the test file. It is set to " +
Configs.test_file_full_path + " please check config.cfg")
sys.exit(1)