def _send_result(environment, results_xml, name): results = Results(name, results_xml, package = name, hostname = "mock_task_runner", environment = environment) DTO_SIGNAL.send(sender = "MockTaskRunner", dto = results)
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 _send_result(environment, results_xml, name): results = Results(name, results_xml, package=name, hostname="mock_task_runner", environment=environment) DTO_SIGNAL.send(sender="MockTaskRunner", dto=results)
def _send_testpackages(): pkgs = Packages("hardware_test", [ "tatam_xml_testrunner_results_for__1", "tatam_xml_testrunner_results_for__2", "tatam_xml_testrunner_results_for__3" ]) DTO_SIGNAL.send(sender="MockTaskRunner", dto=pkgs)
def __init__(self): self.results = [] self.tested_packages = {} self.expected_packages = {} self.monitors = [] self.exceptions = [] DTO_SIGNAL.connect(self._callback)
def run(self): pkgs = Packages("hardware_test", ["pkg1-tests"]) DTO_SIGNAL.send(sender = "MockTaskRunner", dto = pkgs) exc = OTSException("mock task runner", 6310) DTO_SIGNAL.send(sender = "MockTaskRunner", dto = exc)
def test_on_message_relay(self): message = AMQPMessageStub() message.body = dumps(Foo()) def test_handler(signal, dto, **kwargs): self.assertTrue(isinstance(dto, Foo)) self.assertEquals(1, dto.bar) DTO_SIGNAL.connect(test_handler) self.taskrunner._on_message(message)
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 __init__(self, request_id, testrun_uuid, sw_product = None, image = None, **kwargs): """ @type request_id: C{str} @param request_id: An identifier for the request from the client @type testrun_uuid: C{str} @param testrun_uuid: The unique identifier for the testrun @type sw_product: C{str} @param sw_product: Name of the sw product this testrun belongs to @type image: C{str} @param image: The URL of the image """ root_dir = os.path.split(os.path.dirname(os.path.abspath(__file__)))[0] plugin_dir = os.path.join(root_dir, "plugins") self._publishers = [] LOG.debug(root_dir) LOG.debug(plugin_dir) LOG.debug(plugins_iter(plugin_dir, "ots.publisher_plugin")) for publisher_klass in plugins_iter(plugin_dir, "ots.publisher_plugin"): LOG.debug("Publisher found: '%s'"%(publisher_klass)) with plugin_exception_policy(self.SWALLOW_EXCEPTIONS): publisher = publisher_klass(request_id, testrun_uuid, sw_product, image, **kwargs) LOG.debug("Adding publisher: '%s'"%(publisher)) self._publishers.append(publisher) self._share_uris(testrun_uuid) DTO_SIGNAL.connect(self._callback)
def __init__(self, request_id, testrun_uuid, sw_product=None, image=None, **kwargs): """ @type request_id: C{str} @param request_id: An identifier for the request from the client @type testrun_uuid: C{str} @param testrun_uuid: The unique identifier for the testrun @type sw_product: C{str} @param sw_product: Name of the sw product this testrun belongs to @type image: C{str} @param image: The URL of the image """ root_dir = os.path.split(os.path.dirname(os.path.abspath(__file__)))[0] plugin_dir = os.path.join(root_dir, "plugins") self._publishers = [] LOG.debug(root_dir) LOG.debug(plugin_dir) LOG.debug(plugins_iter(plugin_dir, "ots.publisher_plugin")) for publisher_klass in plugins_iter(plugin_dir, "ots.publisher_plugin"): LOG.debug("Publisher found: '%s'" % (publisher_klass)) with plugin_exception_policy(self.SWALLOW_EXCEPTIONS): publisher = publisher_klass(request_id, testrun_uuid, sw_product, image, **kwargs) LOG.debug("Adding publisher: '%s'" % (publisher)) self._publishers.append(publisher) self._share_uris(testrun_uuid) DTO_SIGNAL.connect(self._callback)
def _send_testpackages(): pkgs = Packages("hardware_test", ["tatam_xml_testrunner_results_for__1", "tatam_xml_testrunner_results_for__2"]) DTO_SIGNAL.send(sender = "MockTaskRunner", dto = pkgs) pkgs_2 = Packages("host.unittest", ["tatam_xml_testrunner_results_for__1", "tatam_xml_testrunner_results_for__2"]) DTO_SIGNAL.send(sender = "MockTaskRunner", dto = pkgs_2) pkgs_3 = Packages("chroot.unittest", ["tatam_xml_testrunner_results_for__1", "tatam_xml_testrunner_results_for__2"]) DTO_SIGNAL.send(sender = "MockTaskRunner", dto = pkgs_3)
def _send_testpackages(): pkgs = Packages("hardware_test", [ "tatam_xml_testrunner_results_for__1", "tatam_xml_testrunner_results_for__2" ]) DTO_SIGNAL.send(sender="MockTaskRunner", dto=pkgs) pkgs_2 = Packages("host.unittest", [ "tatam_xml_testrunner_results_for__1", "tatam_xml_testrunner_results_for__2" ]) DTO_SIGNAL.send(sender="MockTaskRunner", dto=pkgs_2) pkgs_3 = Packages("chroot.unittest", [ "tatam_xml_testrunner_results_for__1", "tatam_xml_testrunner_results_for__2" ]) DTO_SIGNAL.send(sender="MockTaskRunner", dto=pkgs_3)
def run(self): pkgs = Packages("hardware_test", ["pkg1-tests"]) DTO_SIGNAL.send(sender="MockTaskRunner", dto=pkgs) exc = OTSException("mock task runner", 6310) DTO_SIGNAL.send(sender="MockTaskRunner", dto=exc)
def _send_testpackages(): pkgs = Packages("hardware_test", ["tatam_xml_testrunner_results_for__1", "tatam_xml_testrunner_results_for__2", "tatam_xml_testrunner_results_for__3"]) DTO_SIGNAL.send(sender = "MockTaskRunner", dto = pkgs)
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))