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 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 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 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 get_latest_build(self): """ Find latest build of a test subject @return: Path to the build package on the Tapper server @rtype : str """ builds = [] arch = buildarchs[self.testrun.resources['bitness']] version = chk_subject(self.testrun.subject['name']) pattern = buildpattern % (version.replace('.', '\.'), arch) subjectdir = builddir % (arch, version) try: for build in os.listdir(subjectdir): if re.match(pattern, build): builds.append(build) except OSError: message = 'Build directory "%s" does not exist.' raise ValueError(message % (subjectdir, )) if len(builds) < 1: message = 'No builds available for %s on %s.\nBuilddir is %s' raise ValueError(message % (version, arch, subjectdir)) builds.sort() return os.path.join(subjectdir, builds.pop())