1+ import logging
2+ import os
3+ import random as rd
4+ import sys
5+
6+ from ...graphdatascience.session.aura_api import AuraApi
7+
8+ logging.basicConfig(level=logging.INFO)
9+
10+
11+ def run_tests(uri, username, password):
12+ cmd = f'NEO4J_URI={uri} NEO4J_USER={username} NEO4J_PASSWORD={password} tox -e \$(tox -l | grep aura | grep main | paste -sd \',\' -)'
13+
14+ if os.system(cmd) != 0:
15+ raise Exception('Failed to run tests')
16+
17+
18+ def run_notebooks(uri, username, password):
19+ cmd = f'NEO4J_URI={uri} NEO4J_USER={username} NEO4J_PASSWORD={password} tox -e jupyter-notebook-ci'
20+
21+ if os.system(cmd) != 0:
22+ raise Exception('Failed to run notebooks')
23+
24+
25+ def main():
26+ aura_api = AuraApi(
27+ os.environ.get('AURA_API_CLIENT_ID'),
28+ os.environ.get('AURA_API_CLIENT_SECRET')
29+ )
30+ MAX_INT = 2**31
31+
32+ create_result = aura_api.create_instance(
33+ name='ci-instance-' + str(rd.randint(0, MAX_INT)),
34+ memory='8GB',
35+ cloud_provider='gcp',
36+ region='europe-west1'
37+ )
38+ instance_id = create_result.id
39+ logging.info('Creation of database accepted')
40+
41+ try:
42+ aura_api.wait_for_instance_running(instance_id)
43+ logging.info('Database %s up and running', instance_id)
44+
45+ if sys.argv[1] == 'tests':
46+ run_tests(
47+ create_result['connection_url'],
48+ create_result['username'],
49+ create_result['password'],
50+ )
51+ logging.info('Tests ran successfully')
52+ elif sys.argv[1] == 'notebooks':
53+ run_notebooks(
54+ create_result['connection_url'],
55+ create_result['username'],
56+ create_result['password'],
57+ )
58+ logging.info('Notebooks ran successfully')
59+ else:
60+ logging.error(f'Invalid target: {sys.argv[1]}')
61+ finally:
62+ logging.info('Teardown of instance %s', instance_id)
63+ aura_api.delete_instance(instance_id)
64+
65+
66+ if __name__ == '__main__':
67+ main()
0 commit comments