From fa7c4d10cf1bc132bbab77fcdf147a34e40f6c7e Mon Sep 17 00:00:00 2001 From: Xavier Bustamante Talavera Date: Tue, 23 Oct 2018 22:54:27 +0200 Subject: [PATCH] Check for html version of device in dummy; add TestDataStorage incidence from SMART --- ereuse_devicehub/dummy/dummy.py | 6 +++++ ereuse_devicehub/resources/event/models.py | 26 ++++++++++++++++++---- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/ereuse_devicehub/dummy/dummy.py b/ereuse_devicehub/dummy/dummy.py index 1b59aa05..b984e9c5 100644 --- a/ereuse_devicehub/dummy/dummy.py +++ b/ereuse_devicehub/dummy/dummy.py @@ -6,6 +6,7 @@ from typing import Set import click import click_spinner import yaml +from ereuse_utils.test import ANY from ereuse_devicehub.client import UserClient from ereuse_devicehub.db import db @@ -139,6 +140,11 @@ class Dummy: res=m.Event) # todo Receive + user.get(res=Device, item=sample_pc) # Test + anonymous = self.app.test_client() + html, _ = anonymous.get(res=Device, item=sample_pc, accept=ANY) + assert 'intel core2 duo cpu' in html + # For netbook: to preapre -> torepair -> to dispose -> disposed print('⭐ Done.') diff --git a/ereuse_devicehub/resources/event/models.py b/ereuse_devicehub/resources/event/models.py index 8610978a..81edf3fc 100644 --- a/ereuse_devicehub/resources/event/models.py +++ b/ereuse_devicehub/resources/event/models.py @@ -745,11 +745,29 @@ class TestDataStorage(Test): offline_uncorrectable = Column(SmallInteger) remaining_lifetime_percentage = Column(SmallInteger) - def __str__(self) -> str: - return '{}. Lifetime of {:.1f} years'.format(inflection.humanize(self.status), - self.lifetime.days / 365) + def __init__(self, **kwargs) -> None: + super().__init__(**kwargs) + # 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.' - # todo remove lifetime / passed_lifetime as I think they are the same + def __str__(self) -> str: + t = inflection.humanize(self.status) + if self.lifetime: + t += ' with a lifetime of {:.1f} years.'.format(self.lifetime.days / 365) + t += self.description + return t class StressTest(Test):