|
13 | 13 | # See the License for the specific language governing permissions and |
14 | 14 | # limitations under the License. |
15 | 15 |
|
| 16 | +""" |
| 17 | +Reset, purge and/or (re)create a Rucio test database. |
| 18 | +
|
| 19 | +Behavior |
| 20 | +------------------------+-----------------------+---------------------------+ |
| 21 | + Flag(s) | What happens | Subsequent actions | |
| 22 | +------------------------+-----------------------+---------------------------+ |
| 23 | + (no flag) | destroy_database() | build_database() + | |
| 24 | + | # drop_orm_tables | create_base_vo() + | |
| 25 | + | | create_root_account() | |
| 26 | +------------------------+-----------------------+---------------------------+ |
| 27 | + -b / --purge-build | drop_everything() | build_database() + | |
| 28 | + | # purge_db | create_base_vo() + | |
| 29 | + | | create_root_account() | |
| 30 | +------------------------+-----------------------+---------------------------+ |
| 31 | + -p / --purge | drop_everything() | nothing else.. | |
| 32 | + | # purge_db | the script ends | |
| 33 | +------------------------+-----------------------+---------------------------+ |
| 34 | +""" |
| 35 | + |
16 | 36 | import os.path |
17 | 37 | import sys |
| 38 | +from argparse import ArgumentParser |
18 | 39 |
|
| 40 | +# Ensure package imports work when executed from any cwd |
19 | 41 | base_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
20 | 42 | sys.path.append(base_path) |
21 | 43 | os.chdir(base_path) |
22 | 44 |
|
23 | | -from argparse import ArgumentParser # noqa: E402 |
24 | | - |
25 | | -from rucio.db.sqla.util import build_database, create_base_vo, create_root_account, destroy_database, drop_everything # noqa: E402 |
| 45 | +from rucio.db.sqla.util import ( # noqa: E402 |
| 46 | + build_database, # noqa: E402 |
| 47 | + create_base_vo, # noqa: E402 |
| 48 | + create_root_account, # noqa: E402 |
| 49 | + destroy_database, # noqa: E402 |
| 50 | + drop_everything, # noqa: E402 |
| 51 | +) |
26 | 52 |
|
27 | 53 | if __name__ == '__main__': |
28 | 54 |
|
29 | | - parser = ArgumentParser() |
30 | | - parser.add_argument('-d', '--drop-everything', action="store_true", default=False, help='Drop all tables and constraints') |
| 55 | + parser = ArgumentParser( |
| 56 | + prog="reset_database.py", |
| 57 | + description="Reset the local Rucio database used in tests." |
| 58 | + ) |
| 59 | + g = parser.add_mutually_exclusive_group() |
| 60 | + g.add_argument( |
| 61 | + "-b", "--purge-build", |
| 62 | + action="store_true", |
| 63 | + help="Purge EVERYTHING (tables, constraints, schema) " |
| 64 | + "and then rebuild a fresh schema with base VO + root account.", |
| 65 | + ) |
| 66 | + g.add_argument( |
| 67 | + "-p", "--purge", |
| 68 | + action="store_true", |
| 69 | + help="Purge EVERYTHING and stop – do NOT recreate schema or accounts.", |
| 70 | + ) |
31 | 71 | args = parser.parse_args() |
32 | 72 |
|
33 | | - if args.drop_everything: |
| 73 | + # ------------------------------------------------------------------ |
| 74 | + # 1. Decide how to reset |
| 75 | + # ------------------------------------------------------------------ |
| 76 | + if args.purge_build or args.purge: |
34 | 77 | drop_everything() |
35 | 78 | else: |
36 | 79 | destroy_database() |
37 | 80 |
|
38 | | - build_database() |
39 | | - create_base_vo() |
40 | | - create_root_account() |
| 81 | + # ------------------------------------------------------------------ |
| 82 | + # 2. Decide what to rebuild |
| 83 | + # ------------------------------------------------------------------ |
| 84 | + if not args.purge: |
| 85 | + build_database() |
| 86 | + create_base_vo() |
| 87 | + create_root_account() |
0 commit comments