Skip to content

Commit 3b5e45c

Browse files
authored
Merge pull request #753 from FlorentinD/aura-ci-cleanup-sigterm
aura ci cleanup sigterm
2 parents 0455f75 + e00477a commit 3b5e45c

File tree

4 files changed

+45
-9
lines changed

4 files changed

+45
-9
lines changed

scripts/ci/aura_api_ci.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,6 @@ def create_instance(self, name: str, memory: str, type: str) -> Dict[str, Any]:
8181
if should_retry:
8282
logging.debug(f"Error code: {response.status_code} - Retrying in {wait_time} s")
8383

84-
response.raise_for_status()
85-
8684
return response.json()["data"] # type: ignore
8785

8886
def check_running(self, db_id: str) -> None:
@@ -115,7 +113,7 @@ def check_running(self, db_id: str) -> None:
115113

116114
response.raise_for_status()
117115

118-
def teardown_instance(self, db_id: str) -> None:
116+
def teardown_instance(self, db_id: str) -> bool:
119117
TEARDOWN_MAX_WAIT_TIME = 10
120118

121119
should_retry = True
@@ -138,8 +136,13 @@ def teardown_instance(self, db_id: str) -> None:
138136
if should_retry:
139137
logging.debug(f"Status code: {response.status_code} - Retrying in {wait_time} s")
140138

139+
if response.status_code == 404:
140+
return False
141+
141142
response.raise_for_status()
142143

144+
return True
145+
143146
def get_tenant_id(self) -> str:
144147
if self._tenant_id:
145148
return self._tenant_id

scripts/ci/run_targeting_aura_sessions.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import logging
44
import os
55
import random as rd
6+
import signal
67
import sys
78

89
from aura_api_ci import AuraApiCI
@@ -23,6 +24,15 @@ def main() -> None:
2324
instance_id = create_result["id"]
2425
logging.info(f"Creation of database with id '{instance_id}'")
2526

27+
# Teardown instance on SIGNAL
28+
def handle_signal(sig, frame):
29+
logging.info("Received SIGNAL, tearing down instance")
30+
aura_api.teardown_instance(instance_id)
31+
sys.exit(1)
32+
33+
signal.signal(signal.SIGINT, handle_signal)
34+
signal.signal(signal.SIGTERM, handle_signal)
35+
2636
try:
2737
aura_api.check_running(instance_id)
2838
logging.info("Database up and running")

scripts/ci/run_targeting_aurads.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import logging
22
import os
33
import random as rd
4+
import signal
45
import sys
56

67
from aura_api_ci import AuraApiCI
@@ -28,7 +29,7 @@ def run_notebooks(uri: str, username: str, password: str) -> None:
2829
def main() -> None:
2930
client_id = os.environ["AURA_API_CLIENT_ID"]
3031
client_secret = os.environ["AURA_API_CLIENT_SECRET"]
31-
tenant_id = os.environ.get("TENANT_ID")
32+
tenant_id = os.environ.get("AURA_API_TENANT_ID")
3233
aura_api = AuraApiCI(client_id=client_id, client_secret=client_secret, tenant_id=tenant_id)
3334

3435
MAX_INT = 1000000
@@ -38,6 +39,14 @@ def main() -> None:
3839
instance_id = create_result["id"]
3940
logging.info("Creation of database accepted")
4041

42+
def handle_signal(sig, frame):
43+
logging.info("Received SIGNAL, tearing down instance")
44+
aura_api.teardown_instance(instance_id)
45+
sys.exit(1)
46+
47+
signal.signal(signal.SIGINT, handle_signal)
48+
signal.signal(signal.SIGTERM, handle_signal)
49+
4150
try:
4251
aura_api.check_running(instance_id)
4352
logging.info("Database %s up and running", instance_id)

scripts/run_notebooks.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env python3
22

3+
import signal
34
import sys
45
from datetime import datetime
56
from pathlib import Path
@@ -29,6 +30,16 @@ def init_notebook(self, version_cell_index: int, tear_down_cells: List[IndexedCe
2930

3031
# run the cell of a notebook
3132
def preprocess_cell(self, cell: Any, resources: Any, index: int) -> None:
33+
if index == 0:
34+
35+
def handle_signal(sig, frame):
36+
print("Received SIGNAL, running tear down cells")
37+
self.teardown(resources)
38+
sys.exit(1)
39+
40+
signal.signal(signal.SIGINT, handle_signal)
41+
signal.signal(signal.SIGTERM, handle_signal)
42+
3243
try:
3344
if not self._skip_rest:
3445
super().preprocess_cell(cell, resources, index) # type: ignore
@@ -40,13 +51,16 @@ def preprocess_cell(self, cell: Any, resources: Any, index: int) -> None:
4051

4152
if self.tear_down_cells:
4253
print(f"Running tear down cells due to error in notebook execution: {e}")
43-
for td_cell, td_idx in self.tear_down_cells:
44-
try:
45-
super().preprocess_cell(td_cell, resources, td_idx) # type: ignore
46-
except CellExecutionError as td_e:
47-
print(f"Error running tear down cell {td_idx}: {td_e}")
54+
self.teardown(resources)
4855
raise e
4956

57+
def teardown(self, resources) -> None:
58+
for td_cell, td_idx in self.tear_down_cells:
59+
try:
60+
super().preprocess_cell(td_cell, resources, td_idx) # type: ignore
61+
except CellExecutionError as td_e:
62+
print(f"Error running tear down cell {td_idx}: {td_e}")
63+
5064

5165
class GdsTearDownCollector(ExecutePreprocessor):
5266
def __init__(self, **kw: Any):

0 commit comments

Comments
 (0)