Skip to content

Commit f7b5dc3

Browse files
Kwaizeranfimovdm
andauthored
Keep VM alive if a particular error string is encountered (#159)
Apply suggestions from code review Co-authored-by: Daniil Anfimov <64651799+anfimovdm@users.noreply.github.com>
1 parent 0047ca0 commit f7b5dc3

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

alts/shared/constants.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@
6363
'publickey',
6464
]
6565

66+
ERROR_STRINGS = (
67+
'Error: Failed to wait virtual machine to be in RUNNING state',
68+
)
69+
6670

6771
class TapStatusEnum(IntEnum):
6872
FAILED = 0

alts/shared/utils/log_utils.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from tempfile import NamedTemporaryFile
33
from typing import IO, Tuple
44

5+
from alts.shared.constants import ERROR_STRINGS
56

67
def get_temp_log_files(prefix: str) -> Tuple[IO, IO]:
78
temp_file_kwargs = {
@@ -27,3 +28,22 @@ def read_and_cleanup_temp_log_files(
2728
file.close()
2829
os.unlink(file.name)
2930
return out, err
31+
32+
33+
def check_for_error_string(stage_data: dict) -> bool:
34+
"""
35+
Checks if we encounter errors during testing that worth keepin VM alive.
36+
37+
Parameters
38+
----------
39+
stage_data: dict
40+
41+
Returns
42+
-------
43+
bool
44+
True if we encounter any error from the list. False otherwise
45+
"""
46+
err = stage_data.get('stderr', '')
47+
if any(error_str in err for error_str in ERROR_STRINGS):
48+
return True
49+
return False

alts/worker/runners/base.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
from alts.shared.utils.log_utils import (
5858
get_temp_log_files,
5959
read_and_cleanup_temp_log_files,
60+
check_for_error_string,
6061
)
6162
from alts.shared.utils.plumbum_utils import wait_bg_process
6263
from alts.worker import CONFIG, RESOURCES_DIR
@@ -1554,6 +1555,11 @@ def setup(self, skip_provision: bool = False):
15541555

15551556
def teardown(self, publish_artifacts: bool = True):
15561557
try:
1558+
if not self.vm_alive:
1559+
for _, stage_data in self.artifacts.items():
1560+
self.vm_alive = check_for_error_string(stage_data)
1561+
for _, inner_data in stage_data.items():
1562+
self.vm_alive = check_for_error_string(inner_data)
15571563
self.stop_env()
15581564
except Exception as e:
15591565
self._logger.exception('Error while stop environment: %s', e)

0 commit comments

Comments
 (0)