1f08c3bdfSopenharmony_ci#!/usr/bin/env python3 2f08c3bdfSopenharmony_ci''' 3f08c3bdfSopenharmony_ci Access Control Lists testing based on newpynfs framework 4f08c3bdfSopenharmony_ci Aurelien Charbon - Bull SA 5f08c3bdfSopenharmony_ci''' 6f08c3bdfSopenharmony_cifrom random_gen import * 7f08c3bdfSopenharmony_ciimport subprocess 8f08c3bdfSopenharmony_ciimport os 9f08c3bdfSopenharmony_ciimport threading 10f08c3bdfSopenharmony_ciimport time 11f08c3bdfSopenharmony_ciimport random 12f08c3bdfSopenharmony_ci 13f08c3bdfSopenharmony_cialphabet='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789_-() ~' 14f08c3bdfSopenharmony_cit_alphabet=len(alphabet) 15f08c3bdfSopenharmony_ci 16f08c3bdfSopenharmony_cidef test_acl_default(path): 17f08c3bdfSopenharmony_ci 18f08c3bdfSopenharmony_ci# set default acl on the test directory 19f08c3bdfSopenharmony_ci u = subprocess.getoutput('mkdir ' + path + "/" + testdir) 20f08c3bdfSopenharmony_ci u = subprocess.getoutput('getfacl ' + path + "/" + testdir) 21f08c3bdfSopenharmony_ci acl=[] 22f08c3bdfSopenharmony_ci for i in range (len(splitedresult)-1): 23f08c3bdfSopenharmony_ci splitedline = splitedresult[i].split('::') 24f08c3bdfSopenharmony_ci name = splitedline[0] 25f08c3bdfSopenharmony_ci entry = splitedline[1] 26f08c3bdfSopenharmony_ci acl.append(name,entry) 27f08c3bdfSopenharmony_ci# create a file in this directory 28f08c3bdfSopenharmony_ci u = subprocess.getoutput('touch ' + path + "/" + testdir + testfile) 29f08c3bdfSopenharmony_ci# get the file's ACL and verify 30f08c3bdfSopenharmony_ci u = subprocess.getoutput('getfacl ' + path + "/" + testdir + testfile) 31f08c3bdfSopenharmony_ci splitedresult = u.split('\n') 32f08c3bdfSopenharmony_ci acl2=[] 33f08c3bdfSopenharmony_ci for i in range (len(splitedresult)-1): 34f08c3bdfSopenharmony_ci splitedline = splitedresult[i].split('::') 35f08c3bdfSopenharmony_ci name = splitedline[0] 36f08c3bdfSopenharmony_ci entry = splitedline[1] 37f08c3bdfSopenharmony_ci acl2.append(name,entry) 38f08c3bdfSopenharmony_ci 39f08c3bdfSopenharmony_ci result_final = True 40f08c3bdfSopenharmony_ci while i < len(acl2): 41f08c3bdfSopenharmony_ci result = False 42f08c3bdfSopenharmony_ci while j < len(acl2) and result == False: 43f08c3bdfSopenharmony_ci if acl2[i] == acl[j]: 44f08c3bdfSopenharmony_ci result = True 45f08c3bdfSopenharmony_ci if result == False: 46f08c3bdfSopenharmony_ci result_final = False 47f08c3bdfSopenharmony_ci 48f08c3bdfSopenharmony_ci''' Measuring time to add an ACE to a list regarding the number of ACE already in the list''' 49f08c3bdfSopenharmony_ci''' Doing the measurement on 100 files ''' 50f08c3bdfSopenharmony_cidef test_acl_long(): 51f08c3bdfSopenharmony_ci path = '/mnt/nfs/test-acl' 52f08c3bdfSopenharmony_ci test = RandomGen() 53f08c3bdfSopenharmony_ci test.createFile(path,100) 54f08c3bdfSopenharmony_ci test.getUserList() 55f08c3bdfSopenharmony_ci t0=time.time() 56f08c3bdfSopenharmony_ci for test_file in test.fList: 57f08c3bdfSopenharmony_ci for user in test.uList: 58f08c3bdfSopenharmony_ci mode = test.createRandomMode() 59f08c3bdfSopenharmony_ci u = subprocess.getoutput('setfacl -m u:' + user + ':' + mode + " " + path + "/" + test_file) 60f08c3bdfSopenharmony_ci t1=time.time() 61f08c3bdfSopenharmony_ci print(t1-t0) 62f08c3bdfSopenharmony_ci 63f08c3bdfSopenharmony_cidef test_nfs_acl(): 64f08c3bdfSopenharmony_ci print("test acl 10000\n") 65f08c3bdfSopenharmony_ci test = RandomGen() 66f08c3bdfSopenharmony_ci f = open('/tmp/acl-result-10000','w') 67f08c3bdfSopenharmony_ci path = '/mnt/nfs/test-acl' 68f08c3bdfSopenharmony_ci for i in range(10000): 69f08c3bdfSopenharmony_ci print("test avec " + str(i) + " ACE") 70f08c3bdfSopenharmony_ci test.getUserList() 71f08c3bdfSopenharmony_ci testfile = 'testfile' + str(i) 72f08c3bdfSopenharmony_ci u = subprocess.getoutput('touch ' + path + "/" + testfile) 73f08c3bdfSopenharmony_ci t0=time.time() 74f08c3bdfSopenharmony_ci for j in range(i): 75f08c3bdfSopenharmony_ci user = test.uList.pop() 76f08c3bdfSopenharmony_ci mode = test.createRandomMode() 77f08c3bdfSopenharmony_ci u = subprocess.getoutput('setfacl -m u:' + user + ':' + mode + " " + path + "/" + testfile) 78f08c3bdfSopenharmony_ci t1=time.time() 79f08c3bdfSopenharmony_ci f.write(str(i) + "\t" + str(t1-t0)+"\n") 80f08c3bdfSopenharmony_ci f.close() 81f08c3bdfSopenharmony_ci 82f08c3bdfSopenharmony_ci 83f08c3bdfSopenharmony_cidef test_nfs_getfacl(): 84f08c3bdfSopenharmony_ci # mesures sur le getfacl 85f08c3bdfSopenharmony_ci test = RandomGen() 86f08c3bdfSopenharmony_ci 87f08c3bdfSopenharmony_ci path = '/mnt/nfs/test-acl' # NFS mounted directory 88f08c3bdfSopenharmony_ci u = subprocess.getoutput('rm ' + path + "/*") # clean directory 89f08c3bdfSopenharmony_ci print("test acl getfacl\n") 90f08c3bdfSopenharmony_ci f = open('/tmp/acl-result-getfacl','w') 91f08c3bdfSopenharmony_ci for i in range(37): 92f08c3bdfSopenharmony_ci 93f08c3bdfSopenharmony_ci test.getUserList() 94f08c3bdfSopenharmony_ci testfile = 'testfile' + str(i) 95f08c3bdfSopenharmony_ci 96f08c3bdfSopenharmony_ci u = subprocess.getoutput('touch ' + path + "/" + testfile) 97f08c3bdfSopenharmony_ci print("setfacl " + str(i) + " " + u) 98f08c3bdfSopenharmony_ci for j in range(i): 99f08c3bdfSopenharmony_ci user = test.uList.pop() 100f08c3bdfSopenharmony_ci mode = test.createRandomMode() 101f08c3bdfSopenharmony_ci u = subprocess.getoutput('setfacl -m u:' + user + ':' + mode + " " + path + "/" + testfile) 102f08c3bdfSopenharmony_ci 103f08c3bdfSopenharmony_ci t1=time.time() 104f08c3bdfSopenharmony_ci u = subprocess.getoutput('getfacl ' + path + "/" + testfile) 105f08c3bdfSopenharmony_ci print("getfacl - " + str(i) + u + "\n") 106f08c3bdfSopenharmony_ci t2=time.time() 107f08c3bdfSopenharmony_ci f.write(str(i) + "\t" + str(t2-t1)+"\n") 108f08c3bdfSopenharmony_ci f.close() 109f08c3bdfSopenharmony_ci 110f08c3bdfSopenharmony_ci 111f08c3bdfSopenharmony_cidef main(): 112f08c3bdfSopenharmony_ci # test getFileList 113f08c3bdfSopenharmony_ci path = '/mnt/nfs/test-acl' 114f08c3bdfSopenharmony_ci test = RandomGen() 115f08c3bdfSopenharmony_ci test.getFileList(path) 116f08c3bdfSopenharmony_ci print(test.fList) 117f08c3bdfSopenharmony_cimain() 118f08c3bdfSopenharmony_ci 119f08c3bdfSopenharmony_ci 120f08c3bdfSopenharmony_ci 121f08c3bdfSopenharmony_ci 122f08c3bdfSopenharmony_ci 123