Skip to content

Commit 9416ce0

Browse files
committed
More tests, including stashcp and xroot copy from cache
1 parent 19bd456 commit 9416ce0

File tree

2 files changed

+52
-18
lines changed

2 files changed

+52
-18
lines changed

osgtest/tests/test_155_stashcache.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88

99

1010
CACHE_DIR = "/tmp/sccache"
11-
CACHE_PORT = 1094 # can't change this - stashcp doesn't allow you to specify port
11+
CACHE_XROOT_PORT = 1094 # can't change this - stashcp doesn't allow you to specify port
1212
CACHE_HTTP_PORT = 8001
13-
ORIGIN_PORT = 1095
13+
ORIGIN_XROOT_PORT = 1095
1414
ORIGIN_DIR = "/tmp/scorigin"
1515
CACHE_AUTHFILE_PATH = "/etc/xrootd/Authfile-cache"
1616
CACHE_CONFIG_PATH = "/etc/xrootd/xrootd-stashcache-cache-server.cfg"
@@ -33,7 +33,7 @@
3333
3434
ofs.osslib libXrdPss.so
3535
# normally this is the redirector but we don't have one in this environment
36-
pss.origin localhost:{ORIGIN_PORT}
36+
pss.origin localhost:{ORIGIN_XROOT_PORT}
3737
pss.cachelib libXrdFileCache.so
3838
pss.setopt DebugLevel 1
3939
@@ -52,7 +52,7 @@
5252
sec.protbind * none
5353
xrd.protocol http:{CACHE_HTTP_PORT} libXrdHttp.so
5454
55-
xrd.port {CACHE_PORT}
55+
xrd.port {CACHE_XROOT_PORT}
5656
5757
http.listingdeny yes
5858
http.staticpreload http://static/robots.txt /etc/xrootd/stashcache-robots.txt
@@ -87,7 +87,7 @@
8787
oss.localroot {ORIGIN_DIR}
8888
all.export /
8989
90-
xrd.port {ORIGIN_PORT}
90+
xrd.port {ORIGIN_XROOT_PORT}
9191
all.role server
9292
9393
xrootd.trace emsg login stall redirect
@@ -129,7 +129,8 @@ def test_01_configure(self):
129129
("cache_http_port", CACHE_HTTP_PORT),
130130
("origin_dir", ORIGIN_DIR),
131131
("cache_dir", CACHE_DIR),
132-
("origin_port", ORIGIN_PORT)
132+
("origin_xroot_port", ORIGIN_XROOT_PORT),
133+
("cache_xroot_port", CACHE_XROOT_PORT)
133134
]:
134135
_setcfg(key, val)
135136

osgtest/tests/test_460_stashcache.py

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import os
22
import pwd
3+
import random
4+
import tempfile
35

46
from osgtest.library import core
57
from osgtest.library import files
@@ -21,35 +23,66 @@ def _setcfg(key, val):
2123

2224

2325
class TestStashCache(OSGTestCase):
24-
_text = "this is a test"
26+
# testfiles with random contents
27+
testfiles = [
28+
("testfile%d" % x, str(random.random()))
29+
for x in range(4)
30+
]
31+
32+
def assertCached(self, name, contents):
33+
fpath = os.path.join(_getcfg("cache_dir"), name)
34+
self.assertTrue(os.path.exists(fpath),
35+
name + " not cached")
36+
self.assertEqual(contents, files.read(fpath, as_single_string=True),
37+
"cached file %s contents do not match expected" % name)
2538

2639
@core.elrelease(7,8)
2740
def setUp(self):
2841
core.skip_ok_unless_installed("stashcache-origin-server", "stashcache-cache-server", "stashcache-client")
2942
self.skip_bad_unless(service.is_running("xrootd@stashcache-origin-server"))
3043
self.skip_bad_unless(service.is_running("xrootd@stashcache-cache-server"))
3144

32-
def test_01_create_file(self):
45+
def test_01_create_files(self):
3346
xrootd_user = pwd.getpwnam("xrootd")
34-
files.write(os.path.join(_getcfg("origin_dir"), "testfile"),
35-
self._text, backup=False, chmod=0o644,
36-
chown=(xrootd_user.pw_uid, xrootd_user.pw_gid))
47+
for name, contents in self.testfiles:
48+
files.write(os.path.join(_getcfg("origin_dir"), name),
49+
contents, backup=False, chmod=0o644,
50+
chown=(xrootd_user.pw_uid, xrootd_user.pw_gid))
3751

38-
def test_02_fetch_from_origin(self):
52+
def test_02_xroot_fetch_from_origin(self):
53+
name, contents = self.testfiles[0]
3954
result, _, _ = \
4055
core.check_system(["xrdcp", "-d1", "-N", "-f",
41-
"root://localhost:%d//testfile" % _getcfg("origin_port"),
56+
"root://localhost:%d//%s" % (_getcfg("origin_xroot_port"), name),
4257
"-"], "Checking xroot copy from origin")
43-
self.assertEqual(result, self._text, "downloaded file does not match expected")
58+
self.assertEqual(result, contents, "downloaded file does not match expected")
4459

4560
def test_03_http_fetch_from_cache(self):
61+
name, contents = self.testfiles[1]
4662
try:
4763
f = urlopen(
48-
"http://localhost:%d/testfile" % _getcfg("cache_http_port")
64+
"http://localhost:%d/%s" % (_getcfg("cache_http_port"), name)
4965
)
5066
result = f.read()
5167
except IOError as e:
5268
self.fail("Unable to download from cache via http: %s" % e)
53-
self.assertEqual(result, self._text, "downloaded file does not match expected")
54-
self.assertTrue(os.path.exists(os.path.join(_getcfg("cache_dir"), "testfile")),
55-
"testfile not cached")
69+
self.assertEqual(result, contents, "downloaded file does not match expected")
70+
self.assertCached(name, contents)
71+
72+
def test_04_xroot_fetch_from_cache(self):
73+
name, contents = self.testfiles[2]
74+
result, _, _ = \
75+
core.check_system(["xrdcp", "-d1", "-N", "-f",
76+
"root://localhost:%d//%s" % (_getcfg("cache_xroot_port"), name),
77+
"-"], "Checking xroot copy from cache")
78+
self.assertEqual(result, contents, "downloaded file does not match expected")
79+
self.assertCached(name, contents)
80+
81+
def test_05_stashcp(self):
82+
name, contents = self.testfiles[3]
83+
with tempfile.NamedTemporaryFile(mode="r+b") as tf:
84+
core.check_system(["stashcp", "-d", "/"+name, tf.name],
85+
"Checking stashcp")
86+
result = tf.read()
87+
self.assertEqual(result, contents, "stashcp'ed file does match expected")
88+
self.assertCached(name, contents)

0 commit comments

Comments
 (0)