gitlab-runner-tart-driver 0.3.4__tar.gz → 0.3.5__tar.gz

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.
Files changed (29) hide show
  1. {gitlab-runner-tart-driver-0.3.4/gitlab_runner_tart_driver.egg-info → gitlab-runner-tart-driver-0.3.5}/PKG-INFO +1 -1
  2. gitlab-runner-tart-driver-0.3.5/gitlab_runner_tart_driver/__init__.py +1 -0
  3. {gitlab-runner-tart-driver-0.3.4 → gitlab-runner-tart-driver-0.3.5}/gitlab_runner_tart_driver/cli.py +1 -2
  4. {gitlab-runner-tart-driver-0.3.4 → gitlab-runner-tart-driver-0.3.5}/gitlab_runner_tart_driver/commands/prepare.py +94 -16
  5. {gitlab-runner-tart-driver-0.3.4 → gitlab-runner-tart-driver-0.3.5/gitlab_runner_tart_driver.egg-info}/PKG-INFO +1 -1
  6. {gitlab-runner-tart-driver-0.3.4 → gitlab-runner-tart-driver-0.3.5}/setup.py +2 -2
  7. gitlab-runner-tart-driver-0.3.4/gitlab_runner_tart_driver/__init__.py +0 -1
  8. {gitlab-runner-tart-driver-0.3.4 → gitlab-runner-tart-driver-0.3.5}/LICENSE.txt +0 -0
  9. {gitlab-runner-tart-driver-0.3.4 → gitlab-runner-tart-driver-0.3.5}/MANIFEST.in +0 -0
  10. {gitlab-runner-tart-driver-0.3.4 → gitlab-runner-tart-driver-0.3.5}/README.md +0 -0
  11. {gitlab-runner-tart-driver-0.3.4 → gitlab-runner-tart-driver-0.3.5}/gitlab_runner_tart_driver/__main__.py +0 -0
  12. {gitlab-runner-tart-driver-0.3.4 → gitlab-runner-tart-driver-0.3.5}/gitlab_runner_tart_driver/commands/__init__.py +0 -0
  13. {gitlab-runner-tart-driver-0.3.4 → gitlab-runner-tart-driver-0.3.5}/gitlab_runner_tart_driver/commands/cleanup.py +0 -0
  14. {gitlab-runner-tart-driver-0.3.4 → gitlab-runner-tart-driver-0.3.5}/gitlab_runner_tart_driver/commands/config.py +0 -0
  15. {gitlab-runner-tart-driver-0.3.4 → gitlab-runner-tart-driver-0.3.5}/gitlab_runner_tart_driver/commands/run.py +0 -0
  16. {gitlab-runner-tart-driver-0.3.4 → gitlab-runner-tart-driver-0.3.5}/gitlab_runner_tart_driver/modules/__init__.py +0 -0
  17. {gitlab-runner-tart-driver-0.3.4 → gitlab-runner-tart-driver-0.3.5}/gitlab_runner_tart_driver/modules/gitlab_custom_command_config.py +0 -0
  18. {gitlab-runner-tart-driver-0.3.4 → gitlab-runner-tart-driver-0.3.5}/gitlab_runner_tart_driver/modules/gitlab_custom_driver_config.py +0 -0
  19. {gitlab-runner-tart-driver-0.3.4 → gitlab-runner-tart-driver-0.3.5}/gitlab_runner_tart_driver/modules/tart.py +0 -0
  20. {gitlab-runner-tart-driver-0.3.4 → gitlab-runner-tart-driver-0.3.5}/gitlab_runner_tart_driver/modules/utils.py +0 -0
  21. {gitlab-runner-tart-driver-0.3.4 → gitlab-runner-tart-driver-0.3.5}/gitlab_runner_tart_driver/scripts/install-gitlab-runner.sh.j2 +0 -0
  22. {gitlab-runner-tart-driver-0.3.4 → gitlab-runner-tart-driver-0.3.5}/gitlab_runner_tart_driver.egg-info/SOURCES.txt +0 -0
  23. {gitlab-runner-tart-driver-0.3.4 → gitlab-runner-tart-driver-0.3.5}/gitlab_runner_tart_driver.egg-info/dependency_links.txt +0 -0
  24. {gitlab-runner-tart-driver-0.3.4 → gitlab-runner-tart-driver-0.3.5}/gitlab_runner_tart_driver.egg-info/entry_points.txt +0 -0
  25. {gitlab-runner-tart-driver-0.3.4 → gitlab-runner-tart-driver-0.3.5}/gitlab_runner_tart_driver.egg-info/not-zip-safe +0 -0
  26. {gitlab-runner-tart-driver-0.3.4 → gitlab-runner-tart-driver-0.3.5}/gitlab_runner_tart_driver.egg-info/requires.txt +0 -0
  27. {gitlab-runner-tart-driver-0.3.4 → gitlab-runner-tart-driver-0.3.5}/gitlab_runner_tart_driver.egg-info/top_level.txt +0 -0
  28. {gitlab-runner-tart-driver-0.3.4 → gitlab-runner-tart-driver-0.3.5}/pyproject.toml +0 -0
  29. {gitlab-runner-tart-driver-0.3.4 → gitlab-runner-tart-driver-0.3.5}/setup.cfg +0 -0
@@ -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.5
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
@@ -0,0 +1 @@
1
+ __version__ = "0.3.5"
@@ -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,19 @@ 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
+ _create_vm(
239
+ tart_client=tart,
240
+ vm_name=tart_vm_name,
241
+ volume_mounts=volume_mounts,
242
+ params=p,
243
+ system_failure_exit_code=system_failure_exit_code,
244
+ )
245
+ _get_vm_ip(tart_client=tart, vm_name=tart_vm_name, params=p, system_failure_exit_code=system_failure_exit_code)
246
+ ssh_session = _create_ssh_session(
247
+ tart_client=tart, vm_name=tart_vm_name, params=p, system_failure_exit_code=system_failure_exit_code
248
+ )
252
249
 
253
250
  try:
254
- ssh_session = tart.ssh_session(name=p.vm_name(), username=p.ssh_username, password=p.ssh_password)
255
251
  ssh_session.exec_ssh_command(
256
252
  f"sudo mkdir -p {remote_script_dir} && sudo chown {p.ssh_username}:{p.ssh_username} {remote_script_dir}",
257
253
  )
@@ -289,3 +285,85 @@ def prepare(
289
285
  tart.print_spec(tart_vm_name)
290
286
 
291
287
  sys.exit(0)
288
+
289
+
290
+ def _create_vm(
291
+ tart_client, vm_name, volume_mounts, params, system_failure_exit_code, max_retries=3, retry_timeout_in_sec=5
292
+ ):
293
+ try:
294
+ tart_client.run(vm_name, volume_mounts, no_graphics=params.headless, softnet=params.softnet_enabled)
295
+ # check if vm is listed
296
+ retry_count = 0
297
+ while True:
298
+ try:
299
+ vm = tart_client.get(vm_name)
300
+ if vm:
301
+ click.echo(f"[INFO] VM '{vm_name}' is running")
302
+ break
303
+ else:
304
+ raise Exception("VM not found")
305
+ except Exception:
306
+ if retry_count < max_retries:
307
+ retry_count += 1
308
+ click.secho(
309
+ f"[WARNING] Failed to get IP of VM '{vm_name}'. [{retry_count+1}/{max_retries}] Retrying in '{retry_timeout_in_sec}' seconds...",
310
+ fg="yellow",
311
+ )
312
+ time.sleep(retry_timeout_in_sec)
313
+ else:
314
+ click.secho(f"[ERROR] VM '{vm_name}' could not be started.")
315
+ sys.exit(system_failure_exit_code)
316
+ except Exception:
317
+ click.secho(f"[ERROR] Failed to start VM '{vm_name}'", fg="red")
318
+ sys.exit(system_failure_exit_code)
319
+
320
+
321
+ def _get_vm_ip(tart_client, vm_name, params, system_failure_exit_code, max_retries=3, retry_timeout_in_sec=5):
322
+ retry_count = 0
323
+ while True:
324
+ try:
325
+ vm_ip_address = tart_client.ip(vm_name, timeout=params.timeout)
326
+ if vm_ip_address:
327
+ break
328
+ else:
329
+ raise Exception("VM IP 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] Failed to get IP of VM '{vm_name}'.")
340
+ sys.exit(system_failure_exit_code)
341
+
342
+ return vm_ip_address
343
+
344
+
345
+ def _create_ssh_session(tart_client, vm_name, params, system_failure_exit_code, max_retries=3, retry_timeout_in_sec=5):
346
+ ssh_session = None
347
+ retry_count = 0
348
+ while True:
349
+ try:
350
+ ssh_session = tart_client.ssh_session(
351
+ name=vm_name, username=params.ssh_username, password=params.ssh_password
352
+ )
353
+ if ssh_session:
354
+ break
355
+ else:
356
+ raise Exception("SSH Session could not be established.")
357
+ except Exception:
358
+ if retry_count < max_retries:
359
+ retry_count += 1
360
+ click.secho(
361
+ f"[WARNING] Failed to setup ssh connection with '{vm_name}'. Retrying in '{retry_timeout_in_sec}' seconds...",
362
+ fg="yellow",
363
+ )
364
+ time.sleep(retry_timeout_in_sec)
365
+ else:
366
+ click.secho(f"[ERROR] Failed to setup ssh connection with '{vm_name}'.")
367
+ sys.exit(system_failure_exit_code)
368
+
369
+ 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.5
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
@@ -10,9 +10,9 @@ this_directory = os.path.abspath(os.path.dirname(__file__))
10
10
  with open(os.path.join(this_directory, "README.md"), encoding="utf-8") as f:
11
11
  long_description = f.read()
12
12
 
13
- version = "0.3.4"
13
+ version = "0.3.5"
14
14
 
15
- version = f"{version}{os.environ.get('PIP_VERSION_POSTFIX','')}"
15
+ version = f"{version}{os.environ.get('PIP_VERSION_POSTFIX', '')}"
16
16
 
17
17
  # read the requirements from requirements.txt
18
18
  requirements = []
@@ -1 +0,0 @@
1
- __version__ = "0.3.4"