|
|
|
@ -107,10 +107,13 @@ def get_git_version(request): |
|
|
|
|
def update_cine(request): |
|
|
|
|
req = request.GET.dict() |
|
|
|
|
cinema_ip = req.get('ip') |
|
|
|
|
print('-'*100) |
|
|
|
|
print(f'开始更新 {cinema_ip}') |
|
|
|
|
|
|
|
|
|
# 获取当前版本 |
|
|
|
|
org_ver = get_cinema_ver_by_ip(ip=cinema_ip) |
|
|
|
|
update_time = timezone.now() |
|
|
|
|
print(f'原始版本 {org_ver}') |
|
|
|
|
|
|
|
|
|
# 处理命令格式 |
|
|
|
|
cmd_dict = {} |
|
|
|
@ -120,7 +123,7 @@ def update_cine(request): |
|
|
|
|
cmd_dict[cmd['process']].append(cmd['id']) |
|
|
|
|
else: |
|
|
|
|
cmd_dict[cmd['process']] = [cmd['id']] |
|
|
|
|
print(cmd_dict) |
|
|
|
|
# print(cmd_dict) |
|
|
|
|
|
|
|
|
|
# 增加状态 |
|
|
|
|
update_status = { |
|
|
|
@ -142,22 +145,21 @@ def update_cine(request): |
|
|
|
|
if redis_conn.exists(redis_key): |
|
|
|
|
# update_status = copy.deepcopy(json.loads(redis_conn.get(redis_key))) |
|
|
|
|
val = json.loads(redis_conn.get(redis_key)) |
|
|
|
|
print(val) |
|
|
|
|
print(f'存在redis key {redis_key} 对应的数据', val) |
|
|
|
|
if val['result'] == 'running': |
|
|
|
|
print('redis存在key', redis_key) |
|
|
|
|
return JsonResponse({'result': 'fail', 'ip': cinema_ip, 'msg': '该影院正在升级中,请稍后再试!'}) |
|
|
|
|
# 如果存在对应的键值,且结果为running,则提示升级中 |
|
|
|
|
|
|
|
|
|
redis_conn.set(redis_key, json.dumps(update_status), 5 * 60) |
|
|
|
|
|
|
|
|
|
print('update_status', update_status) |
|
|
|
|
# print('update_status', update_status) |
|
|
|
|
|
|
|
|
|
# redis_conn.set(f'cinema_update_status_{cinema_ip}', json.dumps(update_status), 10*60) |
|
|
|
|
# print("ws调试", cinema_update_status) |
|
|
|
|
|
|
|
|
|
short_release = req.get('version') |
|
|
|
|
cmd_list = json.loads(req.get('cmd')) |
|
|
|
|
print(cinema_ip, short_release, cmd_list) |
|
|
|
|
print('执行升级任务:', cmd_list) |
|
|
|
|
|
|
|
|
|
# cinema_ip = '172.16.3.88' |
|
|
|
|
# short_release = '2.0.33.0338_Release' |
|
|
|
@ -167,7 +169,7 @@ def update_cine(request): |
|
|
|
|
redis_conn.set(redis_key, json.dumps(update_status), 5 * 60) |
|
|
|
|
|
|
|
|
|
# 获取并写入cine.sql |
|
|
|
|
print('获取并写入cine.sql') |
|
|
|
|
print('-'*20, '步骤一:获取并写入cine.sql', '-'*20) |
|
|
|
|
try: |
|
|
|
|
update_status['git']['result'] = 'running' |
|
|
|
|
redis_conn.set(redis_key, json.dumps(update_status), 5 * 60) |
|
|
|
@ -177,19 +179,20 @@ def update_cine(request): |
|
|
|
|
update_status['git']['msg'] = git_output |
|
|
|
|
redis_conn.set(redis_key, json.dumps(update_status), 5 * 60) |
|
|
|
|
except Exception as e: |
|
|
|
|
print('git', e) |
|
|
|
|
print('步骤一:获取并写入cine.sql异常', e) |
|
|
|
|
update_status['result'] = 'fail' |
|
|
|
|
update_status['git']['result'] = 'fail' |
|
|
|
|
update_status['git']['msg'] = str(e) |
|
|
|
|
print('最后执行状态', json.dumps(update_status)) |
|
|
|
|
redis_conn.set(redis_key, json.dumps(update_status), 5 * 60) |
|
|
|
|
# redis_conn.delete(redis_key) |
|
|
|
|
UpdateLog.objects.create(ip=cinema_ip, type='toolbox', origin_ver=org_ver, target_ver=short_release[:11], |
|
|
|
|
time=update_time, result=update_status['result'], |
|
|
|
|
time=update_time, result='fail', |
|
|
|
|
result_detail=json.dumps(update_status)) |
|
|
|
|
return JsonResponse({'result': 'fail', 'ip': cinema_ip, 'msg': str(e)}) |
|
|
|
|
|
|
|
|
|
# 执行setup |
|
|
|
|
print('执行setup') |
|
|
|
|
print('-'*20, '步骤二:执行setup', '-'*20) |
|
|
|
|
try: |
|
|
|
|
update_status['setup']['result'] = 'running' |
|
|
|
|
redis_conn.set(redis_key, json.dumps(update_status), 5 * 60) |
|
|
|
@ -203,10 +206,11 @@ def update_cine(request): |
|
|
|
|
update_status['setup']['msg'] = setup_output |
|
|
|
|
redis_conn.set(redis_key, json.dumps(update_status), 5 * 60) |
|
|
|
|
except Exception as e: |
|
|
|
|
print('setup', e) |
|
|
|
|
print('步骤二:执行setup异常', e) |
|
|
|
|
update_status['result'] = 'fail' |
|
|
|
|
update_status['setup']['result'] = 'fail' |
|
|
|
|
update_status['setup']['msg'] = str(e) |
|
|
|
|
print('最后执行状态', json.dumps(update_status)) |
|
|
|
|
redis_conn.set(redis_key, json.dumps(update_status), 5 * 60) |
|
|
|
|
# redis_conn.delete(redis_key) |
|
|
|
|
UpdateLog.objects.create(ip=cinema_ip, type='toolbox', origin_ver=org_ver, target_ver=short_release[:11], |
|
|
|
@ -217,7 +221,7 @@ def update_cine(request): |
|
|
|
|
# 数据库对比 |
|
|
|
|
sql_list = list(set(cmd_list) & set(cmd_dict['sql'])) |
|
|
|
|
if len(sql_list) > 0: |
|
|
|
|
print('数据库对比') |
|
|
|
|
print('-'*20, '步骤三:数据库对比', '-'*20) |
|
|
|
|
try: |
|
|
|
|
update_status['sql']['result'] = 'running' |
|
|
|
|
redis_conn.set(redis_key, json.dumps(update_status), 5 * 60) |
|
|
|
@ -227,10 +231,11 @@ def update_cine(request): |
|
|
|
|
update_status['sql']['msg'] = sql_output |
|
|
|
|
redis_conn.set(redis_key, json.dumps(update_status), 5 * 60) |
|
|
|
|
except Exception as e: |
|
|
|
|
print('sql', e) |
|
|
|
|
print('步骤三:数据库对比异常', e) |
|
|
|
|
update_status['result'] = 'fail' |
|
|
|
|
update_status['sql']['result'] = 'fail' |
|
|
|
|
update_status['sql']['msg'] = str(e) |
|
|
|
|
print('最后执行状态', json.dumps(update_status)) |
|
|
|
|
redis_conn.set(redis_key, json.dumps(update_status), 5 * 60) |
|
|
|
|
# redis_conn.delete(redis_key) |
|
|
|
|
UpdateLog.objects.create(ip=cinema_ip, type='toolbox', origin_ver=org_ver, target_ver=short_release[:11], |
|
|
|
@ -239,7 +244,7 @@ def update_cine(request): |
|
|
|
|
return JsonResponse({'result': 'fail', 'ip': cinema_ip, 'msg': str(e)}) |
|
|
|
|
|
|
|
|
|
# 修改设置 |
|
|
|
|
print('执行config(teardown前)') |
|
|
|
|
print('-'*20, '第四步:执行config(teardown前)', '-'*20) |
|
|
|
|
try: |
|
|
|
|
update_status['config']['result'] = 'running' |
|
|
|
|
redis_conn.set(redis_key, json.dumps(update_status), 5 * 60) |
|
|
|
@ -250,10 +255,11 @@ def update_cine(request): |
|
|
|
|
update_status['config']['msg'] = config_before_output |
|
|
|
|
redis_conn.set(redis_key, json.dumps(update_status), 5 * 60) |
|
|
|
|
except Exception as e: |
|
|
|
|
print('config', e) |
|
|
|
|
print('第四步:执行config(teardown前)异常', e) |
|
|
|
|
update_status['result'] = 'fail' |
|
|
|
|
update_status['config']['result'] = 'fail' |
|
|
|
|
update_status['config']['msg'] = str(e) |
|
|
|
|
print('最后执行状态', json.dumps(update_status)) |
|
|
|
|
redis_conn.set(redis_key, json.dumps(update_status), 5 * 60) |
|
|
|
|
# redis_conn.delete(redis_key) |
|
|
|
|
UpdateLog.objects.create(ip=cinema_ip, type='toolbox', origin_ver=org_ver, target_ver=short_release[:11], |
|
|
|
@ -264,7 +270,7 @@ def update_cine(request): |
|
|
|
|
# 执行teardown |
|
|
|
|
teardown_list = list(set(cmd_list) & set(cmd_dict['teardown'])) |
|
|
|
|
if len(teardown_list) > 0: |
|
|
|
|
print('执行teardown') |
|
|
|
|
print('-' * 20, '第五步:执行teardown', '-' * 20) |
|
|
|
|
try: |
|
|
|
|
update_status['teardown']['result'] = 'running' |
|
|
|
|
redis_conn.set(redis_key, json.dumps(update_status), 5 * 60) |
|
|
|
@ -276,10 +282,11 @@ def update_cine(request): |
|
|
|
|
update_status['teardown']['msg'] = '执行升级脚本:执行成功' |
|
|
|
|
redis_conn.set(redis_key, json.dumps(update_status), 5 * 60) |
|
|
|
|
except Exception as e: |
|
|
|
|
print('teardown', e) |
|
|
|
|
print('第五步:执行teardown异常', e) |
|
|
|
|
update_status['result'] = 'fail' |
|
|
|
|
update_status['teardown']['result'] = 'fail' |
|
|
|
|
update_status['teardown']['msg'] = str(e) |
|
|
|
|
print('最后执行状态', json.dumps(update_status)) |
|
|
|
|
redis_conn.set(redis_key, json.dumps(update_status), 5 * 60) |
|
|
|
|
# redis_conn.delete(redis_key) |
|
|
|
|
UpdateLog.objects.create(ip=cinema_ip, type='toolbox', origin_ver=org_ver, target_ver=short_release[:11], |
|
|
|
@ -288,7 +295,7 @@ def update_cine(request): |
|
|
|
|
return JsonResponse({'result': 'fail', 'ip': cinema_ip, 'msg': str(e)}) |
|
|
|
|
|
|
|
|
|
# 修改设置 |
|
|
|
|
print('执行config(teardown后)') |
|
|
|
|
print('-' * 20, '第六步:执行config(teardown后)', '-' * 20) |
|
|
|
|
try: |
|
|
|
|
update_status['config']['result'] = 'running' |
|
|
|
|
redis_conn.set(redis_key, json.dumps(update_status), 5 * 60) |
|
|
|
@ -299,10 +306,11 @@ def update_cine(request): |
|
|
|
|
update_status['config']['msg'] = config_before_output + '<br/>' + config_after_output |
|
|
|
|
redis_conn.set(redis_key, json.dumps(update_status), 5 * 60) |
|
|
|
|
except Exception as e: |
|
|
|
|
print('config', e) |
|
|
|
|
print('第六步:执行config(teardown后)异常', e) |
|
|
|
|
update_status['result'] = 'fail' |
|
|
|
|
update_status['config']['result'] = 'fail' |
|
|
|
|
update_status['config']['msg'] = config_before_output + '<br/>' + str(e) |
|
|
|
|
print('最后执行状态', json.dumps(update_status)) |
|
|
|
|
redis_conn.set(redis_key, json.dumps(update_status), 5 * 60) |
|
|
|
|
# redis_conn.delete(redis_key) |
|
|
|
|
UpdateLog.objects.create(ip=cinema_ip, type='toolbox', origin_ver=org_ver, target_ver=short_release[:11], |
|
|
|
@ -313,21 +321,21 @@ def update_cine(request): |
|
|
|
|
# 传输客户端 |
|
|
|
|
client_list = list(set(cmd_list) & set(cmd_dict['client'])) |
|
|
|
|
if len(client_list) > 0: |
|
|
|
|
print('传输客户端1') |
|
|
|
|
print('-' * 20, '第七步:传输客户端', '-' * 20) |
|
|
|
|
try: |
|
|
|
|
update_status['client']['result'] = 'running' |
|
|
|
|
redis_conn.set(redis_key, json.dumps(update_status), 5 * 60) |
|
|
|
|
client_release = ClientUtil() |
|
|
|
|
print('client_release.client_process') |
|
|
|
|
client_name = client_release.client_process(cinema_ip, short_release) |
|
|
|
|
update_status['client']['result'] = 'success' |
|
|
|
|
update_status['client']['msg'] = f'客户端上传成功: {client_name}' |
|
|
|
|
redis_conn.set(redis_key, json.dumps(update_status), 5 * 60) |
|
|
|
|
except Exception as e: |
|
|
|
|
print('client', e) |
|
|
|
|
print('第七步:传输客户端异常', e) |
|
|
|
|
update_status['result'] = 'fail' |
|
|
|
|
update_status['client']['result'] = 'fail' |
|
|
|
|
update_status['client']['msg'] = str(e) |
|
|
|
|
print('最后执行状态', json.dumps(update_status)) |
|
|
|
|
redis_conn.set(redis_key, json.dumps(update_status), 5 * 60) |
|
|
|
|
# redis_conn.delete(redis_key) |
|
|
|
|
UpdateLog.objects.create(ip=cinema_ip, type='toolbox', origin_ver=org_ver, target_ver=short_release[:11], |
|
|
|
@ -338,10 +346,8 @@ def update_cine(request): |
|
|
|
|
update_status['result'] = 'success' |
|
|
|
|
redis_conn.set(redis_key, json.dumps(update_status), 5 * 60) |
|
|
|
|
|
|
|
|
|
print('update_status', update_status) |
|
|
|
|
print('redis_get', redis_conn.get(redis_key)) |
|
|
|
|
print('完成升级', json.dumps(update_status)) |
|
|
|
|
|
|
|
|
|
print('update_time', update_time) |
|
|
|
|
UpdateLog.objects.create(ip=cinema_ip, type='toolbox', origin_ver=org_ver, target_ver=short_release[:11], |
|
|
|
|
time=update_time, result=update_status['result'], result_detail=json.dumps(update_status)) |
|
|
|
|
return JsonResponse({'result': 'success', 'ip': cinema_ip, 'msg': ''}) |
|
|
|
|