diff --git a/lnt/lnttool/updatedb.py b/lnt/lnttool/updatedb.py index e2cd8813..727eeba4 100644 --- a/lnt/lnttool/updatedb.py +++ b/lnt/lnttool/updatedb.py @@ -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, - 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 @@ -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() diff --git a/tests/lnttool/UpdateDB.py b/tests/lnttool/updatedb.shtest similarity index 50% rename from tests/lnttool/UpdateDB.py rename to tests/lnttool/updatedb.shtest index f4557c9a..a6c4c898 100644 --- a/tests/lnttool/UpdateDB.py +++ b/tests/lnttool/updatedb.shtest @@ -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" = ? @@ -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" = ?