Esempio n. 1
0
def history_model(test_list, options):
    """
    Test package distribution based on history.

    @type test_list: C{list}
    @param test_list: List of test packages

    @type options: C{Options}
    @param options: Testrun options in an ots.server.hub.options object
    
    @rtype: C{list}
    @return: List of conductor_commands 

    """

    commands = []
    
    req_options = REQUEST_OPTIONS
    
    max_runtime = int(req_options.get("target_execution_time", DEFAULT_RUNTIME))
    max_groups = int(req_options.get("max_worker_amount", DEFAULT_GROUPS))
    
    if not test_list:
        raise ValueError("test_list not defined for distribution model")

    if 'device' in test_list:
        test_packages = test_list['device'].split(",")
        test_history = get_test_package_history(test_packages)
        LOG.debug(test_history)
        package_groups = group_packages(test_history, max_runtime, max_groups)
        LOG.debug(package_groups)
        for group in package_groups:
            options['test_packages'] = string.join(group, ",")
            cmd = conductor_command(options, 
                                    host_testing = False,
                                    chroot_testing = False)
            commands.append(Task(cmd))
        
        # Rest groups are for host based packages
        max_groups = max_groups - len(package_groups)

    # If we have host based packages
    # Lets use rest of the groups for them
    if 'host' in test_list:
        test_packages = test_list['host'].split(",")
        test_history = get_test_package_history(test_packages)
        LOG.debug(test_history)
        if max_groups <= 0:
            max_groups = 1
        LOG.debug(max_groups)
        package_groups = group_packages(test_history, max_runtime, max_groups)
        LOG.debug(package_groups)
        for group in package_groups:
            options['test_packages'] = string.join(group, ",")
            cmd = conductor_command(options, 
                                    host_testing = True,
                                    chroot_testing = False)
            commands.append(Task(cmd))

    return commands
Esempio n. 2
0
 def test_transition(self):
     task = Task([1], 0)
     self.assertEquals(task._WAITING, task.current_state)
     task.transition(TaskCondition.START)
     self.assertEquals(task._STARTED, task.current_state)
     task.transition(TaskCondition.FINISH)
     self.assertEquals(task._FINISHED, task.current_state)
     self.assertRaises(TaskException, task.transition, "foo")
     self.assertRaises(TaskException, task.transition, TaskCondition.START)
Esempio n. 3
0
    def test_dispatch_tasks(self):
        task_1 = Task(["1", "2"], 10)
        task_2 = Task(["1", "2"], 10)
        self.taskrunner._tasks = [task_1, task_2]
        self.taskrunner._dispatch_tasks()

        def test_cb(message):
            self.channel.basic_ack(delivery_tag=message.delivery_tag)
            self.assertEquals("1 2", loads(message.body).command)

        self.channel.basic_qos(0, 1, False)
        self.channel.basic_consume(queue="test_taskrunner", callback=test_cb)
        self.channel.wait()
        self.channel.wait()
Esempio n. 4
0
    def test_on_message_status(self):
        task_1 = Task([1, 2], 10)
        task_2 = Task([1, 2], 10)

        start_msg = StateChangeMessage(task_1.task_id, TaskCondition.START)
        message = AMQPMessageStub()
        message.body = dumps(start_msg)

        self.taskrunner._tasks = [task_1, task_2]
        self.taskrunner._on_message(message)
        self.assertEquals(2, len(self.taskrunner._tasks))

        end_msg = StateChangeMessage(task_1.task_id, TaskCondition.FINISH)
        message = AMQPMessageStub()
        message.body = dumps(end_msg)

        self.taskrunner._on_message(message)
        self.assertEquals(1, len(self.taskrunner._tasks))
        self.assertEquals(task_2, self.taskrunner._tasks[0])
Esempio n. 5
0
    def add_task(self, command):
        """
        Add a Task to be run

        @type command: C{list} 
        @param command: The CL to be run  
        """
        if self._is_run:
            raise TaskRunnerException("This TaskRunner has already been run")
        if isinstance(command, Task):
            command.set_timeout(self._execution_timeout)
            self._tasks.append(command)
        else:
            self._tasks.append(Task(command, self._execution_timeout))
Esempio n. 6
0
 def test_transition(self):
     task = Task([1], 0)
     self.assertEquals(task._WAITING, task.current_state)
     task.transition(TaskCondition.START)
     self.assertEquals(task._STARTED, task.current_state)
     task.transition(TaskCondition.FINISH)
     self.assertEquals(task._FINISHED, task.current_state)
     self.assertRaises(TaskException, task.transition, "foo")
     self.assertRaises(TaskException, task.transition, TaskCondition.START)
Esempio n. 7
0
    def test_server_side_global_timeout(self):

        # taskrunner with long enough queue timeout to get message processed
        # and very short global timeout to get hit after task started
        taskrunner = TaskRunner("guest", "guest", "localhost", "/", "ots",
                                5672, "test_taskrunner", 1, 1, 1, 1)

        _init_queue(self.channel, "test_taskrunner",
                    taskrunner._services_exchange, "test_taskrunner")

        # Create a task
        task_1 = Task(["1", "2"], 10)

        # Create a "started" state change message

        taskrunner._tasks = [task_1]
        self._publish_message(task_1.task_id, taskrunner._testrun_queue)
        self.assertRaises(OtsExecutionTimeoutError, taskrunner.run)
Esempio n. 8
0
 def test_is_finished(self):
     task = Task([1], 0)
     self.assertFalse(task.is_finished)
     task.current_state = task._FINISHED
     self.assertTrue(task.is_finished)
Esempio n. 9
0
 def test_is_finished(self):
     task = Task([1], 0)
     self.assertFalse(task.is_finished)
     task.current_state = task._FINISHED
     self.assertTrue(task.is_finished)
def single_task_distribution(test_list, options):
    """Creates a single task (one command line) for all test packages"""

    single_cmd = []
    tasks = []

    if not test_list:
        options['test_packages'] = ""
        cmd = conductor_command(options,
                                host_testing = False,
                                chroot_testing = False)
        single_cmd.extend(cmd)

    if 'device' in test_list:
        options['test_packages'] = test_list['device']
        cmd = conductor_command(options,
                                host_testing = False,
                                chroot_testing = False)
        single_cmd.extend(cmd)

    if 'host' in test_list:
        options['test_packages'] = test_list['host']
        cmd = conductor_command(options,
                                host_testing = True,
                                chroot_testing = False)
        # If there are device tests, have a ; to do them both.
        # Note: This means they're run under one timeout, in one shell.
        #       Coming improvements in task distribution could soon
        #       facilitate in improving this too.
        if single_cmd:
            single_cmd.append(';')
        single_cmd.extend(cmd)
        
    if 'chroot' in test_list:
        options['test_packages'] = test_list['chroot']
        cmd = conductor_command(options,
                                host_testing = False,
                                chroot_testing = True)

        if single_cmd:
            single_cmd.append(';')
        single_cmd.extend(cmd)
    
    if len(single_cmd) > 0:
        tasks.append(Task(single_cmd))
    
    # For test plan based executions
    # hw and host are in own tasks.
    # Test plan merging is not working.
    if 'hw_testplans' in test_list:
        test_plans = test_list.get("hw_testplans")
        options['test_packages'] = ""
        for test_plan in test_plans:
            options['testplan_name'] = test_plan.name
            cmd = conductor_command(options,
                                    host_testing = False,
                                    chroot_testing = False)
            task = Task(cmd)
            task.set_test_plan(test_plan)
            tasks.append(task)
        
    if 'host_testplans' in test_list:
        test_plans = test_list.get("host_testplans")
        options['test_packages'] = ""
        for test_plan in test_plans:
            options['testplan_name'] = test_plan.name
            cmd = conductor_command(options,
                                    host_testing = True,
                                    chroot_testing = False)
            task = Task(cmd)
            task.set_test_plan(test_plan)
            tasks.append(task)

    return tasks
def perpackage_distribution(test_list, options):
    """Creates a separate task (conductor command) for each test package"""

    commands = []

    if not test_list:
        raise ValueError("test_list not defined for distribution model")

    if 'device' in test_list:
        for test_package in test_list['device'].split(","):
            options['test_packages'] = test_package
            cmd = conductor_command(options,
                                    host_testing = False,
                                    chroot_testing = False)
            commands.append(Task(cmd))

    if 'host' in test_list:
        for test_package in test_list['host'].split(","):
            options['test_packages'] = test_package
            cmd = conductor_command(options,
                                    host_testing = True,
                                    chroot_testing = False)
            commands.append(Task(cmd))
    
    if 'hw_testplans' in test_list:
        test_plans = test_list.get("hw_testplans")
        options['test_packages'] = ""
        for test_plan in test_plans:
            options['testplan_name'] = test_plan.name
            cmd = conductor_command(options,
                                    host_testing = False,
                                    chroot_testing = False)
            task = Task(cmd)
            task.set_test_plan(test_plan)
            commands.append(task)
        
    if 'host_testplans' in test_list:
        test_plans = test_list.get("host_testplans")
        options['test_packages'] = ""
        for test_plan in test_plans:
            options['testplan_name'] = test_plan.name
            cmd = conductor_command(options,
                                    host_testing = True,
                                    chroot_testing = False)
            task = Task(cmd)
            task.set_test_plan(test_plan)
            commands.append(task)

    if 'chroot' in test_list:
        for test_package in test_list['chroot'].split(","):
            options['test_packages'] = test_package
            cmd = conductor_command(options,
                                    host_testing = False,
                                    chroot_testing = True)
            commands.append(Task(cmd))

    return commands