def getNodebyParentandChildrenMatch (datafile, pnode, cnode, cvalue, rnode, rvalue, lnode): """ Searches XML file for the parent node. Finds the 1st child node and checks its value if value is a match, then search for second child and check if its value matches. If that is a match, then obtain the value of the third child datafile = xml file searched pnode = parent node cnode = child node cvalue = child node value rnode = reference node rvalue = refernce node value lnode = lastnode """ tree = ElementTree.parse(datafile) root = tree.getroot() lnodev = False for node in root.findall(pnode): value = node.find(cnode).text if value == cvalue: if node.find(rnode) is not None: rnodev = node.find(rnode).text # print_debug("rnodev : '%s'" % rnodev) if rnodev == rvalue: lnodev = node.find(lnode).text break print_debug("getNodebyParentandChildrenMatch_Status: %s" % lnodev) return lnodev
def close(self): '''Calls the telnetlib close and terminates the telnet session''' try: self.tnet.close() print_debug("TELNET CONNECTION CLOSING...") except Exception: print_error("Error occured while closing telnet session") return False
def get_response(self, cmd_string, prompt, timeout=120): ''' Reads the output till the prompt and returns the result and reports Failure on mismatch of response''' self.write(cmd_string) try: self.cmd_resp = self.read(prompt, timeout) except re.error: print_debug("Expected Response:{0}".format(prompt)) print_debug("Received Response:{0}".format(self.cmd_rsp)) return self.cmd_resp
def read(self, prompt='', timeout=60): ''' Reads the output till the prompt and returns the result and reports Failure on mismatch of response''' if not prompt: prompt = self.ne_prompt res = self.tnet.expect([prompt], timeout) self.cmd_rsp = res[2] try: if res: self.log.write(res[2]) self.log.flush() else: self.log.write("Expected Prompt Not found.", res) self.log.flush() #re.search(prompt, self.cmd_rsp) except re.error: print_debug("Expected Response:{0}".format(prompt)) print_debug("Received Response:{0}".format(self.cmd_rsp)) return self.cmd_rsp
if dnode == None: status = True # print_debug("BREAK dnode = None, status '%s'" % status) return status elif node.find(dnode) is not None: dnodev = node.find(dnode).text # print_debug("Values : dnodev :%s, dvalue : %s" % (dnodev, dvalue)) if dnodev == dvalue: # print_debug("MATCH: dnode : %s, dvalue : %s, dnodev : %s" % (dnode, dvalue, dnodev)) status = True # print_debug("BREAK END METHOD verifyParentandChildrenMatch_Status %s " % status) return status print_debug("FINAL END METHOD verifyParentandChildrenMatch_Status %s" % status) return status def getElementsListWithTagAttribValueMatch(datafile, tag, attrib, value): """ This method takes an xml document as input and finds all the sub elements (parent/children) containing specified tag and an attribute with the specified value. Returns a list of matching elements. Arguments: datafile = input xml file to be parsed. tag = tag value of the sub-element(parent/child) to be searched for. attrib = attribute name for the sub-element with above given tag should have. value = attribute value that the sub-element with above given tag, attribute should have. """