Merge pull request #291 from eReuse/feature/3462-snapshotlog-old-api
add snapshotLog in old api
This commit is contained in:
commit
d7023a9496
|
@ -129,6 +129,8 @@ class SnapshotView(SnapshotMixin):
|
|||
# snapshot, and we want to wait to flush snapshot at the end
|
||||
|
||||
def __init__(self, snapshot_json: dict, resource_def, schema):
|
||||
from ereuse_devicehub.parser.models import SnapshotsLog
|
||||
|
||||
self.schema = schema
|
||||
self.resource_def = resource_def
|
||||
self.tmp_snapshots = app.config['TMP_SNAPSHOTS']
|
||||
|
@ -136,18 +138,29 @@ class SnapshotView(SnapshotMixin):
|
|||
snapshot_json.pop('debug', None)
|
||||
try:
|
||||
self.snapshot_json = resource_def.schema.load(snapshot_json)
|
||||
except ValidationError as err:
|
||||
from ereuse_devicehub.parser.models import SnapshotsLog
|
||||
snapshot = self.build()
|
||||
except Exception as err:
|
||||
txt = "{}".format(err)
|
||||
uuid = snapshot_json.get('uuid')
|
||||
version = snapshot_json.get('version')
|
||||
error = SnapshotsLog(
|
||||
description=txt, snapshot_uuid=uuid, severity=Severity.Error
|
||||
description=txt,
|
||||
snapshot_uuid=uuid,
|
||||
severity=Severity.Error,
|
||||
version=str(version),
|
||||
)
|
||||
error.save(commit=True)
|
||||
raise err
|
||||
|
||||
snapshot = self.build()
|
||||
db.session.add(snapshot)
|
||||
snap_log = SnapshotsLog(
|
||||
description='Ok',
|
||||
snapshot_uuid=snapshot.uuid,
|
||||
severity=Severity.Info,
|
||||
version=str(snapshot.version),
|
||||
snapshot=snapshot,
|
||||
)
|
||||
snap_log.save()
|
||||
db.session().final_flush()
|
||||
self.response = self.schema.jsonify(snapshot) # transform it back
|
||||
self.response.status_code = 201
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
<th scope="col">SID</th>
|
||||
<th scope="col">Snapshot id</th>
|
||||
<th scope="col">Version</th>
|
||||
<th scope="col">Device</th>
|
||||
<th scope="col">DHID</th>
|
||||
<th scope="col">Status</th>
|
||||
<th scope="col" data-type="date" data-format="DD-MM-YYYY">Time</th>
|
||||
</tr>
|
||||
|
|
|
@ -189,6 +189,12 @@ def test_snapshot_power_on_hours(user: UserClient):
|
|||
== test_data_storage.power_on_hours
|
||||
)
|
||||
|
||||
errors = SnapshotsLog.query.filter().all()
|
||||
snap_log = errors[0]
|
||||
assert str(snap_log.snapshot.uuid) == snap['uuid']
|
||||
assert len(errors) == 1
|
||||
assert errors[0].description == 'Ok'
|
||||
|
||||
|
||||
@pytest.mark.mvp
|
||||
def test_snapshot_component_add_remove(user: UserClient):
|
||||
|
@ -765,6 +771,7 @@ def test_save_snapshot_with_debug(app: Devicehub, user: UserClient):
|
|||
|
||||
|
||||
@pytest.mark.mvp
|
||||
@pytest.mark.usefixtures(conftest.app_context.__name__)
|
||||
def test_backup_snapshot_with_errors(app: Devicehub, user: UserClient):
|
||||
"""This test check if the file snapshot is create when some snapshot is wrong"""
|
||||
tmp_snapshots = app.config['TMP_SNAPSHOTS']
|
||||
|
@ -776,6 +783,13 @@ def test_backup_snapshot_with_errors(app: Devicehub, user: UserClient):
|
|||
with pytest.raises(KeyError):
|
||||
response = user.post(res=Snapshot, data=json_encode(snapshot_no_hid))
|
||||
|
||||
errors = SnapshotsLog.query.filter().all()
|
||||
snap_log = errors[0]
|
||||
assert snap_log.description == "'BenchmarkProcessorr'"
|
||||
assert snap_log.version == "11.0b9"
|
||||
assert str(snap_log.snapshot_uuid) == '9a3e7485-fdd0-47ce-bcc7-65c55226b598'
|
||||
assert len(errors) == 1
|
||||
|
||||
files = [x for x in os.listdir(path_dir_base) if uuid in x]
|
||||
if files:
|
||||
path_snapshot = os.path.join(path_dir_base, files[0])
|
||||
|
|
Reference in a new issue