def delete(self, args): """Remove a given key for a given subject. Arguments: subject -- Name of the subject this entry applies to bitness -- Bitness of the test subject (0 = 32-bit, 1 = 64-bit) key -- Key to delete """ checks.chk_arg_count(args, 3) subject, bitness, key = args subject = checks.chk_subject(subject) bitness = checks.chk_bitness(bitness) key = checks.chk_grubkey(key) self.cursor.execute(''' SELECT subject_id FROM subject WHERE subject_name=? AND is_64bit=?''', (subject, bitness)) row = self.cursor.fetchone() if row == None: raise ValueError('No such test subject.') subjectid = row[0] self.cursor.execute(''' SELECT completion_id FROM completion WHERE subject_id=? AND key=?''', (subjectid, key)) result = self.cursor.fetchall() if result != None: self.cursor.execute(''' DELETE FROM completion WHERE subject_id=? AND key=?''', (subjectid, key)) self.connection.commit()
def list(self, args): """Return a list of all completions. Arguments (optional): subject -- Name of the subject this entry applies to bitness -- Bitness of the test subject (0 = 32-bit, 1 = 64-bit) Returns: A tuple of dictionaries containing pairs of column name and value """ query = ''' SELECT subject_name, is_64bit, key, value FROM completion LEFT JOIN subject ON subject.subject_id=completion.subject_id %s''' if len(args) == 0: self.cursor.execute(query % ('ORDER BY subject_name', )) elif len(args) == 2: subject, bitness = args subject = checks.chk_subject(subject) bitness = checks.chk_bitness(bitness) self.cursor.execute(''' SELECT subject_id FROM subject WHERE subject_name=? AND is_64bit=?''', (subject, bitness)) subjectid = self.cursor.fetchone() if subjectid == None: raise ValueError('No such test subject.') query = query % ('WHERE completion.subject_id=?', ) self.cursor.execute(query, subjectid) else: raise ValueError('Wrong number of arguments.') return fetchassoc(self.cursor)
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)
def delete(self, args): """Remove a test subject from the database. This will also remove all schedule entries for this subject. Arguments: subject -- Name of the test subject """ checks.chk_arg_count(args, 2) subject, bitness = args subject = checks.chk_subject(subject) bitness = checks.chk_bitness(bitness) self.cursor.execute(''' SELECT subject_id FROM subject WHERE subject_name=? AND is_64bit=?''', (subject, bitness)) subjectid = self.cursor.fetchone() if subjectid == None: raise ValueError('No such test subject.') queue = TapperQueue(subject, bitness) queue.delete() self.cursor.execute(''' DELETE FROM subject_schedule WHERE subject_id=?''', subjectid) self.cursor.execute(''' DELETE FROM completion WHERE subject_id=?''', subjectid) self.cursor.execute(''' DELETE FROM subject WHERE subject_id=?''', subjectid) self.connection.commit()
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()
def add(self, args): """Add a new host to the database. Arguments: hostname -- Name of the host system memory -- Amount of memory available on the host system cores -- Amount of CPU cores available on the host system bitness -- Bitness of the host OS (0 = 32-bit, 1 = 64-bit) """ checks.chk_arg_count(args, 4) hostname, memory, cores, bitness = args hostname = checks.chk_hostname(hostname) memory = checks.chk_memory(memory) cores = checks.chk_cores(cores) bitness = checks.chk_bitness(bitness) try: self.cursor.execute(''' INSERT INTO host (host_name, host_memory, host_cores, is_64bit) VALUES (?,?,?,?)''', (hostname, memory, cores, bitness)) except sqlite3.IntegrityError: raise ValueError('Host 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 host_name=? AND test_id NOT NULL AND image_id NOT NULL''', (hostname, )) self.connection.commit()
def bitness(self, args): """Set the bitness of the operating system installed on a system Arguments: hostname -- Name of the host system bitness -- Bitness of the host OS (0 = 32-bit, 1 = 64-bit) """ checks.chk_arg_count(args, 2) hostname, bitness = args hostid = self.__get_host_id(hostname) bitness = checks.chk_bitness(bitness) self.cursor.execute('''UPDATE host SET is_64bit=? WHERE host_id=?''', (bitness, hostid)) self.connection.commit()
def do_command(self, args): """Validate the number of given arguments, write guest configurations, and ouput a YAML precondition string """ if len(args) == 1: hostname = chk_hostname(args[0]) subjectops = preparation.SubjectPreparation(hostname) subjectops.gen_precondition() elif len(args) == 3: hostname = chk_hostname(args[0]) subject = chk_subject(args[1]) bitness = chk_bitness(args[2]) subjectops = preparation.SubjectPreparation( hostname, subject, bitness) subjectops.gen_precondition() else: raise ValueError('Wrong number of arguments.')
def add(self, args): """Add a completion for given subject. Arguments: subject -- Name of the test subject this entry applies to bitness -- Bitness of the test subject (0 = 32-bit, 1 = 64-bit) key -- String that is present in the template value -- Substitution for key """ checks.chk_arg_count(args, 4) subject, bitness, key, value = args subject = checks.chk_subject(subject) bitness = checks.chk_bitness(bitness) key = checks.chk_grubkey(key) value = checks.grubvalues[key](value) self.cursor.execute(''' SELECT subject_id FROM subject WHERE subject_name=? AND is_64bit=?''', (subject, bitness)) row = self.cursor.fetchone() if row == None: raise ValueError('No such test subject.') subjectid = row[0] self.cursor.execute(''' SELECT key, value FROM completion WHERE subject_id=? AND key=?''', (subjectid, key)) if self.cursor.fetchone() != None: self.cursor.execute(''' UPDATE completion SET value=? WHERE subject_id=? AND key=?''', (value, subjectid, key)) sys.stderr.write( ('Key "%s" already existed for subject "%s".\n' + 'The key got updated with the new value.\n') % (key, subject)) else: self.cursor.execute(''' INSERT INTO completion(subject_id, key, value) VALUES (?,?,?)''', (subjectid, key, value)) self.connection.commit()
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()