Exemplo n.º 1
0
    def state(self, args):
        """Set the state of a test subject to enabled or disabled

        Arguments: A list with following items in that order
            * Name of the test subject
            * State of the test subject as specified in checks.chk_state()
        """
        if len(args) == 3:
            subject, bitness, state = args
            priority = None
        elif len(args) == 4:
            subject, bitness, state, priority = args
        else:
            raise ValueError('Wrong number of arguments.')
        subject = checks.chk_subject(subject)
        bitness = checks.chk_bitness(bitness)
        state = checks.chk_state(state)
        if state == 0 and priority != None:
            raise ValueError('Priority can only be updated during enabling.')
        self.cursor.execute('''
                SELECT subject_prio FROM subject
                WHERE subject_name=? AND is_64bit=?''',
                (subject, bitness))
        dataset = self.cursor.fetchone()
        if dataset == None:
            raise ValueError('No such test subject.')
        if state == 0:
            self.__disable(subject, bitness)
        else:
            if priority == None:
                priority, = dataset
            priority = checks.chk_priority(priority)
            self.__enable(subject, bitness, priority)
Exemplo n.º 2
0
    def add(self, args):
        """Add a new test subject to the database.

        The state of the newly created test subject will be set to disabled.

        Arguments:
            subject  -- Name of the test subject
            bitness  -- Bitness of the test subject (0 = 32-bit, 1 = 64-bit)
            priority -- Bandwidth setting of the Tapper queue (int)
        """
        checks.chk_arg_count(args, 3)
        subject, bitness, priority = args
        subject = checks.chk_subject(subject)
        bitness = checks.chk_bitness(bitness)
        priority = checks.chk_priority(priority)
        self.cursor.execute('''
                SELECT * FROM subject
                WHERE subject_name=? AND is_64bit=?''', (subject, bitness))
        if self.cursor.fetchone() != None:
            raise ValueError('Test subject already exists.')
        self.cursor.execute('''
                INSERT INTO subject
                (subject_name, subject_prio, last_vendor_id,
                is_64bit, is_enabled)
                VALUES (?,?,?,?,?)''',
                (subject, priority, 0, bitness, 0))
        self.cursor.execute('''
                INSERT INTO subject_schedule (subject_id, test_id, image_id)
                SELECT subject_id, test_id, image_id
                FROM subject LEFT JOIN image
                LEFT JOIN test ON test.os_type_id=image.os_type_id
                WHERE subject_name=? AND test_id NOT NULL
                AND image_id NOT NULL''', (subject, ))
        self.connection.commit()