Skip to content

Commit 4542da7

Browse files
authored
Introduced flag for keeping VMs alive (#110)
* Introduced flag for keeping VMs alive * Update opennebula.py
1 parent 0f3de68 commit 4542da7

File tree

4 files changed

+17
-7
lines changed

4 files changed

+17
-7
lines changed

alts/worker/runners/base.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ def __init__(
209209
package_channel: Optional[str] = None,
210210
test_configuration: Optional[dict] = None,
211211
test_flavor: Optional[Dict[str, str]] = None,
212+
vm_alive: bool = False,
212213
verbose: bool = False,
213214
):
214215
# Environment ID and working directory preparation
@@ -279,6 +280,7 @@ def __init__(
279280
self._stats = {}
280281
self._verbose = verbose
281282
self.package_channel = package_channel
283+
self.vm_alive = vm_alive
282284

283285
@property
284286
def artifacts(self):
@@ -1634,6 +1636,7 @@ def __init__(
16341636
package_channel: Optional[str] = None,
16351637
test_configuration: Optional[dict] = None,
16361638
test_flavor: Optional[Dict[str, str]] = None,
1639+
vm_alive: bool = False,
16371640
verbose: bool = False,
16381641
):
16391642
super().__init__(
@@ -1652,6 +1655,7 @@ def __init__(
16521655
self._tests_dir = CONFIG.tests_base_dir
16531656
self._ssh_client: Optional[Union[AsyncSSHClient, LongRunSSHClient]] = None
16541657
self._vm_ip = None
1658+
self._vm_alive = vm_alive
16551659

16561660
def _wait_for_ssh(self, retries=60):
16571661
ansible = local[self.ansible_binary]
@@ -1746,12 +1750,13 @@ def setup(self, skip_provision: bool = False):
17461750
self._ssh_client = LongRunSSHClient(**params)
17471751

17481752
def teardown(self, publish_artifacts: bool = True):
1749-
if self._ssh_client:
1750-
try:
1751-
self._ssh_client.close()
1752-
except:
1753-
pass
1754-
super().teardown(publish_artifacts=publish_artifacts)
1753+
if not self._vm_alive:
1754+
if self._ssh_client:
1755+
try:
1756+
self._ssh_client.close()
1757+
except:
1758+
pass
1759+
super().teardown(publish_artifacts=publish_artifacts)
17551760

17561761
def exec_command(self, *args, **kwargs) -> Tuple[int, str, str]:
17571762
command = ' '.join(args)

alts/worker/runners/docker.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ def __init__(
6868
dist_arch: str = 'x86_64',
6969
test_configuration: Optional[dict] = None,
7070
test_flavor: Optional[Dict[str, str]] = None,
71+
vm_alive: bool = False,
7172
artifacts_uploader: Optional[BaseLogsUploader] = None,
7273
package_channel: Optional[str] = None,
7374
verbose: bool = False,
@@ -97,6 +98,7 @@ def __init__(
9798
dist_arch=dist_arch,
9899
test_configuration=test_configuration,
99100
test_flavor=test_flavor,
101+
vm_alive=vm_alive,
100102
artifacts_uploader=artifacts_uploader,
101103
package_channel=package_channel,
102104
verbose=verbose,

alts/worker/runners/opennebula.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ def __init__(
4949
package_channel: Optional[str] = None,
5050
test_configuration: Optional[dict] = None,
5151
test_flavor: Optional[Dict[str, str]] = None,
52+
vm_alive: bool = False,
5253
verbose: bool = False,
5354
):
5455
super().__init__(
@@ -62,6 +63,7 @@ def __init__(
6263
package_channel=package_channel,
6364
test_configuration=test_configuration,
6465
test_flavor=test_flavor,
66+
vm_alive=vm_alive,
6567
verbose=verbose,
6668
)
6769
user = CONFIG.opennebula_config.username

alts/worker/tasks.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,8 @@ def set_artifacts_when_stage_has_unexpected_exception(
160160
'dist_arch': task_params.get('dist_arch', 'x86_64'),
161161
'package_channel': task_params.get('package_channel', 'beta'),
162162
'test_configuration': task_params.get('test_configuration', {}),
163-
'test_flavor': task_params.get('test_flavor', {})
163+
'test_flavor': task_params.get('test_flavor', {}),
164+
'vm_alive': task_params.get('vm_alive')
164165
}
165166

166167
runner_class = RUNNER_MAPPING[task_params['runner_type']]

0 commit comments

Comments
 (0)