def action_run(self, kwargs): cmdlist = [] cmd_programlist = [] unitdev_list = self.detect_ses_dev() if len(unitdev_list) == 0: _LOGGER.info("Don not find the sg dev") return False _LOGGER.info("the unit is %s" % unitdev_list) for devopt in unitdev_list: for cmdopt in self.cmd: cmd = cmdopt + devopt cmdlist.append(cmd) for cmdopt in cmdlist: cmd_program = command.CommandLocalViaSystem(cmdopt) cmd_programlist.append(cmd_program) _LOGGER.info("the cmdlist is %s" % cmdlist) for opt in cmd_programlist: try: value = opt.apply() time.sleep(4) except OSError: return False i = value.find("fail") if -1 != i: _LOGGER.info("fail to program fw") return False time.sleep(4) return True
def detect_ses_dev(product_id): cmd = "ls /dev/sg*" cmd_detect = command.CommandLocalViaSystem(cmd) cmd_sg = "sg_inq" try: value = cmd_detect.apply() except OSError: return False unitdev_list = [] value = value.strip() list_item = value.split("\n") for item in list_item: item_tmp = item.strip() item = item_tmp[7:] cmd = cmd_sg + " " + "/dev/sg" + item cmd_det = command.CommandLocalViaSystem(cmd) value = cmd_det.apply() if -1 != value.find(product_id): unit = item unit = str(unit) unitdev_list.append(unit) return unitdev_list
def match_ses_dev(dev_list, sg_id): cmd = "sg_ses --page=0x01 /dev/sg" flag = 0 for i in dev_list: cmd_match = command.CommandLocalViaSystem(cmd + str(i)) value = cmd_match.apply() if -1 != value.find("relative ES process id:"): num = value.find("relative ES process id:") + len("relative ES process id:") + 1 dev_id = value[num:num+1] if dev_id == sg_id: flag = 1 break if flag == 1: return i else: _LOGGER.info("Don't find the match sg id") raise ValueError("Don't find the match sg id %s" % sg_id)
def action_init(self, kwargs): self.pathlist = [] self.cmd = [] testcasexml = kwargs.get("testcase") node = self.parameter.find(self.item_type) node = analyse_fw_node(testcasexml, node, self.item_type) for cmdopt in node.findall("cmd"): self.cmd.append(cmdopt.get("value")) vend_node = node.find("vend_id") self.vend_id = vend_node.get("name") product_node = node.find("product_id") self.product_id = product_node.get("name") cmd = "ls /dev/sg*" self.cmd_detect = command.CommandLocalViaSystem(cmd) self.cmd_sg = "sg_inq" return True
def action_init(self, kwargs): self.pathlist = [] testcasexml = kwargs.get("testcase") node = self.parameter.find(self.item_type) node = analyse_fw_node(testcasexml, node, self.item_type) self.cmd = "diag_ui" for pathopt in node.findall("path"): path = pathopt.get("file") self.pathlist.append(path) vend_node = node.find("vend_id") self.vend_id = vend_node.get("name") product_node = node.find("product_id") self.product_id = product_node.get("name") cmd = "ls /dev/sg*" # self.cmd_detect = command.CommandLocalViaPopen(cmd) self.cmd_detect = command.CommandLocalViaSystem(cmd) self.cmd_sg = "sg_inq" return True
def detect_ses_dev(self): try: value = self.cmd_detect.apply() except OSError: return False unitdev_list = [] value = value.strip() list_item = value.split("\n") for item in list_item: item_tmp = item.strip() item = item_tmp[7:] cmd = self.cmd_sg + " " + "/dev/sg" + item cmd_det = command.CommandLocalViaSystem(cmd) value = cmd_det.apply() if -1 != value.find(self.product_id): unit = hex(int(item))[2:] unit = str(unit) unitdev_list.append(unit) return unitdev_list
def action_run(self, kwargs): """ Execute the command. """ dev_list = detect_ses_dev(self.product_id) dev_id = match_ses_dev(dev_list, self.sg_id) dev_id = str(dev_id) cmd_phy = "cls_cli_tool -d /dev/sg" + dev_id + " -c phyinfo" self.cmd = command.CommandLocalViaSystem(cmd_phy) try: value = self.cmd.apply() time.sleep(3) except ValueError: return False iovalue = self.parse_pyhinfo(value) ret = self.compare_value(self.list_xmlphyd, iovalue) if ret: return True else: return False
def action_run(self, kwargs): cmdlist = [] cmd_programlist = [] unit = [] unit = self.detect_ses_dev() for i in unit: for pathopt in self.pathlist: cmd = self.cmd + " -d " + "13.4." + i + ".0" + " -x -f " + "\"" + pathopt + "\"" + " -d 1 -v " + "\"" + self.vend_id + "\"" + " -p " + "\"" + self.product_id + "\"" + " -r 0" cmdlist.append(cmd) for cmdopt in cmdlist: cmd_program = command.CommandLocalViaSystem(cmdopt) cmd_programlist.append(cmd_program) for cmd_program in cmd_programlist: try: value = cmd_program.apply() except OSError: return False i = value.find("Fail") if -1 != i: _LOGGER.info("fail to program fw") return False return True