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