Beispiel #1
0
 def gen_tests(self):
     """Generate a single test and its configuration
     """
     count = 0
     while self.resources['memory'] >= 1024  and self.resources['cores'] > 0:
         test = self.get_test()
         if test   == None and len(self.tests) == 0:
             raise ValueError('Nothing to do.')
         elif test == None:
             break
         test.update(self.get_test_config(test))
         if self.schedule == 'host':
             test['datadir'] = virtdirman
         else:
             test['datadir'] = virtdirauto
         test['vnc']         = count
         test['runid']       = count + 1
         test['macaddr']     = self.gen_macaddr(count + 1)
         test['format']      = checks.chk_imageformat(test['format'])
         test['image']       = checks.chk_imagename(test['image'])
         test['test']        = checks.chk_testname(test['test'])
         test['testcommand'] = checks.chk_testcommand(test['testcommand'])
         test['ostype']      = checks.chk_ostype(test['ostype'])
         test['runtime']     = checks.chk_runtime(test['runtime'])
         test['timeout']     = checks.chk_timeout(test['timeout'])
         self.tests.append(test)
         count += 1
Beispiel #2
0
    def add(self, args):
        """Add a new test program for a specific operating system type
        to the database.

        Arguments:
            testname    -- Name of the test program
            ostype      -- Name of the OS the test program is meant to run on
            testcommand -- Command to start the test program
            runtime     -- Runtime for testsuite (seconds)
            timeout     -- Timeout for testsuite (seconds)
        """
        checks.chk_arg_count(args, 5)
        testname, ostype, testcommand, runtime, timeout = args
        testname = checks.chk_testname(testname)
        ostype = checks.chk_ostype(ostype)
        testcommand = checks.chk_testcommand(testcommand)
        runtime = checks.chk_runtime(runtime)
        timeout = checks.chk_timeout(timeout)
        if runtime > timeout:
            raise ValueError('Test suite runtime is greater than the timeout.')
        self.cursor.execute('''
                SELECT os_type_id FROM os_type
                WHERE os_type_name=?''', (ostype, ))
        row = self.cursor.fetchone()
        if row == None:
            raise ValueError('No such OS type.')
        ostypeid = row[0]
        self.cursor.execute('''
                SELECT * FROM test
                WHERE test_name=? AND os_type_id=?''', (testname, ostypeid))
        if self.cursor.fetchone() != None:
            raise ValueError('Test already exists.')
        self.cursor.execute('''
                INSERT INTO test
                (test_name, os_type_id, test_command, runtime, timeout)
                VALUES (?,?,?,?,?)''',
                (testname, ostypeid, testcommand, runtime, timeout))
        self.cursor.execute('''
                INSERT INTO host_schedule (host_id, test_id, image_id)
                SELECT host_id, test_id, image_id
                FROM host LEFT JOIN image
                LEFT JOIN test ON test.os_type_id=image.os_type_id
                WHERE test_name=? AND test.os_type_id=?
                AND host_id NOT NULL AND image_id NOT NULL''',
                (testname, ostypeid))
        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 test_name=? and test.os_type_id=?
                AND subject_id NOT NULL AND image_id NOT NULL''',
                (testname, ostypeid))
        self.connection.commit()