示例#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 state(self, args):
        """Set the state of a guest image to enabled or disabled

        Arguments: A list with following items in that order
            * Filename of the guest image
            * State of the guest image as specified in checks.chk_state()
        """
        checks.chk_arg_count(args, 2)
        imagename, state = args
        imagename = checks.chk_imagename(imagename)
        state = checks.chk_state(state)
        self.cursor.execute('''
                SELECT * FROM image WHERE image_name=?''', (imagename, ))
        if self.cursor.fetchone() == None:
            raise ValueError('No such guest image.')
        self.cursor.execute('''UPDATE image SET is_enabled=?
                WHERE image_name=?''', (state, imagename))
        self.connection.commit()
示例#3
0
    def delete(self, args):
        """Remove a guest image from the database.

        This will also remove all schedule entries for this guest image.
        Arguments:
            imagename -- Filename of the guest image
        """
        checks.chk_arg_count(args, 1)
        imagename, = args
        imagename = checks.chk_imagename(imagename)
        self.cursor.execute('''
                SELECT image_id FROM image
                WHERE image_name=?''', (imagename, ))
        imageid = self.cursor.fetchone()
        if imageid == None:
            raise ValueError('No such image.')
        self.cursor.execute('''
                DELETE FROM host_schedule WHERE image_id=?''', imageid)
        self.cursor.execute('''
                DELETE FROM subject_schedule WHERE image_id=?''', imageid)
        self.cursor.execute('DELETE FROM image WHERE image_id=?', imageid)
        self.connection.commit()
示例#4
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()