change SnapshotErrors for SnapshotsLog

This commit is contained in:
Cayo Puigdefabregas 2022-05-18 11:03:58 +02:00
parent d9e94e66d3
commit a7ceab2cde
6 changed files with 23 additions and 23 deletions

View File

@ -11,7 +11,7 @@ from werkzeug.exceptions import Unauthorized
from ereuse_devicehub.auth import Auth from ereuse_devicehub.auth import Auth
from ereuse_devicehub.db import db from ereuse_devicehub.db import db
from ereuse_devicehub.parser.models import SnapshotErrors from ereuse_devicehub.parser.models import SnapshotsLog
from ereuse_devicehub.parser.parser import ParseSnapshotLsHw from ereuse_devicehub.parser.parser import ParseSnapshotLsHw
from ereuse_devicehub.parser.schemas import Snapshot_lite from ereuse_devicehub.parser.schemas import Snapshot_lite
from ereuse_devicehub.resources.action.views.snapshot import ( from ereuse_devicehub.resources.action.views.snapshot import (
@ -80,7 +80,7 @@ class InventoryView(LoginMixin, SnapshotMixin):
txt = "{}".format(err) txt = "{}".format(err)
uuid = snapshot_json.get('uuid') uuid = snapshot_json.get('uuid')
sid = snapshot_json.get('sid') sid = snapshot_json.get('sid')
error = SnapshotErrors( error = SnapshotsLog(
description=txt, snapshot_uuid=uuid, severity=Severity.Error, sid=sid description=txt, snapshot_uuid=uuid, severity=Severity.Error, sid=sid
) )
error.save(commit=True) error.save(commit=True)

View File

@ -27,7 +27,7 @@ from wtforms import (
from wtforms.fields import FormField from wtforms.fields import FormField
from ereuse_devicehub.db import db from ereuse_devicehub.db import db
from ereuse_devicehub.parser.models import SnapshotErrors from ereuse_devicehub.parser.models import SnapshotsLog
from ereuse_devicehub.parser.parser import ParseSnapshotLsHw from ereuse_devicehub.parser.parser import ParseSnapshotLsHw
from ereuse_devicehub.parser.schemas import Snapshot_lite from ereuse_devicehub.parser.schemas import Snapshot_lite
from ereuse_devicehub.resources.action.models import Snapshot, Trade from ereuse_devicehub.resources.action.models import Snapshot, Trade
@ -250,7 +250,7 @@ class UploadSnapshotForm(SnapshotMixin, FlaskForm):
txt = "{}".format(err) txt = "{}".format(err)
uuid = snapshot_json.get('uuid') uuid = snapshot_json.get('uuid')
sid = snapshot_json.get('sid') sid = snapshot_json.get('sid')
error = SnapshotErrors( error = SnapshotsLog(
description=txt, description=txt,
snapshot_uuid=uuid, snapshot_uuid=uuid,
severity=Severity.Error, severity=Severity.Error,

View File

@ -14,7 +14,7 @@ from ereuse_utils.nested_lookup import (
) )
from ereuse_devicehub.parser import base2, unit, utils from ereuse_devicehub.parser import base2, unit, utils
from ereuse_devicehub.parser.models import SnapshotErrors from ereuse_devicehub.parser.models import SnapshotsLog
from ereuse_devicehub.parser.utils import Dumpeable from ereuse_devicehub.parser.utils import Dumpeable
from ereuse_devicehub.resources.enums import Severity from ereuse_devicehub.resources.enums import Severity
@ -457,7 +457,7 @@ class Computer(Device):
return return
logger.error(txt) logger.error(txt)
error = SnapshotErrors( error = SnapshotsLog(
description=txt, snapshot_uuid=uuid, severity=severity, sid=sid description=txt, snapshot_uuid=uuid, severity=severity, sid=sid
) )
error.save() error.save()

View File

@ -8,7 +8,7 @@ from marshmallow.exceptions import ValidationError
from ereuse_devicehub.parser import base2 from ereuse_devicehub.parser import base2
from ereuse_devicehub.parser.computer import Computer from ereuse_devicehub.parser.computer import Computer
from ereuse_devicehub.parser.models import SnapshotErrors from ereuse_devicehub.parser.models import SnapshotsLog
from ereuse_devicehub.resources.action.schemas import Snapshot from ereuse_devicehub.resources.action.schemas import Snapshot
from ereuse_devicehub.resources.enums import DataStorageInterface, Severity from ereuse_devicehub.resources.enums import DataStorageInterface, Severity
@ -552,7 +552,7 @@ class ParseSnapshotLsHw:
logger.error(txt) logger.error(txt)
self._errors.append(txt) self._errors.append(txt)
error = SnapshotErrors( error = SnapshotsLog(
description=txt, snapshot_uuid=self.uuid, severity=severity, sid=self.sid description=txt, snapshot_uuid=self.uuid, severity=severity, sid=self.sid
) )
error.save() error.save()

View File

@ -11,7 +11,7 @@ from marshmallow import ValidationError
from sqlalchemy.util import OrderedSet from sqlalchemy.util import OrderedSet
from ereuse_devicehub.db import db from ereuse_devicehub.db import db
from ereuse_devicehub.parser.models import SnapshotErrors from ereuse_devicehub.parser.models import SnapshotsLog
from ereuse_devicehub.resources.action.models import Snapshot from ereuse_devicehub.resources.action.models import Snapshot
from ereuse_devicehub.resources.device.models import Computer from ereuse_devicehub.resources.device.models import Computer
from ereuse_devicehub.resources.device.sync import Sync from ereuse_devicehub.resources.device.sync import Sync
@ -140,7 +140,7 @@ class SnapshotView(SnapshotMixin):
except ValidationError as err: except ValidationError as err:
txt = "{}".format(err) txt = "{}".format(err)
uuid = snapshot_json.get('uuid') uuid = snapshot_json.get('uuid')
error = SnapshotErrors( error = SnapshotsLog(
description=txt, snapshot_uuid=uuid, severity=Severity.Error description=txt, snapshot_uuid=uuid, severity=Severity.Error
) )
error.save(commit=True) error.save(commit=True)

View File

@ -15,10 +15,10 @@ from requests.exceptions import HTTPError
from teal.db import DBError, UniqueViolation from teal.db import DBError, UniqueViolation
from teal.marshmallow import ValidationError from teal.marshmallow import ValidationError
from ereuse_devicehub.client import UserClient, Client from ereuse_devicehub.client import Client, UserClient
from ereuse_devicehub.db import db from ereuse_devicehub.db import db
from ereuse_devicehub.devicehub import Devicehub from ereuse_devicehub.devicehub import Devicehub
from ereuse_devicehub.parser.models import SnapshotErrors from ereuse_devicehub.parser.models import SnapshotsLog
from ereuse_devicehub.resources.action.models import ( from ereuse_devicehub.resources.action.models import (
Action, Action,
BenchmarkDataStorage, BenchmarkDataStorage,
@ -977,7 +977,7 @@ def test_snapshot_wb_lite(user: UserClient):
assert '00:28:f8:a6:d5:7e' in dev.hid assert '00:28:f8:a6:d5:7e' in dev.hid
assert dev.actions[0].power_on_hours == 6032 assert dev.actions[0].power_on_hours == 6032
errors = SnapshotErrors.query.filter().all() errors = SnapshotsLog.query.filter().all()
assert errors == [] assert errors == []
@ -986,9 +986,7 @@ def test_snapshot_wb_lite(user: UserClient):
def test_snapshot_wb_lite_qemu(user: UserClient): def test_snapshot_wb_lite_qemu(user: UserClient):
"""This test check the minimum validation of json that come from snapshot""" """This test check the minimum validation of json that come from snapshot"""
snapshot = file_json( snapshot = file_json("qemu-cc9927a9-55ad-4937-b36b-7185147d9fa9.json")
"qemu-cc9927a9-55ad-4937-b36b-7185147d9fa9.json"
)
body, res = user.post(snapshot, uri="/api/inventory/") body, res = user.post(snapshot, uri="/api/inventory/")
assert body['sid'] == "VL0L5" assert body['sid'] == "VL0L5"
@ -1172,7 +1170,7 @@ def test_snapshot_lite_error_in_components(user: UserClient):
dev = m.Device.query.filter_by(devicehub_id=bodyLite['dhid']).one() dev = m.Device.query.filter_by(devicehub_id=bodyLite['dhid']).one()
assert 'Motherboard' not in [x.type for x in dev.components] assert 'Motherboard' not in [x.type for x in dev.components]
error = SnapshotErrors.query.all()[0] error = SnapshotsLog.query.all()[0]
assert 'StopIteration' in error.description assert 'StopIteration' in error.description
@ -1225,12 +1223,12 @@ def test_snapshot_errors(user: UserClient):
}, },
} }
assert SnapshotErrors.query.all() == [] assert SnapshotsLog.query.all() == []
body11, res = user.post(snapshot_11, res=Snapshot) body11, res = user.post(snapshot_11, res=Snapshot)
assert SnapshotErrors.query.all() == [] assert SnapshotsLog.query.all() == []
bodyLite, res = user.post(snapshot_lite, uri="/api/inventory/") bodyLite, res = user.post(snapshot_lite, uri="/api/inventory/")
dev = m.Device.query.filter_by(devicehub_id=bodyLite['dhid']).one() dev = m.Device.query.filter_by(devicehub_id=bodyLite['dhid']).one()
assert len(SnapshotErrors.query.all()) == 2 assert len(SnapshotsLog.query.all()) == 2
assert body11['device'].get('hid') == dev.hid assert body11['device'].get('hid') == dev.hid
assert body11['device']['id'] == dev.id assert body11['device']['id'] == dev.id
@ -1267,7 +1265,7 @@ def test_snapshot_errors_no_serial_number(user: UserClient):
bodyLite, res = user.post(snapshot_lite, uri="/api/inventory/") bodyLite, res = user.post(snapshot_lite, uri="/api/inventory/")
assert res.status_code == 201 assert res.status_code == 201
assert len(SnapshotErrors.query.all()) == 0 assert len(SnapshotsLog.query.all()) == 0
dev = m.Device.query.filter_by(devicehub_id=bodyLite['dhid']).one() dev = m.Device.query.filter_by(devicehub_id=bodyLite['dhid']).one()
assert not dev.model assert not dev.model
assert not dev.manufacturer assert not dev.manufacturer
@ -1286,9 +1284,11 @@ def test_snapshot_errors_no_serial_number(user: UserClient):
@pytest.mark.usefixtures(conftest.app_context.__name__) @pytest.mark.usefixtures(conftest.app_context.__name__)
def test_snapshot_check_tests_lite(user: UserClient): def test_snapshot_check_tests_lite(user: UserClient):
"""This test check the minimum validation of json that come from snapshot""" """This test check the minimum validation of json that come from snapshot"""
snapshot_lite = file_json('test_lite/2022-4-13-19-5_user@dhub.com_b27dbf43-b88a-4505-ae27-10de5a95919e.json') snapshot_lite = file_json(
'test_lite/2022-4-13-19-5_user@dhub.com_b27dbf43-b88a-4505-ae27-10de5a95919e.json'
)
bodyLite, res = user.post(snapshot_lite, uri="/api/inventory/") bodyLite, res = user.post(snapshot_lite, uri="/api/inventory/")
assert res.status_code == 201 assert res.status_code == 201
SnapshotErrors.query.all() SnapshotsLog.query.all()
dev = m.Device.query.filter_by(devicehub_id=bodyLite['dhid']).one() dev = m.Device.query.filter_by(devicehub_id=bodyLite['dhid']).one()