Skip to content

Commit 0b706a5

Browse files
committed
Bug fixes and add missing uploaded=True to artifact upload
1 parent 1690279 commit 0b706a5

File tree

4 files changed

+55
-26
lines changed

4 files changed

+55
-26
lines changed

simvue/api/objects/artifact.py

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -248,28 +248,42 @@ def _upload(self, file: io.BytesIO) -> None:
248248
super().commit()
249249
return
250250

251-
if _url := self._init_data.get("url"):
252-
_name = self._staging["name"]
253-
254-
_response = sv_post(
255-
url=_url,
256-
headers={},
257-
is_json=False,
258-
files={"file": file},
259-
data=self._init_data.get("fields"),
260-
)
251+
if not (_url := self._init_data.get("url")):
252+
return
261253

262-
self._logger.debug(
263-
"Got status code %d when uploading artifact",
264-
_response.status_code,
265-
)
254+
_name = self._staging["name"]
266255

267-
get_json_from_response(
268-
expected_status=[http.HTTPStatus.OK, http.HTTPStatus.NO_CONTENT],
269-
allow_parse_failure=True, # JSON response from S3 not parsible
270-
scenario=f"uploading artifact '{_name}' to object storage",
271-
response=_response,
272-
)
256+
_response = sv_post(
257+
url=_url,
258+
headers={},
259+
is_json=False,
260+
files={"file": file},
261+
data=self._init_data.get("fields"),
262+
)
263+
264+
self._logger.debug(
265+
"Got status code %d when uploading artifact",
266+
_response.status_code,
267+
)
268+
269+
get_json_from_response(
270+
expected_status=[http.HTTPStatus.OK, http.HTTPStatus.NO_CONTENT],
271+
allow_parse_failure=True, # JSON response from S3 not parsible
272+
scenario=f"uploading artifact '{_name}' to object storage",
273+
response=_response,
274+
)
275+
276+
_response = sv_put(
277+
url=f"{self.url}",
278+
data={"uploaded": True},
279+
headers=self._headers,
280+
)
281+
282+
get_json_from_response(
283+
response=_response,
284+
scenario=f"Information server of upload of file for artifact '{self._identifier}'",
285+
expected_status=[http.HTTPStatus.OK],
286+
)
273287

274288
def _get(
275289
self, storage: str | None = None, url: str | None = None, **kwargs

simvue/api/objects/storage/base.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
import pydantic
1111
import datetime
12-
import abc
1312

1413
from simvue.api.objects.base import SimvueObject, staging_check, write_only
1514
from simvue.models import NAME_REGEX, DATETIME_FORMAT
@@ -34,7 +33,6 @@ def __init__(
3433
super().__init__(identifier, _read_only=_read_only, **kwargs)
3534

3635
@classmethod
37-
@abc.abstractmethod
3836
def new(cls, **kwargs):
3937
"""Create a new instance of a storage type"""
4038
pass

simvue/api/objects/storage/fetch.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
with an identifier, use a generic storage object.
77
"""
88

9+
import abc
910
import typing
1011
import http
1112
import pydantic
@@ -31,6 +32,11 @@ def __new__(cls, identifier: str | None = None, **kwargs):
3132

3233
raise RuntimeError(f"Unknown backend '{_storage_pre.backend}'")
3334

35+
@classmethod
36+
@abc.abstractmethod
37+
def new(cls, **_) -> typing.Self:
38+
pass
39+
3440
@classmethod
3541
@pydantic.validate_call
3642
def get(

tests/conftest.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,11 @@ def log_messages(caplog):
5757
@pytest.fixture
5858
def create_test_run(request) -> typing.Generator[typing.Tuple[sv_run.Run, dict], None, None]:
5959
with sv_run.Run() as run:
60-
yield run, setup_test_run(run, True, request)
60+
_test_run_data = setup_test_run(run, True, request)
61+
yield run, _test_run_data
62+
sv_api_obj.Folder(identifier=run._folder.id).delete(recursive=True, delete_runs=True, runs_only=False)
63+
for alert_id in _test_run_data.get("alert_ids", []):
64+
sv_api_obj.Alert(identifier=alert_id).delete()
6165
clear_out_files()
6266

6367

@@ -134,29 +138,33 @@ def setup_test_run(run: sv_run.Run, create_objects: bool, request: pytest.Fixtur
134138
if run._dispatcher:
135139
run._dispatcher._max_buffer_size = MAX_BUFFER_SIZE
136140

141+
_alert_ids = []
142+
137143
if create_objects:
138144
for i in range(5):
139145
run.log_event(f"{TEST_DATA['event_contains']} {i}")
140146

141147
TEST_DATA['created_alerts'] = []
142148

149+
143150
for i in range(5):
144-
run.create_event_alert(
151+
_aid = run.create_event_alert(
145152
name=f"test_alert/alert_{i}/{fix_use_id}",
146153
frequency=1,
147154
pattern=TEST_DATA['event_contains']
148155
)
149156
TEST_DATA['created_alerts'].append(f"test_alert/alert_{i}/{fix_use_id}")
157+
_alert_ids.append(_aid)
150158

151-
run.create_metric_threshold_alert(
159+
_ta_id = run.create_metric_threshold_alert(
152160
name=f'test_alert/value_below_1/{fix_use_id}',
153161
frequency=1,
154162
rule='is below',
155163
threshold=1,
156164
metric='metric_counter',
157165
window=2
158166
)
159-
run.create_metric_range_alert(
167+
_mr_id = run.create_metric_range_alert(
160168
name=f'test_alert/value_within_1/{fix_use_id}',
161169
frequency=1,
162170
rule = "is inside range",
@@ -165,6 +173,7 @@ def setup_test_run(run: sv_run.Run, create_objects: bool, request: pytest.Fixtur
165173
metric='metric_counter',
166174
window=2
167175
)
176+
_alert_ids += [_ta_id, _mr_id]
168177
TEST_DATA['created_alerts'] += [
169178
f"test_alert/value_below_1/{fix_use_id}",
170179
f"test_alert/value_within_1/{fix_use_id}"
@@ -204,6 +213,8 @@ def setup_test_run(run: sv_run.Run, create_objects: bool, request: pytest.Fixtur
204213
run.save_file(test_script, category="code", name="test_code_upload")
205214
TEST_DATA["file_3"] = "test_code_upload"
206215

216+
TEST_DATA["alert_ids"] = _alert_ids
217+
207218
return TEST_DATA
208219

209220

0 commit comments

Comments
 (0)