Skip to content
Browse files

more lantorrent tests

cleanup of rows once they are determined to be complete
other patches
  • Loading branch information...
1 parent f0bea60 commit d196876af8758a7e2b854f0332cf79470bbad09e BuzzTroll committed Sep 3, 2010
Showing with 93 additions and 33 deletions.
  1. +1 −1 lantorrent/etc/lt.sql
  2. +9 −4 lantorrent/pylantorrent/daemon.py
  3. +65 −26 lantorrent/pylantorrent/request.py
  4. +18 −2 lantorrent/tests/request_test.py
View
2 lantorrent/etc/lt.sql
@@ -9,6 +9,6 @@ create table requests(
state INTEGER DEFAULT 0,
message TEXT,
entry_time DATETIME,
- UNIQUE(group_id, hostname, port, dst_filename)
+ UNIQUE(hostname, port, dst_filename)
);
View
13 lantorrent/pylantorrent/daemon.py
@@ -70,8 +70,13 @@ def do_it_live(con, rows):
v = LTServer(client, client)
v.store_and_forward()
- u = "update requests set state = ? where group_id = ?"
- data = (1,group_id,)
+ rids_str = ""
+ delim = ""
+ for r in rows:
+ rids_str = rids_str + delim + "'" + r[4] + "'"
+ delim = ", "
+ u = "update requests set state = ? where rid in (" + rids_str + ")"
+ data = (1,)
c.execute(u, data)
state = 0
degree = degree + 1
@@ -89,8 +94,8 @@ def do_it_live(con, rows):
pylantorrent.log(logging.ERROR, "error trying to send %s" % (str(e)))
rid = e['id']
bad_rid.append(rid)
- u = "update requests set state = ?, message = ? where rid = ? and group_id = ?"
- data = (state,str(e),rid,group_id,)
+ u = "update requests set state = ?, message = ? where rid = ?"
+ data = (state,str(e),rid,)
c.execute(u, data)
con.commit()
View
91 lantorrent/pylantorrent/request.py
@@ -11,11 +11,29 @@
import uuid
import time
import datetime
+import pynimbusauthz
+from pynimbusauthz.cmd_opts import cbOpts
+
+def setup_options(argv):
+
+ u = """[options]
+Submit a transfer request
+ """
+ (parser, all_opts) = pynimbusauthz.get_default_options(u)
+
+ opt = cbOpts("nonblock", "n", "Do not block waiting for completion", False, flag=True)
+ all_opts.append(opt)
+ opt = cbOpts("reattach", "a", "Reattach", None)
+ all_opts.append(opt)
+
+ (o, args) = pynimbusauthz.parse_args(parser, all_opts, argv)
+ return (o, args, parser)
+
def wait_until_sent(con, rid):
done = False
while not done:
- s = "select state,messsage from requests where rid = ?"
+ s = "select state,message from requests where rid = ?"
data = (rid,)
c = con.cursor()
c.execute(s, data)
@@ -26,24 +44,23 @@ def wait_until_sent(con, rid):
if state == 0:
time.sleep(1)
else:
- return (state, message)
-
-def main(argv=sys.argv[1:]):
- """
- This program allows a file to be requested from the lantorrent system. The
- file will be sent out of band. When the file has been delived the
- database entry for this request will be updated. This program will
- block until that entry is update.
+ done = True
- As options, the program takes the source file, the
- target file location, the group_id and the group count.
+ # cleanup
+ d = "delete from requests where rid = ?"
+ data = (rid,)
+ c = con.cursor()
+ c.execute(d, data)
+ con.commit()
- The lantorrent config file must have the ip and port that the requester
- is using for lantorrent delivery.
- """
+ if state == 1:
+ rc = 0
+ else:
+ rc = 1
+ return (rc, message)
- pylantorrent.log(logging.INFO, "enter")
+def request(argv, con):
src_filename = argv[0]
dst_filename = argv[1]
# the user provides the rid. that way we know they have it to look
@@ -62,33 +79,55 @@ def main(argv=sys.argv[1:]):
else:
port = 5893
- con_str = pylantorrent.config.dbfile
now = datetime.datetime.now()
- con = sqlite3.connect(con_str)
-
i = "insert into requests(src_filename, dst_filename, hostname, port, rid, entry_time) values (?, ?, ?, ?, ?, ?)"
data = (src_filename, dst_filename, host, port, rid, now,)
c = con.cursor()
c.execute(i, data)
con.commit()
- s = "select count(*) from requests where group_id = ?"
- data = (group_id,)
- c = con.cursor()
- c.execute(s, data)
- rs = c.fetchone()
- con.commit()
- cnt = int(rs[0])
+ return rid
+
+
+def main(argv=sys.argv[1:]):
+ """
+ This program allows a file to be requested from the lantorrent system. The
+ file will be sent out of band. When the file has been delived the
+ database entry for this request will be updated. This program will
+ block until that entry is update.
+
+ As options, the program takes the source file, the
+ target file location, the group_id and the group count.
+
+ The lantorrent config file must have the ip and port that the requester
+ is using for lantorrent delivery.
+ """
+
+ pylantorrent.log(logging.INFO, "enter")
+
+ (o, args, p) = setup_options(argv)
+
+ con_str = pylantorrent.config.dbfile
+ con = sqlite3.connect(con_str)
+
+ if o.reattach == None:
+ rid = request(args, con)
+ rc = 0
+ else:
+ rid = o.reattach
+
+ if not o.nonblock:
+ (rc, message) = wait_until_sent(con, rid)
- (rc, message) = wait_until_sent(con, rid)
if rc == 0:
print "Success"
else:
print "Failure: %s" % (message)
return rc
+
if __name__ == "__main__":
rc = main()
sys.exit(rc)
View
20 lantorrent/tests/request_test.py
@@ -29,19 +29,35 @@ def tearDown(self):
f = self.files.pop(0)
os.remove(f)
+ def _get_temp_file(self):
+ (osf, fname) = tempfile.mkstemp()
+ os.close(osf)
+ self.files.append(fname)
+ return fname
+
def _t_file_compare(self, f):
rc = filecmp.cmp(self.src_file, f)
self.assertTrue(rc)
def test_request_one(self):
port = int(self.ports_a[0])
host = "localhost:%d" % (port)
- (osf, fname) = tempfile.mkstemp()
- os.close(osf)
+ fname = self._get_temp_file()
rc = pylantorrent.request.main([self.src_file, fname, str(uuid.uuid1()), host])
self.assertEqual(rc, 0, "rc should be 0 but is %d" % (rc))
self._t_file_compare(fname)
+ def test_request_many_block(self):
+ port = int(self.ports_a[0])
+ host = "localhost:%d" % (port)
+
+ for i in range(0, 10):
+ fname = self._get_temp_file()
+ rc = pylantorrent.request.main([self.src_file, fname, str(uuid.uuid1()), host])
+ self.assertEqual(rc, 0, "rc should be 0 but is %d" % (rc))
+ self._t_file_compare(fname)
+
+

0 comments on commit d196876

Please sign in to comment.
Something went wrong with that request. Please try again.