def file_compare(self, left, right): tmp_script_file = self.std_tmp_path + "/tmp_script_file.txt" tmp_result_file = self.std_tmp_path + "/compare_result.html" #tmp_result_file = "F:\\cc.html" fp = open(tmp_script_file, "w") fp.write(SCRIPT) fp.close() self.left_tmp = self.std_tmp_path + "/tmp_left.txt" self.right_tmp = self.std_tmp_path + "/tmp_right.txt" self.make_nospace_file(left, self.left_tmp) self.make_nospace_file(right, self.right_tmp) cmd = "%s @%s %s %s %s -silent" % (self.tool, tmp_script_file, self.left_tmp, self.right_tmp, tmp_result_file) process = RunCmd(cmd) process.run() self.change_lines += self.check_diff(tmp_result_file) if os.path.exists(tmp_script_file): os.remove(tmp_script_file) if os.path.exists(tmp_result_file): os.remove(tmp_result_file) if os.path.exists(self.left_tmp): os.remove(self.left_tmp) if os.path.exists(self.right_tmp): os.remove(self.right_tmp)
def ingest_vddb_testdata_vdna_ingest(self, host, username, password, dna_file): #media_file = CI_SCRIPT_ROOT + "/" + media_file #vdna_ingest -s192.168.1.14 -uzhang_jin -w123 -TDNA -i tt.dna cmd = ["vdna_ingest", "-s%s" % host, "-u%s" % username, "-w%s" % password, "-TDNA -i", dna_file] process = RunCmd(" ".join(cmd)) return_code = process.run() return process.stdout
def far_split(self, far_file, dir_far): far_file = CI_SCRIPT_ROOT + '/' + far_file dir_far = CI_SCRIPT_ROOT + '/' + dir_far cmd = ["far_split", "-i %s" % far_file, "-d %s" % dir_far] process = RunCmd(" ".join(cmd)) return_code = process.run() return process.stdout
def generator_far_media(self, media_file, dir_far): media_file = ' '.join( map(lambda s: CI_SCRIPT_ROOT + s, media_file.split(','))) dir_far = CI_SCRIPT_ROOT + '/' + dir_far cmd = ["VDNAGen", "-o", "%s" % dir_far, "%s" % media_file, "-q"] process = RunCmd(" ".join(cmd)) return_code = process.run() return process.stdout
def run_different_cmds(self, **kwargs): rlt = {} for k, v in kwargs.items(): cmd = " ".join([k, v]) process = RunCmd(cmd) return_code = process.run() r = process.stdout rlt.setdefault(k, r) return rlt
def __pyweb_sut_run(self, module, argv): cmd = self.__make_cmd(module, argv) #logger.warn(cmd) for i in range(len(cmd)): if i >= 8: cmd[i] = urllib.quote_plus(cmd[i]) process = RunCmd(" ".join(cmd)) return_code = process.run() return process.stdout
def generator_far_dna(self, media_file, dir_far): media_file = CI_SCRIPT_ROOT + '/' + media_file dir_far = CI_SCRIPT_ROOT + '/' + dir_far cmd = [ "VDNAGen", "-TDNA", "%s" % media_file, "-o", "%s" % dir_far, "-q" ] process = RunCmd(" ".join(cmd)) return_code = process.run() return process.stdout
def ingest_media_file(self, host, username, password, media_file): media_file = CI_SCRIPT_ROOT + "/" + media_file cmd = [ "VDNAGen", "-s%s" % host, "-u%s" % username, "-p%s" % password, media_file, "-q" ] process = RunCmd(" ".join(cmd)) return_code = process.run() return process.stdout
def run_same_cmds(self, cmd, count, *cmdargs): rlt = {} for arg in cmdargs: t_r = [] c = " ".join([cmd, str(arg)]) for i in range(count): process = RunCmd(c) return_code = process.run() r = process.stdout t_r.append(r) rlt.setdefault(arg, t_r) return rlt
def vdna_query(self, host, username, password, media_file): media_file = CI_SCRIPT_ROOT + '/' + media_file cmd = [ "vdna_query", "-s %s" % host, "-u %s" % username, "-w %s" % password, "-Tdna -i %s" % media_file ] process = RunCmd(" ".join(cmd)) return_code = process.run() return process.stdout
def run(self): while True: try: self.connection.settimeout(600) buf = self.connection.recv(2048) try: msg = json.loads(buf) if msg.keys()[0] == "RunCmd": cmd = unhexlify(msg["RunCmd"]) process = RunCmd(cmd) process.run() print process.cmd #print process.stdout #print process.stderr return_msg = "" if msg["stdout"] == "true": return_msg += process.stdout if return_msg != "" and return_msg[-1] != "\n": return_msg += "\r\n" if msg["stderr"] == "true": return_msg += process.stderr print return_msg msg = hexlify(return_msg) while True: send_msg = {} if len(msg) <= 1024: send_msg["is_finish"] = True send_msg["msg"] = msg self.connection.send(json.dumps(send_msg)) break else: send_msg["is_finish"] = False send_msg["msg"] = msg[0:1024] self.connection.send(json.dumps(send_msg)) time.sleep(0.02) msg = msg[1024:] else: self.connection.send("message: %s error" % json.dumps(msg)) except TypeError, ex: self.connection.send("%s TypeError: %s" % (msg, str(ex))) except ValueError, ex: self.connection.send("JSON format error") except Exception, ex: self.connection.send("%s message error: %s" % (msg, str(ex)))
def vdna_query(self, cmd, *args, **kwargs): ''' host, username, password, dna_file''' keys_list = kwargs.keys() args_list = ['host', 'username', 'password', 'dna_file'] in_list = list(set(args_list).intersection(set(keys_list))) if sorted(args_list) != sorted(in_list): raise AssertionError('%s args error: %s' % (cmd, in_list)) cmd = ["%s" % cmd, "-u%s" % kwargs['username'], "-w%s" % kwargs['password'], "-s%s" % kwargs['host'], "-TDNA", "-i %s" % kwargs['dna_file']] for a in args: cmd.append(a) difference_list = list(set(keys_list).difference(set(args_list))) if difference_list: for a in difference_list: cmd.append(str(a) + '=' + kwargs[a]) process = RunCmd(" ".join(cmd)) return_code = process.run() return process.stdout
def file_compare(self, left, right): #self.make_nospace_file(left, self.left_tmp) #self.make_nospace_file(right, self.right_tmp) cmd = "%s @%s %s %s %s -silent" % (self.tool, self.tmp_script_file, self.left_tmp, self.right_tmp, self.tmp_result_file) process = RunCmd(cmd) ret = process.run() #print 'ret = %s' % ret if 0 == ret: self.change_lines += self.check_diff(self.tmp_result_file) else: self.make_nospace_file_err(left, self.left_tmp) self.make_nospace_file_err(right, self.right_tmp) cmd = "%s @%s %s %s %s -silent" % (self.tool, self.tmp_script_file, self.left_tmp, self.right_tmp, self.tmp_result_file) process = RunCmd(cmd) ret = process.run() self.change_lines += self.check_diff(self.tmp_result_file) if os.path.exists(self.tmp_result_file): os.remove(self.tmp_result_file) if os.path.exists(self.left_tmp): os.remove(self.left_tmp) if os.path.exists(self.right_tmp): os.remove(self.right_tmp)
def generator_far_for_batch(self): r = [] source_file_path = CI_SCRIPT_ROOT + '/data/VDNAGen_data/source_file' far_path = CI_SCRIPT_ROOT + '/data/VDNAGen_data/generator_far' for n in os.listdir(source_file_path): far_name = '.'.join(n.split('.')[:-1]) + '.far' cmd = [ "VDNAGen", "-o" % (far_path + far_name), "%s" % (source_file_path + n), "-q" ] process = RunCmd(" ".join(cmd)) r.append(process.stdout) return r
def check_vdnagen_ver(self): cmd = ["VDNAGen", "-v"] process = RunCmd(" ".join(cmd)) return_code = process.run() return process.stdout[:-1]
def case_exe(self, schedule_id, content): self.schedule_started_at = datetime.now() self.schedule_start = time.time() exe_list = self.get_exe_list(content) case_total = len(exe_list) case_pass = 0 case_pass_list = [] case_fail = 0 case_fail_list = [] case_miss = 0 case_miss_list = [] case_bad = 0 case_bad_list = [] case_exed = 0 for case_id in exe_list: case_name = case_id now_time = datetime.now().strftime('%Y_%m_%d_%H_%M_%S') log_file = str("/tmp/%s_%s_%s" % (now_time, self.pid, case_name)) query_result = self.get_module(case_id) msg = {} msg["exed"] = "%s" % case_exed msg["total"] = "%s" % case_total msg["successful"] = "%s" % case_pass msg["failed"] = "%s" % case_fail msg["noExe"] = "%s" % case_miss msg["bad"] = "%s" % case_bad msg["suc_list"] = case_pass_list msg["fail_list"] = case_fail_list msg["noExe_list"] = case_miss_list msg["bad_list"] = case_bad_list msg = json.dumps(msg) self.schedule_result_update(schedule_id, "testing", msg = msg, current_case = case_name) case_result = "noExe" self.case_started_at = datetime.now() self.case_start = time.time() if query_result == []: print "*" * 100 print "case " + case_name + " is running (%s/%s)..." % (case_exed + 1, case_total) print "cannot found " + case_name print "case " + case_name + " end..." case_exed += 1 case_result = "noExe" case_miss += 1 case_miss_list.append(case_name) else: module = query_result[0].module_name case_path = self.case_script_path % module if os.path.exists(case_path + case_name + ".py"): cmd = ("python", case_path + case_name + ".py", log_file) print "*" * 100 print "case " + case_name + " is running (%s/%s)..." % (case_exed + 1, case_total) process = RunCmd(" ".join(cmd), 300) return_code = process.run() #item = run_cmd(" ".join(cmd)) print "case " + case_name + " end..." case_exed += 1 if return_code != -9: if -1 != process.stdout.find("%s false" % case_name) and os.path.exists(log_file): case_result = 'failed' case_fail += 1 case_fail_list.append(case_name) print "case " + case_name + " fail..." elif -1 != process.stdout.find("%s succeed" % case_name) and os.path.exists(log_file): case_result = "successful" case_pass += 1 case_pass_list.append(case_name) print "case " + case_name + " succeed..." else: case_result = 'bad' case_bad += 1 case_bad_list.append(case_name) print "case " + case_name + " bad..." else: case_result = "killed" case_fail += 1 case_fail_list.append(case_name) print "case " + case_name + " killed..." else: case_result = "noExe" case_exed += 1 case_miss += 1 case_miss_list.append(case_name) self.set_case_result(case_id, schedule_id, case_result, log_file) if log_file is not None: if os.path.exists(log_file): os.remove(log_file) msg = {} msg["exed"] = "%s" % case_exed msg["total"] = "%s" % case_total msg["successful"] = "%s" % case_pass msg["failed"] = "%s" % case_fail msg["noExe"] = "%s" % case_miss msg["bad"] = "%s" % case_bad msg["suc_list"] = case_pass_list msg["fail_list"] = case_fail_list msg["noExe_list"] = case_miss_list msg["bad_list"] = case_bad_list msg = json.dumps(msg) print "*" * 100 self.schedule_result_update(schedule_id, "finished", msg = msg)
def generator_far(self, cmd, dir_far, media_file): source_file_name = CI_SCRIPT_ROOT + '/data/VDNAGen_data/source_file/' + media_file far_name = CI_SCRIPT_ROOT + '/data/VDNAGen_data/generator_far/' + dir_far cmd = [cmd, "-o" % source_file_name, "%s" % far_name, "-q"] process = RunCmd(" ".join(cmd)) return process.stdout
def cat_cmd(self, cmd): cmd = "cat " + CI_SCRIPT_ROOT + cmd process = RunCmd(" ".join(cmd)) return_code = process.run() return process.stdout
def run_cmd(self, cmd): process = RunCmd(" ".join(cmd)) return_code = process.run() return process.stdout