Skip to content

Commit

Permalink
Merge pull request #34 from canfar/ght31
Browse files Browse the repository at this point in the history
Merge in so that DD will keep  testing
  • Loading branch information
ijiraq committed Jun 17, 2014
2 parents c63d1e6 + f0e0638 commit 8ecb947
Show file tree
Hide file tree
Showing 15 changed files with 795 additions and 309 deletions.
20 changes: 19 additions & 1 deletion runtest
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,22 @@ else
endif

python2.7 -m trace --count -s -m -C cover --ignore-dir=/usr/lib64:/usr/lib \
--ignore-module=test_cadcCache vos/test/TestCadcCache.py vos/test/Test_vofs.py
--ignore-module=BitVector --ignore-module=fuse --ignore-module=html2text \
--ignore-module=TestAll --ignore-module=Test_vos \
--ignore-module=TestNodeCache --ignore-module=TestCadcCache \
--ignore-module=Test_vofs --ignore-module=Test_vofile \
--ignore-module=TestCacheMetaData \
vos/test/TestAll.py

#python2.7 -m trace --count -s -m -C cover --ignore-dir=/usr/lib64:/usr/lib \
#--ignore-module=Test_vofs vos/test/TestCadcCache.py vos/test/Test_vofs.py

#python2.7 -m trace --count -s -m -C cover --ignore-dir=/usr/lib64:/usr/lib \
# --ignore-module=Test_vos vos/test/Test_vos.py

#python2.7 -m trace --count -s -m -C cover --ignore-dir=/usr/lib64:/usr/lib \
#--ignore-module=Test_vos vos/test/Test_vos.py vos/test/Test_vos.py

#python2.7 -m trace --count -s -m -C cover --ignore-dir=/usr/lib64:/usr/lib \
#--ignore-module=Test_vofs vos/test/Test_vofs.py

Expand All @@ -25,3 +40,6 @@ python2.7 -m trace --count -s -m -C cover --ignore-dir=/usr/lib64:/usr/lib \

#python2.7 -m trace --count -s -m -C cover --ignore-dir=/usr/lib64:/usr/lib \
# --ignore-module=TestCacheMetaData vos/test/TestCacheMetaData.py

#python2.7 -m trace --count -s -m -C cover --ignore-dir=/usr/lib64:/usr/lib \
#--ignore-module=TestNodeCache vos/test/TestNodeCache.py
2 changes: 1 addition & 1 deletion scripts/vlock
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ A node is locked by setting the islocked property. When a node is
locked, it cannot be copied to, moved or deleted. """


from vos import Node
import logging
import optparse
import sys
import vos
from vos.vos import Node
import os
import signal

Expand Down
12 changes: 6 additions & 6 deletions test/scripts/vospace-lock-atest.tcsh
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ foreach pythonVersion ($CADC_PYTHON_TEST_TARGETS)
set RMCMD = "$pythonVersion $CADC_ROOT/scripts/vrm"
set CPCMD = "$pythonVersion $CADC_ROOT/scripts/vcp"

set MVCMD = "python $CADC_ROOT/scripts/vmv"
set RMDIRCMD = "python $CADC_ROOT/scripts/vrmdir"
set CHMODCMD = "python $CADC_ROOT/scripts/vchmod"
set TAGCMD = "python $CADC_ROOT/scripts/vtag"
set LNCMD = "python $CADC_ROOT/scripts/vln"
set LOCKCMD = "python $CADC_ROOT/scripts/vlock"
set MVCMD = "$pythonVersion $CADC_ROOT/scripts/vmv"
set RMDIRCMD = "$pythonVersion $CADC_ROOT/scripts/vrmdir"
set CHMODCMD = "$pythonVersion $CADC_ROOT/scripts/vchmod"
set TAGCMD = "$pythonVersion $CADC_ROOT/scripts/vtag"
set LNCMD = "$pythonVersion $CADC_ROOT/scripts/vln"
set LOCKCMD = "$pythonVersion $CADC_ROOT/scripts/vlock"

set CERT = " --cert=$A/test-certificates/x509_CADCRegtest1.pem"

Expand Down
15 changes: 8 additions & 7 deletions test/scripts/vospace-mountvospace-atest.tcsh
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ foreach pythonVersion ($CADC_PYTHON_TEST_TARGETS)

## we cannot feasibly test the --xsv option, but it is here to fiddle with in development
set LSCMD = "$pythonVersion $CADC_ROOT/scripts/vls"
set MOUNTCMD = "$pythonVersion $CADC_ROOT/scripts/mountvofs --cache_limit=$CACHETEST_LIMIT"
set MOUNTCMD = "$pythonVersion $CADC_ROOT/scripts/mountvofs --cache_limit=$CACHETEST_LIMIT --cache_nodes"
set MKDIRCMD = "$pythonVersion $CADC_ROOT/scripts/vmkdir"
set RMCMD = "$pythonVersion $CADC_ROOT/scripts/vrm"
set CPCMD = "$pythonVersion $CADC_ROOT/scripts/vcp"
Expand Down Expand Up @@ -143,7 +143,7 @@ foreach pythonVersion ($CADC_PYTHON_TEST_TARGETS)
# --- test exceeding the local cache ---
echo -n "copy cache test data to container"
rm foo.dat >& /dev/null
truncate -s $CACHETEST_FSIZE foo.dat >& /dev/null
cat /dev/zero | head -c $CACHETEST_FSIZE_BYTES /dev/zero > foo.dat
foreach i ( `seq $CACHETEST_NFILES` )
echo -n "."
$CPCMD $CERTFILE foo.dat $CONTAINER/foo$i.dat >& /dev/null || echo " [FAIL]" && exit -1
Expand Down Expand Up @@ -176,14 +176,15 @@ foreach pythonVersion ($CADC_PYTHON_TEST_TARGETS)


echo -n "delete non-empty container "
rm $MCONTAINER >& /dev/null && echo " [FAIL]" && exit -1
ls $MCONTAINER/foo >& /dev/null || echo " [FAIL]" && exit -1
ls $MCONTAINER >& /dev/null || echo " [FAIL]" && exit -1
ls $MCONTAINER
rm -rf $MCONTAINER || echo " [FAIL]" && exit -1
ls $MCONTAINER/foo >& /dev/null && echo " [FAIL]" && exit -1
ls $MCONTAINER >& /dev/null && echo " [FAIL]" && exit -1
$LSCMD $CERT $CONTAINER >& /dev/null && echo " [FAIL]" && exit -1
echo " [OK]"

echo -n "delete empty container "
rmdir $MCONTAINER/* >& /dev/null || echo " [FAIL]" && exit -1
#rm $MCONTAINER/* >& /dev/null || echo " [FAIL]" && exit -1 #TODO activate when cp succeeds
mkdir $MCONTAINER
rmdir $MCONTAINER > /dev/null || echo " [FAIL]" && exit -1
$LSCMD $CERT $CONTAINER >& /dev/null && echo " [FAIL]" && exit -1
echo " [OK]"
Expand Down
124 changes: 124 additions & 0 deletions vos/NodeCache.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
# A node cache class, extended from dict.

import threading
import vos


class NodeCache(dict):
""" usage:
# Create a node cache:
nodeCache = NodeCache()
with nodeCache.volatile(nodeURI):
# Do things which make the nodes cached under nodeURI unreliable.
# The cache will be cleared on entry
with nodeCache.watch(nodeURI) as watch:
# Do things which shouldn't be cached when the node is
# volatile.
watch.insert(node)
# The node will not be cached if the tree became volatile
# at any point while the nodeURI was being watched.
"""

def __init__(self, *args):
""" Initialize the node cache."""
dict.__init__(self, args)
self.lock = threading.Lock()
self.watchedNodes = []
self.volatileNodes = []

def watch(self, uri):
"""Factory for watch objects"""
return self.Watch(self, uri.rstrip('/'))

def volatile(self, uri):
"""Factory for volatile objects."""
return self.Volatile(self, uri.rstrip('/'))

def __missing__(self, key):
"""Attempting to access a non-cached node returns None rather than
raising an exception."""
return None

def __setitem__(self, key, object):
"""If an node is directly inserted into the cache, automatically create
a watch."""
with self.watch(key) as w:
w.insert(object)

def __getitem__(self, key):
return dict.__getitem__(self, key.rstrip('/'))

def __contains__(self, key):
return dict.__contains__(self, key.rstrip('/'))

class Volatile(object):
""" Objects that mark a code segment where a uri is volatile and
shouldn't be used from the cache."""

def __init__(self, nodeCache, uri):
self.nodeCache = nodeCache
self.uri = uri.rstrip('/')

def __enter__(self):
""" Mark any sub-trees being watched as being dirty
add to self.nodeCache.volatileNodes.
Remove any cached nodes in the volatile subtree.
"""

with self.nodeCache.lock:
# Add this volatile objecty to a list of all active volatile
# objects.
self.nodeCache.volatileNodes.append(self)

# Remove any cached nodes in the volatile sub-tree.
for uri in self.nodeCache.keys():
if uri.startswith(self.uri):
del self.nodeCache[uri]

# Mark any watched nodes in the volatile sub-tree dirty
for watchedNode in self.nodeCache.watchedNodes:
if watchedNode.uri.startswith(self.uri):
watchedNode.dirty = True

return self

def __exit__(self, exc_type, exc_value, traceback):
""" Remove this volitile object from the list of active volatiles.
"""
with self.nodeCache.lock:
self.nodeCache.volatileNodes.remove(self)

class Watch(object):
""" Objects that mark a code segment where a node has been read from
vospace, and is intended to be cached.
"""

def __init__(self, nodeCache, uri):
self.nodeCache = nodeCache
self.uri = uri
self.dirty = False

def __enter__(self):
with self.nodeCache.lock:
# Add this watch object to the list of active watch objects.
self.nodeCache.watchedNodes.append(self)

# Check to see if this watch object is in an existing volatile
# tree. If it is, mark this watch object as dirty.
for thisVolatile in self.nodeCache.volatileNodes:
if self.uri.startswith(thisVolatile.uri):
self.dirty = True
return self
return self

def __exit__(self, exc_type, exc_value, traceback):
with self.nodeCache.lock:
self.nodeCache.watchedNodes.remove(self)

def insert(self, object):
""" Insert an object in the cache, but only if the watch is not
dirty."""
if not self.dirty:
dict.__setitem__(self.nodeCache, self.uri, object)
2 changes: 1 addition & 1 deletion vos/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version = "1.10.0-c"
version = "1.10.0-d"
26 changes: 26 additions & 0 deletions vos/test/TestAll.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import Test_vos
import TestNodeCache
import TestCadcCache
import Test_vofs
import Test_vofile
import TestCacheMetaData

if not Test_vos.run().wasSuccessful():
print "FAIL"
exit()
if not TestNodeCache.run().wasSuccessful():
print "FAIL"
exit()
if not TestCadcCache.run().wasSuccessful():
print "FAIL"
exit()
if not Test_vofs.run().wasSuccessful():
print "FAIL"
exit()
if not Test_vofile.run().wasSuccessful():
print "FAIL"
exit()
if not TestCacheMetaData.run().wasSuccessful():
print "FAIL"
exit()
print "SUCCESS"
8 changes: 6 additions & 2 deletions vos/test/TestCacheMetaData.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,13 @@ def testRange(self):



def run():
suite = unittest.TestLoader().loadTestsFromTestCase(TestCacheMetaData)
return unittest.TextTestRunner(verbosity=2).run(suite)

if __name__=='__main__':
run()

suite = unittest.TestLoader().loadTestsFromTestCase(TestCacheMetaData)
unittest.TextTestRunner(verbosity=2).run(suite)


if __name__ == '__main__':
Expand Down
41 changes: 22 additions & 19 deletions vos/test/TestCadcCache.py
Original file line number Diff line number Diff line change
Expand Up @@ -1272,7 +1272,7 @@ def test_03_flushNode2(self):
fh.flushNode()
self.assertTrue(fh.flushException[0] is IOError)

@unittest.skipIf(skipTests, "Individual tests")
#@unittest.skipIf(skipTests, "Individual tests")
def test_03_flushNode3(self):
"""flush node with an exception raised by checkCacheSpace
The test is that no exception is raised"""
Expand All @@ -1281,10 +1281,10 @@ def test_03_flushNode3(self):
ioObject = IOProxyForTest()
fh = testObject.open("/dir1/dir2/file", False, False, ioObject,
False)
fh.writerLock.acquire(shared=False)
testObject.checkCacheSpace = Mock(side_effect=OSError(errno.ENOENT,
"checkCacheSpaceError *EXPECTED*"))
fh.flushNode()
self.assertTrue(fh.flushException[0] is IOError)


@unittest.skipIf(skipTests, "Individual tests")
Expand Down Expand Up @@ -1585,7 +1585,7 @@ def notifyAfter1S(self,cond,fh):
cond.notify_all()


#@unittest.skipIf(skipTests, "Individual tests")
@unittest.skipIf(skipTests, "Individual tests")
def test_00_determineCacheSize(self):
""" Test checking the cache space """
if os.path.exists(testDir):
Expand Down Expand Up @@ -1687,7 +1687,7 @@ def test_04_removeEmptyDirs(self):
with self.assertRaises(OSError):
testCache.removeEmptyDirs(testDir + "/dir1/dir2/dir4")

#@unittest.skipIf(skipTests, "Individual tests")
@unittest.skipIf(skipTests, "Individual tests")
def test_04_truncate(self):
""" Test file truncate"""
testIOProxy = IOProxyForTest()
Expand Down Expand Up @@ -1976,18 +1976,21 @@ def test_isNewReadBest(self):
self.assertEquals(mandatoryEnd, crt.mandatoryEnd)


logging.getLogger('CadcCache').setLevel(logging.DEBUG)
logging.getLogger('CadcCache').addHandler(logging.StreamHandler())

suite1 = unittest.TestLoader().loadTestsFromTestCase(TestCacheCondtion)
suite2 = unittest.TestLoader().loadTestsFromTestCase(TestSharedLock)
suite3 = unittest.TestLoader().loadTestsFromTestCase(TestCacheError)
suite4 = unittest.TestLoader().loadTestsFromTestCase(TestCacheRetry)
suite5 = unittest.TestLoader().loadTestsFromTestCase(TestCacheAborted)
suite6 = unittest.TestLoader().loadTestsFromTestCase(TestIOProxy)
suite7 = unittest.TestLoader().loadTestsFromTestCase(TestCadcCacheReadThread)
suite8 = unittest.TestLoader().loadTestsFromTestCase(TestCadcCache)
alltests = unittest.TestSuite([suite1, suite2, suite3, suite4, suite5,
suite6, suite7, suite8])
unittest.TextTestRunner(verbosity=2).run(alltests)

def run():
logging.getLogger('CadcCache').setLevel(logging.DEBUG)
logging.getLogger('CadcCache').addHandler(logging.StreamHandler())

suite1 = unittest.TestLoader().loadTestsFromTestCase(TestCacheCondtion)
suite2 = unittest.TestLoader().loadTestsFromTestCase(TestSharedLock)
suite3 = unittest.TestLoader().loadTestsFromTestCase(TestCacheError)
suite4 = unittest.TestLoader().loadTestsFromTestCase(TestCacheRetry)
suite5 = unittest.TestLoader().loadTestsFromTestCase(TestCacheAborted)
suite6 = unittest.TestLoader().loadTestsFromTestCase(TestIOProxy)
suite7 = unittest.TestLoader().loadTestsFromTestCase(TestCadcCacheReadThread)
suite8 = unittest.TestLoader().loadTestsFromTestCase(TestCadcCache)
alltests = unittest.TestSuite([suite1, suite2, suite3, suite4, suite5,
suite6, suite7, suite8])
return(unittest.TextTestRunner(verbosity=2).run(alltests))

if __name__ == "__main__":
run()
Loading

0 comments on commit 8ecb947

Please sign in to comment.