1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
def delete_database(database_id):
import azure.cosmos.cosmos_client as cosmos_client
import azure.cosmos.exceptions as exceptions
import test_config
print("Cleaning up test resources.")
config = test_config._test_config
host = config.host
masterKey = config.masterKey
connectionPolicy = config.connectionPolicy
try:
client = cosmos_client.CosmosClient(host, masterKey, "Session", connection_policy=connectionPolicy)
# This is to soft-fail the teardown while cosmos tests are not running automatically
except Exception:
pass
else:
try:
client.delete_database(database_id)
print("Deleted " + database_id)
except exceptions.CosmosResourceNotFoundError:
pass
print("Clean up completed!")
if __name__== "__main__":
import sys
if len(sys.argv) < 2:
raise ValueError("database_id for deletion not provided.")
import os.path as path
root_path = path.abspath(path.join(__file__, "..", ".."))
sys.path.append(root_path)
database_id = sys.argv[1]
delete_database(database_id)
|