Make DB path work
This commit takes the db code from previous commits, the api, models, and schema migrations and fixes the bugs in them to make them work as intended. From here we have a working base which can be expanded to make the tool more feature rich. It should probably be noted that the one test I did at this point had terrible performance. I loaded a tempest run subunit ouput file with roughly 2300 tests in it. This might have been either a sqlite issue or my use of session is far from ideal. I'm assuming the latter.
This commit is contained in:
@@ -41,7 +41,7 @@ def get_session(autocommit=True, expire_on_commit=False):
|
||||
expire_on_commit=expire_on_commit)
|
||||
|
||||
|
||||
def create_test(test_id, run_count=0, success=0, failure=0):
|
||||
def create_test(test_id, run_count=0, success=0, failure=0, session=None):
|
||||
"""Create a new test record in the database
|
||||
|
||||
:param test_id: test_id identifying the test
|
||||
@@ -65,7 +65,8 @@ def create_test(test_id, run_count=0, success=0, failure=0):
|
||||
return test
|
||||
|
||||
|
||||
def create_run(skips=0, fails=0, passes=0, run_time=0, artifacts=None):
|
||||
def create_run(skips=0, fails=0, passes=0, run_time=0, artifacts=None,
|
||||
session=None):
|
||||
"""Create a new run record in the database
|
||||
|
||||
:param skips: total number of skiped tests
|
||||
@@ -79,9 +80,8 @@ def create_run(skips=0, fails=0, passes=0, run_time=0, artifacts=None):
|
||||
run.fails = fails
|
||||
run.passes = passes
|
||||
run.run_time = run_time
|
||||
if artifacts:
|
||||
run.artifacts = artifacts
|
||||
session = get_session()
|
||||
run.artifacts = artifacts
|
||||
session = session or get_session()
|
||||
with session.begin():
|
||||
session.add(run)
|
||||
return run
|
||||
@@ -99,7 +99,7 @@ def create_test_run(test_id, run_id, status, start_time=None,
|
||||
test_run = models.TestRun()
|
||||
test_run.test_id = test_id
|
||||
test_run.run_id = run_id
|
||||
test_run.end_time = end_time
|
||||
test_run.stop_time = end_time
|
||||
test_run.start_time = start_time
|
||||
session = get_session()
|
||||
with session.begin():
|
||||
@@ -113,25 +113,25 @@ def get_all_tests():
|
||||
|
||||
|
||||
def get_all_runs():
|
||||
query = db_utils.models_query(models.Run)
|
||||
query = db_utils.model_query(models.Run)
|
||||
return query.all()
|
||||
|
||||
|
||||
def get_all_test_runs():
|
||||
query = db_utils.models_query(models.TestRun)
|
||||
query = db_utils.model_query(models.TestRun)
|
||||
return query.all()
|
||||
|
||||
|
||||
def get_test_by_id(id, session=None):
|
||||
session = session or get_session()
|
||||
test = db_utils.models_query(models.Test, session).filter_by(
|
||||
test = db_utils.model_query(models.Test, session).filter_by(
|
||||
id=id).first()
|
||||
return test
|
||||
|
||||
|
||||
def get_test_by_test_id(test_id, session=None):
|
||||
session = session or get_session()
|
||||
test = db_utils.models_query(models.Test, session).filter_by(
|
||||
test = db_utils.model_query(models.Test, session).filter_by(
|
||||
test_id=test_id).first()
|
||||
return test
|
||||
|
||||
|
||||
@@ -16,9 +16,12 @@ import uuid
|
||||
|
||||
from oslo.db.sqlalchemy import models # noqa
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy.ext import declarative
|
||||
|
||||
BASE = declarative.declarative_base()
|
||||
|
||||
|
||||
class SubunitBase(models.ModelBase, models.TimestampMixin):
|
||||
class SubunitBase(models.ModelBase):
|
||||
"""Base class for Subunit Models."""
|
||||
__table_args__ = {'mysql_engine': 'InnoDB'}
|
||||
__table_initialized__ = False
|
||||
@@ -37,34 +40,37 @@ class SubunitBase(models.ModelBase, models.TimestampMixin):
|
||||
return self.__dict__.items()
|
||||
|
||||
def to_dict(self):
|
||||
d = self.__dict__.copy()
|
||||
d.pop("_sa_instance_state")
|
||||
return self.__dict__.copy()
|
||||
|
||||
|
||||
class Test(SubunitBase):
|
||||
class Test(BASE, SubunitBase):
|
||||
__tablename__ = 'tests'
|
||||
__table_args__ = ()
|
||||
__table_args__ = (sa.Index('ix_id', 'id'),
|
||||
sa.Index('ix_test_id', 'test_id'))
|
||||
id = sa.Column(sa.String(36), primary_key=True,
|
||||
default=lambda: str(uuid.uuid4()))
|
||||
test_id = sa.String(256)
|
||||
run_count = sa.Integer()
|
||||
success = sa.Integer()
|
||||
failure = sa.Integer()
|
||||
test_id = sa.Column(sa.String(256))
|
||||
run_count = sa.Column(sa.Integer())
|
||||
success = sa.Column(sa.Integer())
|
||||
failure = sa.Column(sa.Integer())
|
||||
|
||||
|
||||
class Run(SubunitBase):
|
||||
class Run(BASE, SubunitBase):
|
||||
__tablename__ = 'runs'
|
||||
__table_args__ = ()
|
||||
# __table_args__ = (sa.Index('ix_run_id', 'id'), )
|
||||
id = sa.Column(sa.String(36), primary_key=True,
|
||||
default=lambda: str(uuid.uuid4()))
|
||||
skips = sa.Integer()
|
||||
fails = sa.Integer()
|
||||
passes = sa.Integer()
|
||||
run_time = sa.Integer()
|
||||
artifacts = sa.Text()
|
||||
skips = sa.Column(sa.Integer())
|
||||
fails = sa.Column(sa.Integer())
|
||||
passes = sa.Column(sa.Integer())
|
||||
run_time = sa.Column(sa.Integer())
|
||||
artifacts = sa.Column(sa.Text())
|
||||
|
||||
|
||||
class TestRun(SubunitBase):
|
||||
__tablename__ = 'test_run'
|
||||
class TestRun(BASE, SubunitBase):
|
||||
__tablename__ = 'test_runs'
|
||||
__table_args__ = (sa.Index('ix_test_run_test_id', 'test_id'),
|
||||
sa.Index('ix_test_run_run_id', 'run_id'),
|
||||
sa.UniqueConstraint('test_id', 'run_id',
|
||||
@@ -76,5 +82,5 @@ class TestRun(SubunitBase):
|
||||
nullable=False)
|
||||
run_id = sa.Column(sa.String(36), sa.ForeignKey('runs.id'), nullable=False)
|
||||
status = sa.Column(sa.String(256))
|
||||
start_time = sa.DateTime()
|
||||
end_time = sa.DateTime()
|
||||
start_time = sa.Column(sa.DateTime())
|
||||
stop_time = sa.Column(sa.DateTime())
|
||||
|
||||
@@ -34,7 +34,7 @@ def upgrade():
|
||||
sa.Column('id', sa.String(36), primary_key=True),
|
||||
sa.Column('skips', sa.Integer()),
|
||||
sa.Column('fails', sa.Integer()),
|
||||
sa.Column('pass', sa.Integer()),
|
||||
sa.Column('passes', sa.Integer()),
|
||||
sa.Column('run_time', sa.Integer()),
|
||||
sa.Column('artifacts', sa.Text()),
|
||||
mysql_engine=True)
|
||||
|
||||
@@ -31,8 +31,9 @@ import sqlalchemy as sa
|
||||
|
||||
def upgrade():
|
||||
op.create_table('tests',
|
||||
sa.Column('id', sa.String(36), primary_key=True),
|
||||
sa.Column('test_id', sa.String(256)),
|
||||
sa.Column('id', sa.String(36), primary_key=True,
|
||||
nullable=False),
|
||||
sa.Column('test_id', sa.String(256), nullable=False),
|
||||
sa.Column('run_count', sa.Integer()),
|
||||
sa.Column('success', sa.Integer()),
|
||||
sa.Column('failure', sa.Integer()),
|
||||
|
||||
@@ -56,8 +56,9 @@ def process_results(results):
|
||||
db_test = api.get_test_by_test_id(test, session)
|
||||
if not db_test:
|
||||
db_test = api.create_test(test)
|
||||
api.create_test_run(db_test.id, db_run.id, test['status'],
|
||||
test['start_time'], test['end_time'])
|
||||
api.create_test_run(db_test.id, db_run.id, results[test]['status'],
|
||||
results[test]['start_time'],
|
||||
results[test]['end_time'])
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
Reference in New Issue
Block a user