def testSingleRowEmpty(self): try: cur = TestEmptyCursor() db.singleRowSql(cur,"") assert False, "must raise SQLDidNotReturnSingleRow" except db.SQLDidNotReturnSingleRow,e: pass
def testSingleRowEmpty(self): try: cur = TestEmptyCursor() db.singleRowSql(cur, "") assert False, "must raise SQLDidNotReturnSingleRow" except db.SQLDidNotReturnSingleRow, e: pass
def _has_signature_report(self, signature, cursor): try: singleRowSql( cursor, """ SELECT 1 FROM reports WHERE signature = %s LIMIT 1""", (signature, )) return True except SQLDidNotReturnSingleRow: return False
def _has_signature_report(self, signature, cursor): try: singleRowSql( cursor, """SELECT 1 FROM reports WHERE signature = %s LIMIT 1""", (signature,) ) return True except SQLDidNotReturnSingleRow: return False
def testSingleRowMulti(self): try: cur = TestMultiCursor(numRows=5, numCols=1) assert ["Row 0, Column 0"] == db.singleRowSql(cur,"") except Exception, e: assert False, "must not raise this exception"
def testSingleRowSingle(self): try: cur = TestSingleCursor() assert ["Row 0, Column 0"] == db.singleRowSql(cur,"") except Exception, e: assert False, "must not raise this exception"
def testSingleRowMulti(self): try: cur = TestMultiCursor(numRows=5, numCols=1) assert ["Row 0, Column 0"] == db.singleRowSql(cur, "") except Exception, e: assert False, "must not raise this exception"
def testSingleRowSingle(self): try: cur = TestSingleCursor() assert ["Row 0, Column 0"] == db.singleRowSql(cur, "") except Exception, e: assert False, "must not raise this exception"
def run(self, connection): # record_associations logger = self.config.logger try: # KeyError if it's never run successfully # TypeError if self.job_information is None last_run = self.job_information['last_success'] except (KeyError, TypeError): last_run = utc_now() - datetime.timedelta( days=self.config.days_into_past and self.config.days_into_past or 30) last_run_formatted = last_run.strftime('%Y-%m-%d') query = self.config.query % last_run_formatted cursor = connection.cursor() for bug_id, status, resolution, short_desc, signature_set in self._iterator( query): logger.debug("bug %s (%s, %s) %s: %s", bug_id, status, resolution, short_desc, signature_set) if not signature_set: cursor.execute( """ DELETE FROM bugs WHERE id = %s """, (bug_id, )) continue useful = False insert_made = False try: status_db, resolution_db, short_desc_db = singleRowSql( cursor, """ SELECT status, resolution, short_desc FROM bugs WHERE id = %s """, (bug_id, )) if status_db != status or resolution_db != resolution or short_desc_db != short_desc: cursor.execute( """ UPDATE bugs SET status = %s, resolution = %s, short_desc = %s WHERE id = %s""", (status, resolution, short_desc, bug_id)) logger.info("bug status updated: %s - %s, %s", bug_id, status, resolution) useful = True cursor.execute( """ SELECT signature FROM bug_associations WHERE bug_id = %s""", (bug_id, )) signatures_db = [x[0] for x in cursor.fetchall()] for signature in signatures_db: if signature not in signature_set: cursor.execute( """ DELETE FROM bug_associations WHERE signature = %s and bug_id = %s""", (signature, bug_id)) logger.info('association removed: %s - "%s"', bug_id, signature) useful = True except SQLDidNotReturnSingleRow: cursor.execute( """ INSERT INTO bugs (id, status, resolution, short_desc) VALUES (%s, %s, %s, %s)""", (bug_id, status, resolution, short_desc)) insert_made = True signatures_db = [] for signature in signature_set: if signature not in signatures_db: if self._has_signature_report(signature, cursor): cursor.execute( """ INSERT INTO bug_associations (signature, bug_id) VALUES (%s, %s)""", (signature, bug_id)) logger.info('new association: %s - "%s"', bug_id, signature) useful = True else: logger.info( 'rejecting association (no reports with this ' 'signature): %s - "%s"', bug_id, signature) if useful: connection.commit() if insert_made: logger.info('new bug: %s - %s, %s, "%s"', bug_id, status, resolution, short_desc) else: connection.rollback() if insert_made: logger.info( 'rejecting bug (no useful information): ' '%s - %s, %s, "%s"', bug_id, status, resolution, short_desc) else: logger.info( 'skipping bug (no new information): ' '%s - %s, %s, "%s"', bug_id, status, resolution, short_desc)
def run(self, connection): # record_associations logger = self.config.logger try: # KeyError if it's never run successfully # TypeError if self.job_information is None last_run = self.job_information['last_success'] except (KeyError, TypeError): last_run = (datetime.datetime.now(tz.gettz('UTC')) - datetime.timedelta(days=self.config.days_into_past)) # bugzilla runs on PST, so we need to communicate in its time zone PST = tz.gettz('PST8PDT') last_run_formatted = last_run.astimezone(PST).strftime('%Y-%m-%d') query = self.config.query % last_run_formatted cursor = connection.cursor() for i in self._iterator(query): bug_id, status, resolution, short_desc, signature_set = i logger.debug( "bug %s (%s, %s) %s: %s", bug_id, status, resolution, short_desc, signature_set) if not signature_set: cursor.execute(""" DELETE FROM bugs WHERE id = %s """, (bug_id,)) continue useful = False insert_made = False try: status_db, resolution_db, short_desc_db = singleRowSql( cursor, """ SELECT status, resolution, short_desc FROM bugs WHERE id = %s """, (bug_id,)) if (status_db != status or resolution_db != resolution or short_desc_db != short_desc): cursor.execute( """ UPDATE bugs SET status = %s, resolution = %s, short_desc = %s WHERE id = %s """, (status, resolution, short_desc, bug_id)) logger.info("bug status updated: %s - %s, %s", bug_id, status, resolution) useful = True cursor.execute( """ SELECT signature FROM bug_associations WHERE bug_id = %s """, (bug_id,) ) signatures_db = [x[0] for x in cursor.fetchall()] for signature in signatures_db: if signature not in signature_set: cursor.execute( """ DELETE FROM bug_associations WHERE signature = %s and bug_id = %s """, (signature, bug_id)) logger.info('association removed: %s - "%s"', bug_id, signature) useful = True except SQLDidNotReturnSingleRow: cursor.execute( """ INSERT INTO bugs (id, status, resolution, short_desc) VALUES (%s, %s, %s, %s) """, (bug_id, status, resolution, short_desc)) insert_made = True signatures_db = [] for signature in signature_set: if signature not in signatures_db: if self._has_signature_report(signature, cursor): cursor.execute( """ INSERT INTO bug_associations (signature, bug_id) VALUES (%s, %s) """, (signature, bug_id)) logger.info('new association: %s - "%s"', bug_id, signature) useful = True else: logger.info( 'rejecting association (no reports with this ' 'signature): %s - "%s"', bug_id, signature) if useful: connection.commit() if insert_made: logger.info('new bug: %s - %s, %s, "%s"', bug_id, status, resolution, short_desc) else: connection.rollback() if insert_made: logger.info('rejecting bug (no useful information): ' '%s - %s, %s, "%s"', bug_id, status, resolution, short_desc) else: logger.info('skipping bug (no new information): ' '%s - %s, %s, "%s"', bug_id, status, resolution, short_desc)