|
|
@ -53,19 +53,31 @@ class UpdateCommandUtil: |
|
|
|
Q(is_delete='0') & Q(id__in=cmd_list) & Q(process='setup')).order_by('run_num').all() |
|
|
|
Q(is_delete='0') & Q(id__in=cmd_list) & Q(process='setup')).order_by('run_num').all() |
|
|
|
checked_teardown_result = self.model.objects.filter( |
|
|
|
checked_teardown_result = self.model.objects.filter( |
|
|
|
Q(is_delete='0') & Q(id__in=cmd_list) & Q(process='teardown')).order_by('run_num').all() |
|
|
|
Q(is_delete='0') & Q(id__in=cmd_list) & Q(process='teardown')).order_by('run_num').all() |
|
|
|
sys_cmd = [sys.command for sys in sys_result] |
|
|
|
sys_cmd = [{'desc': sys.desc, 'cmd': sys.command} for sys in sys_result] |
|
|
|
checked_setup_cmd = [setup.command for setup in checked_setup_result] |
|
|
|
checked_setup_cmd = [{'desc': setup.desc, 'cmd': setup.command} for setup in checked_setup_result] |
|
|
|
checked_teardown_cmd = [teardown.command for teardown in checked_teardown_result] |
|
|
|
checked_teardown_cmd = [{'desc': teardown.desc, 'cmd': teardown.command} for teardown in |
|
|
|
|
|
|
|
checked_teardown_result] |
|
|
|
return {'sys': sys_cmd, 'setup': checked_setup_cmd, 'teardown': checked_teardown_cmd} |
|
|
|
return {'sys': sys_cmd, 'setup': checked_setup_cmd, 'teardown': checked_teardown_cmd} |
|
|
|
|
|
|
|
|
|
|
|
def exec_cmd(self, cinema_ip, _exec_cmd_list): |
|
|
|
def exec_cmd(self, cinema_ip, _exec_cmd_list): |
|
|
|
self.connect(cinema_ip) |
|
|
|
self.connect(cinema_ip) |
|
|
|
|
|
|
|
exec_output = [] |
|
|
|
for exec_cmd in _exec_cmd_list: |
|
|
|
for exec_cmd in _exec_cmd_list: |
|
|
|
print(exec_cmd) |
|
|
|
print(exec_cmd) |
|
|
|
stdin, stdout, stderr = self.client.exec_command(exec_cmd) |
|
|
|
stdin, stdout, stderr = self.client.exec_command(exec_cmd['cmd']) |
|
|
|
print(stdout.read().decode('utf-8')) |
|
|
|
out = stdout.read().decode('utf-8') |
|
|
|
print(stderr.read().decode('utf-8')) |
|
|
|
err = stderr.read().decode('utf-8') |
|
|
|
|
|
|
|
print('out', out, 'err', err) |
|
|
|
|
|
|
|
if err == '': |
|
|
|
|
|
|
|
if out == '': |
|
|
|
|
|
|
|
exec_output.append(exec_cmd['desc'] + ':执行成功') |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
exec_output.append(exec_cmd['desc'] + ':执行成功 ' + out.strip()) |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
exec_output.append(exec_cmd['desc'] + ':执行失败 ' + err.strip()) |
|
|
|
self.disconnect() |
|
|
|
self.disconnect() |
|
|
|
|
|
|
|
print(exec_output) |
|
|
|
|
|
|
|
return '\n'.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) |
|
|
@ -78,47 +90,50 @@ class UpdateCommandUtil: |
|
|
|
else: |
|
|
|
else: |
|
|
|
cmds = exec_cmd_data['sys'] |
|
|
|
cmds = exec_cmd_data['sys'] |
|
|
|
for cmd in cmds: |
|
|
|
for cmd in cmds: |
|
|
|
if '<params>' in cmd: |
|
|
|
if '<params>' in cmd['cmd']: |
|
|
|
cmd = cmd.replace('<params>', short_release) |
|
|
|
cmd['cmd'] = cmd['cmd'].replace('<params>', short_release) |
|
|
|
exec_cmd_list.append(cmd) |
|
|
|
exec_cmd_list.append(cmd) |
|
|
|
elif cmd.startswith('<multi>'): |
|
|
|
elif cmd['cmd'].startswith('<multi>'): |
|
|
|
cmd = cmd.replace('<multi>', '') |
|
|
|
cmd['cmd'] = cmd['cmd'].replace('<multi>', '') |
|
|
|
for c in cmd.split('|||'): |
|
|
|
for c in cmd['cmd'].split('|||'): |
|
|
|
exec_cmd_list.append(c) |
|
|
|
exec_cmd_list.append({'desc': cmd['desc'], 'cmd':c}) |
|
|
|
else: |
|
|
|
else: |
|
|
|
exec_cmd_list.append(cmd) |
|
|
|
exec_cmd_list.append(cmd) |
|
|
|
self.exec_cmd(cinema_ip, exec_cmd_list) |
|
|
|
output = self.exec_cmd(cinema_ip, exec_cmd_list) |
|
|
|
|
|
|
|
return output |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 执行设置相关 |
|
|
|
# 执行设置相关 |
|
|
|
class UpdateConfigUtil: |
|
|
|
class UpdateConfigUtil: |
|
|
|
def __init__(self, cinema_ip, checked_list): |
|
|
|
def __init__(self, cinema_ip, checked_list, run_before_teardown): |
|
|
|
self.ip = cinema_ip |
|
|
|
self.ip = cinema_ip |
|
|
|
self.checked_list = checked_list |
|
|
|
self.checked_list = checked_list |
|
|
|
|
|
|
|
self.run_before_teardown = run_before_teardown |
|
|
|
|
|
|
|
|
|
|
|
def exec_config(self): |
|
|
|
def exec_config(self): |
|
|
|
cmd_list = self.get_all_exec_cmd() |
|
|
|
cmd_list = self.get_all_exec_cmd() |
|
|
|
db_config = Cinema.objects.filter(ip=self.ip).values()[0] |
|
|
|
db_config = Cinema.objects.filter(ip=self.ip).values()[0] |
|
|
|
print(db_config) |
|
|
|
|
|
|
|
print(db_config['db_user'], db_config['db_pwd']) |
|
|
|
|
|
|
|
db_conn = pymysql.Connect(host=self.ip, port=3306, user=db_config['db_user'], passwd=db_config['db_pwd'], |
|
|
|
db_conn = pymysql.Connect(host=self.ip, port=3306, user=db_config['db_user'], passwd=db_config['db_pwd'], |
|
|
|
database='cine') |
|
|
|
database='cine') |
|
|
|
db_cursor = db_conn.cursor() |
|
|
|
db_cursor = db_conn.cursor() |
|
|
|
|
|
|
|
result_list = [] |
|
|
|
for cmds in cmd_list: |
|
|
|
for cmds in cmd_list: |
|
|
|
for cmd in cmds: |
|
|
|
for cmd in cmds['cmd']: |
|
|
|
db_cursor.execute(cmd) |
|
|
|
r = db_cursor.execute(cmd) |
|
|
|
|
|
|
|
print("exec_config", cmds['desc'], r) |
|
|
|
|
|
|
|
result_list.append(cmds['desc'] + (':执行失败(设置无需修改)' if r == 0 else ':执行成功')) |
|
|
|
db_conn.commit() |
|
|
|
db_conn.commit() |
|
|
|
db_cursor.close() |
|
|
|
db_cursor.close() |
|
|
|
db_conn.close() |
|
|
|
db_conn.close() |
|
|
|
|
|
|
|
return '\n'.join(result_list) |
|
|
|
|
|
|
|
|
|
|
|
def get_all_exec_cmd(self): |
|
|
|
def get_all_exec_cmd(self): |
|
|
|
all_config_obj = UpdateCommand.objects.filter(Q(process='config') & Q(is_delete=False)).values() |
|
|
|
all_config_obj = UpdateCommand.objects.filter( |
|
|
|
print(all_config_obj) |
|
|
|
Q(process='config') & Q(run=self.run_before_teardown) & Q(is_delete=False)).values() |
|
|
|
cmd_list = [] |
|
|
|
cmd_list = [] |
|
|
|
for config_item in all_config_obj: |
|
|
|
for config_item in all_config_obj: |
|
|
|
print(config_item) |
|
|
|
|
|
|
|
if config_item['id'] in self.checked_list: |
|
|
|
if config_item['id'] in self.checked_list: |
|
|
|
cmd_list.append(json.loads(config_item['command'])['checked']) |
|
|
|
cmd_list.append({"desc": config_item['desc'], "cmd": json.loads(config_item['command'])['checked']}) |
|
|
|
else: |
|
|
|
else: |
|
|
|
cmd_list.append(json.loads(config_item['command'])['unchecked']) |
|
|
|
cmd_list.append({"desc": config_item['desc'], "cmd": json.loads(config_item['command'])['unchecked']}) |
|
|
|
return cmd_list |
|
|
|
return cmd_list |
|
|
|