def testErrorlog(self): """ This test validates if watchMswErrors() works fine. Instantiating the class will create the files. Then add a newline to the msw error log file. Now, watchMswErrors() should detect the new addition """ # instantiate the class myMswInfo = msw.MSWInfo('mymsw') errorWatch = MswErrorWatch(myMswInfo) # Put the content in errorlog file at MSW message = "MswErrorWatch: dummyline to test Error log feature" mswcmd = "echo %s > %s" % (message, errorWatch.mswlogpath) errorWatch.mymsw.ssh.sendline(mswcmd) #creating dummy result myresult = Result(Result.TEST, "DUMMY 1", annotations={}) # find error log difference errorWatch.watchMswErrors(myresult, False) # Assertions self.assertEqual(myresult.get('MSW fault'), 'MSW reported error')
def Lookup(self, test_id): """Look up the expected outcome for the given test. 'test_id' -- test-id for which the outcome is queried. returns -- a Result object associated with this test_id.""" return Result(Result.TEST, test_id)
def GetResult(self): try: id, kind, outcome = self._r_buffer.next() except StopIteration: return None annotations = {} for result_id, result_kind, key, value in self._a_buffer: if (result_id, result_kind) != (id, kind): self._a_buffer.rewind() break annotations[key] = value return Result(kind, id, outcome, annotations)
def _ReportItem(self, kind, item_id, name, test_runs, parent): """Report a single item. 'kind' -- The kind of item to report. 'item_id' -- The item id to report. 'name' -- The item's name (usually either the absolute or relative id). 'test_runs' -- The list of test runs. 'parent' -- An XML element to insert new nodes into.""" # Create one item node per id... item = self.__document.createElement('item') item.setAttribute('id', name) item.setAttribute('qid', item_id) item.setAttribute('kind', kind) parent.appendChild(item) # ...and fill it with one result per test run. for results, expectations in test_runs: result = results.GetResult(item_id, kind) if not result: result = Result(kind, item_id, Result.UNTESTED) # Inject two new annotations containing the expectation values. if expectations: exp = expectations.GetResult(item_id, kind) if exp: result['qmtest.expected_outcome'] = exp.GetOutcome() cause = exp.get('qmtest.cause') if cause: result['qmtest.expected_cause'] = cause child = result.MakeDomNode(self.__document) # Remove redundant attributes child.removeAttribute('id') child.removeAttribute('kind') item.appendChild(child)
def __init__(self, arguments=None, **args): # Initialize the base class. super(DejaGNUReader, self).__init__(arguments, **args) # DejaGNU files start with "Test Run". if self.file.read(len("Test Run")) != "Test Run": raise FileResultReader.InvalidFile, \ "file is not a DejaGNU result stream" self.file.seek(0) if self.__UseCombinedMode(): test_id, dejagnu_outcome, cause = self.__NextOutcome() if test_id: self.__next_result = Result(Result.TEST, test_id) self.__UpdateResult(self.__next_result, dejagnu_outcome, cause)
def GetResult(self): if self.__UseCombinedMode(): result = self.__next_result if not result: return None self.__next_result = None else: result = None while True: test_id, dejagnu_outcome, cause = self.__NextOutcome() # If there are no more results, stop. if not test_id: break if self.__UseCombinedMode() and test_id != result.GetId(): self.__next_result = Result(Result.TEST, test_id) self.__UpdateResult(self.__next_result, dejagnu_outcome, cause) break elif not self.__UseCombinedMode(): result = Result(Result.TEST, test_id) self.__UpdateResult(result, dejagnu_outcome, cause) if not self.__UseCombinedMode(): break return result
def Lookup(self, test_id): outcome, description = Result.PASS, '' for rule_id, rule_outcome, rule_annotations, rule_description in self._expectations: if re.match(rule_id, test_id): match = True for a in rule_annotations.iteritems(): if (a[0] not in self.testrun_parameters or not re.match(a[1], self.testrun_parameters[a[0]])): match = False if match: outcome = rule_outcome description = rule_description return Result(Result.TEST, test_id, outcome, annotations={'description': description})
def _GetResultFromDomNode(self, node): """Extract a result from a DOM node. 'node' -- A DOM node corresponding to a "result" element. returns -- A 'Result' object.""" assert node.tagName == "result" # Extract the outcome. outcome = node.getAttribute("outcome") # If the outcome doesn't exist as an attribute, fall back # to the outcome child node. if not outcome: outcome = qm.xmlutil.get_child_text(node, "outcome").strip() # Extract the test ID. test_id = node.getAttribute("id") kind = node.getAttribute("kind") # Build a Result. result = Result(kind, test_id, outcome) # Extract annotations. for n in node.childNodes: if n.nodeType != node.ELEMENT_NODE: continue if n.tagName == "annotation": quoted = 1 elif n.tagName == "property": # Versions of QMTest before 2.1 used the "property" tag, # and did not quote the contained text. quoted = 0 else: continue # Get the name of the annotation. name = n.getAttribute("name") # Get the value of the annotation. value = qm.xmlutil.get_dom_text(n) if quoted: # Remove whitespace and then remove the enclosing quotes. value = value.strip()[1:-1] # Remember the annotation. result[name] = value return result
def postcondition(self, res_streams): if self.postcampaignList != []: return # Get post campaign snapshots for resource in self.resourceList: self.postcampaignList.append(resource.getSnapshot(self.primaryMsw)) if self.bkupexists: self.bkupPostcampaignList.append(resource.getSnapshot(self.backupMsw)) # Debug log self.log.debug("ResourceWatch: postCampaign snapshot taken") # Create result object to write result resrcResult = Result(Result.TEST,"MSW Resource Watch") for i in range(len(self.precampaignList)): #dictionaries can be directly compared. if self.precampaignList[i] != self.postcampaignList[i]: # resource leakage, just print the pre and post elements resrcResult.SetOutcome(Result.ERROR,"Resource leak happened") logResult =self._formResultDictionary(self.precampaignList[i], self.postcampaignList[i]) resrcResult.Annotate(logResult) # write to debug log self.log.error("MSW RESOURCE WATCH: Resource leak occured") for key in logResult.keys(): self.log.error("%s :: %s" % (key, logResult[key])) # write to the result streams for rstream in res_streams: rstream.WriteResult(resrcResult) # Do the resource check on backup MSW if self.bkupexists: # Create result object to write result bkupResult = Result(Result.TEST,"BKUP MSW Resource Watch") for i in range(len(self.bkupPrecampaignList)): #dictionaries can be directly compared. if self.bkupPrecampaignList[i] != self.bkupPostcampaignList[i]: # resource leakage, print the pre and post elements bkupResult.SetOutcome(Result.ERROR,"Resourceleak happened") logResult =self._formResultDictionary(self.bkupPrecampaignList[i], self.bkupPostcampaignList[i]) resrcResult.Annotate(logResult) # write to debug log self.log.error("BKUP MSW RESOURCE WATCH: leakage occured") for key in logResult.keys(): self.log.error("%s :: %s" % (key, logResult[key])) # write to the result streams for rstream in res_streams: rstream.WriteResult(bkupResult)
def Lookup(self, test_id): return self._results.get(test_id) or Result(Result.TEST, test_id)