From e009bf4bc13abcaadce4f99898621581eb7231dd Mon Sep 17 00:00:00 2001 From: Xavier Bustamante Talavera Date: Thu, 8 Nov 2018 17:37:14 +0100 Subject: [PATCH] Change Event.error/incidence for Event.severity --- .../files/dell-optiplexgx520.snapshot.11.yaml | 8 +- .../dummy/files/hp1.snapshot.11.yaml | 8 +- .../dummy/files/hp2.snapshot.11.yaml | 14 +- .../files/lenovo-3493BAG.snapshot.11.yaml | 8 +- .../dummy/files/nec.snapshot.11.yaml | 8 +- .../dummy/files/oreo.snapshot.yaml | 276 +++++++++--------- .../dummy/files/pc-laudem.snapshot.11.yaml | 4 +- .../files/real-eee-1001pxd.snapshot.11.yaml | 8 +- .../files/real-hp-quad-core.snapshot.11.yaml | 2 +- .../dummy/files/real-hp.snapshot.11.yaml | 4 +- .../dummy/files/real-toshiba.snapshot.11.yaml | 4 +- .../dummy/files/smart.snapshot.11.yaml | 4 +- .../files/workbench-server-1.snapshot.yaml | 2 +- ereuse_devicehub/resources/enums.py | 40 ++- ereuse_devicehub/resources/event/models.py | 65 ++--- ereuse_devicehub/resources/event/models.pyi | 44 ++- ereuse_devicehub/resources/event/schemas.py | 7 +- tests/files/erase-sectors-2-hdd.snapshot.yaml | 12 +- tests/files/erase-sectors.snapshot.yaml | 4 +- tests/files/real-custom.snapshot.11.yaml | 4 +- tests/files/workbench-10.snapshot.yaml | 58 ++-- .../files/workbench-server-2.stress-test.yaml | 4 +- tests/files/workbench-server-3.erase.yaml | 4 +- tests/files/workbench-server-4.install.yaml | 4 +- tests/test_device.py | 6 +- tests/test_event.py | 4 +- tests/test_snapshot.py | 7 +- tests/test_workbench.py | 8 +- 28 files changed, 319 insertions(+), 302 deletions(-) diff --git a/ereuse_devicehub/dummy/files/dell-optiplexgx520.snapshot.11.yaml b/ereuse_devicehub/dummy/files/dell-optiplexgx520.snapshot.11.yaml index 756e065a..74bbfb97 100644 --- a/ereuse_devicehub/dummy/files/dell-optiplexgx520.snapshot.11.yaml +++ b/ereuse_devicehub/dummy/files/dell-optiplexgx520.snapshot.11.yaml @@ -9,7 +9,7 @@ "elapsed": 2 }, { - "error": false, + "severity": "Info", "type": "StressTest", "elapsed": 60 }, @@ -91,14 +91,14 @@ { "steps": [ { - "error": false, + "severity": "Info", "type": "StepRandom", "startTime": "2018-07-11T11:20:01.005336", "endTime": "2018-07-11T11:42:12.971177" } ], "zeros": false, - "error": false, + "severity": "Info", "type": "EraseBasic", "endTime": "2018-07-11T11:42:12.975358", "startTime": "2018-07-11T11:20:01.004892" @@ -111,7 +111,7 @@ }, { "length": "Short", - "error": true, + "severity": "Error", "type": "TestDataStorage", "status": "Unspecified Error. Self-test not started.", "elapsed": 0 diff --git a/ereuse_devicehub/dummy/files/hp1.snapshot.11.yaml b/ereuse_devicehub/dummy/files/hp1.snapshot.11.yaml index e622d238..87a7f348 100644 --- a/ereuse_devicehub/dummy/files/hp1.snapshot.11.yaml +++ b/ereuse_devicehub/dummy/files/hp1.snapshot.11.yaml @@ -74,13 +74,13 @@ "type": "EraseBasic", "zeros": false, "endTime": "2018-07-11T11:56:52.390306", - "error": false, + "severity": "Info", "startTime": "2018-07-11T10:49:31.998217", "steps": [ { "type": "StepRandom", "endTime": "2018-07-11T11:56:52.386505", - "error": false, + "severity": "Info", "startTime": "2018-07-11T10:49:31.998609" } ] @@ -89,7 +89,7 @@ "length": "Short", "type": "TestDataStorage", "status": "Unspecified Error. Self-test not started.", - "error": true, + "severity": "Error", "elapsed": 0 }, { @@ -130,7 +130,7 @@ }, { "type": "StressTest", - "error": false, + "severity": "Info", "elapsed": 60 } ], diff --git a/ereuse_devicehub/dummy/files/hp2.snapshot.11.yaml b/ereuse_devicehub/dummy/files/hp2.snapshot.11.yaml index eaf9e783..aa456507 100644 --- a/ereuse_devicehub/dummy/files/hp2.snapshot.11.yaml +++ b/ereuse_devicehub/dummy/files/hp2.snapshot.11.yaml @@ -69,7 +69,7 @@ { "elapsed": 1, "type": "TestDataStorage", - "error": true, + "severity": "Error", "status": "Unspecified Error. Self-test not started.", "length": "Short" }, @@ -83,13 +83,13 @@ "startTime": "2018-07-11T10:32:14.445306", "zeros": false, "type": "EraseBasic", - "error": false, + "severity": "Info", "endTime": "2018-07-11T10:53:46.442123", "steps": [ { "startTime": "2018-07-11T10:32:14.445496", "type": "StepRandom", - "error": false, + "severity": "Info", "endTime": "2018-07-11T10:53:46.438901" } ] @@ -107,7 +107,7 @@ { "elapsed": 0, "type": "TestDataStorage", - "error": true, + "severity": "Error", "status": "Unspecified Error. Self-test not started.", "length": "Short" }, @@ -115,13 +115,13 @@ "startTime": "2018-07-11T10:53:46.442187", "zeros": false, "type": "EraseBasic", - "error": false, + "severity": "Info", "endTime": "2018-07-11T11:16:28.469899", "steps": [ { "startTime": "2018-07-11T10:53:46.442343", "type": "StepRandom", - "error": false, + "severity": "Info", "endTime": "2018-07-11T11:16:28.463789" } ] @@ -157,7 +157,7 @@ "chassis": "Tower", "events": [ { - "error": false, + "severity": "Info", "elapsed": 60, "type": "StressTest" }, diff --git a/ereuse_devicehub/dummy/files/lenovo-3493BAG.snapshot.11.yaml b/ereuse_devicehub/dummy/files/lenovo-3493BAG.snapshot.11.yaml index eb1c6e05..cd3e4ae4 100644 --- a/ereuse_devicehub/dummy/files/lenovo-3493BAG.snapshot.11.yaml +++ b/ereuse_devicehub/dummy/files/lenovo-3493BAG.snapshot.11.yaml @@ -10,7 +10,7 @@ { "elapsed": 60, "type": "StressTest", - "error": false + "severity": "Info" }, { "elapsed": 1, @@ -92,7 +92,7 @@ "elapsed": 15 }, { - "error": true, + "severity": "Error", "type": "TestDataStorage", "elapsed": 0, "length": "Short", @@ -102,13 +102,13 @@ "startTime": "2018-07-11T13:28:07.319948", "type": "EraseBasic", "endTime": "2018-07-11T14:04:04.864425", - "error": false, + "severity": "Info", "steps": [ { "startTime": "2018-07-11T13:28:07.320244", "type": "StepRandom", "endTime": "2018-07-11T14:04:04.861590", - "error": false + "severity": "Info" } ], "zeros": false diff --git a/ereuse_devicehub/dummy/files/nec.snapshot.11.yaml b/ereuse_devicehub/dummy/files/nec.snapshot.11.yaml index 3ad7629f..c7cabd57 100644 --- a/ereuse_devicehub/dummy/files/nec.snapshot.11.yaml +++ b/ereuse_devicehub/dummy/files/nec.snapshot.11.yaml @@ -6,7 +6,7 @@ "manufacturer": "NEC Computers SAS", "events": [ { - "error": false, + "severity": "Info", "elapsed": 60, "type": "StressTest" }, @@ -101,7 +101,7 @@ "size": 305245, "events": [ { - "error": false, + "severity": "Info", "endTime": "2018-07-11T11:33:41.531918", "startTime": "2018-07-11T10:30:35.643855", "zeros": false, @@ -111,7 +111,7 @@ "type": "StepRandom", "endTime": "2018-07-11T11:33:41.529224", "startTime": "2018-07-11T10:30:35.644043", - "error": false + "severity": "Info" } ] }, @@ -125,7 +125,7 @@ "type": "TestDataStorage", "length": "Short", "elapsed": 1, - "error": true, + "severity": "Error", "status": "Unspecified Error. Self-test not started." } ], diff --git a/ereuse_devicehub/dummy/files/oreo.snapshot.yaml b/ereuse_devicehub/dummy/files/oreo.snapshot.yaml index 29443538..c728a881 100644 --- a/ereuse_devicehub/dummy/files/oreo.snapshot.yaml +++ b/ereuse_devicehub/dummy/files/oreo.snapshot.yaml @@ -2,137 +2,137 @@ "uuid": "de4f495e-c58b-40e1-a33e-46ab5e84767e", "endTime": "2018-10-24T11:03:36.113006+00:00", "components": [ + { + "speed": 1000, + "manufacturer": "Realtek Semiconductor Co., Ltd.", + "wireless": false, + "model": "RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller", + "serialNumber": "00:26:18:96:dc:af", + "type": "NetworkAdapter", + "events": [] + }, + { + "speed": 1333.0, + "manufacturer": null, + "interface": "DDR", + "model": null, + "serialNumber": null, + "type": "RamModule", + "format": "DIMM", + "size": 2048, + "events": [] + }, + { + "speed": 1333.0, + "manufacturer": null, + "interface": "DDR", + "model": null, + "serialNumber": null, + "type": "RamModule", + "format": "DIMM", + "size": 2048, + "events": [] + }, + { + "speed": 1333.0, + "manufacturer": null, + "interface": "DDR", + "model": null, + "serialNumber": null, + "type": "RamModule", + "format": "DIMM", + "size": 2048, + "events": [] + }, + { + "speed": 1333.0, + "manufacturer": null, + "interface": "DDR", + "model": null, + "serialNumber": null, + "type": "RamModule", + "format": "DIMM", + "size": 2048, + "events": [] + }, + { + "manufacturer": "Intel Corporation", + "model": "5 Series/3400 Series Chipset High Definition Audio", + "serialNumber": null, + "type": "SoundCard", + "events": [] + }, + { + "speed": 2.5330000000000004, + "manufacturer": "Intel Corp.", + "cores": 4, + "address": 64, + "model": "Intel Core i7 CPU 860 @ 2.80GHz", + "serialNumber": null, + "type": "Processor", + "threads": 8, + "events": [ { - "speed": 1000, - "manufacturer": "Realtek Semiconductor Co., Ltd.", - "wireless": false, - "model": "RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller", - "serialNumber": "00:26:18:96:dc:af", - "type": "NetworkAdapter", - "events": [] + "elapsed": 9, + "type": "BenchmarkProcessorSysbench", + "rate": 8.7418 }, { - "speed": 1333.0, - "manufacturer": null, - "interface": "DDR", - "model": null, - "serialNumber": null, - "type": "RamModule", - "format": "DIMM", - "size": 2048, - "events": [] - }, - { - "speed": 1333.0, - "manufacturer": null, - "interface": "DDR", - "model": null, - "serialNumber": null, - "type": "RamModule", - "format": "DIMM", - "size": 2048, - "events": [] - }, - { - "speed": 1333.0, - "manufacturer": null, - "interface": "DDR", - "model": null, - "serialNumber": null, - "type": "RamModule", - "format": "DIMM", - "size": 2048, - "events": [] - }, - { - "speed": 1333.0, - "manufacturer": null, - "interface": "DDR", - "model": null, - "serialNumber": null, - "type": "RamModule", - "format": "DIMM", - "size": 2048, - "events": [] - }, - { - "manufacturer": "Intel Corporation", - "model": "5 Series/3400 Series Chipset High Definition Audio", - "serialNumber": null, - "type": "SoundCard", - "events": [] - }, - { - "speed": 2.5330000000000004, - "manufacturer": "Intel Corp.", - "cores": 4, - "address": 64, - "model": "Intel Core i7 CPU 860 @ 2.80GHz", - "serialNumber": null, - "type": "Processor", - "threads": 8, - "events": [ - { - "elapsed": 9, - "type": "BenchmarkProcessorSysbench", - "rate": 8.7418 - }, - { - "elapsed": 0, - "type": "BenchmarkProcessor", - "rate": 44937.520000000004 - } - ] - }, - { - "manufacturer": null, - "interface": "ATA", - "model": "SAMSUNG HD103SJ", - "serialNumber": "S246J90Z406422", - "type": "HardDrive", - "size": 953869, - "events": [ - { - "elapsed": 120, - "lifetime": 14298, - "currentPendingSectorCount": 0, - "type": "TestDataStorage", - "status": "Completed without error", - "powerCycleCount": 693, - "assessment": true, - "offlineUncorrectable": 0, - "error": false, - "length": "Short", - "reallocatedSectorCount": 0 - }, - { - "readSpeed": 136.0, - "elapsed": 9, - "type": "BenchmarkDataStorage", - "writeSpeed": 35.0 - } - ] - }, - { - "manufacturer": "NVIDIA Corporation", - "model": "G84 GeForce 8600 GT", - "serialNumber": null, - "type": "GraphicCard", - "memory": 256.0, - "events": [] - }, - { - "firewire": 1, - "manufacturer": "ASUSTeK Computer INC.", - "usb": 2, - "model": "P7P55D", - "serialNumber": "101005570001137", - "type": "Motherboard", - "pcmcia": 0, - "slots": 4, - "serial": 1, - "events": [] + "elapsed": 0, + "type": "BenchmarkProcessor", + "rate": 44937.520000000004 } + ] + }, + { + "manufacturer": null, + "interface": "ATA", + "model": "SAMSUNG HD103SJ", + "serialNumber": "S246J90Z406422", + "type": "HardDrive", + "size": 953869, + "events": [ + { + "elapsed": 120, + "lifetime": 14298, + "currentPendingSectorCount": 0, + "type": "TestDataStorage", + "status": "Completed without error", + "powerCycleCount": 693, + "assessment": true, + "offlineUncorrectable": 0, + "severity": "Info", + "length": "Short", + "reallocatedSectorCount": 0 + }, + { + "readSpeed": 136.0, + "elapsed": 9, + "type": "BenchmarkDataStorage", + "writeSpeed": 35.0 + } + ] + }, + { + "manufacturer": "NVIDIA Corporation", + "model": "G84 GeForce 8600 GT", + "serialNumber": null, + "type": "GraphicCard", + "memory": 256.0, + "events": [] + }, + { + "firewire": 1, + "manufacturer": "ASUSTeK Computer INC.", + "usb": 2, + "model": "P7P55D", + "serialNumber": "101005570001137", + "type": "Motherboard", + "pcmcia": 0, + "slots": 4, + "serial": 1, + "events": [] + } ], "elapsed": 203, "device": { @@ -142,19 +142,19 @@ "type": "Desktop", "serialNumber": null, "events": [ - { - "elapsed": 60, - "type": "StressTest", - "error": false - }, - { - "elapsed": 1, - "type": "BenchmarkRamSysbench", - "rate": 0.8315 - } + { + "elapsed": 60, + "type": "StressTest", + "severity": "Info" + }, + { + "elapsed": 1, + "type": "BenchmarkRamSysbench", + "rate": 0.8315 + } ], "tags": [ - {"id": "A0000000000003", "type": "Tag"} + {"id": "A0000000000003", "type": "Tag"} ] }, "version": "11.0a6", diff --git a/ereuse_devicehub/dummy/files/pc-laudem.snapshot.11.yaml b/ereuse_devicehub/dummy/files/pc-laudem.snapshot.11.yaml index cf2c6749..3223e1be 100644 --- a/ereuse_devicehub/dummy/files/pc-laudem.snapshot.11.yaml +++ b/ereuse_devicehub/dummy/files/pc-laudem.snapshot.11.yaml @@ -62,7 +62,7 @@ "assessment": true, "currentPendingSectorCount": 0, "elapsed": 134, - "error": false, + "severity": "Info", "length": "Short", "lifetime": 19549, "offlineUncorrectable": 0, @@ -106,7 +106,7 @@ "events": [ { "elapsed": 60, - "error": false, + "severity": "Info", "type": "StressTest" }, { diff --git a/ereuse_devicehub/dummy/files/real-eee-1001pxd.snapshot.11.yaml b/ereuse_devicehub/dummy/files/real-eee-1001pxd.snapshot.11.yaml index 70d838e2..75002dae 100644 --- a/ereuse_devicehub/dummy/files/real-eee-1001pxd.snapshot.11.yaml +++ b/ereuse_devicehub/dummy/files/real-eee-1001pxd.snapshot.11.yaml @@ -90,7 +90,7 @@ "type": "TestDataStorage", "length": "Short", "elapsed": 2, - "error": true, + "severity": "Error", "status": "Unspecified Error. Self-test not started." }, { @@ -99,12 +99,12 @@ { "type": "StepRandom", "startTime": "2018-07-03T09:15:22.257059", - "error": false, + "severity": "Info", "endTime": "2018-07-03T10:32:11.843190" } ], "startTime": "2018-07-03T09:15:22.256074", - "error": false, + "severity": "Info", "zeros": false, "endTime": "2018-07-03T10:32:11.848455" } @@ -143,7 +143,7 @@ }, { "type": "StressTest", - "error": false, + "severity": "Info", "elapsed": 60 }, { diff --git a/ereuse_devicehub/dummy/files/real-hp-quad-core.snapshot.11.yaml b/ereuse_devicehub/dummy/files/real-hp-quad-core.snapshot.11.yaml index 86a38a0c..6bc97a45 100644 --- a/ereuse_devicehub/dummy/files/real-hp-quad-core.snapshot.11.yaml +++ b/ereuse_devicehub/dummy/files/real-hp-quad-core.snapshot.11.yaml @@ -83,7 +83,7 @@ "elapsed": 0, "type": "TestDataStorage", "status": "Unspecified Error. Self-test not started.", - "error": true, + "severity": "Error", "length": "Short" } ] diff --git a/ereuse_devicehub/dummy/files/real-hp.snapshot.11.yaml b/ereuse_devicehub/dummy/files/real-hp.snapshot.11.yaml index 7288f5e0..87c12b7b 100644 --- a/ereuse_devicehub/dummy/files/real-hp.snapshot.11.yaml +++ b/ereuse_devicehub/dummy/files/real-hp.snapshot.11.yaml @@ -88,7 +88,7 @@ }, { "status": "Unspecified Error. Self-test not started.", - "error": true, + "severity": "Error", "type": "TestDataStorage", "elapsed": 1, "length": Short @@ -142,7 +142,7 @@ { "type": "StressTest", "elapsed": 60, - "error": false + "severity": "Info" }, { "rate": 0.9759, diff --git a/ereuse_devicehub/dummy/files/real-toshiba.snapshot.11.yaml b/ereuse_devicehub/dummy/files/real-toshiba.snapshot.11.yaml index 1ea7be17..add7bc12 100644 --- a/ereuse_devicehub/dummy/files/real-toshiba.snapshot.11.yaml +++ b/ereuse_devicehub/dummy/files/real-toshiba.snapshot.11.yaml @@ -96,7 +96,7 @@ "status": "Unspecified Error. Self-test not started.", "type": "TestDataStorage", "length": Short, - "error": true + "severity": "Error" } ], "type": "HardDrive", @@ -122,7 +122,7 @@ "events": [ { "type": "StressTest", - "error": false, + "severity": "Info", "elapsed": 120 }, { diff --git a/ereuse_devicehub/dummy/files/smart.snapshot.11.yaml b/ereuse_devicehub/dummy/files/smart.snapshot.11.yaml index 4b622cd5..3d73dec3 100644 --- a/ereuse_devicehub/dummy/files/smart.snapshot.11.yaml +++ b/ereuse_devicehub/dummy/files/smart.snapshot.11.yaml @@ -15,7 +15,7 @@ { "type": "StressTest", "elapsed": 300, - "error": false + "severity": "Info" } ], "serialNumber": "CZC0408YJG", @@ -125,7 +125,7 @@ "offlineUncorrectable": 1, "powerCycleCount": 1838, "assessment": true, - "error": false, + "severity": "Info", "type": "TestDataStorage", "lifetime": 10546, "reallocatedSectorCount": 0, diff --git a/ereuse_devicehub/dummy/files/workbench-server-1.snapshot.yaml b/ereuse_devicehub/dummy/files/workbench-server-1.snapshot.yaml index e533d06e..55a422bc 100644 --- a/ereuse_devicehub/dummy/files/workbench-server-1.snapshot.yaml +++ b/ereuse_devicehub/dummy/files/workbench-server-1.snapshot.yaml @@ -64,7 +64,7 @@ components: elapsed: 21 - type: TestDataStorage elapsed: 233 - error: False + severity: Info status: Completed without error length: Short lifetime: 99 diff --git a/ereuse_devicehub/resources/enums.py b/ereuse_devicehub/resources/enums.py index e116f5a5..fe4b45c8 100644 --- a/ereuse_devicehub/resources/enums.py +++ b/ereuse_devicehub/resources/enums.py @@ -273,9 +273,10 @@ class DataStoragePrivacyCompliance(Enum): """Returns the correct enum depending of the passed-in erasure.""" from ereuse_devicehub.resources.event.models import EraseSectors if isinstance(erasure, EraseSectors): - return cls.EraseSectors if not erasure.error else cls.EraseSectorsError + c = cls.EraseSectors if erasure.severity != Severity.Error else cls.EraseSectorsError else: - return cls.EraseBasic if not erasure.error else cls.EraseBasicError + c = cls.EraseBasic if erasure.severity == Severity.Error else cls.EraseBasicError + return c class PrinterTechnology(Enum): @@ -285,3 +286,38 @@ class PrinterTechnology(Enum): SolidInk = 'Solid ink' Dye = 'Dye-sublimation' Thermal = 'Thermal' + + +class Severity(IntEnum): + """A flag evaluating the event execution. Ex. failed events + have the value `Severity.Error`. + + Devicehub uses 4 severity levels: + + - Info: default neutral severity. The event succeeded. + - Notice: The event succeeded but it is raising awareness. + Notices are not usually that important but something + (good or bad) worth checking. + - Warning: The event succeeded but there is something important + to check negatively affecting the event. + - Error: the event failed. + + Devicehub specially raises user awareness when an event + has a Severity of ``Warning`` or greater. + """ + + Info = 0 + Notice = 1 + Warning = 2 + Error = 3 + + def __str__(self): + if self == self.Info: + m = '✓' + elif self == self.Notice: + m = 'ℹ️' + elif self == self.Warning: + m = '⚠' + else: + m = '❌' + return m diff --git a/ereuse_devicehub/resources/event/models.py b/ereuse_devicehub/resources/event/models.py index f509fdd2..83482855 100644 --- a/ereuse_devicehub/resources/event/models.py +++ b/ereuse_devicehub/resources/event/models.py @@ -6,11 +6,12 @@ from typing import Set, Union from uuid import uuid4 import inflection +import teal.db from boltons import urlutils from citext import CIText from flask import current_app as app, g from sqlalchemy import BigInteger, Boolean, CheckConstraint, Column, DateTime, Enum as DBEnum, \ - Float, ForeignKey, Interval, JSON, Numeric, SmallInteger, Unicode, event, orm, Integer + Float, ForeignKey, Integer, Interval, JSON, Numeric, SmallInteger, Unicode, event, orm from sqlalchemy.dialects.postgresql import UUID from sqlalchemy.ext.declarative import declared_attr from sqlalchemy.ext.orderinglist import ordering_list @@ -27,9 +28,9 @@ from ereuse_devicehub.db import db from ereuse_devicehub.resources.agent.models import Agent from ereuse_devicehub.resources.device.models import Component, Computer, DataStorage, Desktop, \ Device, Laptop, Server -from ereuse_devicehub.resources.enums import AppearanceRange, Bios, \ - FunctionalityRange, PriceSoftware, RATE_NEGATIVE, RATE_POSITIVE, RatingRange, RatingSoftware, \ - ReceiverRole, SnapshotExpectedEvents, SnapshotSoftware, TestDataStorageLength +from ereuse_devicehub.resources.enums import AppearanceRange, Bios, FunctionalityRange, \ + PriceSoftware, RATE_NEGATIVE, RATE_POSITIVE, RatingRange, RatingSoftware, ReceiverRole, \ + Severity, SnapshotExpectedEvents, SnapshotSoftware, TestDataStorageLength from ereuse_devicehub.resources.models import STR_SM_SIZE, Thing from ereuse_devicehub.resources.user.models import User @@ -48,22 +49,14 @@ class Event(Thing): name.comment = """ A name or title for the event. Used when searching for events. """ - incidence = Column(Boolean, default=False, nullable=False) - incidence.comment = """ - Should this event be reviewed due some anomaly? - """ + severity = Column(teal.db.IntEnum(Severity), default=Severity.Info, nullable=False) + severity.comment = Severity.__doc__ closed = Column(Boolean, default=True, nullable=False) closed.comment = """ Whether the author has finished the event. After this is set to True, no modifications are allowed. By default events are closed when performed. """ - error = Column(Boolean, default=False, nullable=False) - error.comment = """ - Did the event fail? - For example, a failure in ``Erase`` means that the data storage - unit did not erase correctly. - """ description = Column(Unicode, default='', nullable=False) description.comment = """ A comment about the event. @@ -181,6 +174,7 @@ class Event(Thing): args = {POLYMORPHIC_ID: cls.t} if cls.t == 'Event': args[POLYMORPHIC_ON] = cls.type + # noinspection PyUnresolvedReferences if JoinedTableMixin in cls.mro(): args[INHERIT_COND] = cls.id == Event.id return args @@ -197,16 +191,15 @@ class Event(Thing): raise ValidationError('The event cannot start after it finished.') return start_time - @property - def _err_str(self): - return '❌ Error.' if self.error else '✓' - @property def _date_str(self): return '{:%c}'.format(self.end_time or self.created) def __str__(self) -> str: - return '{}'.format(self._err_str) + return '{}'.format(self.severity) + + def __repr__(self): + return '<{0.t} {0.id} {0.severity}>'.format(self) class EventComponent(db.Model): @@ -232,7 +225,7 @@ class EventWithOneDevice(JoinedTableMixin, Event): primaryjoin=Device.id == device_id) def __repr__(self) -> str: - return '<{0.t} {0.id!r} device={0.device!r}>'.format(self) + return '<{0.t} {0.id} {0.severity} device={0.device!r}>'.format(self) @declared_attr def __mapper_args__(cls): @@ -260,7 +253,7 @@ class EventWithMultipleDevices(Event): collection_class=OrderedSet) def __repr__(self) -> str: - return '<{0.t} {0.id!r} devices={0.devices!r}>'.format(self) + return '<{0.t} {0.id} {0.severity} devices={0.devices!r}>'.format(self) class EventDevice(db.Model): @@ -299,7 +292,7 @@ class EraseBasic(JoinedWithOneDeviceMixin, EventWithOneDevice): # todo return erasure properties like num steps, if it is british... def __str__(self) -> str: - return '{} on {}.'.format(self._err_str, self.end_time) + return '{} on {}.'.format(self.severity, self.end_time) class EraseSectors(EraseBasic): @@ -310,7 +303,7 @@ class Step(db.Model): erasure_id = Column(UUID(as_uuid=True), ForeignKey(EraseBasic.id), primary_key=True) type = Column(Unicode(STR_SM_SIZE), nullable=False) num = Column(SmallInteger, primary_key=True) - error = Column(Boolean, default=False, nullable=False) + severity = Column(teal.db.IntEnum(Severity), default=Severity.Info, nullable=False) start_time = Column(DateTime, nullable=False) start_time.comment = Event.start_time.comment end_time = Column(DateTime, CheckConstraint('end_time > start_time'), nullable=False) @@ -358,7 +351,7 @@ class Snapshot(JoinedWithOneDeviceMixin, EventWithOneDevice): expected_events = Column(ArrayOfEnum(DBEnum(SnapshotExpectedEvents))) def __str__(self) -> str: - return '{}. {} version {}.'.format(self._err_str, self.software, self.version) + return '{}. {} version {}.'.format(self.severity, self.software, self.version) class Install(JoinedWithOneDeviceMixin, EventWithOneDevice): @@ -747,20 +740,18 @@ class TestDataStorage(Test): def __init__(self, **kwargs) -> None: super().__init__(**kwargs) + + # Define severity # As of https://www.backblaze.com/blog/hard-drive-smart-stats/ and # https://www.backblaze.com/blog-smart-stats-2014-8.html - # We can guess some future disk failures by analyzing some - # SMART data - if (self.reallocated_sector_count or 0) > 10: - self.incidence = True - self.description = 'Warning: Chance of disk failure within a year.' - if (self.current_pending_sector_count or 0) > 40 \ - and (self.reported_uncorrectable_errors or 0) > 10: - self.incidence = True - self.description = 'Warning: Chance of disk failure within a year.' - if not self.assessment: - self.incidence = True - self.description = 'Warning: Drive failure expected soon.' + # We can guess some future disk failures by analyzing some SMART data. + if self.severity is None: + # Test finished successfully + if not self.assessment: + self.severity = Severity.Error + elif self.current_pending_sector_count and self.current_pending_sector_count > 40 \ + or self.reallocated_sector_count and self.reallocated_sector_count > 10: + self.severity = Severity.Warning def __str__(self) -> str: t = inflection.humanize(self.status) @@ -780,7 +771,7 @@ class StressTest(Test): return value def __str__(self) -> str: - return '{}. Computing for {}'.format(self._err_str, self.elapsed) + return '{}. Computing for {}'.format(self.severity, self.elapsed) class Benchmark(JoinedWithOneDeviceMixin, EventWithOneDevice): diff --git a/ereuse_devicehub/resources/event/models.pyi b/ereuse_devicehub/resources/event/models.pyi index 20f09d8d..1479ce82 100644 --- a/ereuse_devicehub/resources/event/models.pyi +++ b/ereuse_devicehub/resources/event/models.pyi @@ -17,8 +17,8 @@ from teal.enums import Country from ereuse_devicehub.resources.agent.models import Agent from ereuse_devicehub.resources.device.models import Component, Computer, Device from ereuse_devicehub.resources.enums import AppearanceRange, Bios, FunctionalityRange, \ - PriceSoftware, RatingSoftware, ReceiverRole, SnapshotExpectedEvents, SnapshotSoftware, \ - TestDataStorageLength + PriceSoftware, RatingSoftware, ReceiverRole, Severity, SnapshotExpectedEvents, \ + SnapshotSoftware, TestDataStorageLength from ereuse_devicehub.resources.models import Thing from ereuse_devicehub.resources.user.models import User @@ -27,8 +27,6 @@ class Event(Thing): id = ... # type: Column name = ... # type: Column type = ... # type: Column - error = ... # type: Column - incidence = ... # type: Column description = ... # type: Column snapshot_id = ... # type: Column snapshot = ... # type: relationship @@ -41,17 +39,14 @@ class Event(Thing): start_time = ... # type: Column end_time = ... # type: Column agent_id = ... # type: Column + severity = ... # type: Column - def __init__(self, id=None, name=None, incidence=None, closed=None, error=None, - description=None, start_time=None, end_time=None, snapshot=None, agent=None, - parent=None, created=None, updated=None, author=None) -> None: + def __init__(self, **kwargs) -> None: super().__init__(created, updated) self.id = ... # type: UUID self.name = ... # type: str self.type = ... # type: str - self.incidence = ... # type: bool self.closed = ... # type: bool - self.error = ... # type: bool self.description = ... # type: str self.start_time = ... # type: datetime self.end_time = ... # type: datetime @@ -60,34 +55,25 @@ class Event(Thing): self.parent = ... # type: Computer self.agent = ... # type: Agent self.author = ... # type: User + self.severity = ... # type: Severity @property def url(self) -> urlutils.URL: pass - @property - def _err_str(self): - pass - class EventWithOneDevice(Event): - def __init__(self, id=None, name=None, incidence=None, closed=None, error=None, - description=None, start_time=None, end_time=None, snapshot=None, agent=None, - parent=None, created=None, updated=None, author=None, device=None) -> None: - super().__init__(id, name, incidence, closed, error, description, start_time, end_time, - snapshot, agent, parent, created, updated, author) + def __init__(self, **kwargs) -> None: + super().__init__(**kwargs) self.device = ... # type: Device class EventWithMultipleDevices(Event): devices = ... # type: relationship - def __init__(self, id=None, name=None, incidence=None, closed=None, error=None, - description=None, start_time=None, end_time=None, snapshot=None, agent=None, - parent=None, created=None, updated=None, author=None, devices=None) -> None: - super().__init__(id, name, incidence, closed, error, description, start_time, end_time, - snapshot, agent, parent, created, updated, author) + def __init__(self, **kwargs) -> None: + super().__init__(**kwargs) self.devices = ... # type: Set[Device] @@ -100,15 +86,21 @@ class Remove(EventWithOneDevice): class Step(Model): + type = ... # type: Column + num = ... # type: Column + start_time = ... # type: Column + end_time = ... # type: Column + erasure = ... # type: relationship + severity = ... # type: Column + def __init__(self, num=None, success=None, start_time=None, end_time=None, - erasure=None, error=None) -> None: + erasure=None, severity=None) -> None: self.type = ... # type: str self.num = ... # type: int - self.success = ... # type: bool self.start_time = ... # type: datetime self.end_time = ... # type: datetime self.erasure = ... # type: EraseBasic - self.error = ... # type: bool + self.severity = ... # type: Severity class StepZero(Step): diff --git a/ereuse_devicehub/resources/event/schemas.py b/ereuse_devicehub/resources/event/schemas.py index 12a196cf..074183ae 100644 --- a/ereuse_devicehub/resources/event/schemas.py +++ b/ereuse_devicehub/resources/event/schemas.py @@ -12,7 +12,7 @@ from ereuse_devicehub.marshmallow import NestedOn from ereuse_devicehub.resources.agent.schemas import Agent from ereuse_devicehub.resources.device.schemas import Component, Computer, Device from ereuse_devicehub.resources.enums import AppearanceRange, Bios, FunctionalityRange, \ - PriceSoftware, RATE_POSITIVE, RatingRange, RatingSoftware, ReceiverRole, \ + PriceSoftware, RATE_POSITIVE, RatingRange, RatingSoftware, ReceiverRole, Severity, \ SnapshotExpectedEvents, SnapshotSoftware, TestDataStorageLength from ereuse_devicehub.resources.event import models as m from ereuse_devicehub.resources.models import STR_BIG_SIZE, STR_SIZE @@ -25,9 +25,8 @@ class Event(Thing): name = SanitizedStr(default='', validate=Length(max=STR_BIG_SIZE), description=m.Event.name.comment) - incidence = Boolean(default=False, description=m.Event.incidence.comment) closed = Boolean(missing=True, description=m.Event.closed.comment) - error = Boolean(default=False, description=m.Event.error.comment) + severity = EnumField(Severity, description=m.Event.severity.comment) description = SanitizedStr(default='', description=m.Event.description.comment) start_time = DateTime(data_key='startTime', description=m.Event.start_time.comment) end_time = DateTime(data_key='endTime', description=m.Event.end_time.comment) @@ -85,7 +84,7 @@ class Step(Schema): type = String(description='Only required when it is nested.') start_time = DateTime(required=True, data_key='startTime') end_time = DateTime(required=True, data_key='endTime') - error = Boolean(default=False, description='Did the event fail?') + severity = EnumField(Severity, description=m.Event.severity.comment) class StepZero(Step): diff --git a/tests/files/erase-sectors-2-hdd.snapshot.yaml b/tests/files/erase-sectors-2-hdd.snapshot.yaml index 84eb5a9c..9ce513ad 100644 --- a/tests/files/erase-sectors-2-hdd.snapshot.yaml +++ b/tests/files/erase-sectors-2-hdd.snapshot.yaml @@ -69,12 +69,12 @@ { "endTime": "2018-07-13T11:54:55.096491", "type": "StepRandom", - "error": false, + "severity": "Info", "startTime": "2018-07-13T10:52:45.092981" } ], "type": "EraseBasic", - "error": false, + "severity": "Info", "zeros": false, "startTime": "2018-07-13T10:52:45.092612" }, @@ -84,7 +84,7 @@ "elapsed": 131, "length": "Short", "offlineUncorrectable": 1, - "error": true, + "severity": "Error", "currentPendingSectorCount": 1, "powerCycleCount": 1253, "reallocatedSectorCount": 15, @@ -107,12 +107,12 @@ { "endTime": "2018-07-13T12:55:47.326835", "type": "StepRandom", - "error": false, + "severity": "Info", "startTime": "2018-07-13T11:54:55.100925" } ], "type": "EraseBasic", - "error": false, + "severity": "Info", "zeros": false, "startTime": "2018-07-13T11:54:55.100667" }, @@ -122,7 +122,7 @@ "elapsed": 115, "length": "Short", "offlineUncorrectable": 0, - "error": false, + "severity": "Info", "currentPendingSectorCount": 0, "powerCycleCount": 1956, "reallocatedSectorCount": 0, diff --git a/tests/files/erase-sectors.snapshot.yaml b/tests/files/erase-sectors.snapshot.yaml index d0cd5a1b..ff01f3db 100644 --- a/tests/files/erase-sectors.snapshot.yaml +++ b/tests/files/erase-sectors.snapshot.yaml @@ -21,11 +21,11 @@ components: endTime: 2018-06-01T09:12:06 steps: - type: StepZero - error: False + severity: Info startTime: 2018-06-01T08:15:00 endTime: 2018-06-01T09:16:00 - type: StepZero - error: False + severity: Info startTime: 2018-06-01T08:16:00 endTime: 2018-06-01T09:17:00 - type: Processor diff --git a/tests/files/real-custom.snapshot.11.yaml b/tests/files/real-custom.snapshot.11.yaml index a9ac2697..3d2b4946 100644 --- a/tests/files/real-custom.snapshot.11.yaml +++ b/tests/files/real-custom.snapshot.11.yaml @@ -77,7 +77,7 @@ "status": "Self-test routine in progress", "powerCycleCount": 648, "length": "Short", - "error": false, + "severity": "Error", "lifetime": 202 } ], @@ -110,7 +110,7 @@ "type": "BenchmarkRamSysbench" }, { - "error": false, + "severity": "Info", "elapsed": 60, "type": "StressTest" } diff --git a/tests/files/workbench-10.snapshot.yaml b/tests/files/workbench-10.snapshot.yaml index c336627e..57852d0c 100644 --- a/tests/files/workbench-10.snapshot.yaml +++ b/tests/files/workbench-10.snapshot.yaml @@ -28,12 +28,12 @@ components: serialNumber: 6VMB1A52 size: 238475 test: {'@type': TestHardDrive, CommandTimeout: 1786733725708, CurrentPendingSectorCount: 0, - OfflineUncorrectable: 0, assessment: true, error: false, firstError: null, lifetime: 16947, + OfflineUncorrectable: 0, assessment: true, severity: Info, firstError: null, lifetime: 16947, passedLifetime: 16947, powerCycleCount: 1694, reallocatedSectorCount: 0, reportedUncorrectableErrors: 0, status: Completed without error, type: Short offline} type: HDD -- { '@type': GraphicCard, manufacturer: Intel Corporation, memory: 256.0, model: 4 - Series Chipset Integrated Graphics Controller, serialNumber: null} +- { '@type': GraphicCard, manufacturer: Intel Corporation, memory: 256.0, model: 4 + Series Chipset Integrated Graphics Controller, serialNumber: null} - '@type': Motherboard connectors: {firewire: 0, pcmcia: 0, serial: 1, usb: 8} manufacturer: LENOVO @@ -41,22 +41,22 @@ components: serialNumber: null totalSlots: 0 usedSlots: 2 -- { '@type': NetworkAdapter, manufacturer: Intel Corporation, model: 82567LM-3 Gigabit - Network Connection, serialNumber: '00:21:86:2c:5e:d6', speed: 1000} -- { '@type': SoundCard, manufacturer: Intel Corporation, model: 82801JD/DO HD Audio - Controller, serialNumber: null} +- { '@type': NetworkAdapter, manufacturer: Intel Corporation, model: 82567LM-3 Gigabit + Network Connection, serialNumber: '00:21:86:2c:5e:d6', speed: 1000} +- { '@type': SoundCard, manufacturer: Intel Corporation, model: 82801JD/DO HD Audio + Controller, serialNumber: null} condition: appearance: {general: B} functionality: {general: A} date: '2018-05-09T10:32:15' debug: - capabilities: { dmi-2.5: DMI version 2.5, smbios-2.5: SMBIOS version 2.5, smp: Symmetric - Multi-Processing, smp-1.4: SMP specification v1.4} + capabilities: { dmi-2.5: DMI version 2.5, smbios-2.5: SMBIOS version 2.5, smp: Symmetric + Multi-Processing, smp-1.4: SMP specification v1.4} children: - children: - - capabilities: { acpi: ACPI, biosbootspecification: BIOS boot specification, cdboot: Booting - from CD-ROM/DVD, edd: Enhanced Disk Drive extensions, escd: ESCD, ls120boot: Booting - from LS-120, pci: PCI bus, pnp: Plug-and-Play, shadowing: BIOS shadowing, + - capabilities: { acpi: ACPI, biosbootspecification: BIOS boot specification, cdboot: Booting + from CD-ROM/DVD, edd: Enhanced Disk Drive extensions, escd: ESCD, ls120boot: Booting + from LS-120, pci: PCI bus, pnp: Plug-and-Play, shadowing: BIOS shadowing, smartbattery: Smart battery, upgrade: BIOS EEPROM can be upgraded, usb: USB legacy emulation} capacity: 4128768 @@ -71,9 +71,9 @@ debug: vendor: LENOVO version: 5CKT48AUS - businfo: cpu@0 - capabilities: { acpi: thermal control (ACPI), aperfmperf: true, apic: on-chip - advanced programmable interrupt controller (APIC), arch_perfmon: true, boot: boot - processor, bts: true, clflush: true, cmov: conditional move instruction, + capabilities: { acpi: thermal control (ACPI), aperfmperf: true, apic: on-chip + advanced programmable interrupt controller (APIC), arch_perfmon: true, boot: boot + processor, bts: true, clflush: true, cmov: conditional move instruction, constant_tsc: true, cpufreq: CPU Frequency scaling, cx16: true, cx8: compare and exchange 8-byte, de: debugging extensions, ds_cpl: true, dtes64: true, dtherm: true, dts: debug trace and EMON store MSRs, eagerfpu: true, est: true, @@ -149,16 +149,16 @@ debug: version: 6.7.10 width: 64 - children: - - { claimed: true, class: memory, clock: 1067000000, description: DIMM DDR2 Synchronous - 1067 MHz (0.9 ns), handle: 'DMI:001F', id: 'bank:0', physid: '0', product: '000000000000000000000000000000000000', + - { claimed: true, class: memory, clock: 1067000000, description: DIMM DDR2 Synchronous + 1067 MHz (0.9 ns), handle: 'DMI:001F', id: 'bank:0', physid: '0', product: '000000000000000000000000000000000000', serial: '00000000', size: 2147483648, slot: J6G1, units: bytes, vendor: Unknown, width: 40960} - {claimed: true, class: memory, clock: 1067000000, description: 'DIMM DDR2 Synchronous 1067 MHz (0.9 ns) [empty]', handle: 'DMI:0020', id: 'bank:1', physid: '1', product: 012345678901234567890123456789012345, serial: '01234567', slot: J6G2, vendor: 48spaces} - - { claimed: true, class: memory, clock: 1067000000, description: DIMM DDR2 Synchronous - 1067 MHz (0.9 ns), handle: 'DMI:0021', id: 'bank:2', physid: '2', product: '000000000000000000000000000000000000', + - { claimed: true, class: memory, clock: 1067000000, description: DIMM DDR2 Synchronous + 1067 MHz (0.9 ns), handle: 'DMI:0021', id: 'bank:2', physid: '2', product: '000000000000000000000000000000000000', serial: '00000000', size: 2147483648, slot: J6H1, units: bytes, vendor: Unknown, width: 41984} - {claimed: true, class: memory, clock: 1067000000, description: 'DIMM DDR2 @@ -205,7 +205,7 @@ debug: - businfo: pci@0000:00:00.0 children: - businfo: pci@0000:00:02.0 - capabilities: { bus_master: bus mastering, cap_list: PCI capabilities listing, + capabilities: { bus_master: bus mastering, cap_list: PCI capabilities listing, msi: Message Signalled Interrupts, pm: Power Management, rom: extension ROM, vga_controller: true} claimed: true @@ -265,8 +265,8 @@ debug: version: '03' width: 32 - businfo: pci@0000:00:03.3 - capabilities: { '16550': true, bus_master: bus mastering, cap_list: PCI capabilities - listing, msi: Message Signalled Interrupts, pm: Power Management} + capabilities: { '16550': true, bus_master: bus mastering, cap_list: PCI capabilities + listing, msi: Message Signalled Interrupts, pm: Power Management} claimed: true class: communication clock: 66000000 @@ -280,8 +280,8 @@ debug: version: '03' width: 32 - businfo: pci@0000:00:19.0 - capabilities: { 1000bt-fd: 1Gbit/s (full duplex), 100bt: 100Mbit/s, 100bt-fd: 100Mbit/s - (full duplex), 10bt: 10Mbit/s, 10bt-fd: 10Mbit/s (full duplex), autonegotiation: Auto-negotiation, + capabilities: { 1000bt-fd: 1Gbit/s (full duplex), 100bt: 100Mbit/s, 100bt-fd: 100Mbit/s + (full duplex), 10bt: 10Mbit/s, 10bt-fd: 10Mbit/s (full duplex), autonegotiation: Auto-negotiation, bus_master: bus mastering, cap_list: PCI capabilities listing, ethernet: true, msi: Message Signalled Interrupts, physical: Physical interface, pm: Power Management, tp: twisted pair} @@ -575,8 +575,8 @@ debug: version: '02' width: 32 - businfo: pci@0000:00:1f.2 - capabilities: { ahci_1.0: true, bus_master: bus mastering, cap_list: PCI capabilities - listing, msi: Message Signalled Interrupts, pm: Power Management, storage: true} + capabilities: { ahci_1.0: true, bus_master: bus mastering, cap_list: PCI capabilities + listing, msi: Message Signalled Interrupts, pm: Power Management, storage: true} claimed: true class: storage clock: 66000000 @@ -620,7 +620,7 @@ debug: table} children: - businfo: scsi@0:0.0.0,1 - capabilities: { dir_nlink: directories with 65000+ subdirs, ext2: EXT2/EXT3, + capabilities: { dir_nlink: directories with 65000+ subdirs, ext2: EXT2/EXT3, ext4: true, extended_attributes: Extended Attributes, extents: extent-based allocation, huge_files: 16TB+ files, initialized: initialized volume, journaled: true, large_files: 4GB+ files, primary: Primary partition} @@ -672,8 +672,8 @@ debug: - capabilities: {emulated: Emulated device} children: - businfo: scsi@1:0.0.0 - capabilities: { audio: Audio CD playback, cd-r: CD-R burning, cd-rw: CD-RW - burning, dvd: DVD playback, dvd-r: DVD-R burning, dvd-ram: DVD-RAM burning, + capabilities: { audio: Audio CD playback, cd-r: CD-R burning, cd-rw: CD-RW + burning, dvd: DVD playback, dvd-r: DVD-R burning, dvd-ram: DVD-RAM burning, removable: support is removable} claimed: true class: disk diff --git a/tests/files/workbench-server-2.stress-test.yaml b/tests/files/workbench-server-2.stress-test.yaml index 5c048615..9f29c6c2 100644 --- a/tests/files/workbench-server-2.stress-test.yaml +++ b/tests/files/workbench-server-2.stress-test.yaml @@ -8,5 +8,5 @@ type: 'StressTest' elapsed: 300 -error: False -# snapshot: None fulfill! \ No newline at end of file +severity: Info +# snapshot: None fulfill! diff --git a/tests/files/workbench-server-3.erase.yaml b/tests/files/workbench-server-3.erase.yaml index 24bde030..913786be 100644 --- a/tests/files/workbench-server-3.erase.yaml +++ b/tests/files/workbench-server-3.erase.yaml @@ -7,7 +7,7 @@ # All numbers are invented type: 'EraseSectors' -error: False +severity: Info # snapshot: None fulfill! # device: None fulfill! zeros: False @@ -17,4 +17,4 @@ steps: - type: 'StepRandom' startTime: '2018-01-01T10:10:10' endTime: '2018-01-01T12:10:10' - error: False + severity: Info diff --git a/tests/files/workbench-server-4.install.yaml b/tests/files/workbench-server-4.install.yaml index ba8dd3b4..45e9abe7 100644 --- a/tests/files/workbench-server-4.install.yaml +++ b/tests/files/workbench-server-4.install.yaml @@ -8,7 +8,7 @@ type: 'Install' elapsed: 420 -error: False +severity: Info # snapshot: None fulfill! # device: None fulfill! -name: 'LinuxMint 18.01 32b' \ No newline at end of file +name: 'LinuxMint 18.01 32b' diff --git a/tests/test_device.py b/tests/test_device.py index 57af1d43..30c68ec3 100644 --- a/tests/test_device.py +++ b/tests/test_device.py @@ -20,7 +20,7 @@ from ereuse_devicehub.resources.device.exceptions import NeedsId from ereuse_devicehub.resources.device.schemas import Device as DeviceS from ereuse_devicehub.resources.device.sync import MismatchBetweenTags, MismatchBetweenTagsAndHid, \ Sync -from ereuse_devicehub.resources.enums import ComputerChassis, DisplayTech +from ereuse_devicehub.resources.enums import ComputerChassis, DisplayTech, Severity from ereuse_devicehub.resources.event import models as m from ereuse_devicehub.resources.event.models import Remove, Test from ereuse_devicehub.resources.tag.model import Tag @@ -393,7 +393,7 @@ def test_get_device(app: Devicehub, user: UserClient): db.session.add(pc) db.session.add(Test(device=pc, elapsed=timedelta(seconds=4), - error=False, + severity=Severity.Info, agent=Person(name='Timmy'), author=User(email='bar@bar.com'))) db.session.commit() @@ -402,7 +402,7 @@ def test_get_device(app: Devicehub, user: UserClient): assert pc['events'][0]['type'] == 'Test' assert pc['events'][0]['device'] == 1 assert pc['events'][0]['elapsed'] == 4 - assert not pc['events'][0]['error'] + assert pc['events'][0]['severity'] == 'Info' assert UUID(pc['events'][0]['author']) assert 'events_components' not in pc, 'events_components are internal use only' assert 'events_one' not in pc, 'they are internal use only' diff --git a/tests/test_event.py b/tests/test_event.py index 687bb34f..d7240ade 100644 --- a/tests/test_event.py +++ b/tests/test_event.py @@ -13,7 +13,7 @@ from ereuse_devicehub.db import db from ereuse_devicehub.resources.device import states from ereuse_devicehub.resources.device.models import Desktop, Device, GraphicCard, HardDrive, \ RamModule, SolidStateDrive -from ereuse_devicehub.resources.enums import ComputerChassis, TestDataStorageLength +from ereuse_devicehub.resources.enums import ComputerChassis, Severity, TestDataStorageLength from ereuse_devicehub.resources.event import models from tests import conftest from tests.conftest import create_user, file @@ -89,7 +89,7 @@ def test_erase_sectors_steps(): def test_test_data_storage(): test = models.TestDataStorage( device=HardDrive(serial_number='foo', manufacturer='bar', model='foo-bar'), - error=False, + severity=Severity.Info, elapsed=timedelta(minutes=25), length=TestDataStorageLength.Short, status='ok!', diff --git a/tests/test_snapshot.py b/tests/test_snapshot.py index f8708e44..4b6eeb80 100644 --- a/tests/test_snapshot.py +++ b/tests/test_snapshot.py @@ -310,13 +310,13 @@ def test_erase(user: UserClient): assert erasure['device']['id'] == storage['id'] for step in erasure['steps']: assert step['type'] == 'StepZero' - assert step['error'] is False + assert step['severity'] == 'Info' assert 'num' not in step assert storage['privacy'] == erasure['device']['privacy'] == 'EraseSectors' # Let's try a second erasure with an error s['uuid'] = uuid4() - s['components'][0]['events'][0]['error'] = True + s['components'][0]['events'][0]['severity'] = 'Error' snapshot, _ = user.post(s, res=Snapshot) assert snapshot['components'][0]['hid'] == 'c1mr-c1s-c1ml' assert snapshot['components'][0]['privacy'] == 'EraseSectorsError' @@ -330,8 +330,7 @@ def test_test_data_storage(user: UserClient): ev for ev in snapshot['events'] if ev.get('reallocatedSectorCount', None) == 15 ) - assert incidence_test['incidence'] - assert incidence_test['description'] == 'Warning: Drive failure expected soon.' + incidence_test['severity'] == 'Error' def test_snapshot_computer_monitor(user: UserClient): diff --git a/tests/test_workbench.py b/tests/test_workbench.py index 6cafb0ff..5bb23719 100644 --- a/tests/test_workbench.py +++ b/tests/test_workbench.py @@ -49,7 +49,7 @@ def test_workbench_server_condensed(user: UserClient): ('TestDataStorage', 6) } assert snapshot['closed'] - assert not snapshot['error'] + assert snapshot['severity'] == 'Info' device, _ = user.get(res=Device, item=snapshot['device']['id']) assert device['dataStorageSize'] == 1100 assert device['chassis'] == 'Tower' @@ -59,7 +59,7 @@ def test_workbench_server_condensed(user: UserClient): assert device['processorModel'] == device['components'][3]['model'] == 'p1-1ml' assert device['ramSize'] == 2048, 'There are 3 RAM: 2 x 1024 and 1 None sizes' assert device['rate']['closed'] - assert not device['rate']['error'] + assert device['rate']['severity'] == 'Info' assert device['rate']['rating'] == 0 assert device['rate']['workbench'] assert device['rate']['appearanceRange'] == 'A' @@ -129,7 +129,7 @@ def test_workbench_server_phases(user: UserClient): assert events[8]['type'] == 'Install' assert events[8]['device'] == 6 assert snapshot['closed'] - assert not snapshot['error'] + assert snapshot['severity'] == 'Info' pc, _ = user.get(res=Device, item=snapshot['id']) assert len(pc['events']) == 10 # todo shall I add child events? @@ -264,7 +264,7 @@ def test_snapshot_real_eee_1001pxd(user: UserClient): assert erase['endTime'] assert erase['startTime'] assert erase['zeros'] is False - assert erase['error'] is False + assert erase['severity'] == 'Info' assert hdd['privacy'] == 'EraseBasic' mother = components[8] assert mother['hid'] == 'asustek_computer_inc-eee0123456789-1001pxd'