Commit b5d5d2cf authored by 金凯强's avatar 金凯强 🎨

受黄总压迫增加分页

parent 94f5c4ca
...@@ -5,75 +5,75 @@ import requests ...@@ -5,75 +5,75 @@ import requests
if __name__ == '__main__': if __name__ == '__main__':
data = {'user_name': 'jkq', 'password': 'jkq_test'} data = {'user_name': 'jkq', 'password': 'jkq_test'}
# 设置登录信息 # # 设置登录信息
requests.post('http://localhost:5000/authorization/',json=data) # requests.post('http://localhost:5000/authorization/',json=data)
#
# 登录 # # 登录
res = requests.post('http://localhost:5000/authorization/login/',json=data) # res = requests.post('http://localhost:5000/authorization/login/',json=data)
print(res.json()) # print(res.json())
#
# 获取项目链接 # 获取项目链接
res = requests.get('http://localhost:5000/connection/') res = requests.get('http://localhost:5000/connection/')
print(res.json()) print(res.json())
#
json_data = {"project_no": "jkq_test", "db_ip": "47.97.206.38", "db_port": "9610", "db_user": "huansi", # json_data = {"project_no": "jkq_test", "db_ip": "47.97.206.38", "db_port": "9610", "db_user": "huansi",
"db_password": "huansi", "mes_db_name": "HSGmtMes", "tiip_db_name": "HSTIIP", # "db_password": "huansi", "mes_db_name": "HSGmtMes", "tiip_db_name": "HSTIIP",
"host_ip": "192.168.4.116","id":"1237937496479928320"} # "host_ip": "192.168.4.116","id":"1237937496479928320"}
#
# 设置项目链接 # # 设置项目链接
res = requests.post('http://localhost:5000/connection/', json=json_data) # res = requests.post('http://localhost:5000/connection/', json=json_data)
print(res.json()) # print(res.json())
#
# 测试项目数据库连接 # # 测试项目数据库连接
res = requests.get('http://localhost:5000/connection/jkq_test/HSGmtMEs/') # res = requests.get('http://localhost:5000/connection/jkq_test/HSGmtMEs/')
print(res.json()) # print(res.json())
#
json_data = {"project_no": "jkq_test", "server_ip": "192.168.4.116", "server_ssh_port": "1111", # json_data = {"project_no": "jkq_test", "server_ip": "192.168.4.116", "server_ssh_port": "1111",
"server_user": "root", # "server_user": "root",
"server_password": "huansi.net","id":1237968030966910976} # "server_password": "huansi.net","id":1237968030966910976}
#
# 设置远程服务器连接 # # 设置远程服务器连接
res = requests.post('http://localhost:5000/connection/remote_server/', json=json_data) # res = requests.post('http://localhost:5000/connection/remote_server/', json=json_data)
print(res.json()) # print(res.json())
#
# 获取远程服务器连接 # 获取远程服务器连接
res = requests.get('http://localhost:5000/connection/remote_server/') res = requests.get('http://localhost:5000/connection/remote_server/')
print(res.json()) print(res.json())
#
# 测试端口是否开放 # # 测试端口是否开放
res = requests.get('http://localhost:5000/connection/test_port/23002/') # res = requests.get('http://localhost:5000/connection/test_port/23002/')
print(res.json()) # print(res.json())
#
# 获取app_list # # 获取app_list
res = requests.get('http://localhost:5000/info/app_list/') # res = requests.get('http://localhost:5000/info/app_list/')
print(json.dumps(res.json(), indent=4)) # print(json.dumps(res.json(), indent=4))
#
# 配置app升级信息 # # 配置app升级信息
json_data = [ # json_data = [
{"app_code": "rabbitMQ", "app_name": "rabbitMQ", "app_image": "47.110.145.204:8084/huansi/mq:latest"}, # {"app_code": "rabbitMQ", "app_name": "rabbitMQ", "app_image": "47.110.145.204:8084/huansi/mq:latest"},
{"app_code": "Redis", "app_name": "Redis", "app_image": "47.110.145.204:8084/huansi/redis:latest"}, # {"app_code": "Redis", "app_name": "Redis", "app_image": "47.110.145.204:8084/huansi/redis:latest"},
{"app_code": "Tool", "app_name": "tools工具集", "app_image": "47.110.145.204:8084/huansi/hs_tools:1.1"}] # {"app_code": "Tool", "app_name": "tools工具集", "app_image": "47.110.145.204:8084/huansi/hs_tools:1.1"}]
#
res = requests.post('http://localhost:5000/info/app_upgrade/', json=json_data) # res = requests.post('http://localhost:5000/info/app_upgrade/', json=json_data)
print(res.json()) # print(res.json())
#
# 获取app升级日志列表 # # 获取app升级日志列表
res = requests.get('http://localhost:5000/info/upgrade_log/') # res = requests.get('http://localhost:5000/info/upgrade_log/')
print(json.dumps(res.json(), indent=4)) # print(json.dumps(res.json(), indent=4))
#
#
# 获取app单次升级日志明细 # # 获取app单次升级日志明细
res = requests.get('http://localhost:5000/info/upgrade_log_dtl/1237995081698545664/') # res = requests.get('http://localhost:5000/info/upgrade_log_dtl/1237995081698545664/')
print(json.dumps(res.json(), indent=4)) # print(json.dumps(res.json(), indent=4))
#
# 安装runner # # 安装runner
res = requests.get('http://localhost:5000/install/runner/') # res = requests.get('http://localhost:5000/install/runner/')
print(json.dumps(res.json(), indent=4)) # print(json.dumps(res.json(), indent=4))
#
# 回滚升级 # # 回滚升级
res = requests.get('http://localhost:5000/upgrade/rollback/1238022723059486720/') # res = requests.get('http://localhost:5000/upgrade/rollback/1238022723059486720/')
print(json.dumps(res.json(), indent=4)) # print(json.dumps(res.json(), indent=4))
#
# 远程升级 # # 远程升级
res = requests.get('http://localhost:5000/upgrade/remote/') # res = requests.get('http://localhost:5000/upgrade/remote/')
print(json.dumps(res.json(), indent=4)) # print(json.dumps(res.json(), indent=4))
...@@ -30,7 +30,8 @@ class InfoAPI(ApiController): ...@@ -30,7 +30,8 @@ class InfoAPI(ApiController):
获取app升级日志列表 获取app升级日志列表
:return: :return:
''' '''
return InfoService().get_upgrade_log() args = request.args
return InfoService().get_upgrade_log(args)
@api('upgrade_log_dtl/<int:log_id>') @api('upgrade_log_dtl/<int:log_id>')
def get_upgrade_log_dtl(self, log_id): def get_upgrade_log_dtl(self, log_id):
...@@ -39,4 +40,5 @@ class InfoAPI(ApiController): ...@@ -39,4 +40,5 @@ class InfoAPI(ApiController):
:param log_id: :param log_id:
:return: :return:
''' '''
return InfoService().get_upgrade_log_dtl(log_id) args = request.args
return InfoService().get_upgrade_log_dtl(log_id, args)
...@@ -135,49 +135,72 @@ values ...@@ -135,49 +135,72 @@ values
return {'message': '写入成功'} return {'message': '写入成功'}
def get_upgrade_log(self): def get_upgrade_log(self, args):
''' '''
获取升级历史信息 获取升级历史信息
:return: :return:
''' '''
per_page = args.get('per_page',10)
page = args.get('page',1)
offset = (int(page) - 1) * int(per_page)
sql = '''select A.*,(select count(*) from app_upgrade_log_dtl where log_id=A.id) as count sql = '''select A.*,(select count(*) from app_upgrade_log_dtl where log_id=A.id) as count
from app_upgrade_log A from app_upgrade_log A
order by A.default_version desc, A.upgrade_time desc order by A.default_version desc, A.upgrade_time desc
limit {},{}
'''.format(offset, per_page)
count_sql = '''select count(*) as count
from app_upgrade_log A
order by A.default_version desc, A.upgrade_time desc
''' '''
with db_driver as session: with db_driver as session:
data = session.query_sql(sql) data = session.query_sql(sql)
count_data = session.retrive_sql(count_sql)
page_data = { page_data = {
"paging": { "paging": {
"page": 1, "page": page,
"per_page": 10, "per_page": per_page,
"total": 10 "total": count_data['count'] if count_data else 0
}, },
"table": data "table": data if data else []
} }
return page_data return page_data
def get_upgrade_log_dtl(self, log_id): def get_upgrade_log_dtl(self, log_id, args):
''' '''
获取升级历史信息详情 获取升级历史信息详情
:param log_id: :param log_id:
:return: :return:
''' '''
per_page = args.get('per_page',10)
page = args.get('page',1)
offset = (int(page) - 1) * int(per_page)
sql = f'''select A.* sql = f'''select A.*
from app_upgrade_log_dtl A from app_upgrade_log_dtl A
where A.log_id={log_id} where A.log_id={log_id}
limit {offset},{per_page}
''' '''
count_sql = f'''select count(*) as count
from app_upgrade_log_dtl A
where A.log_id={log_id}'''
with db_driver as session: with db_driver as session:
data = session.query_sql(sql) data = session.query_sql(sql)
count_data = session.retrive_sql(count_sql)
page_data = { page_data = {
"paging": { "paging": {
"page": 1, "page": page,
"per_page": 10, "per_page": per_page,
"total": 10 "total": count_data['count'] if count_data else 0
}, },
"table": data "table": data if data else []
} }
return page_data return page_data
...@@ -45,7 +45,7 @@ class TestGetInfo(unittest.TestCase): ...@@ -45,7 +45,7 @@ class TestGetInfo(unittest.TestCase):
print(res.json) print(res.json)
def test_get_upgrade_log_dtl(self): def test_get_upgrade_log_dtl(self):
log_id = 1237310513316270080 log_id = 1238385199009665024
res = self.client.get('/info/upgrade_log_dtl/{}/'.format(log_id)) res = self.client.get('/info/upgrade_log_dtl/{}/?per_page=2&page=2'.format(log_id))
self.assertEqual(res.status_code, 200) self.assertEqual(res.status_code, 200)
print(res.json) print(res.json)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment