Example #1
0
def main():
    """ Main function """

    (options, parser) = _parse_command_line(sys.argv[1:])
    if not _check_command_line_options(options):
        parser.print_help()
        sys.exit(1)

    stand_alone = not options.testrun_id and not options.otsserver

    device_n = 0
    if options.device_n:
        device_n = options.device_n
    _setup_logging(options.verbose, device_n)

    responseclient = None

    if not stand_alone:
        responseclient = _initialize_remote_connections(options.otsserver,
                                                        options.testrun_id,
                                                        device_n)
        if not responseclient:
            sys.exit(1)

    LOG.debug(70*"=") #for log file
    LOG.info("Starting conductor at %s" % gethostname())
    LOG.info("Incoming command line parameters: %s" \
                % " ".join([arg for arg in sys.argv[1:]]))
    LOG.debug("os.getenv('USERNAME') = %s" % os.getenv('USERNAME'))
    LOG.debug("os.environ.get('HOME') = %s" % os.environ.get("HOME"))
    LOG.debug("os.getcwd() = %s" % os.getcwd())

    LOG.debug("Reading configuration file")

    config = _read_configuration_files(options.config_file, device_n)

    try:
        timeout = float(options.timeout)
        testrun = TestRunData(options, config)
        executor = Executor(testrun, stand_alone, responseclient, \
                            gethostname(), timeout)
        executor.set_target()
    except ValueError, err:
        LOG.error("Error: %s" % err)
        sys.exit(1)
Example #2
0
def main():
    """ Main function """

    (options, parser) = _parse_command_line(sys.argv[1:])
    if not _check_command_line_options(options):
        parser.print_help()
        sys.exit(1)

    stand_alone = not options.testrun_id and not options.otsserver

    device_n = 0
    if options.device_n:
        device_n = options.device_n
    _setup_logging(options.verbose, device_n)

    responseclient = None

    if not stand_alone:
        responseclient = _initialize_remote_connections(
            options.otsserver, options.testrun_id, device_n)
        if not responseclient:
            sys.exit(1)

    LOG.debug(70 * "=")  #for log file
    LOG.info("Starting conductor at %s" % gethostname())
    LOG.info("Incoming command line parameters: %s" \
                % " ".join([arg for arg in sys.argv[1:]]))
    LOG.debug("os.getenv('USERNAME') = %s" % os.getenv('USERNAME'))
    LOG.debug("os.environ.get('HOME') = %s" % os.environ.get("HOME"))
    LOG.debug("os.getcwd() = %s" % os.getcwd())

    LOG.debug("Reading configuration file")

    config = _read_configuration_files(options.config_file, device_n)

    try:
        timeout = float(options.timeout)
        testrun = TestRunData(options, config)
        executor = Executor(testrun, stand_alone, responseclient, \
                            gethostname(), timeout)
        executor.set_target()
    except ValueError, err:
        LOG.error("Error: %s" % err)
        sys.exit(1)
Example #3
0
class TestExecutorSignalHandler(unittest.TestCase):
    """Tests for ExecutorSignalHandler"""

    def setUp(self):
        from ots.worker.conductor.executor import TestRunData
        from ots.worker.conductor.executor import Executor
        from ots.worker.conductor.conductor import ExecutorSignalHandler
        from StringIO import StringIO

        testrun = TestRunData(Options(), config=_conductor_config_simple())
        self.workdir = tempfile.mkdtemp("_test_conductor")
        testrun.base_dir = self.workdir
        responseclient = Stub_ResponseClient("", "", 0)
        self.executor = Executor(testrun=testrun, stand_alone=True, responseclient=responseclient, hostname="hostname")
        self.executor.set_target()

        self.executor_signal_handler = ExecutorSignalHandler(self.executor)
        self.process_listed_info_commands_called = False

        self.logger = logging.getLogger("conductor")
        self.log_stream = StringIO()

        self.logger.setLevel(logging.WARNING)
        self.logger.addHandler(logging.StreamHandler(self.log_stream))

        self.flash_logger = logging.getLogger("default_flasher")
        self.flash_log_stream = StringIO()
        self.flash_logger.setLevel(logging.DEBUG)
        self.flash_logger.addHandler(logging.StreamHandler(self.flash_log_stream))

    #
    # Tests
    #

    def test_skips_reboot_if_no_testrunner_lite_running(self):
        self._send_sigusr1()
        self.assertTrue(self.log_stream.getvalue().find("SIGUSR1 caught but no testrunner-lite running") >= 0)

    def test_reboots_device(self):
        self._prepare_executor_mocks()
        self._send_sigusr1()
        self.assertTrue(self.executor.testrun.flasher_module.device_rebooted)
        self.assertEquals(self.executor.trlite_command.signal_sent, signal.SIGUSR1)

    def test_sends_sigterm_on_connection_test_failed(self):
        self._prepare_executor_mocks()
        self.executor.testrun.flasher_module = Mock_Flasher(FlashFailed("Testing"))
        self.executor.target._flasher = self.executor.testrun.flasher_module
        self._send_sigusr1()
        self.assertTrue(self.executor.testrun.flasher_module.device_rebooted)
        self.assertEquals(self.executor.trlite_command.signal_sent, signal.SIGTERM)

    def test_save_environment_details_after_reboot(self):
        self._prepare_executor_mocks()
        self._send_sigusr1()
        self.assertTrue(self.save_environment_details)
        pass

    #
    # Private methods
    #

    def _send_sigusr1(self):
        self.executor_signal_handler.reboot_device(sig_num=signal.SIGUSR1, frame=None)

    def _prepare_executor_mocks(self):
        self.executor.trlite_command = Mock_Command("#echo Mocked Command")
        self.executor.testrun.flasher_module = Mock_Flasher()
        self.executor.target._flasher = self.executor.testrun.flasher_module
        self.executor.save_environment_details = self._save_env_details_mock

    def _save_env_details_mock(self):
        self.save_environment_details = True
Example #4
0
class TestExecutorSignalHandler(unittest.TestCase):
    """Tests for ExecutorSignalHandler"""
    def setUp(self):
        from ots.worker.conductor.executor import TestRunData
        from ots.worker.conductor.executor import Executor
        from ots.worker.conductor.conductor import ExecutorSignalHandler
        from StringIO import StringIO

        testrun = TestRunData(Options(), config=_conductor_config_simple())
        self.workdir = tempfile.mkdtemp("_test_conductor")
        testrun.base_dir = self.workdir
        responseclient = Stub_ResponseClient("", "", 0)
        self.executor = Executor(testrun=testrun,
                                 stand_alone=True,
                                 responseclient=responseclient,
                                 hostname="hostname")
        self.executor.set_target()

        self.executor_signal_handler = ExecutorSignalHandler(self.executor)
        self.process_listed_info_commands_called = False

        self.logger = logging.getLogger('conductor')
        self.log_stream = StringIO()

        self.logger.setLevel(logging.WARNING)
        self.logger.addHandler(logging.StreamHandler(self.log_stream))

        self.flash_logger = logging.getLogger('default_flasher')
        self.flash_log_stream = StringIO()
        self.flash_logger.setLevel(logging.DEBUG)
        self.flash_logger.addHandler(
            logging.StreamHandler(self.flash_log_stream))

    #
    # Tests
    #

    def test_skips_reboot_if_no_testrunner_lite_running(self):
        self._send_sigusr1()
        self.assertTrue(self.log_stream.getvalue().find( \
                "SIGUSR1 caught but no testrunner-lite running") >= 0)

    def test_reboots_device(self):
        self._prepare_executor_mocks()
        self._send_sigusr1()
        self.assertTrue(self.executor.testrun.flasher_module.device_rebooted)
        self.assertEquals(self.executor.trlite_command.signal_sent,
                          signal.SIGUSR1)

    def test_sends_sigterm_on_connection_test_failed(self):
        self._prepare_executor_mocks()
        self.executor.testrun.flasher_module = \
                            Mock_Flasher(FlashFailed("Testing"))
        self.executor.target._flasher = self.executor.testrun.flasher_module
        self._send_sigusr1()
        self.assertTrue(self.executor.testrun.flasher_module.device_rebooted)
        self.assertEquals(self.executor.trlite_command.signal_sent,
                          signal.SIGTERM)

    def test_save_environment_details_after_reboot(self):
        self._prepare_executor_mocks()
        self._send_sigusr1()
        self.assertTrue(self.save_environment_details)
        pass

    #
    # Private methods
    #

    def _send_sigusr1(self):
        self.executor_signal_handler.reboot_device(sig_num=signal.SIGUSR1,
                                                   frame=None)

    def _prepare_executor_mocks(self):
        self.executor.trlite_command = Mock_Command("#echo Mocked Command")
        self.executor.testrun.flasher_module = Mock_Flasher()
        self.executor.target._flasher = self.executor.testrun.flasher_module
        self.executor.save_environment_details = self._save_env_details_mock

    def _save_env_details_mock(self):
        self.save_environment_details = True