|
| 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 | + |
| 9 | + |
| 10 | +CACHE_DIR = "/tmp/sccache" |
| 11 | +CACHE_XROOT_PORT = 1094 # can't change this - stashcp doesn't allow you to specify port |
| 12 | +CACHE_HTTP_PORT = 8001 |
| 13 | +ORIGIN_XROOT_PORT = 1095 |
| 14 | +ORIGIN_DIR = "/tmp/scorigin" |
| 15 | +CACHE_AUTHFILE_PATH = "/etc/xrootd/Authfile-cache" |
| 16 | +CACHE_CONFIG_PATH = "/etc/xrootd/xrootd-stashcache-cache-server.cfg" |
| 17 | +ORIGIN_CONFIG_PATH = "/etc/xrootd/xrootd-stashcache-origin-server.cfg" |
| 18 | +CACHES_JSON_PATH = "/etc/stashcache/caches.json" |
| 19 | + |
| 20 | + |
| 21 | +# TODO Set up authenticated stashcache as well |
| 22 | +CACHE_CONFIG_TEXT = """\ |
| 23 | +all.export / |
| 24 | +set cachedir = {CACHE_DIR} |
| 25 | +xrd.allow host * |
| 26 | +sec.protocol host |
| 27 | +all.adminpath /var/spool/xrootd |
| 28 | +
|
| 29 | +xrootd.trace emsg login stall redirect |
| 30 | +ofs.trace all |
| 31 | +xrd.trace all |
| 32 | +cms.trace all |
| 33 | +
|
| 34 | +ofs.osslib libXrdPss.so |
| 35 | +# normally this is the redirector but we don't have one in this environment |
| 36 | +pss.origin localhost:{ORIGIN_XROOT_PORT} |
| 37 | +pss.cachelib libXrdFileCache.so |
| 38 | +pss.setopt DebugLevel 1 |
| 39 | +
|
| 40 | +oss.localroot $(cachedir) |
| 41 | +
|
| 42 | +pfc.blocksize 512k |
| 43 | +pfc.ram 1024m |
| 44 | +# ^ xrootd won't start without a gig |
| 45 | +pfc.prefetch 10 |
| 46 | +pfc.diskusage 0.90 0.95 |
| 47 | +
|
| 48 | +ofs.authorize 1 |
| 49 | +acc.audit deny grant |
| 50 | +
|
| 51 | +acc.authdb {CACHE_AUTHFILE_PATH} |
| 52 | +sec.protbind * none |
| 53 | +xrd.protocol http:{CACHE_HTTP_PORT} libXrdHttp.so |
| 54 | +
|
| 55 | +xrd.port {CACHE_XROOT_PORT} |
| 56 | +
|
| 57 | +http.listingdeny yes |
| 58 | +http.staticpreload http://static/robots.txt /etc/xrootd/stashcache-robots.txt |
| 59 | +
|
| 60 | +# Tune the client timeouts to more aggressively timeout. |
| 61 | +pss.setopt ParallelEvtLoop 10 |
| 62 | +pss.setopt RequestTimeout 25 |
| 63 | +#pss.setopt TimeoutResolution 1 |
| 64 | +pss.setopt ConnectTimeout 25 |
| 65 | +pss.setopt ConnectionRetry 2 |
| 66 | +#pss.setopt StreamTimeout 35 |
| 67 | +
|
| 68 | +all.sitename osgtest |
| 69 | +
|
| 70 | +xrootd.diglib * /etc/xrootd/digauth.cf |
| 71 | +""".format(**globals()) |
| 72 | + |
| 73 | + |
| 74 | +CACHE_AUTHFILE_TEXT = """\ |
| 75 | +u * / rl |
| 76 | +""" |
| 77 | + |
| 78 | + |
| 79 | +ORIGIN_CONFIG_TEXT = """\ |
| 80 | +xrd.allow host * |
| 81 | +sec.protocol host |
| 82 | +sec.protbind * none |
| 83 | +all.adminpath /var/spool/xrootd |
| 84 | +all.pidpath /var/run/xrootd |
| 85 | +
|
| 86 | +# The directory on local disk containing the files to share, e.g. "/stash". |
| 87 | +oss.localroot {ORIGIN_DIR} |
| 88 | +all.export / |
| 89 | +
|
| 90 | +xrd.port {ORIGIN_XROOT_PORT} |
| 91 | +all.role server |
| 92 | +
|
| 93 | +xrootd.trace emsg login stall redirect |
| 94 | +ofs.trace all |
| 95 | +xrd.trace all |
| 96 | +cms.trace all |
| 97 | +""".format(**globals()) |
| 98 | + |
| 99 | + |
| 100 | +CACHES_JSON_TEXT = """\ |
| 101 | +[ |
| 102 | +{"name":"root://localhost", "status":1, "longitude":-89.4012, "latitude":43.0731} |
| 103 | +] |
| 104 | +""" |
| 105 | + |
| 106 | + |
| 107 | +_NAMESPACE = "stashcache" |
| 108 | + |
| 109 | + |
| 110 | +def _getcfg(key): |
| 111 | + return core.config["%s.%s" % (_NAMESPACE, key)] |
| 112 | + |
| 113 | + |
| 114 | +def _setcfg(key, val): |
| 115 | + core.config["%s.%s" % (_NAMESPACE, key)] = val |
| 116 | + |
| 117 | + |
| 118 | +class TestStartStashCache(OSGTestCase): |
| 119 | + @core.elrelease(7,8) |
| 120 | + def setUp(self): |
| 121 | + core.skip_ok_unless_installed("stashcache-origin-server", "stashcache-cache-server", "stashcache-client") |
| 122 | + |
| 123 | + def test_01_configure(self): |
| 124 | + for key, val in [ |
| 125 | + ("cache_authfile_path", CACHE_AUTHFILE_PATH), |
| 126 | + ("cache_config_path", CACHE_CONFIG_PATH), |
| 127 | + ("origin_config_path", ORIGIN_CONFIG_PATH), |
| 128 | + ("caches_json_path", CACHES_JSON_PATH), |
| 129 | + ("cache_http_port", CACHE_HTTP_PORT), |
| 130 | + ("origin_dir", ORIGIN_DIR), |
| 131 | + ("cache_dir", CACHE_DIR), |
| 132 | + ("origin_xroot_port", ORIGIN_XROOT_PORT), |
| 133 | + ("cache_xroot_port", CACHE_XROOT_PORT) |
| 134 | + ]: |
| 135 | + _setcfg(key, val) |
| 136 | + |
| 137 | + xrootd_user = pwd.getpwnam("xrootd") |
| 138 | + for d in [_getcfg("origin_dir"), _getcfg("cache_dir"), |
| 139 | + os.path.dirname(_getcfg("caches_json_path"))]: |
| 140 | + files.safe_makedirs(d) |
| 141 | + os.chown(d, xrootd_user.pw_uid, xrootd_user.pw_gid) |
| 142 | + |
| 143 | + for key, text in [ |
| 144 | + ("cache_config_path", CACHE_CONFIG_TEXT), |
| 145 | + ("cache_authfile_path", CACHE_AUTHFILE_TEXT), |
| 146 | + ("origin_config_path", ORIGIN_CONFIG_TEXT), |
| 147 | + ("caches_json_path", CACHES_JSON_TEXT) |
| 148 | + ]: |
| 149 | + files.write(_getcfg(key), text, owner=_NAMESPACE, chmod=0o644) |
| 150 | + |
| 151 | + def test_02_start_origin(self): |
| 152 | + if not service.is_running("xrootd@stashcache-origin-server"): |
| 153 | + service.check_start("xrootd@stashcache-origin-server") |
| 154 | + |
| 155 | + def test_03_start_cache(self): |
| 156 | + if not service.is_running("xrootd@stashcache-cache-server"): |
| 157 | + service.check_start("xrootd@stashcache-cache-server") |
0 commit comments