예제 #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
예제 #2
0
    def delete(self, args):
        """Remove a test program from the database.

        This will also remove all schedule entries for this test program.
        Arguments:
            testname    -- Name of the test program
            ostype      -- Name of the OS the test program is meant to run on
        """
        checks.chk_arg_count(args, 2)
        testname, ostype = args
        testname = checks.chk_testname(testname)
        ostype = checks.chk_ostype(ostype)
        self.cursor.execute('''
                SELECT test_id FROM test
                LEFT JOIN os_type ON os_type.os_type_id=test.os_type_id
                WHERE test_name=? AND os_type_name=?''', (testname, ostype))
        testid = self.cursor.fetchone()
        if testid == None:
            raise ValueError('No such test.')
        self.cursor.execute('''
                DELETE FROM host_schedule WHERE test_id=?''', testid)
        self.cursor.execute('''
                DELETE FROM subject_schedule WHERE test_id=?''', testid)
        self.cursor.execute('DELETE FROM test WHERE test_id=?', testid)
        self.connection.commit()
예제 #3
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()
예제 #4
0
    def add(self, args):
        """Add a new operating system type to the database.

        Arguments:
            ostype -- Name of the operating system type to be added
        """
        checks.chk_arg_count(args, 1)
        ostype, = args
        ostype = checks.chk_ostype(ostype)
        try:
            self.cursor.execute('''
                    INSERT INTO os_type
                    (os_type_name) VALUES (?)''', (ostype, ))
            self.connection.commit()
        except sqlite3.IntegrityError:
            raise ValueError('OS type already exists.')
예제 #5
0
    def delete(self, args):
        """Remove an operating system type from the database.

        This will also remove all image files, tests, and
        schedule entries linked to this operating system type.
        Arguments:
            ostype -- Name of the operating system type to be removed
        """
        checks.chk_arg_count(args, 1)
        ostype, = args
        ostype = checks.chk_ostype(ostype)
        self.cursor.execute('''
                SELECT os_type_id FROM os_type
                WHERE os_type_name=?''', (ostype, ))
        ostypeid = self.cursor.fetchone()
        if ostypeid == None:
            raise ValueError('No such OS type.')
        self.cursor.execute('''
                SELECT image_id FROM image WHERE os_type_id=?''', ostypeid)
        result = self.cursor.fetchall()
        if result != None:
            imagelist = ()
            for imageid in result:
                imagelist += imageid
            wildcards = ','.join(['?'] * len(imagelist))
            self.cursor.execute('''
                    DELETE FROM host_schedule
                    WHERE image_id IN (%s)''' % wildcards, imagelist)
            self.cursor.execute('''
                    DELETE FROM subject_schedule
                    WHERE image_id IN (%s)''' % wildcards, imagelist)
            self.cursor.execute('''
                    DELETE FROM image WHERE os_type_id=?''', ostypeid)
        self.cursor.execute('DELETE FROM test WHERE os_type_id=?', ostypeid)
        self.cursor.execute('DELETE FROM os_type WHERE os_type_id=?', ostypeid)
        self.connection.commit()
예제 #6
0
    def add(self, args):
        """Add a new guest image to the database.

        Arguments:
            imagename -- Filename of the guest image
            imgformat -- Format of the guest image
            vendor    -- Vendor or distributor name of the guests OS
            ostype    -- Operating system type of the guest image
            bitness   -- 1 for 64-bit guests, 0 for 32-bit guests
            bigmem    -- 1 for 32-bit PAE and 64-bit guests, otherwise 0
            smp       -- 1 for SMP guests, otherwise 0
        """
        checks.chk_arg_count(args, 7)
        imagename, imgformat, vendor, ostype, bitness, bigmem, smp = args
        imagename = checks.chk_imagename(imagename)
        imgformat = checks.chk_imageformat(imgformat)
        vendor = checks.chk_vendor(vendor)
        ostype = checks.chk_ostype(ostype)
        bitness = checks.chk_bitness(bitness)
        bigmem = checks.chk_bigmem(bigmem)
        smp = checks.chk_smp(smp)
        if bitness == 1:
            bigmem = 1
        self.cursor.execute('''
                SELECT vendor_id FROM vendor
                WHERE vendor_name=?''', (vendor, ))
        row = self.cursor.fetchone()
        if row == None:
            raise ValueError('No such vendor.')
        vendorid = row[0]
        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]
        try:
            self.cursor.execute('''
                    INSERT INTO image
                    (image_name, image_format, vendor_id, os_type_id,
                     is_64bit, is_bigmem, is_smp, is_enabled)
                    VALUES (?,?,?,?,?,?,?,?)''',
                    (imagename, imgformat, vendorid, ostypeid,
                    bitness, bigmem, smp, 1))
        except sqlite3.IntegrityError:
            raise ValueError('Image already exists.')
        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 image_name=? AND host_id NOT NULL
                AND test_id NOT NULL''', (imagename, ))
        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 image_name=? AND subject_id NOT NULL
                AND test_id NOT NULL''', (imagename, ))
        self.connection.commit()