gitlab-runner-tart-driver 0.3.2__py3-none-any.whl → 0.3.4__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.2"
1
+ __version__ = "0.3.4"
@@ -115,6 +115,12 @@ def prepare(
115
115
  if not p.tart_executor_timeout:
116
116
  p.tart_executor_timeout = timeout
117
117
 
118
+ # retrieve the SYSTEM_FAILURE_EXIT_CODE from the environment
119
+ system_failure_exit_code = os.getenv("SYSTEM_FAILURE_EXIT_CODE", None)
120
+ if not system_failure_exit_code:
121
+ click.secho("[WARNING] SYSTEM_FAILURE_EXIT_CODE not set, defaulting to '1'", fg="red")
122
+ system_failure_exit_code = 1
123
+
118
124
  tart = Tart(exec_path=tart_executable)
119
125
  tart_images = tart.list()
120
126
  tart_vm_map = {}
@@ -157,7 +163,7 @@ def prepare(
157
163
  tart.pull(p.ci_job_image)
158
164
  except:
159
165
  click.secho(f"[ERROR] Failed to pull image '{p.ci_job_image}'", fg="red")
160
- sys.exit(1)
166
+ sys.exit(system_failure_exit_code)
161
167
  else:
162
168
  click.echo(f"[INFO] Skipping '{p.ci_job_image}' [pull_policy={p.pull_policy}]")
163
169
 
@@ -182,14 +188,14 @@ def prepare(
182
188
  click.secho(
183
189
  f"[ERROR] The limit of running VMs [{p.tart_max_vm_count}] is exceeded [{len(list_running_vms)}].", fg="red"
184
190
  )
185
- sys.exit(1)
191
+ sys.exit(system_failure_exit_code)
186
192
 
187
193
  click.echo(f"[INFO] Cloning VM instance '{tart_vm_name}' from '{p.ci_job_image}'")
188
194
  try:
189
195
  tart.clone(p.ci_job_image, tart_vm_name)
190
196
  except:
191
197
  click.secho(f"[ERROR] failed to clone image f'{p.ci_job_image}'", fg="red")
192
- sys.exit(1)
198
+ sys.exit(system_failure_exit_code)
193
199
 
194
200
  if cpu or memory or p.display:
195
201
  click.echo(f"[INFO] Configuring instance '{tart_vm_name}' from '{p.ci_job_image}'")
@@ -232,17 +238,17 @@ def prepare(
232
238
  tart.run(tart_vm_name, volume_mounts, no_graphics=p.headless, softnet=p.softnet_enabled)
233
239
  except:
234
240
  click.secho(f"[ERROR] Failed to start VM '{tart_vm_name}'", fg="red")
235
- sys.exit(1)
241
+ sys.exit(system_failure_exit_code)
236
242
 
237
243
  try:
238
244
  ip = tart.ip(tart_vm_name, timeout=p.timeout)
239
245
  except:
240
246
  click.secho(f"[ERROR] Failed to get IP of VM '{tart_vm_name}'", fg="red")
241
- sys.exit(1)
247
+ sys.exit(system_failure_exit_code)
242
248
 
243
249
  if not ip:
244
250
  click.echo(f"[ERROR] Error, VM was not reacheable after '{p.timeout}' seconds")
245
- sys.exit(1)
251
+ sys.exit(system_failure_exit_code)
246
252
 
247
253
  try:
248
254
  ssh_session = tart.ssh_session(name=p.vm_name(), username=p.ssh_username, password=p.ssh_password)
@@ -268,7 +274,7 @@ def prepare(
268
274
  )
269
275
  except:
270
276
  click.secho(f"[ERROR] Failed so prepare VM '{tart_vm_name}'", fg="red")
271
- sys.exit(1)
277
+ sys.exit(system_failure_exit_code)
272
278
 
273
279
  if p.install_gitlab_runner:
274
280
  click.echo(
@@ -278,7 +284,7 @@ def prepare(
278
284
  tart.install_gitlab_runner(name=tart_vm_name, username=p.ssh_username, password=p.ssh_password)
279
285
  except:
280
286
  click.secho(f"[ERROR] Failed to install GitLab Runner '{gitlab_runner_version}'", fg="red")
281
- sys.exit(1)
287
+ sys.exit(system_failure_exit_code)
282
288
 
283
289
  tart.print_spec(tart_vm_name)
284
290
 
@@ -32,6 +32,18 @@ def run(ssh_timeout, tart_executable, shell, script, stage):
32
32
  """Run commands."""
33
33
  p = GitLabCustomCommandConfig()
34
34
 
35
+ # retrieve the BUILD_FAILURE_EXIT_CODE from the environment
36
+ build_failure_exit_code = os.getenv("BUILD_FAILURE_EXIT_CODE", None)
37
+ if not build_failure_exit_code:
38
+ click.secho("[WARNING] BUILD_FAILURE_EXIT_CODE not set, defaulting to '1'", fg="red")
39
+ build_failure_exit_code = 1
40
+
41
+ # retrieve the SYSTEM_FAILURE_EXIT_CODE from the environment
42
+ system_failure_exit_code = os.getenv("SYSTEM_FAILURE_EXIT_CODE", None)
43
+ if not system_failure_exit_code:
44
+ click.secho("[WARNING] SYSTEM_FAILURE_EXIT_CODE not set, defaulting to '1'", fg="red")
45
+ system_failure_exit_code = 1
46
+
35
47
  if not p.tart_executor_shell:
36
48
  p.tart_executor_shell = shell
37
49
  ######################################################################
@@ -48,13 +60,13 @@ def run(ssh_timeout, tart_executable, shell, script, stage):
48
60
  f"[{stage}][ERROR] Could not establish SSH conntection to '{tart_vm_name}' after '{ssh_timeout}' seconds.",
49
61
  fg="red",
50
62
  )
51
- sys.exit(1)
63
+ sys.exit(system_failure_exit_code)
52
64
 
53
65
  try:
54
66
  ssh_session = tart.ssh_session(name=p.vm_name(), username=p.ssh_username, password=p.ssh_password)
55
67
  except:
56
68
  click.secho(f"[{stage}][ERROR] Could not establish SSH session with '{p.ssh_username}@{tart_ip}'", fg="red")
57
- sys.exit(1)
69
+ sys.exit(system_failure_exit_code)
58
70
 
59
71
  remote_temp_dir = "/opt/temp"
60
72
  script_name = os.path.basename(script)
@@ -67,4 +79,8 @@ def run(ssh_timeout, tart_executable, shell, script, stage):
67
79
  # ssh_session.exec_ssh_command(f"cd {remote_build_dir}")
68
80
  script_exit_code = ssh_session.exec_ssh_command(f"{p.shell} -l {remote_script_path}", get_pty=True)
69
81
 
70
- sys.exit(script_exit_code)
82
+ if script_exit_code != 0:
83
+ click.secho(f"[{stage}][ERROR] Script '{script}' failed with exit code '{script_exit_code}'", fg="red")
84
+ sys.exit(build_failure_exit_code)
85
+
86
+ sys.exit(0)
@@ -28,6 +28,8 @@ class TartVmSpec(BaseModel):
28
28
  display: str
29
29
  running: bool
30
30
  ip_address: str
31
+ os: str
32
+ size: str
31
33
 
32
34
 
33
35
  class TartVolume(BaseModel):
@@ -126,43 +128,53 @@ class Tart(object):
126
128
  # 'spec' will look like this:
127
129
  #
128
130
  # tart version < 2.7
129
- # CPU Memory Disk Display Running
130
- # 4 8192 46 1024x768 true
131
+ # CPU Memory Disk Display Running
132
+ # 4 8192 46 1024x768 true
131
133
  #
132
134
  # tart version > 2.6
133
135
  # CPU Memory Disk Size Display State
134
136
  # 4 8192 50 20.794 1024x768 running
137
+ #
138
+ # tart version > 2.8
139
+ # OS CPU Memory Disk Size Display State
140
+ # darwin 4 8192 50 22.294 1024x768 stopped
141
+
142
+ # Read headers
143
+ headers = specs.split("\n")[0]
144
+ header_elements = headers.split(" ")
145
+ header_elements = [s.strip().lower() for s in header_elements if s]
135
146
 
136
- spec_line = specs.split("\n")[1]
137
- spec_elements = spec_line.split(" ")
147
+ spec = specs.split("\n")[1]
148
+ spec_elements = spec.split(" ")
138
149
  spec_elements = [s.strip() for s in spec_elements if s]
139
150
 
140
- # old version
141
- if len(spec_elements) == 5:
142
- spec = TartVmSpec(
143
- cpu_count=int(spec_elements[0]),
144
- memory=int(spec_elements[1]),
145
- disk=int(spec_elements[2]),
146
- display=spec_elements[3],
147
- running=True if spec_elements[4].lower() == "true" else False,
148
- ip_address="n/a",
149
- )
150
- elif len(spec_elements) == 6:
151
- spec = TartVmSpec(
152
- cpu_count=int(spec_elements[0]),
153
- memory=int(spec_elements[1]),
154
- disk=int(spec_elements[2]),
155
- display=spec_elements[4],
156
- running=True if spec_elements[5].lower() == "running" else False,
157
- ip_address="n/a",
158
- )
151
+ specs = {}
152
+ for i, spec_element in enumerate(spec_elements):
153
+ specs[header_elements[i]] = spec_element
154
+
155
+ # check the state of the machine
156
+ vm_state = specs.get("state", "n/a")
157
+ running = True
158
+ if vm_state == "running" or vm_state == "true":
159
+ running = True
159
160
  else:
160
- raise ValueError("cloud not determine vm specs")
161
+ running = False
162
+
163
+ vm_spec = TartVmSpec(
164
+ cpu_count=int(specs.get("cpu", 0)),
165
+ memory=int(specs.get("memory", 0)),
166
+ disk=int(specs.get("disk", 0)),
167
+ display=specs.get("display", "n/a"),
168
+ running=running,
169
+ ip_address="n/a",
170
+ os=specs.get("os", "n/a"),
171
+ size=specs.get("size", "n/a"),
172
+ )
161
173
 
162
- if spec.running:
163
- spec.ip_address = self.ip(name)
174
+ if vm_spec.running:
175
+ vm_spec.ip_address = self.ip(name)
164
176
 
165
- return spec
177
+ return vm_spec
166
178
 
167
179
  def print_spec(self, name, tablefmt="fancy_grid"):
168
180
  spec = self.get(name)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: gitlab-runner-tart-driver
3
- Version: 0.3.2
3
+ Version: 0.3.4
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
@@ -13,7 +13,7 @@ Requires-Python: >=3.9
13
13
  Description-Content-Type: text/markdown
14
14
  License-File: LICENSE.txt
15
15
  Requires-Dist: click
16
- Requires-Dist: pydantic >=2.0.0
16
+ Requires-Dist: pydantic>=2.0.0
17
17
  Requires-Dist: pydantic-settings
18
18
  Requires-Dist: paramiko
19
19
  Requires-Dist: psutil
@@ -1,20 +1,20 @@
1
- gitlab_runner_tart_driver/__init__.py,sha256=vNiWJ14r_cw5t_7UDqDQIVZvladKFGyHH2avsLpN7Vg,22
1
+ gitlab_runner_tart_driver/__init__.py,sha256=oYLGMpySamd16KLiaBTfRyrAS7_oyp-TOEHmzmeumwg,22
2
2
  gitlab_runner_tart_driver/__main__.py,sha256=FiyMv64vDC-R8i3CGEP9QP48djZFHm7utyChwZJWCeY,107
3
3
  gitlab_runner_tart_driver/cli.py,sha256=1eFi9m8L4zcBO5eE4g4EP8phtE1znF54qt-xAigPsOE,596
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=FCINFtBakV8hiKbHGba3ZWwyNwICp6UV5mKZVCyP8h4,10487
8
- gitlab_runner_tart_driver/commands/run.py,sha256=2grP79TARRL0xzmppRITbSpIH0WL4YPxlxq1fYQZxlM,2235
7
+ gitlab_runner_tart_driver/commands/prepare.py,sha256=zCfeqbmmDH0IxuFC9XqJ2uVWDuyJSzjq_uvBhfNX-og,10981
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
11
11
  gitlab_runner_tart_driver/modules/gitlab_custom_driver_config.py,sha256=ujxlzP1ZbfsZyLIsghID5c_jLPSt-1pDazE2B5CPORY,447
12
- gitlab_runner_tart_driver/modules/tart.py,sha256=bXwUTtR60oIdI_o-lDNakVQ_FL-12a6qykmeFlEl3VY,9677
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.2.dist-info/LICENSE.txt,sha256=TiYXQpEfbzcPBNGb7k1NslUngq_un-5cxGyT4W1S_f4,3303
16
- gitlab_runner_tart_driver-0.3.2.dist-info/METADATA,sha256=Ns7pOOlS-y1GeZlM0T6-Xf3jsX3F1hWNewRbRqOi0ek,20706
17
- gitlab_runner_tart_driver-0.3.2.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
18
- gitlab_runner_tart_driver-0.3.2.dist-info/entry_points.txt,sha256=xmvpGQf1wvFPy5wqDWXu8k5FD_k9KkCNCkpuworTsr0,82
19
- gitlab_runner_tart_driver-0.3.2.dist-info/top_level.txt,sha256=JjRzCs2sr24xG4SV_5tIBPpNC1Tec7I4AbK4IKMDqOc,26
20
- gitlab_runner_tart_driver-0.3.2.dist-info/RECORD,,
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,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.43.0)
2
+ Generator: bdist_wheel (0.45.1)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5