add wbid and owner in snapshot_errors

This commit is contained in:
Cayo Puigdefabregas 2022-04-12 10:24:32 +02:00
parent e37e3b4c12
commit b9a04b59f5
2 changed files with 23 additions and 9 deletions

View file

@ -1,10 +1,12 @@
from citext import CIText
from flask import g
from sqlalchemy import BigInteger, Column, Sequence, SmallInteger
from sqlalchemy.dialects.postgresql import UUID
from ereuse_devicehub.db import db
from ereuse_devicehub.resources.enums import Severity
from ereuse_devicehub.resources.models import Thing
from ereuse_devicehub.resources.user.models import User
class SnapshotErrors(Thing):
@ -12,8 +14,16 @@ class SnapshotErrors(Thing):
id = Column(BigInteger, Sequence('snapshot_errors_seq'), primary_key=True)
description = Column(CIText(), default='', nullable=False)
wbid = Column(CIText(), nullable=True)
severity = Column(SmallInteger, default=Severity.Info, nullable=False)
snapshot_uuid = Column(UUID(as_uuid=True), nullable=False)
owner_id = db.Column(
UUID(as_uuid=True),
db.ForeignKey(User.id),
nullable=False,
default=lambda: g.user.id,
)
owner = db.relationship(User, primaryjoin=owner_id == User.id)
def save(self, commit=False):
db.session.add(self)

View file

@ -314,6 +314,7 @@ class ParseSnapshotLsHw:
def __init__(self, snapshot, default="n/a"):
self.default = default
self.uuid = snapshot.get("uuid")
self.wbid = snapshot.get("wbid")
self.dmidecode_raw = snapshot["data"]["dmidecode"]
self.smart = snapshot["data"]["smart"]
self.hwinfo_raw = snapshot["data"]["hwinfo"]
@ -347,8 +348,9 @@ class ParseSnapshotLsHw:
except ValidationError as err:
txt = "{}".format(err)
uuid = self.snapshot_json.get('uuid')
wbid = self.snapshot_json.get('wbid')
error = SnapshotErrors(
description=txt, snapshot_uuid=uuid, severity=Severity.Error
description=txt, snapshot_uuid=uuid, severity=Severity.Error, wbid=wbid
)
error.save(commit=True)
raise err
@ -403,8 +405,8 @@ class ParseSnapshotLsHw:
def get_ram_size(self, ram):
size = ram.get("Size")
if not len(size.split(" ")) == 2:
txt = "Error: Snapshot: {uuid} have this ram Size: {size}".format(
uuid=self.uuid, size=size
txt = "Error: Snapshot: {uuid}, tag: {wbid} have this ram Size: {size}".format(
uuid=self.uuid, size=size, wbid=self.wbid
)
self.errors(txt)
return 128
@ -414,8 +416,8 @@ class ParseSnapshotLsHw:
def get_ram_speed(self, ram):
speed = ram.get("Speed", "100")
if not len(speed.split(" ")) == 2:
txt = "Error: Snapshot: {uuid} have this ram Speed: {speed}".format(
uuid=self.uuid, speed=speed
txt = "Error: Snapshot: {uuid}, tag: {wbid} have this ram Speed: {speed}".format(
uuid=self.uuid, speed=speed, wbid=self.wbid
)
self.errors(txt)
return 100
@ -449,8 +451,8 @@ class ParseSnapshotLsHw:
uuid.UUID(dmi_uuid)
except (ValueError, AttributeError) as err:
self.errors("{}".format(err))
txt = "Error: Snapshot: {uuid} have this uuid: {device}".format(
uuid=self.uuid, device=dmi_uuid
txt = "Error: Snapshot: {uuid} tag: {wbid} have this uuid: {device}".format(
uuid=self.uuid, device=dmi_uuid, wbid=self.wbid
)
self.errors(txt)
dmi_uuid = None
@ -493,7 +495,9 @@ class ParseSnapshotLsHw:
try:
DataStorageInterface(interface.upper())
except ValueError as err:
txt = "interface {} is not in DataStorageInterface Enum".format(interface)
txt = "tag: {}, interface {} is not in DataStorageInterface Enum".format(
interface, self.wbid
)
self.errors("{}".format(err))
self.errors(txt)
return "ATA"
@ -539,6 +543,6 @@ class ParseSnapshotLsHw:
logger.error(txt)
self._errors.append(txt)
error = SnapshotErrors(
description=txt, snapshot_uuid=self.uuid, severity=severity
description=txt, snapshot_uuid=self.uuid, severity=severity, wbid=self.wbid
)
error.save()