-
Notifications
You must be signed in to change notification settings - Fork 795
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2283 from steemit/2042-Implement-and-deploy-regre…
…ssion-testing-system 2042 implement and deploy regression testing system
- Loading branch information
Showing
26 changed files
with
1,536 additions
and
485 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
#!/usr/bin/env python3 | ||
import sys | ||
import json | ||
import socket | ||
|
||
class JSONSocket(object): | ||
""" | ||
Class encapsulates socket object with special handling json rpc. | ||
timeout is ignored now - nonblicking socket not supported. | ||
""" | ||
def __init__(self, host, port, path, timeout=None): | ||
""" | ||
host in form [http[s]://]<ip_address>[:port] | ||
if port not in host must be spefified as argument | ||
""" | ||
self.__sock = None | ||
if host.find("http://") == 0 or host.find("https://") == 0: | ||
host = host[host.find("//")+2 : len(host)] | ||
_host = host | ||
if port != None: | ||
host = host + ":" + str(port) | ||
else: | ||
colon_pos = host.rfind(":") | ||
_host = host[0 : colon_pos] | ||
port = int(host[colon_pos+1 : len(host)]) | ||
self.__fullpath = host + path | ||
self.__host = bytes(host, "utf-8") | ||
self.__path = bytes(path, "utf-8") | ||
#print("<host>: {}; <port>: {}".format(_host, port)) | ||
self.__sock = socket.create_connection((_host, port)) | ||
self.__sock.setblocking(True) | ||
#self.__sock.settimeout(timeout) | ||
self.__head = b"POST " + self.__path + b" HTTP/1.0\r\n" + \ | ||
b"HOST: " + self.__host + b"\r\n" + \ | ||
b"Content-type: application/json\r\n" | ||
|
||
def get_fullpath(self): | ||
return self.__fullpath | ||
|
||
def request(self, data=None, json=None): | ||
""" | ||
data - complete binary form of json request (ends with '\r\n' | ||
json - json request as python dict | ||
return value in form of json response as python dict | ||
""" | ||
if data == None: | ||
data = bytes(json.dumps(json), "utf-8") + b"\r\n" | ||
length = bytes(str(len(data)), "utf-8") | ||
request = self.__head + \ | ||
b"Content-length: " + length + b"\r\n\r\n" + \ | ||
data | ||
#print("request:", request.decode("utf-8")) | ||
self.__sock.sendall(request) | ||
#self.__sock.send(request) | ||
status, response = self.__read() | ||
#if response == {}: | ||
# print("response is empty for request:", request.decode("utf-8")) | ||
return status, response | ||
|
||
def __call__(self, data=None, json=None): | ||
return self.request(data, json) | ||
|
||
def __read(self): | ||
response = '' | ||
binary = b'' | ||
while True: | ||
temp = self.__sock.recv(4096) | ||
if not temp: break | ||
binary += temp | ||
|
||
response = binary.decode("utf-8") | ||
|
||
if response.find("HTTP") == 0: | ||
response = response[response.find("\r\n\r\n")+4 : len(response)] | ||
if response and response != '': | ||
r = json.loads(response) | ||
if 'result' in r: | ||
return True, r | ||
else: | ||
return False, r | ||
|
||
return False, {} | ||
|
||
def __del__(self): | ||
if self.__sock: | ||
self.__sock.close() | ||
|
||
|
||
def steemd_call(host, data=None, json=None, max_tries=10, timeout=0.1): | ||
""" | ||
host - [http[s]://<ip_address>:<port> | ||
data - binary form of request body, if missing json object should be provided (as python dict/array) | ||
""" | ||
# try: | ||
# jsocket = JSONSocket(host, None, "/rpc", timeout) | ||
# except: | ||
# print("Cannot open socket for:", host) | ||
# return False, {} | ||
|
||
for i in range(max_tries): | ||
try: | ||
jsocket = JSONSocket(host, None, "/rpc", timeout) | ||
except: | ||
type, value, traceback = sys.exc_info() | ||
print("Error: {}:{} {} {}".format(1, type, value, traceback)) | ||
print("Error: Cannot open JSONSocket for:", host) | ||
continue | ||
try: | ||
status, response = jsocket(data, json) | ||
if status: | ||
return status, response | ||
except: | ||
type, value, traceback = sys.exc_info() | ||
print("Error: {}:{} {} {}".format(1, type, value, traceback)) | ||
print("Error: JSONSocket request failed for: {} ({})".format(host, data.decode("utf-8"))) | ||
continue | ||
else: | ||
return False, {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
#!/usr/bin/env python3 | ||
""" | ||
Create list of all steem accounts in file. | ||
Usage: create_account_list.py <server_address> [<output_filename>] | ||
""" | ||
import sys | ||
import json | ||
from jsonsocket import JSONSocket | ||
from jsonsocket import steemd_call | ||
|
||
def list_accounts(url): | ||
""" | ||
url in form <ip_address>:<port> | ||
""" | ||
last_account = "" | ||
end = False | ||
accounts_count = 0 | ||
accounts = [] | ||
|
||
while end == False: | ||
request = bytes( json.dumps( { | ||
"jsonrpc": "2.0", | ||
"id": 0, | ||
"method": "database_api.list_accounts", | ||
"params": { "start": last_account, "limit": 1000, "order": "by_name" } | ||
} ), "utf-8" ) + b"\r\n" | ||
|
||
status, response = steemd_call(url, data=request) | ||
|
||
if status == False: | ||
print( "rpc failed for last_account: " + last_account ) | ||
return [] | ||
|
||
account_list = response["result"]["accounts"] | ||
|
||
if last_account != "": | ||
assert account_list[0]["name"] == last_account | ||
del account_list[0] | ||
|
||
if len( account_list ) == 0: | ||
end = True | ||
continue | ||
|
||
last_account = account_list[-1]["name"] | ||
accounts_count += len( accounts ) | ||
for account in account_list: | ||
accounts.append( account["name"] ) | ||
|
||
# while end == False | ||
return accounts | ||
|
||
|
||
def main(): | ||
if len( sys.argv ) < 2 or len( sys.argv ) > 3: | ||
exit( "Usage: create_account_list.py <server_address> [<output_filename>]" ) | ||
|
||
url = sys.argv[1] | ||
print( url ) | ||
|
||
accounts = list_accounts( url ) | ||
|
||
if len(accounts) == 0: | ||
exit(-1) | ||
|
||
if len( sys.argv ) == 3: | ||
filename = sys.argv[2] | ||
|
||
try: file = open( filename, "w" ) | ||
except: exit( "Cannot open file " + filename ) | ||
|
||
for account in accounts: | ||
file.write(account + "\n") | ||
|
||
file.close() | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#!/usr/bin/env python3 | ||
""" | ||
Create list of all steem comments in file. | ||
Usage: list_comment.py <server_address> [<output_filename>] | ||
""" | ||
import sys | ||
import json | ||
from jsonsocket import JSONSocket | ||
from jsonsocket import steemd_call | ||
|
||
def list_comments(url): | ||
""" | ||
url in form <ip_address>:<port> | ||
""" | ||
last_cashout_time = "2016-01-01T00-00-00" | ||
end = False | ||
comments = [] | ||
|
||
while end == False: | ||
request = bytes( json.dumps( { | ||
"jsonrpc": "2.0", | ||
"id": 0, | ||
"method": "database_api.list_comments", | ||
"params": { "start":[ last_cashout_time, "", "" ], "limit": 5, "order": "by_cashout_time" } | ||
} ), "utf-8" ) + b"\r\n" | ||
|
||
status, response = steemd_call(url, data=request) | ||
|
||
if status == False: | ||
print( "rpc failed for last_cashout_time: " + last_cashout_time ) | ||
return [] | ||
|
||
comment_list = response["result"]["comments"] | ||
|
||
actual_cashout_time = comment_list[-1]["cashout_time"] | ||
|
||
if actual_cashout_time == last_cashout_time: | ||
end = True | ||
continue | ||
|
||
last_cashout_time = actual_cashout_time | ||
|
||
for comment in comment_list: | ||
comments.append( comment["permlink"]+";"+comment["author"] +";"+comment["last_update"] ) | ||
|
||
# while end == False | ||
return comments | ||
|
||
|
||
def main(): | ||
if len( sys.argv ) < 2 or len( sys.argv ) > 3: | ||
exit( "Usage: list_comment.py <server_address> [<output_filename>]" ) | ||
|
||
url = sys.argv[1] | ||
print( url ) | ||
|
||
comments = list_comments( url ) | ||
|
||
if len(comments) == 0: | ||
exit(-1) | ||
|
||
if len( sys.argv ) == 3: | ||
filename = sys.argv[2] | ||
|
||
try: file = open( filename, "w" ) | ||
except: exit( "Cannot open file " + filename ) | ||
|
||
for comment in comments: | ||
file.write(comment + "\n") | ||
|
||
file.close() | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Oops, something went wrong.