Skip to content

Commit cbbb464

Browse files
committed
Try xrdcp from origin and http from cache
1 parent 7026549 commit cbbb464

File tree

4 files changed

+79
-7
lines changed

4 files changed

+79
-7
lines changed

osgtest/library/files.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,3 +237,12 @@ def filesBackedup(path, owner):
237237
return True
238238
else:
239239
return False
240+
241+
242+
def safe_makedirs(directory, mode=0o777):
243+
"""Create a directory and all its parent directories, unless it already
244+
exists.
245+
246+
"""
247+
if not os.path.isdir(directory):
248+
os.makedirs(directory, mode)

osgtest/tests/test_155_stashcache.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import os
2+
import pwd
3+
24
from osgtest.library import core
35
from osgtest.library import files
46
from osgtest.library.osgunittest import OSGTestCase
@@ -126,13 +128,17 @@ def test_01_configure(self):
126128
("caches_json_path", CACHES_JSON_PATH),
127129
("cache_http_port", CACHE_HTTP_PORT),
128130
("origin_dir", ORIGIN_DIR),
129-
("cache_dir", CACHE_DIR)
131+
("cache_dir", CACHE_DIR),
132+
("origin_port", ORIGIN_PORT)
130133
]:
131134
_setcfg(key, val)
132135

133-
d = os.path.dirname(CACHES_JSON_PATH)
134-
if not os.path.isdir(d):
135-
os.makedirs(os.path.dirname(d))
136+
xrootd_user = pwd.getpwnam("xrootd")
137+
for d in [_getcfg("origin_dir"), _getcfg("cache_dir"),
138+
os.path.dirname(_getcfg("caches_json_path"))]:
139+
files.safe_makedirs(d)
140+
os.chown(d, xrootd_user.pw_uid, xrootd_user.pw_gid)
141+
136142
for key, text in [
137143
("cache_config_path", CACHE_CONFIG_TEXT),
138144
("cache_authfile_path", CACHE_AUTHFILE_TEXT),
Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,55 @@
1-
# hiii
1+
import os
2+
import pwd
3+
4+
from osgtest.library import core
5+
from osgtest.library import files
6+
from osgtest.library.osgunittest import OSGTestCase
7+
from osgtest.library import service
8+
try:
9+
from urllib2 import urlopen
10+
except ImportError:
11+
from urllib.request import urlopen
12+
13+
14+
_NAMESPACE = "stashcache"
15+
16+
def _getcfg(key):
17+
return core.config["%s.%s" % (_NAMESPACE, key)]
18+
19+
def _setcfg(key, val):
20+
core.config["%s.%s" % (_NAMESPACE, key)] = val
21+
22+
23+
class TestStashCache(OSGTestCase):
24+
_text = "this is a test"
25+
26+
@core.elrelease(7,8)
27+
def setUp(self):
28+
core.skip_ok_unless_installed("stashcache-origin-server", "stashcache-cache-server", "stashcache-client")
29+
self.skip_bad_unless(service.is_running("xrootd@stashcache-origin-server"))
30+
self.skip_bad_unless(service.is_running("xrootd@stashcache-cache-server"))
31+
32+
def test_01_create_file(self):
33+
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))
37+
38+
def test_02_fetch_from_origin(self):
39+
result, _, _ = \
40+
core.check_system(["xrdcp", "-d1", "-N", "-f",
41+
"root://localhost:%d//testfile" % _getcfg("origin_port"),
42+
"-"], "Checking xroot copy from origin")
43+
self.assertEqual(result, self._text, "downloaded file does not match expected")
44+
45+
def test_03_http_fetch_from_cache(self):
46+
try:
47+
f = urlopen(
48+
"http://localhost:%d/testfile" % _getcfg("cache_http_port")
49+
)
50+
result = f.read()
51+
except IOError as e:
52+
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")

osgtest/tests/test_835_stashcache.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import shutil
23
from osgtest.library import core
34
from osgtest.library import files
45
from osgtest.library.osgunittest import OSGTestCase
@@ -36,5 +37,7 @@ def test_03_unconfigure(self):
3637
]:
3738
files.restore(_getcfg(key), owner=_NAMESPACE)
3839

39-
def test_04_clean_dirs(self):
40-
pass
40+
def test_04_delete_dirs(self):
41+
for key in ["origin_dir", "cache_dir"]:
42+
if os.path.isdir(_getcfg(key)):
43+
shutil.rmtree(_getcfg(key))

0 commit comments

Comments
 (0)