def setUp(self): super(atest_unittest, self).setUp() self.atest = topic_common.atest() self.atest.afe = rpc.afe_comm() if 'AUTOTEST_WEB' in os.environ: del os.environ['AUTOTEST_WEB']
def main(): """ The generic syntax is: atest <topic> <action> <options> atest-<topic> <action> <options> atest --help """ cli = os.path.basename(sys.argv[0]) syntax_obj = topic_common.atest() # Normalize the various --help, -h and help to -h sys.argv = [re.sub('--help|help', '-h', arg) for arg in sys.argv] match = re.search('^atest-(\w+)$', cli) if match: topic = match.group(1) else: if len(sys.argv) > 1: topic = sys.argv.pop(1) else: syntax_obj.invalid_syntax('No topic argument') if topic == '-h': sys.argv.insert(1, '-h') syntax_obj.parse() # The ignore flag should *only* be used by unittests. ignore_site = '--ignore_site_file' in sys.argv if ignore_site: sys.argv.remove('--ignore_site_file') # Import the topic specific file cli_dir = os.path.abspath(os.path.dirname(__file__)) if (not ignore_site and os.path.exists(os.path.join(cli_dir, 'site_%s.py' % topic))): topic = 'site_%s' % topic elif not os.path.exists(os.path.join(cli_dir, '%s.py' % topic)): syntax_obj.invalid_syntax('Invalid topic %s' % topic) topic_module = common.setup_modules.import_module(topic, 'autotest.cli') # If we have a syntax error now, it should # refer to the topic class. topic_class = getattr(topic_module, topic) topic_obj = topic_class() if len(sys.argv) > 1: action = sys.argv.pop(1) if action == '-h': action = 'help' sys.argv.insert(1, '-h') else: topic_obj.invalid_syntax('No action argument') # Any backward compatibility changes? action = topic_obj.backward_compatibility(action, sys.argv) # Instantiate a topic object try: action_class = getattr(topic_module, topic + '_' + action) except AttributeError: topic_obj.invalid_syntax('Invalid action %s' % action) action_obj = action_class() action_obj.parse() results = 0 try: try: results = action_obj.execute() except topic_common.CliError: pass except Exception as err: traceback.print_exc() action_obj.generic_error("Unexpected exception: %s" % err) else: try: action_obj.output(results) except Exception: traceback.print_exc() finally: # set rtn = 0 if there were no errors # set rtn = 1 if there were only errors # set rtn = 2 if there was both output and error rtn = action_obj.show_all_failures() if (results): if (rtn): # we had errors and output rtn = 2 return rtn
def setUp(self): super(atest_unittest, self).setUp() self.atest = topic_common.atest() self.atest.afe = rpc.afe_comm() if 'AUTOTEST_WEB' in os.environ: del os.environ['AUTOTEST_WEB']
def main(): """ The generic syntax is: atest <topic> <action> <options> atest-<topic> <action> <options> atest --help """ cli = os.path.basename(sys.argv[0]) syntax_obj = topic_common.atest() # Normalize the various --help, -h and help to -h sys.argv = [re.sub('--help|help', '-h', arg) for arg in sys.argv] match = re.search('^atest-(\w+)$', cli) if match: topic = match.group(1) else: if len(sys.argv) > 1: topic = sys.argv.pop(1) else: syntax_obj.invalid_syntax('No topic argument') if topic == '-h': sys.argv.insert(1, '-h') syntax_obj.parse() # The ignore flag should *only* be used by unittests. ignore_site = '--ignore_site_file' in sys.argv if ignore_site: sys.argv.remove('--ignore_site_file') # Import the topic specific file cli_dir = os.path.abspath(os.path.dirname(__file__)) if (not ignore_site and os.path.exists(os.path.join(cli_dir, 'site_%s.py' % topic))): topic = 'site_%s' % topic elif not os.path.exists(os.path.join(cli_dir, '%s.py' % topic)): syntax_obj.invalid_syntax('Invalid topic %s' % topic) topic_module = common.setup_modules.import_module(topic, 'autotest.cli') # If we have a syntax error now, it should # refer to the topic class. topic_class = getattr(topic_module, topic) topic_obj = topic_class() if len(sys.argv) > 1: action = sys.argv.pop(1) if action == '-h': action = 'help' sys.argv.insert(1, '-h') else: topic_obj.invalid_syntax('No action argument') # Any backward compatibility changes? action = topic_obj.backward_compatibility(action, sys.argv) # Instantiate a topic object try: action_class = getattr(topic_module, topic + '_' + action) except AttributeError: topic_obj.invalid_syntax('Invalid action %s' % action) action_obj = action_class() action_obj.parse() results = 0 try: try: results = action_obj.execute() except topic_common.CliError: pass except Exception, err: traceback.print_exc() action_obj.generic_error("Unexpected exception: %s" % err) else: