Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions lnt/lnttool/updatedb.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@
@click.option("--database", default="default", show_default=True,
help="database to modify")
@click.option("--testsuite", required=True, help="testsuite to modify")
@click.option("--tmp-dir", default="lnt_tmp", show_default=True,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was unused: probably copy-pasted from lnt create

help="name of the temp file directory")
@click.option("--show-sql", is_flag=True,
help="show SQL statements")
@click.option("--delete-machine", "delete_machines", default=[],
type=click.UNPROCESSED, show_default=True, multiple=True,
help="machine names to delete")
@click.option("--delete-run", "delete_runs", default=[], show_default=True,
multiple=True, help="run ids to delete", type=int)
@click.option("--delete-order", default=[], show_default=True,
help="run ids to delete")
def action_updatedb(instance_path, database, testsuite, tmp_dir, show_sql,
delete_machines, delete_runs, delete_order):
@click.option("--delete-machine", "delete_machines", default=[], multiple=True, type=click.UNPROCESSED,
help="Delete the given machine, all runs associated to this machine and their samples. "
"Machines are identified by their name.")
@click.option("--delete-run", "delete_runs", default=[], multiple=True, type=int,
help="Delete the specified run(s) and their samples. "
"Runs are identified by their ID.")
@click.option("--delete-order", "delete_orders", default=[], multiple=True, type=int,
help="Delete all runs associated to the given order(s) and their samples. "
"Orders are identified by their ID.")
def action_updatedb(instance_path, database, testsuite, show_sql,
delete_machines, delete_runs, delete_orders):
"""modify a database"""
from .common import init_logger

Expand All @@ -37,9 +37,9 @@ def action_updatedb(instance_path, database, testsuite, tmp_dir, show_sql,
session = db.make_session()
ts = db.testsuite[testsuite]
# Compute a list of all the runs to delete.
if delete_order:
if delete_orders:
runs = session.query(ts.Run).join(ts.Order) \
.filter(ts.Order.id == delete_order).all()
.filter(ts.Order.id.in_(delete_orders)).all()
else:
runs = session.query(ts.Run) \
.filter(ts.Run.id.in_(delete_runs)).all()
Expand Down
33 changes: 20 additions & 13 deletions tests/lnttool/UpdateDB.py → tests/lnttool/updatedb.shtest
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
# Check that we remove both the samples and the run when we delete a run.
#
# RUN: rm -rf %t.install
# RUN: lnt create %t.install

# Import a test set.
# RUN: lnt import %t.install %{shared_inputs}/sample-a-small.plist \
# RUN: --show-sample-count

# Check that we remove both the sample and the run.
#
# RUN: lnt updatedb %t.install --testsuite nts \
# RUN: --delete-run 1 --show-sql >& %t.out
# RUN: lnt import %t.install %{shared_inputs}/sample-a-small.plist --show-sample-count
# RUN: lnt updatedb %t.install --testsuite nts --delete-run 1 --show-sql >& %t.out
# RUN: filecheck --check-prefix CHECK-RUNRM %s < %t.out

# CHECK-RUNRM: DELETE FROM "NT_Sample" WHERE "NT_Sample"."ID" = ?
Expand All @@ -17,14 +12,26 @@
# CHECK-RUNRM-NEXT: (1,)
# CHECK-RUNRM: COMMIT

# Check that we remove both the samples and the run associated to that order when we delete an order.
#
# RUN: rm -rf %t.install
# RUN: lnt create %t.install
# RUN: lnt import %t.install %{shared_inputs}/sample-a-small.plist --show-sample-count
# RUN: lnt updatedb %t.install --testsuite nts --delete-order 1 --show-sql >& %t.out
# RUN: filecheck --check-prefix CHECK-ORDERRM %s < %t.out

# CHECK-ORDERRM: DELETE FROM "NT_Sample" WHERE "NT_Sample"."ID" = ?
# CHECK-ORDERRM-NEXT: ((1,), (2,))
# CHECK-ORDERRM: DELETE FROM "NT_Run" WHERE "NT_Run"."ID" = ?
# CHECK-ORDERRM-NEXT: (1,)
# CHECK-ORDERRM: COMMIT

# Check that we remove runs when we remove a machine.
#
# RUN: rm -rf %t.install
# RUN: lnt create %t.install
# RUN: lnt import %t.install %{shared_inputs}/sample-a-small.plist \
# RUN: --show-sample-count
# RUN: lnt updatedb %t.install --testsuite nts \
# RUN: --delete-machine "LNT SAMPLE MACHINE" --show-sql >& %t.out
# RUN: lnt import %t.install %{shared_inputs}/sample-a-small.plist --show-sample-count
# RUN: lnt updatedb %t.install --testsuite nts --delete-machine "LNT SAMPLE MACHINE" --show-sql >& %t.out
# RUN: filecheck --check-prefix CHECK-MACHINERM %s < %t.out

# CHECK-MACHINERM: DELETE FROM "NT_Sample" WHERE "NT_Sample"."ID" = ?
Expand Down
Loading