Beispiel #1
0
    def __del__(self):
        """Destructor

           Gracefully stop the packet trace, cleanup files, unmount volume,
           and reset network.
        """
        self.debug_repr(0)
        self._tverbose()
        self._print_msg("")
        self.dprint('DBG7', "Calling %s() destructor" % self.__class__.__name__)
        self.trace_stop()
        self.cleanup()
        # Call base destructor
        NFSUtil.__del__(self)

        if len(self.test_msgs) > 0:
            if getattr(self, 'logfile', None):
                print "\nLogfile: %s" % self.logfile
            msg = "%d tests%s" % self._total_counts(self._msg_count)
            self.write_log("\n" + msg)
            if self._msg_count[FAIL] > 0:
                msg = "\033[31m" + msg + "\033[m" if _isatty else msg
            elif self._msg_count[WARN] > 0:
                msg = "\033[33m" + msg + "\033[m" if _isatty else msg
            else:
                msg = "\033[32m" + msg + "\033[m" if _isatty else msg
            print "\n" + msg
        self.total_time = time.time() - self.test_time[0]
        total_str = "\nTotal time: %s" % self._print_time(self.total_time)
        self.write_log(total_str)
        print total_str
        self.close_log()
Beispiel #2
0
    def __init__(self, **kwargs):
        """Constructor

           Initialize object's private data.

           id:
               Test script ID [default: '']
               This is used to have options targeted for a given ID without
               including these options in any other test script.
           usage:
               Usage string [default: '']
           testnames:
               List of testnames [default: []]
               When this list is not empty, the --runtest option is enabled and
               test scripts should use the run_tests() method to run all the
               tests. Test script should have methods named as <testname>_test.

           Example:
               x = TestUtil(testnames=['basic', 'lock'])

               # The following methods should exist:
               x.basic_test()
               x.lock_test()
        """
        self.id        = kwargs.pop('id', "")
        self.usage     = kwargs.pop('usage', '')
        self.testnames = kwargs.pop('testnames', [])
        self.progname = os.path.basename(sys.argv[0])
        self.testname = ""
        if self.progname[-3:] == '.py':
            # Remove extension
            self.progname = self.progname[:-3]
        self._name = None
        self.tverbose = 1
        self._bugmsgs = []
        self.ignore = False
        self.bugmsgs = None
        self.nocleanup = True
        self.test_time = [time.time()]
        self._fileopt = True
        self.remove_list = []
        self.fileidx = 1
        self.diridx = 1
        self.logidx = 1
        self.files = []
        self.dirs = []
        self.abshash = {}
        self.test_msgs = []
        self._msg_count = {}
        self._reset_files()

        for tid in _test_map:
            self._msg_count[tid] = 0
        self.dindent(4)

        self.optfiles = []
        self.testopts = {}
        NFSUtil.__init__(self)
        self._init_options()