You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

db_teardown.py 878B

12345678910111213141516171819202122
  1. from cassandra.cluster import Cluster
  2. import os
  3. def db_teardown(config):
  4. print(" == DB TEARDOWN SCRIPT == ")
  5. print(f"Attempting Cassandra connection @ {config['cassandra_addresses']}:{config['cassandra_port']}")
  6. cluster = Cluster(config['cassandra_addresses'], port=config['cassandra_port'])
  7. session = cluster.connect(config['cassandra_keyspace'])
  8. print(f"Connection OK")
  9. for folder_name in os.listdir(config['setup_tables_dir']):
  10. print(f"Dropping TABLE '{folder_name}'")
  11. with open(f"{config['setup_tables_dir']}/{folder_name}/DROP.sql") as table_drop:
  12. session.execute(table_drop.read())
  13. with open(f"{config['setup_keyspace_dir']}/DROP.sql") as keyspace_drop:
  14. print(f"Dropping KEYSPACE '{config['cassandra_keyspace']}'")
  15. session.execute(keyspace_drop.read())
  16. print("Done!")
  17. cluster.shutdown()