1 |
bbockelm |
1.1 |
#!/usr/bin/env python
|
2 |
|
|
#-*- coding: ISO-8859-1 -*-
|
3 |
|
|
#
|
4 |
|
|
# Author: Brian Bockelman
|
5 |
|
|
|
6 |
|
|
import os
|
7 |
|
|
import sys
|
8 |
|
|
import time
|
9 |
|
|
import unittest
|
10 |
|
|
import ConfigParser
|
11 |
|
|
|
12 |
|
|
if os.path.exists("src"):
|
13 |
|
|
sys.path.append("src")
|
14 |
|
|
if os.path.exists('../src'):
|
15 |
|
|
sys.path.append('../src')
|
16 |
|
|
|
17 |
|
|
from CmsFileServer.FileManager import Server
|
18 |
|
|
|
19 |
|
|
class TestFileManager(unittest.TestCase):
|
20 |
|
|
|
21 |
|
|
def setUp(self):
|
22 |
|
|
cp = ConfigParser.ConfigParser()
|
23 |
|
|
cp.add_section("file_manager")
|
24 |
|
|
cp.set("file_manager", "base_directory", "/Users/brian/tmp/cms_stuff")
|
25 |
|
|
cp.add_section("transfer_wrapper")
|
26 |
|
|
cp.set("transfer_wrapper", "transfer_command", "srmcp -debug=true " \
|
27 |
|
|
"-srm_protocol_version=2 -retry_num=1 -streams_num=1")
|
28 |
|
|
self.cp = cp
|
29 |
|
|
|
30 |
|
|
def test_main(self):
|
31 |
|
|
# Test case demonstrates:
|
32 |
|
|
# - Single transfer works
|
33 |
|
|
# - Second transfer starts up in parallel
|
34 |
|
|
# - Third transfer notices that it's for the same LFN as the first, and it
|
35 |
|
|
# just sits waiting for the first one to finish.
|
36 |
|
|
# - Cancelling works
|
37 |
|
|
# - Graceful shutdown works
|
38 |
|
|
cp = self.cp
|
39 |
|
|
Server.configure(cp)
|
40 |
|
|
Server.request("/store/data/CRUZET2/Cosmics/RECO/CRUZET2_V1_v2/0018/FEB27E49-B63C-DD11-89D8-000423D6B42C.root")
|
41 |
|
|
time.sleep(10)
|
42 |
|
|
Server.request("/store/data/CRUZET2/Cosmics/RECO/CRUZET2_V1_v2/0018/FEB27E49-B63C-DD11-89D8-000423D6B42C.root")
|
43 |
|
|
Server.request("/store/data/CRUZET2/Cosmics/RECO/CRUZET2_V1_v2/0018/FE989CBF-913C-DD11-BEE5-001617E30CE8.root")
|
44 |
|
|
time.sleep(5)
|
45 |
|
|
print "****", Server.status("/store/data/CRUZET2/Cosmics/RECO/CRUZET2_V1_v2/0018/FE989CBF-913C-DD11-BEE5-001617E30CE8.root")
|
46 |
|
|
print "****", Server.status("/store/data/CRUZET2/Cosmics/RECO/CRUZET2_V1_v2/0018/FEB27E49-B63C-DD11-89D8-000423D6B42C.root")
|
47 |
|
|
time.sleep(30)
|
48 |
|
|
Server.cancel("/store/data/CRUZET2/Cosmics/RECO/CRUZET2_V1_v2/0018/FE989CBF-913C-DD11-BEE5-001617E30CE8.root")
|
49 |
|
|
# Note that the thread pool is all daemon - if the main thread exits, the
|
50 |
|
|
# python process terminates, even if the thread pool is running. Hence, we
|
51 |
|
|
# use the graceful_exit function
|
52 |
|
|
Server.graceful_exit()
|
53 |
|
|
|
54 |
|
|
# At this point, you can hit Ctrl+C, and the partial file will clean up
|
55 |
|
|
# and the transfer will kill itself.
|
56 |
|
|
|
57 |
|
|
# Let this run successfully once, and notice that if you run it again,
|
58 |
|
|
# the file was cached locally and the request returns successfully
|
59 |
|
|
# instantly.
|
60 |
|
|
|
61 |
|
|
if __name__ == '__main__':
|
62 |
|
|
unittest.main()
|
63 |
|
|
|