优化升级处理逻辑

main
RogerWork 10 months ago
parent 613c56700a
commit a88e8afd48
  1. 9937
      logs/dingxin.log
  2. BIN
      reqirement.txt
  3. 7
      update/consumers.py
  4. 13
      update/utils/cmd_extcute.py
  5. 14
      update/views.py

File diff suppressed because it is too large Load Diff

Binary file not shown.

@ -16,8 +16,13 @@ class UpdateConsumer(WebsocketConsumer):
if data.get('msg', False): if data.get('msg', False):
if data['msg'] == 'ping': if data['msg'] == 'ping':
self.send(json.dumps({'msg': 'pong'})) self.send(json.dumps({'msg': 'pong'}))
if data.get('finish', False):
ip = data['finish']
if cinema_update_status.get(ip):
del cinema_update_status[ip]
print(cinema_update_status.get(ip, None))
if data.get('ip', False): if data.get('ip', False):
ip = data['ip'] ip = data['ip']
self.send(json.dumps(cinema_update_status.get(ip, None))) self.send(json.dumps({'status': {'ip': ip, 'result': cinema_update_status.get(ip, None)}}))
else: else:
self.send(text_data) self.send(text_data)

@ -74,10 +74,14 @@ class UpdateCommandUtil:
else: else:
exec_output.append(exec_cmd['desc'] + ':执行成功 ' + out.strip()) exec_output.append(exec_cmd['desc'] + ':执行成功 ' + out.strip())
else: else:
exec_output.append(exec_cmd['desc'] + ':执行失败 ' + err.strip()) if exec_cmd['desc'] in ['检出版本', '拉取代码', '执行升级脚本']:
exec_output.append(exec_cmd['desc'] + ':执行成功')
else:
exec_output.append(exec_cmd['desc'] + ':执行失败 ' + err.strip())
return False, exec_output
self.disconnect() self.disconnect()
print(exec_output) print(exec_output)
return '\n'.join(exec_output) return True, '<br/>'.join(exec_output)
def exec_cmd_by_type(self, cinema_ip, _type, cmd_list, short_release): def exec_cmd_by_type(self, cinema_ip, _type, cmd_list, short_release):
print(cinema_ip, _type, cmd_list, short_release) print(cinema_ip, _type, cmd_list, short_release)
@ -99,8 +103,7 @@ class UpdateCommandUtil:
exec_cmd_list.append({'desc': cmd['desc'], 'cmd':c}) exec_cmd_list.append({'desc': cmd['desc'], 'cmd':c})
else: else:
exec_cmd_list.append(cmd) exec_cmd_list.append(cmd)
output = self.exec_cmd(cinema_ip, exec_cmd_list) return self.exec_cmd(cinema_ip, exec_cmd_list)
return output
# 执行设置相关 # 执行设置相关
@ -125,7 +128,7 @@ class UpdateConfigUtil:
db_conn.commit() db_conn.commit()
db_cursor.close() db_cursor.close()
db_conn.close() db_conn.close()
return '\n'.join(result_list) return '<br/>'.join(result_list)
def get_all_exec_cmd(self): def get_all_exec_cmd(self):
all_config_obj = UpdateCommand.objects.filter( all_config_obj = UpdateCommand.objects.filter(

@ -148,7 +148,9 @@ def update_cine(request):
cinema_update_status[cinema_ip]['setup']['result'] = 'running' cinema_update_status[cinema_ip]['setup']['result'] = 'running'
setup_list = list(set(cmd_list) & set(cmd_dict['setup'])) setup_list = list(set(cmd_list) & set(cmd_dict['setup']))
update_cmd = UpdateCommandUtil() update_cmd = UpdateCommandUtil()
setup_output = update_cmd.exec_cmd_by_type(cinema_ip, 'setup', setup_list, short_release) result, setup_output = update_cmd.exec_cmd_by_type(cinema_ip, 'setup', setup_list, short_release)
if result is False:
raise Exception(setup_output)
cinema_update_status[cinema_ip]['setup']['result'] = 'success' cinema_update_status[cinema_ip]['setup']['result'] = 'success'
cinema_update_status[cinema_ip]['setup']['msg'] = setup_output cinema_update_status[cinema_ip]['setup']['msg'] = setup_output
except Exception as e: except Exception as e:
@ -195,7 +197,9 @@ def update_cine(request):
try: try:
cinema_update_status[cinema_ip]['teardown']['result'] = 'running' cinema_update_status[cinema_ip]['teardown']['result'] = 'running'
update_cmd = UpdateCommandUtil() update_cmd = UpdateCommandUtil()
teardown_output = update_cmd.exec_cmd_by_type(cinema_ip, 'teardown', teardown_list, short_release) result, teardown_output = update_cmd.exec_cmd_by_type(cinema_ip, 'teardown', teardown_list, short_release)
if result is False:
raise Exception(teardown_output)
cinema_update_status[cinema_ip]['teardown']['result'] = 'success' cinema_update_status[cinema_ip]['teardown']['result'] = 'success'
cinema_update_status[cinema_ip]['teardown']['msg'] = '执行升级脚本:执行成功' cinema_update_status[cinema_ip]['teardown']['msg'] = '执行升级脚本:执行成功'
except Exception as e: except Exception as e:
@ -212,17 +216,17 @@ def update_cine(request):
update_config = UpdateConfigUtil(cinema_ip, config_list, False) update_config = UpdateConfigUtil(cinema_ip, config_list, False)
config_after_output = update_config.exec_config() config_after_output = update_config.exec_config()
cinema_update_status[cinema_ip]['config']['result'] = 'success' cinema_update_status[cinema_ip]['config']['result'] = 'success'
cinema_update_status[cinema_ip]['config']['msg'] = update_status['config']['msg'] + '\n' + config_after_output cinema_update_status[cinema_ip]['config']['msg'] = config_before_output + '<br/>' + config_after_output
except Exception as e: except Exception as e:
print('config', e) print('config', e)
cinema_update_status[cinema_ip]['config']['result'] = 'fail' cinema_update_status[cinema_ip]['config']['result'] = 'fail'
cinema_update_status[cinema_ip]['config']['msg'] = update_status['config']['msg'] + '\n' + str(e) cinema_update_status[cinema_ip]['config']['msg'] = config_before_output + '<br/>' + str(e)
return JsonResponse({'result': 'fail', 'ip': cinema_ip, 'msg': str(e)}) return JsonResponse({'result': 'fail', 'ip': cinema_ip, 'msg': str(e)})
# 传输客户端 # 传输客户端
client_list = list(set(cmd_list) & set(cmd_dict['client'])) client_list = list(set(cmd_list) & set(cmd_dict['client']))
if len(client_list) > 0: if len(client_list) > 0:
print('传输客户端') print('传输客户端1')
try: try:
client_release = ClientUtil() client_release = ClientUtil()
client_release.client_process(cinema_ip, short_release) client_release.client_process(cinema_ip, short_release)

Loading…
Cancel
Save