diff options
Diffstat (limited to 'module/common/APIExerciser.py')
-rw-r--r-- | module/common/APIExerciser.py | 114 |
1 files changed, 18 insertions, 96 deletions
diff --git a/module/common/APIExerciser.py b/module/common/APIExerciser.py index f645f12df..b9e67d824 100644 --- a/module/common/APIExerciser.py +++ b/module/common/APIExerciser.py @@ -24,16 +24,19 @@ def createURLs(): AVOID = (0,3,8) class APIExerciser(Thread): - """ tests api randomly """ - - def __init__(self, core): + def __init__(self, core, thrift=False): Thread.__init__(self) self.setDaemon(True) self.core = core - self.methods = core.server_methods self.count = 0 #number of methods self.time = time() + if thrift: + self.api = ThriftClient() + self.api.login("user", "pw") + else: + self.api = core.api + self.start() def run(self): @@ -60,89 +63,8 @@ class APIExerciser(Thread): #sleep(random() / 500) def testAPI(self): - m = ["status_downloads", "status_server", "add_package", "get_package_data", "get_file_data", "del_links", - "del_packages", - "get_queue", "get_collector", "get_queue_info", "get_collector_info", "is_captcha_waiting"] - - method = choice(m) - #print "Testing:", method - - if hasattr(self, method): - res = getattr(self, method)() - else: - res = getattr(self.methods, method)() - - self.count += 1 - - #print res - - def add_package(self): - name = "".join(sample(string.ascii_letters, 10)) - urls = createURLs() - - self.methods.add_package(name, urls, 1) - - - def del_links(self): - info = self.methods.get_queue() - if not info: return - - pid = choice(info.keys()) - pack = info[pid] - links = pack["links"] - #filter links which are not queued, finished or failed - fids = filter(lambda x: links[x]["status"] not in AVOID, links.keys()) - - if len(fids): - fids = sample(fids, randint(1, max(len(fids) / 2, 1))) - self.methods.del_links(fids) - - - def del_packages(self): - info = self.methods.get_queue_info() - if not info: return - - pids = info.keys() - if len(pids): - pids = sample(pids, randint(1, max(len(pids) / 2, 1))) - filtered = [] - - for p in pids: - info = self.methods.get_package_data(p) - append = True - for link in info["links"].itervalues(): - if link["status"] not in AVOID: - append = False - break - - if append: filtered.append(p) - - self.methods.del_packages(filtered) - - def get_file_data(self): - info = self.methods.get_queue() - if info: - p = info[choice(info.keys())] - if p["links"]: - self.methods.get_file_data(choice(p["links"].keys())) - - def get_package_data(self): - info = self.methods.get_queue_info() - if info: - self.methods.get_package_data(choice(info.keys())) - - -class ThriftExerciser(APIExerciser): - def __init__(self, core): - self.thrift = ThriftClient() - self.thrift.login("user", "pw") - - APIExerciser.__init__(self, core) - - def testAPI(self): m = ["statusDownloads", "statusServer", "addPackage", "getPackageData", "getFileData", "deleteFiles", - "deletePackages", - "getQueue", "getCollector", "getQueueData", "getCollectorData", "isCaptchaWaiting"] + "deletePackages", "getQueue", "getCollector", "getQueueData", "getCollectorData", "isCaptchaWaiting"] method = choice(m) #print "Testing:", method @@ -150,7 +72,7 @@ class ThriftExerciser(APIExerciser): if hasattr(self, method): res = getattr(self, method)() else: - res = getattr(self.thrift, method)() + res = getattr(self.api, method)() self.count += 1 @@ -160,11 +82,11 @@ class ThriftExerciser(APIExerciser): name = "".join(sample(string.ascii_letters, 10)) urls = createURLs() - self.thrift.addPackage(name, urls, 0) + self.api.addPackage(name, urls, 0) def deleteFiles(self): - info = self.thrift.getQueueData() + info = self.api.getQueueData() if not info: return pack = choice(info) @@ -172,26 +94,26 @@ class ThriftExerciser(APIExerciser): if len(fids): fids = [f.fid for f in sample(fids, randint(1, max(len(fids) / 2, 1)))] - self.thrift.deleteFiles(fids) + self.api.deleteFiles(fids) def deletePackages(self): - info = self.thrift.getQueue() + info = self.api.getQueue() if not info: return pids = [p.pid for p in info] if len(pids): pids = sample(pids, randint(1, max(len(pids) / 2, 1))) - self.thrift.deletePackages(pids) + self.api.deletePackages(pids) def getFileData(self): - info = self.thrift.getQueueData() + info = self.api.getQueueData() if info: p = choice(info) if p.links: - self.thrift.getFileData(choice(p.links).fid) + self.api.getFileData(choice(p.links).fid) def getPackageData(self): - info = self.thrift.getQueue() + info = self.api.getQueue() if info: - self.thrift.getPackageData(choice(info).pid)
\ No newline at end of file + self.api.getPackageData(choice(info).pid)
\ No newline at end of file |