Merge "Update SQL reporter to store results" into feature/zuulv3

This commit is contained in:
Jenkins
2017-08-04 16:32:38 +00:00
committed by Gerrit Code Review
5 changed files with 56 additions and 28 deletions

View File

@@ -0,0 +1,49 @@
"""Use build_set results
Revision ID: 60c119eb1e3f
Revises: f86c9871ee67
Create Date: 2017-07-27 17:09:20.374782
"""
# revision identifiers, used by Alembic.
revision = '60c119eb1e3f'
down_revision = 'f86c9871ee67'
branch_labels = None
depends_on = None
from alembic import op
import sqlalchemy as sa
BUILDSET_TABLE = 'zuul_buildset'
def upgrade():
op.add_column(BUILDSET_TABLE, sa.Column('result', sa.String(255)))
connection = op.get_bind()
connection.execute(
"""
UPDATE {buildset_table}
SET result=(
SELECT CASE score
WHEN 1 THEN 'SUCCESS'
ELSE 'FAILURE' END)
""".format(buildset_table=BUILDSET_TABLE))
op.drop_column(BUILDSET_TABLE, 'score')
def downgrade():
op.add_column(BUILDSET_TABLE, sa.Column('score', sa.Integer))
connection = op.get_bind()
connection.execute(
"""
UPDATE {buildset_table}
SET score=(
SELECT CASE result
WHEN 'SUCCESS' THEN 1
ELSE -1 END)
""".format(buildset_table=BUILDSET_TABLE))
op.drop_column(BUILDSET_TABLE, 'result')

View File

@@ -83,7 +83,7 @@ class SQLConnection(BaseConnection):
sa.Column('change', sa.Integer, nullable=True),
sa.Column('patchset', sa.Integer, nullable=True),
sa.Column('ref', sa.String(255)),
sa.Column('score', sa.Integer, nullable=True),
sa.Column('result', sa.String(255)),
sa.Column('message', sa.TEXT()),
sa.Column('tenant', sa.String(255)),
)

View File

@@ -25,12 +25,6 @@ class SQLReporter(BaseReporter):
name = 'sql'
log = logging.getLogger("zuul.reporter.mysql.SQLReporter")
def __init__(self, driver, connection, config={}):
super(SQLReporter, self).__init__(
driver, connection, config)
# TODO(jeblair): document this is stored as NULL if unspecified
self.result_score = config.get('score', None)
def report(self, item):
"""Create an entry into a database."""
@@ -49,7 +43,7 @@ class SQLReporter(BaseReporter):
change=change,
patchset=patchset,
ref=ref,
score=self.result_score,
result=item.current_build_set.result,
message=self._formatItemReport(
item, with_jobs=False),
tenant=item.pipeline.layout.tenant.name,