gitlab-runner-tart-driver 0.3.4__py3-none-any.whl → 0.3.6__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- __version__ = "0.3.4"
1
+ __version__ = "0.3.6"
@@ -9,8 +9,7 @@ from gitlab_runner_tart_driver.commands.run import run
9
9
 
10
10
  @click.group()
11
11
  @click.version_option(__version__, "--version", "-v", message="%(version)s")
12
- def cli():
13
- ...
12
+ def cli(): ...
14
13
 
15
14
 
16
15
  cli.add_command(config)
@@ -1,5 +1,6 @@
1
1
  import os
2
2
  import sys
3
+ import time
3
4
 
4
5
  import click
5
6
 
@@ -234,24 +235,37 @@ def prepare(
234
235
  for v in volumes:
235
236
  volume_mounts.append(TartVolume.from_string(v))
236
237
 
237
- try:
238
- tart.run(tart_vm_name, volume_mounts, no_graphics=p.headless, softnet=p.softnet_enabled)
239
- except:
240
- click.secho(f"[ERROR] Failed to start VM '{tart_vm_name}'", fg="red")
241
- sys.exit(system_failure_exit_code)
242
-
243
- try:
244
- ip = tart.ip(tart_vm_name, timeout=p.timeout)
245
- except:
246
- click.secho(f"[ERROR] Failed to get IP of VM '{tart_vm_name}'", fg="red")
247
- sys.exit(system_failure_exit_code)
248
-
249
- if not ip:
250
- click.echo(f"[ERROR] Error, VM was not reacheable after '{p.timeout}' seconds")
251
- sys.exit(system_failure_exit_code)
238
+ max_retries = 3
239
+ retry_count = 0
240
+ while True:
241
+ try:
242
+ _create_vm(
243
+ tart_client=tart,
244
+ vm_name=tart_vm_name,
245
+ volume_mounts=volume_mounts,
246
+ params=p,
247
+ system_failure_exit_code=system_failure_exit_code,
248
+ )
249
+ _get_vm_ip(
250
+ tart_client=tart, vm_name=tart_vm_name, params=p, system_failure_exit_code=system_failure_exit_code
251
+ )
252
+ break
253
+ except Exception:
254
+ if retry_count < max_retries:
255
+ retry_count += 1
256
+ click.secho(
257
+ "[WARNING] VM Coult not be started. Retrying...",
258
+ fg="yellow",
259
+ )
260
+ else:
261
+ click.secho(f"[ERROR] VM '{tart_vm_name}' could not be started.")
262
+ sys.exit(system_failure_exit_code)
263
+
264
+ ssh_session = _create_ssh_session(
265
+ tart_client=tart, vm_name=tart_vm_name, params=p, system_failure_exit_code=system_failure_exit_code
266
+ )
252
267
 
253
268
  try:
254
- ssh_session = tart.ssh_session(name=p.vm_name(), username=p.ssh_username, password=p.ssh_password)
255
269
  ssh_session.exec_ssh_command(
256
270
  f"sudo mkdir -p {remote_script_dir} && sudo chown {p.ssh_username}:{p.ssh_username} {remote_script_dir}",
257
271
  )
@@ -289,3 +303,89 @@ def prepare(
289
303
  tart.print_spec(tart_vm_name)
290
304
 
291
305
  sys.exit(0)
306
+
307
+
308
+ def _create_vm(
309
+ tart_client, vm_name, volume_mounts, params, system_failure_exit_code, max_retries=3, retry_timeout_in_sec=10
310
+ ):
311
+ # ensure that the VM is not running
312
+ try:
313
+ tart_client.delete(vm_name)
314
+ except Exception:
315
+ pass
316
+
317
+ tart_client.run(vm_name, volume_mounts, no_graphics=params.headless, softnet=params.softnet_enabled)
318
+ time.sleep(10) # give the VM some time to start
319
+
320
+ # check if vm is listed
321
+ retry_count = 0
322
+ while True:
323
+ try:
324
+ vm = tart_client.get(vm_name)
325
+ if vm:
326
+ click.echo(f"[INFO] VM '{vm_name}' is running")
327
+ break
328
+ else:
329
+ raise Exception("VM not found")
330
+ except Exception:
331
+ if retry_count < max_retries:
332
+ retry_count += 1
333
+ click.secho(
334
+ f"[WARNING] VM with name '{vm_name}' was not found. Retrying in '{retry_timeout_in_sec}' seconds...",
335
+ fg="yellow",
336
+ )
337
+ time.sleep(retry_timeout_in_sec)
338
+ else:
339
+ click.secho(f"[ERROR] VM '{vm_name}' could not be started.")
340
+ raise Exception("VM not found")
341
+
342
+
343
+ def _get_vm_ip(tart_client, vm_name, params, system_failure_exit_code, max_retries=3, retry_timeout_in_sec=10):
344
+ retry_count = 0
345
+ while True:
346
+ try:
347
+ vm_ip_address = tart_client.ip(vm_name, timeout=params.timeout)
348
+ if vm_ip_address:
349
+ break
350
+ else:
351
+ raise Exception("VM IP not found")
352
+ except Exception:
353
+ if retry_count < max_retries:
354
+ retry_count += 1
355
+ click.secho(
356
+ f"[WARNING] Failed to get IP of VM '{vm_name}'. [{retry_count+1}/{max_retries}] Retrying in '{retry_timeout_in_sec}' seconds...",
357
+ fg="yellow",
358
+ )
359
+ time.sleep(retry_timeout_in_sec)
360
+ else:
361
+ click.secho(f"[ERROR] Failed to get IP of VM '{vm_name}'.")
362
+ raise Exception("VM IP not found")
363
+
364
+ return vm_ip_address
365
+
366
+
367
+ def _create_ssh_session(tart_client, vm_name, params, system_failure_exit_code, max_retries=3, retry_timeout_in_sec=10):
368
+ ssh_session = None
369
+ retry_count = 0
370
+ while True:
371
+ try:
372
+ ssh_session = tart_client.ssh_session(
373
+ name=vm_name, username=params.ssh_username, password=params.ssh_password
374
+ )
375
+ if ssh_session:
376
+ break
377
+ else:
378
+ raise Exception("SSH Session could not be established.")
379
+ except Exception:
380
+ if retry_count < max_retries:
381
+ retry_count += 1
382
+ click.secho(
383
+ f"[WARNING] Failed to setup ssh connection with '{vm_name}'. Retrying in '{retry_timeout_in_sec}' seconds...",
384
+ fg="yellow",
385
+ )
386
+ time.sleep(retry_timeout_in_sec)
387
+ else:
388
+ click.secho(f"[ERROR] Failed to setup ssh connection with '{vm_name}'.")
389
+ sys.exit(system_failure_exit_code)
390
+
391
+ return ssh_session
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: gitlab-runner-tart-driver
3
- Version: 0.3.4
3
+ Version: 0.3.6
4
4
  Home-page: https://gitlab.com/schmieder.matthias/gitlab-runner-tart-driver
5
5
  Author: Matthias Schmieder
6
6
  Author-email: schmieder.matthias@gmail.com
@@ -1,10 +1,10 @@
1
- gitlab_runner_tart_driver/__init__.py,sha256=oYLGMpySamd16KLiaBTfRyrAS7_oyp-TOEHmzmeumwg,22
1
+ gitlab_runner_tart_driver/__init__.py,sha256=W_9dCm49nLvZulVAvvsafxLJjVBSKDBHz9K7szFZllo,22
2
2
  gitlab_runner_tart_driver/__main__.py,sha256=FiyMv64vDC-R8i3CGEP9QP48djZFHm7utyChwZJWCeY,107
3
- gitlab_runner_tart_driver/cli.py,sha256=1eFi9m8L4zcBO5eE4g4EP8phtE1znF54qt-xAigPsOE,596
3
+ gitlab_runner_tart_driver/cli.py,sha256=rCtFzi7i4JUX7VXteBHyII4sEbMzpn8SIpyjyKrQCBI,592
4
4
  gitlab_runner_tart_driver/commands/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
5
  gitlab_runner_tart_driver/commands/cleanup.py,sha256=nFe7TGdxsVSXNR9onm-3iCjmUo6SzujV5LrA_y439fs,1422
6
6
  gitlab_runner_tart_driver/commands/config.py,sha256=cacJ9ms5r3nZGZ_sS2d21Uoz7S-bMjB__lORUmeXZ-4,760
7
- gitlab_runner_tart_driver/commands/prepare.py,sha256=zCfeqbmmDH0IxuFC9XqJ2uVWDuyJSzjq_uvBhfNX-og,10981
7
+ gitlab_runner_tart_driver/commands/prepare.py,sha256=hLybN4q-ppFeOs-DxJfv2Y4uVXJvTaJGNap_c7PZOeg,14488
8
8
  gitlab_runner_tart_driver/commands/run.py,sha256=kXQxi8nxv6QQRFzGrlqifLtFtbjXAYgjCiMVqXkb2_A,3065
9
9
  gitlab_runner_tart_driver/modules/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
10
  gitlab_runner_tart_driver/modules/gitlab_custom_command_config.py,sha256=XvE83QmQUcqtVMYZY3okGOgO86DBX6Y7xhXNenmKxFY,3086
@@ -12,9 +12,9 @@ gitlab_runner_tart_driver/modules/gitlab_custom_driver_config.py,sha256=ujxlzP1Z
12
12
  gitlab_runner_tart_driver/modules/tart.py,sha256=rD6IPtpz57dwsPGVBWaeKeVoqI1MoBvdtkqozXgmAxA,9914
13
13
  gitlab_runner_tart_driver/modules/utils.py,sha256=7ipKjy_5tC5iW67Na_A9XhF4o2lKcAqO8LRTTSJKNd0,923
14
14
  gitlab_runner_tart_driver/scripts/install-gitlab-runner.sh.j2,sha256=-rBzxZ92w7lMrTCVcjMHhlZgqPIK1RJKVoOc2wjZvck,2533
15
- gitlab_runner_tart_driver-0.3.4.dist-info/LICENSE.txt,sha256=TiYXQpEfbzcPBNGb7k1NslUngq_un-5cxGyT4W1S_f4,3303
16
- gitlab_runner_tart_driver-0.3.4.dist-info/METADATA,sha256=Ana3GfNPOS4BJuAFBQ5G2nHv6moeoIVc5YHIhervFrk,20705
17
- gitlab_runner_tart_driver-0.3.4.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
18
- gitlab_runner_tart_driver-0.3.4.dist-info/entry_points.txt,sha256=xmvpGQf1wvFPy5wqDWXu8k5FD_k9KkCNCkpuworTsr0,82
19
- gitlab_runner_tart_driver-0.3.4.dist-info/top_level.txt,sha256=JjRzCs2sr24xG4SV_5tIBPpNC1Tec7I4AbK4IKMDqOc,26
20
- gitlab_runner_tart_driver-0.3.4.dist-info/RECORD,,
15
+ gitlab_runner_tart_driver-0.3.6.dist-info/LICENSE.txt,sha256=TiYXQpEfbzcPBNGb7k1NslUngq_un-5cxGyT4W1S_f4,3303
16
+ gitlab_runner_tart_driver-0.3.6.dist-info/METADATA,sha256=Dnxtm1KtThyxjTt3AJsm2QVnFE2jGQ8NLCJWo-9ns9c,20705
17
+ gitlab_runner_tart_driver-0.3.6.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
18
+ gitlab_runner_tart_driver-0.3.6.dist-info/entry_points.txt,sha256=xmvpGQf1wvFPy5wqDWXu8k5FD_k9KkCNCkpuworTsr0,82
19
+ gitlab_runner_tart_driver-0.3.6.dist-info/top_level.txt,sha256=JjRzCs2sr24xG4SV_5tIBPpNC1Tec7I4AbK4IKMDqOc,26
20
+ gitlab_runner_tart_driver-0.3.6.dist-info/RECORD,,