def test_worker_alive_after_server_timeout_failing_task(self): if not DEBUG: self.worker_processes.start() self.testrun_id = 111 self.testrun_id2 = 112 taskrunner1 = taskrunner_factory( routing_key = ROUTING_KEY, execution_timeout = 10, testrun_id = self.testrun_id, config_file = _distributor_config_filename()) command = ["sleep", "5",";", "command_error_mock", "localhost", str(self.testrun_id)] taskrunner1.add_task(command) self.is_exception_raised = False def cb_handler(signal, dto, **kwargs): if isinstance(dto, Exception): self.is_exception_raised = True DTO_SIGNAL.connect(cb_handler) # Overwrite server side timeout handler with a one that timeouts from ots.server.distributor.timeout import Timeout taskrunner1.timeout_handler = Timeout(1, 1, 1) self.assertRaises(OtsExecutionTimeoutError, taskrunner1.run) # self.assertTrue(self.is_exception_raised) self.is_exception_raised = False time.sleep(10) # Give worker time to reconnect # Trigger another task to make sure worker is still alive taskrunner2 = taskrunner_factory( routing_key = ROUTING_KEY, execution_timeout = 10, testrun_id = self.testrun_id2, config_file = _distributor_config_filename()) taskrunner2.add_task(["echo", "foo"]) taskrunner2.run() self.assertFalse(self.is_exception_raised) self.send_quit() time.sleep(1) self.assertFalse(all(self.worker_processes.exitcodes))
def test_worker_alive_after_server_timeout_failing_task(self): if not DEBUG: self.worker_processes.start() self.testrun_id = 111 self.testrun_id2 = 112 taskrunner1 = taskrunner_factory( routing_key=ROUTING_KEY, execution_timeout=10, testrun_id=self.testrun_id, config_file=_distributor_config_filename()) command = [ "sleep", "5", ";", "command_error_mock", "localhost", str(self.testrun_id) ] taskrunner1.add_task(command) self.is_exception_raised = False def cb_handler(signal, dto, **kwargs): if isinstance(dto, Exception): self.is_exception_raised = True DTO_SIGNAL.connect(cb_handler) # Overwrite server side timeout handler with a one that timeouts from ots.server.distributor.timeout import Timeout taskrunner1.timeout_handler = Timeout(1, 1, 1) self.assertRaises(OtsExecutionTimeoutError, taskrunner1.run) # self.assertTrue(self.is_exception_raised) self.is_exception_raised = False time.sleep(10) # Give worker time to reconnect # Trigger another task to make sure worker is still alive taskrunner2 = taskrunner_factory( routing_key=ROUTING_KEY, execution_timeout=10, testrun_id=self.testrun_id2, config_file=_distributor_config_filename()) taskrunner2.add_task(["echo", "foo"]) taskrunner2.run() self.assertFalse(self.is_exception_raised) self.send_quit() time.sleep(1) self.assertFalse(all(self.worker_processes.exitcodes))
def test_failing_task(self): if not DEBUG: self.worker_processes.start() self.testrun_id = 111 taskrunner = taskrunner_factory( routing_key=ROUTING_KEY, execution_timeout=10, testrun_id=self.testrun_id, config_file=_distributor_config_filename()) command = ["command_error_mock", "localhost", str(self.testrun_id)] taskrunner.add_task(command) self.is_exception_raised = False def cb_handler(signal, dto, **kwargs): if isinstance(dto, Exception): self.is_exception_raised = True DTO_SIGNAL.connect(cb_handler) taskrunner.run() self.assertTrue(self.is_exception_raised) self.send_quit() time.sleep(1) self.assertFalse(all(self.worker_processes.exitcodes))
def test_failing_task(self): if not DEBUG: self.worker_processes.start() self.testrun_id = 111 taskrunner = taskrunner_factory( routing_key = ROUTING_KEY, execution_timeout = 10, testrun_id = self.testrun_id, config_file = _distributor_config_filename()) command = ["command_error_mock", "localhost", str(self.testrun_id)] taskrunner.add_task(command) self.is_exception_raised = False def cb_handler(signal, dto, **kwargs): if isinstance(dto, Exception): self.is_exception_raised = True DTO_SIGNAL.connect(cb_handler) taskrunner.run() self.assertTrue(self.is_exception_raised) self.send_quit() time.sleep(1) self.assertFalse(all(self.worker_processes.exitcodes))
def demo(): """ A rough and ready demo """ taskrunner = taskrunner_factory("foo", 2, 1) taskrunner.add_task(["sleep", "1"]) taskrunner.add_task(["echo", "hello world"]) hub = Hub("example_sw_product", 1111, **options_dict) hub._taskrunner = taskrunner hub.run()
def demo(): """ A rough and ready demo """ taskrunner = taskrunner_factory("foo", 2, 1) taskrunner.add_task(["sleep", "1"]) taskrunner.add_task(["echo", "hello world"]) hub = Hub("example_sw_product", 1111, **options_dict) hub._taskrunner = taskrunner hub.run()
def test_two_tasks_one_worker(self): if not DEBUG: self.worker_processes.start() self.testrun_id = 111 taskrunner = taskrunner_factory(routing_key=ROUTING_KEY, execution_timeout=10, testrun_id=self.testrun_id, config_file=server_config_filename()) # zipfile_1_name = os.path.join(TESTS_MODULE_DIRNAME, "data", "test_definition_1.xml") steps = ["mkdir foo"] self._create_zip_test_definition_file(zipfile_1_name, steps) command_1 = [ "ots_mock", '"%s"' % (zipfile_1_name), "%s" % self.testrun_id ] taskrunner.add_task(command_1) # zipfile_2_name = os.path.join(TESTS_MODULE_DIRNAME, "data", "test_definition_2.xml") steps = ["mkdir bar"] self._create_zip_test_definition_file(zipfile_2_name, steps) command_2 = [ "ots_mock", '"%s"' % (zipfile_2_name), "%s" % self.testrun_id ] taskrunner.add_task(command_2) # command_quit = ["quit"] taskrunner.add_task(command_quit) time_before_run = time.time() time.sleep(1) taskrunner.run() time.sleep(1) time_after_run = time.time() if not DEBUG: foo = os.path.join(EXECUTION_DIRNAME, "foo") foo_time = os.path.getctime(foo) bar = os.path.join(EXECUTION_DIRNAME, "bar") bar_time = os.path.getctime(bar) self.assertTrue(time_before_run < foo_time) self.assertTrue(foo_time <= bar_time) self.assertTrue(bar_time <= time_after_run) # self.assertFalse(all(self.worker_processes.exitcodes))
def main(): """Entry point for command line testing""" from optparse import OptionParser parser = OptionParser() cfg_filename = os.path.join(os.path.dirname(os.path.abspath(__file__)), "config.ini") parser.add_option("-v", "--version", action = "store_true", help = "the version number of ots.distributor") parser.add_option("-d", "--device", default = "foo", help = "the device to be used") parser.add_option("-t", "--timeout", default = 30, help = "the timeout") parser.add_option("-c", "--config", default = cfg_filename, help = "the config filename") parser.add_option("-r", "--command", default = "echo hello world", help = "the command to run") # parse command line args options = parser.parse_args()[0] if options.version: print "Version:", __VERSION__ sys.exit(1) if not os.path.exists(options.config): print "Config file path '%s' does not exist!" % ( options.config ) sys.exit(1) init_logging(options.config) testrun_id = '' taskrunner = taskrunner_factory(options.device, options.timeout, testrun_id, options.config) taskrunner.add_task([options.command]) taskrunner.run()
def main(): """Entry point for command line testing""" from optparse import OptionParser parser = OptionParser() cfg_filename = os.path.join(os.path.dirname(os.path.abspath(__file__)), "config.ini") parser.add_option("-v", "--version", action="store_true", help="the version number of ots.distributor") parser.add_option("-d", "--device", default="foo", help="the device to be used") parser.add_option("-t", "--timeout", default=30, help="the timeout") parser.add_option("-c", "--config", default=cfg_filename, help="the config filename") parser.add_option("-r", "--command", default="echo hello world", help="the command to run") # parse command line args options = parser.parse_args()[0] if options.version: print "Version:", __VERSION__ sys.exit(1) if not os.path.exists(options.config): print "Config file path '%s' does not exist!" % (options.config) sys.exit(1) init_logging(options.config) testrun_id = '' taskrunner = taskrunner_factory(options.device, options.timeout, testrun_id, options.config) taskrunner.add_task([options.command]) taskrunner.run()
def test_two_tasks_one_worker(self): if not DEBUG: self.worker_processes.start() self.testrun_id = 111 taskrunner = taskrunner_factory( routing_key=ROUTING_KEY, execution_timeout=10, testrun_id=self.testrun_id, config_file=server_config_filename(), ) # zipfile_1_name = os.path.join(TESTS_MODULE_DIRNAME, "data", "test_definition_1.xml") steps = ["mkdir foo"] self._create_zip_test_definition_file(zipfile_1_name, steps) command_1 = ["ots_mock", '"%s"' % (zipfile_1_name), "%s" % self.testrun_id] taskrunner.add_task(command_1) # zipfile_2_name = os.path.join(TESTS_MODULE_DIRNAME, "data", "test_definition_2.xml") steps = ["mkdir bar"] self._create_zip_test_definition_file(zipfile_2_name, steps) command_2 = ["ots_mock", '"%s"' % (zipfile_2_name), "%s" % self.testrun_id] taskrunner.add_task(command_2) # command_quit = ["quit"] taskrunner.add_task(command_quit) time_before_run = time.time() time.sleep(1) taskrunner.run() time.sleep(1) time_after_run = time.time() if not DEBUG: foo = os.path.join(EXECUTION_DIRNAME, "foo") foo_time = os.path.getctime(foo) bar = os.path.join(EXECUTION_DIRNAME, "bar") bar_time = os.path.getctime(bar) self.assertTrue(time_before_run < foo_time) self.assertTrue(foo_time <= bar_time) self.assertTrue(bar_time <= time_after_run) # self.assertFalse(all(self.worker_processes.exitcodes))
def run_task(self, routing_key): """ sends 'echo $PPID >> /tmp/routing_key' command to the routing_key and makes sure it is executed by checking that the file exists. Returns the $PPID value read from the file """ self.assertFalse(os.path.isfile("/tmp/%s" % routing_key)) taskrunner1 = taskrunner_factory( routing_key = routing_key, execution_timeout = 2, testrun_id = self.testrun_id, config_file = self._distributor_config_filename()) taskrunner1.add_task(["echo", "$PPID",">>","/tmp/%s" % routing_key]) taskrunner1.run() self.assertTrue(os.path.isfile("/tmp/%s" % routing_key)) f = open('/tmp/%s'% routing_key, 'r') read_data = f.read() f.close() os.system("rm -f /tmp/%s" % routing_key) return read_data
def test_one_task_one_worker(self): """ The simplest configuration... Check that the results come back OK from the Worker """ self.test_definition_file_received = False self.results_file_received = False if not DEBUG: self.worker_processes.start() self.testrun_id = 111 taskrunner = taskrunner_factory(routing_key=ROUTING_KEY, execution_timeout=10, testrun_id=self.testrun_id, config_file=server_config_filename()) #Create a zip file with a test definition zipfile_name = os.path.join(TESTS_MODULE_DIRNAME, "data", "test_definition_1.xml") steps = ["mkdir foo", "mkdir bar", "mkdir baz"] self._create_zip_test_definition_file(zipfile_name, steps) #Add a Task command = ["ots_mock", '"%s"' % (zipfile_name), "%s" % self.testrun_id] taskrunner.add_task(command) # command_quit = ["quit"] taskrunner.add_task(command_quit) #Callback to handler results def cb_handler(signal, dto, **kwargs): self.cb_called = True if isinstance(dto, Results): filename = dto.data.name if filename == "test_definition.xml": self.test_definition_file_received = True self.assertEquals( EXPECTED.replace(' ', '').replace('\n', ''), dto.data.read().replace(' ', '').replace('\n', '')) elif filename == "dummy_results_file.xml": self.results_file_received = True expected = self._dummy_results_xml(filename) self.assertEquals(expected, dto.data.read()) DTO_SIGNAL.connect(cb_handler) #Run... time_before_run = time.time() time.sleep(1) taskrunner.run() time.sleep(1) time_after_run = time.time() #Check the results if not DEBUG: foo = os.path.join(EXECUTION_DIRNAME, "foo") foo_time = os.path.getctime(foo) bar = os.path.join(EXECUTION_DIRNAME, "bar") bar_time = os.path.getctime(bar) baz = os.path.join(EXECUTION_DIRNAME, "baz") baz_time = os.path.getctime(baz) self.assertTrue(time_before_run < foo_time <= bar_time <= baz_time <= time_after_run) self.assertTrue(self.results_file_received) self.assertTrue(self.test_definition_file_received) # self.assertFalse(all(self.worker_processes.exitcodes))
def test_one_task_one_worker(self): """ The simplest configuration... Check that the results come back OK from the Worker """ self.test_definition_file_received = False self.results_file_received = False if not DEBUG: self.worker_processes.start() self.testrun_id = 111 taskrunner = taskrunner_factory( routing_key=ROUTING_KEY, execution_timeout=10, testrun_id=self.testrun_id, config_file=server_config_filename(), ) # Create a zip file with a test definition zipfile_name = os.path.join(TESTS_MODULE_DIRNAME, "data", "test_definition_1.xml") steps = ["mkdir foo", "mkdir bar", "mkdir baz"] self._create_zip_test_definition_file(zipfile_name, steps) # Add a Task command = ["ots_mock", '"%s"' % (zipfile_name), "%s" % self.testrun_id] taskrunner.add_task(command) # command_quit = ["quit"] taskrunner.add_task(command_quit) # Callback to handler results def cb_handler(signal, dto, **kwargs): self.cb_called = True if isinstance(dto, Results): filename = dto.data.name if filename == "test_definition.xml": self.test_definition_file_received = True self.assertEquals( EXPECTED.replace(" ", "").replace("\n", ""), dto.data.read().replace(" ", "").replace("\n", "") ) elif filename == "dummy_results_file.xml": self.results_file_received = True expected = self._dummy_results_xml(filename) self.assertEquals(expected, dto.data.read()) DTO_SIGNAL.connect(cb_handler) # Run... time_before_run = time.time() time.sleep(1) taskrunner.run() time.sleep(1) time_after_run = time.time() # Check the results if not DEBUG: foo = os.path.join(EXECUTION_DIRNAME, "foo") foo_time = os.path.getctime(foo) bar = os.path.join(EXECUTION_DIRNAME, "bar") bar_time = os.path.getctime(bar) baz = os.path.join(EXECUTION_DIRNAME, "baz") baz_time = os.path.getctime(baz) self.assertTrue(time_before_run < foo_time <= bar_time <= baz_time <= time_after_run) self.assertTrue(self.results_file_received) self.assertTrue(self.test_definition_file_received) # self.assertFalse(all(self.worker_processes.exitcodes))