gitlab-runner-tart-driver 0.3.5__py3-none-any.whl → 0.3.7__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.5"
1
+ __version__ = "0.3.7"
@@ -171,78 +171,96 @@ def prepare(
171
171
  ######################################################################
172
172
  # Create VM
173
173
  ######################################################################
174
- tart_vm_name = p.vm_name()
175
- if tart_vm_name in tart_vm_map:
176
- if tart_vm_map[tart_vm_name].running:
177
- click.echo(f"[INFO] Found running VM '{tart_vm_name}'. Going to stop it...")
178
- tart.stop(tart_vm_name)
179
- click.echo(f"[INFO] Found VM '{tart_vm_name}'. Going to delete it...")
180
- tart.delete(tart_vm_name)
181
-
182
- # verfiy that the limit of running VMs is not exceeded
183
- list_running_vms = []
184
- for vm in tart.list():
185
- if vm.running:
186
- list_running_vms.append(vm)
187
-
188
- if len(list_running_vms) > p.tart_max_vm_count:
189
- click.secho(
190
- f"[ERROR] The limit of running VMs [{p.tart_max_vm_count}] is exceeded [{len(list_running_vms)}].", fg="red"
191
- )
192
- sys.exit(system_failure_exit_code)
174
+ max_retries = 3
175
+ retry_count = 0
176
+ while True:
177
+ try:
178
+ tart_vm_name = p.vm_name()
179
+ if tart_vm_name in tart_vm_map:
180
+ if tart_vm_map[tart_vm_name].running:
181
+ click.echo(f"[INFO] Found running VM '{tart_vm_name}'. Going to stop it...")
182
+ tart.stop(tart_vm_name)
183
+ click.echo(f"[INFO] Found VM '{tart_vm_name}'. Going to delete it...")
184
+ tart.delete(tart_vm_name)
185
+
186
+ # verfiy that the limit of running VMs is not exceeded
187
+ list_running_vms = []
188
+ for vm in tart.list():
189
+ if vm.running:
190
+ list_running_vms.append(vm)
191
+
192
+ if len(list_running_vms) > p.tart_max_vm_count:
193
+ click.secho(
194
+ f"[ERROR] The limit of running VMs [{p.tart_max_vm_count}] is exceeded [{len(list_running_vms)}].",
195
+ fg="red",
196
+ )
197
+ sys.exit(system_failure_exit_code)
193
198
 
194
- click.echo(f"[INFO] Cloning VM instance '{tart_vm_name}' from '{p.ci_job_image}'")
195
- try:
196
- tart.clone(p.ci_job_image, tart_vm_name)
197
- except:
198
- click.secho(f"[ERROR] failed to clone image f'{p.ci_job_image}'", fg="red")
199
- sys.exit(system_failure_exit_code)
199
+ click.echo(f"[INFO] Cloning VM instance '{tart_vm_name}' from '{p.ci_job_image}'")
200
+ try:
201
+ tart.clone(p.ci_job_image, tart_vm_name)
202
+ except:
203
+ click.secho(f"[ERROR] failed to clone image f'{p.ci_job_image}'", fg="red")
204
+ sys.exit(system_failure_exit_code)
205
+
206
+ if cpu or memory or p.display:
207
+ click.echo(f"[INFO] Configuring instance '{tart_vm_name}' from '{p.ci_job_image}'")
208
+ click.echo(
209
+ f"[INFO] {tart_vm_name} [cpu={cpu if cpu else 'default'}, memory={memory if memory else 'default'}, display={p.display if p.display else 'default'}]"
210
+ )
211
+ tart.set(tart_vm_name, cpu=cpu, memory=memory, display=display)
212
+ elif auto_resources:
213
+ click.echo("[INFO] Auto resource-disribution enabled.")
214
+ host_spec = get_host_spec()
215
+ tart.set(
216
+ tart_vm_name, cpu=int(host_spec.cpu_count / concurrency), memory=int(host_spec.memory / concurrency)
217
+ )
218
+
219
+ click.echo(f"[INFO] Starting VM instance '{tart_vm_name}'")
220
+
221
+ remote_build_dir = "/opt/builds"
222
+ remote_script_dir = "/opt/temp"
223
+ remote_cache_dir = "/opt/cache"
224
+
225
+ volume_mounts = []
226
+ if cache_dir:
227
+ cache_dir = os.path.abspath(os.path.expanduser(cache_dir))
228
+ os.makedirs(cache_dir, exist_ok=True)
229
+ click.echo(f"[INFO] Cache directory set to '{cache_dir}'")
230
+ volume_mounts.append(TartVolume(source=cache_dir, dest=remote_cache_dir, name="cache", ro=False))
231
+ if builds_dir:
232
+ # Concurrency compatible builds directory
233
+ # see https://docs.gitlab.com/runner/executors/shell.html#run-scripts-as-a-privileged-user
234
+ # <builds_dir>/<short-token>/<concurrent-id>/<namespace>/<project-name>.
235
+ builds_dir = os.path.join(
236
+ os.path.abspath(os.path.expanduser(builds_dir)), p.ci_runner_short_token, p.ci_concurrent_project_id
237
+ )
238
+ os.makedirs(builds_dir, exist_ok=True)
239
+ click.echo(f"[INFO] Builds directory set to '{builds_dir}'")
240
+ volume_mounts.append(TartVolume(source=builds_dir, dest=remote_build_dir, name="builds", ro=False))
241
+
242
+ for v in volumes:
243
+ volume_mounts.append(TartVolume.from_string(v))
244
+
245
+ _create_vm(
246
+ tart_client=tart,
247
+ vm_name=tart_vm_name,
248
+ volume_mounts=volume_mounts,
249
+ params=p,
250
+ )
251
+ _get_vm_ip(tart_client=tart, vm_name=tart_vm_name, params=p)
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)
200
263
 
201
- if cpu or memory or p.display:
202
- click.echo(f"[INFO] Configuring instance '{tart_vm_name}' from '{p.ci_job_image}'")
203
- click.echo(
204
- f"[INFO] {tart_vm_name} [cpu={cpu if cpu else 'default'}, memory={memory if memory else 'default'}, display={p.display if p.display else 'default'}]"
205
- )
206
- tart.set(tart_vm_name, cpu=cpu, memory=memory, display=display)
207
- elif auto_resources:
208
- click.echo("[INFO] Auto resource-disribution enabled.")
209
- host_spec = get_host_spec()
210
- tart.set(tart_vm_name, cpu=int(host_spec.cpu_count / concurrency), memory=int(host_spec.memory / concurrency))
211
-
212
- click.echo(f"[INFO] Starting VM instance '{tart_vm_name}'")
213
-
214
- remote_build_dir = "/opt/builds"
215
- remote_script_dir = "/opt/temp"
216
- remote_cache_dir = "/opt/cache"
217
-
218
- volume_mounts = []
219
- if cache_dir:
220
- cache_dir = os.path.abspath(os.path.expanduser(cache_dir))
221
- os.makedirs(cache_dir, exist_ok=True)
222
- click.echo(f"[INFO] Cache directory set to '{cache_dir}'")
223
- volume_mounts.append(TartVolume(source=cache_dir, dest=remote_cache_dir, name="cache", ro=False))
224
- if builds_dir:
225
- # Concurrency compatible builds directory
226
- # see https://docs.gitlab.com/runner/executors/shell.html#run-scripts-as-a-privileged-user
227
- # <builds_dir>/<short-token>/<concurrent-id>/<namespace>/<project-name>.
228
- builds_dir = os.path.join(
229
- os.path.abspath(os.path.expanduser(builds_dir)), p.ci_runner_short_token, p.ci_concurrent_project_id
230
- )
231
- os.makedirs(builds_dir, exist_ok=True)
232
- click.echo(f"[INFO] Builds directory set to '{builds_dir}'")
233
- volume_mounts.append(TartVolume(source=builds_dir, dest=remote_build_dir, name="builds", ro=False))
234
-
235
- for v in volumes:
236
- volume_mounts.append(TartVolume.from_string(v))
237
-
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
264
  ssh_session = _create_ssh_session(
247
265
  tart_client=tart, vm_name=tart_vm_name, params=p, system_failure_exit_code=system_failure_exit_code
248
266
  )
@@ -287,38 +305,35 @@ def prepare(
287
305
  sys.exit(0)
288
306
 
289
307
 
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)
308
+ def _create_vm(tart_client, vm_name, volume_mounts, params, max_retries=3, retry_timeout_in_sec=10):
309
+ # ensure that the VM is not running
310
+ tart_client.run(vm_name, volume_mounts, no_graphics=params.headless, softnet=params.softnet_enabled)
311
+ time.sleep(10) # give the VM some time to start
312
+
313
+ # check if vm is listed
314
+ retry_count = 0
315
+ while True:
316
+ try:
317
+ vm = tart_client.get(vm_name)
318
+ if vm:
319
+ click.echo(f"[INFO] VM '{vm_name}' is running")
320
+ break
321
+ else:
322
+ raise Exception("VM not found")
323
+ except Exception:
324
+ if retry_count < max_retries:
325
+ retry_count += 1
326
+ click.secho(
327
+ f"[WARNING] VM with name '{vm_name}' was not found. Retrying in '{retry_timeout_in_sec}' seconds...",
328
+ fg="yellow",
329
+ )
330
+ time.sleep(retry_timeout_in_sec)
331
+ else:
332
+ click.secho(f"[ERROR] VM '{vm_name}' could not be started.")
333
+ raise Exception("VM not found")
319
334
 
320
335
 
321
- def _get_vm_ip(tart_client, vm_name, params, system_failure_exit_code, max_retries=3, retry_timeout_in_sec=5):
336
+ def _get_vm_ip(tart_client, vm_name, params, max_retries=3, retry_timeout_in_sec=10):
322
337
  retry_count = 0
323
338
  while True:
324
339
  try:
@@ -331,18 +346,18 @@ def _get_vm_ip(tart_client, vm_name, params, system_failure_exit_code, max_retri
331
346
  if retry_count < max_retries:
332
347
  retry_count += 1
333
348
  click.secho(
334
- f"[WARNING] VM with name '{vm_name}' was not found. Retrying in '{retry_timeout_in_sec}' seconds...",
349
+ f"[WARNING] Failed to get IP of VM '{vm_name}'. [{retry_count+1}/{max_retries}] Retrying in '{retry_timeout_in_sec}' seconds...",
335
350
  fg="yellow",
336
351
  )
337
352
  time.sleep(retry_timeout_in_sec)
338
353
  else:
339
354
  click.secho(f"[ERROR] Failed to get IP of VM '{vm_name}'.")
340
- sys.exit(system_failure_exit_code)
355
+ raise Exception("VM IP not found")
341
356
 
342
357
  return vm_ip_address
343
358
 
344
359
 
345
- def _create_ssh_session(tart_client, vm_name, params, system_failure_exit_code, max_retries=3, retry_timeout_in_sec=5):
360
+ def _create_ssh_session(tart_client, vm_name, params, system_failure_exit_code, max_retries=3, retry_timeout_in_sec=10):
346
361
  ssh_session = None
347
362
  retry_count = 0
348
363
  while True:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: gitlab-runner-tart-driver
3
- Version: 0.3.5
3
+ Version: 0.3.7
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=ThnCuF3X7rsQSd5PAea_jfYA70ZmhLvkFcLBxBPwZnY,22
1
+ gitlab_runner_tart_driver/__init__.py,sha256=J0I0c7-a50EOnWXMryTu_E6xhXSYFBPjVpeYP_a3vRI,22
2
2
  gitlab_runner_tart_driver/__main__.py,sha256=FiyMv64vDC-R8i3CGEP9QP48djZFHm7utyChwZJWCeY,107
3
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=JTxTlPnPELC9C2TMOLqvcu23jOL0sofMxdp9OwpfddU,13964
7
+ gitlab_runner_tart_driver/commands/prepare.py,sha256=UQikIoLpZFWEM3BZQYb36S2x67ElkE4amCTBSqZIyKI,14700
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.5.dist-info/LICENSE.txt,sha256=TiYXQpEfbzcPBNGb7k1NslUngq_un-5cxGyT4W1S_f4,3303
16
- gitlab_runner_tart_driver-0.3.5.dist-info/METADATA,sha256=dI44fmUwC6k_iCygHAOKtp31CoAKM7uBme8-OPdYVo0,20705
17
- gitlab_runner_tart_driver-0.3.5.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
18
- gitlab_runner_tart_driver-0.3.5.dist-info/entry_points.txt,sha256=xmvpGQf1wvFPy5wqDWXu8k5FD_k9KkCNCkpuworTsr0,82
19
- gitlab_runner_tart_driver-0.3.5.dist-info/top_level.txt,sha256=JjRzCs2sr24xG4SV_5tIBPpNC1Tec7I4AbK4IKMDqOc,26
20
- gitlab_runner_tart_driver-0.3.5.dist-info/RECORD,,
15
+ gitlab_runner_tart_driver-0.3.7.dist-info/LICENSE.txt,sha256=TiYXQpEfbzcPBNGb7k1NslUngq_un-5cxGyT4W1S_f4,3303
16
+ gitlab_runner_tart_driver-0.3.7.dist-info/METADATA,sha256=a4QxViHAnAJHDhluxbeEz7XHt0gITfK1ostJNqjNIzM,20705
17
+ gitlab_runner_tart_driver-0.3.7.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
18
+ gitlab_runner_tart_driver-0.3.7.dist-info/entry_points.txt,sha256=xmvpGQf1wvFPy5wqDWXu8k5FD_k9KkCNCkpuworTsr0,82
19
+ gitlab_runner_tart_driver-0.3.7.dist-info/top_level.txt,sha256=JjRzCs2sr24xG4SV_5tIBPpNC1Tec7I4AbK4IKMDqOc,26
20
+ gitlab_runner_tart_driver-0.3.7.dist-info/RECORD,,