#!/usr/bin/env python
# test has been developed by Robert Harakaly and changed for SAM by Victor Galaktionov 
# set LFC directory/file access control lists (lfc_setacl)
# meta: proxy=true
# meta: preconfig=../../LFC-config

import os, lfc, sys
from testClass import _test, _ntest, _testRunner, SAM_Run, LFC_VO, TEST_HOME

global fileName

class test_ok(_test):
    def info(self):
      return "lfc_setacl OK "

    def clean(self):
        lfc.lfc_unlink(fileName)
        lfc.lfc_rmdir(os.path.dirname(fileName))

    def prepare(self):
        lfc.lfc_mkdir(os.path.dirname(fileName),0755)
        self.guid = self.get_guid()
        ret = lfc.lfc_creatg(fileName,self.guid,0664)
        if (ret != 0):
            print "Error: cannot create testing file %s: %s" % (fileName, lfc.sstrerror(lfc.cvar.serrno))
            print "Test is failed"
            return False
        nentries0, self.acls_list = lfc.lfc_getacl(fileName, lfc.CA_MAXACLENTRIES)

    def test(self):
        self.acls_list[0].a_perm=7
        self.acls_list[1].a_perm=5
        self.acls_list[2].a_perm=3
        self.guid = self.get_guid()
        ret = lfc.lfc_setacl(fileName,self.acls_list)
        nentries, acls_list = lfc.lfc_getacl(fileName, lfc.CA_MAXACLENTRIES)
        return (acls_list,ret)

    def ret(self):
        return self.acls_list

    def compare(self, testVal, retVal):
        (ret, retRetVal) = retVal
        (test, testRetVal) = testVal
        retRetVal == testRetVal
        retval = True
        if (retRetVal == testRetVal):
            retval = retval & ( test[0].a_perm == ret[0].a_perm )
            retval = retval & ( test[1].a_perm == ret[1].a_perm )
            retval = retval & ( test[2].a_perm == ret[2].a_perm )
        else:
            retval = False
        return retval

class test_EPERM(_ntest):
	pass
	#TODO

class lfc_setacl_test(_testRunner):
    def __init__(self):
        global fileName
        self.name = "lfc_setacl_test"
        fileName=os.environ['LFC_HOME'] + "/python_setacl_test/python_setacl_test_file"
        self.tests=[test_ok]


#************* Interface for SAM and Python tests ***************
SAM_Run(lfc_setacl_test)

