Skip to content

Commit 5255068

Browse files
committed
Fix vm deletion caused by error string check
1 parent f7b5dc3 commit 5255068

File tree

3 files changed

+7
-11
lines changed

3 files changed

+7
-11
lines changed

alts/shared/utils/log_utils.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,19 @@ def read_and_cleanup_temp_log_files(
3030
return out, err
3131

3232

33-
def check_for_error_string(stage_data: dict) -> bool:
33+
def check_for_error_string(stderr: str) -> bool:
3434
"""
3535
Checks if we encounter errors during testing that worth keepin VM alive.
3636
3737
Parameters
3838
----------
39-
stage_data: dict
39+
stderr: str
4040
4141
Returns
4242
-------
4343
bool
4444
True if we encounter any error from the list. False otherwise
4545
"""
46-
err = stage_data.get('stderr', '')
47-
if any(error_str in err for error_str in ERROR_STRINGS):
46+
if stderr and any(error_str in stderr for error_str in ERROR_STRINGS):
4847
return True
4948
return False

alts/worker/runners/base.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1555,11 +1555,6 @@ def setup(self, skip_provision: bool = False):
15551555

15561556
def teardown(self, publish_artifacts: bool = True):
15571557
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)
15631558
self.stop_env()
15641559
except Exception as e:
15651560
self._logger.exception('Error while stop environment: %s', e)
@@ -1674,7 +1669,7 @@ def __init__(
16741669
self._tests_dir = CONFIG.tests_base_dir
16751670
self._ssh_client: Optional[Union[AsyncSSHClient, LongRunSSHClient]] = None
16761671
self._vm_ip = None
1677-
self._vm_alive = vm_alive
1672+
self.vm_alive = vm_alive
16781673
self.start_env_failed = False
16791674

16801675
def _wait_for_ssh(self, retries=60):
@@ -1762,6 +1757,8 @@ def start_env(self):
17621757
final_exit_code = exit_code or ssh_exit_code
17631758
final_stdout = f'{stdout}\n\n{ssh_stdout}'
17641759
final_stderr = f'{stderr}\n\n{ssh_stderr}'
1760+
if not self.vm_alive:
1761+
self.vm_alive = check_for_error_string(final_stderr)
17651762
return final_exit_code, final_stdout, final_stderr
17661763

17671764
def setup(self, skip_provision: bool = False):

alts/worker/runners/opennebula.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ def _stop_env(self):
177177
)
178178
self._logger.warning(err_msg)
179179
return 0, err_msg, ''
180-
if self._vm_alive:
180+
if self.vm_alive:
181181
return 0, "WARNING: VM won't be destroyed because vm_alive=True was given", ""
182182
stop_exit_code, stop_out, stop_err = super()._stop_env()
183183
if stop_exit_code == 0:

0 commit comments

Comments
 (0)