From c3b860b69c18794ee7ee14b7d67d376fb9239d7b Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Mon, 25 Jan 2021 15:38:09 +0100 Subject: [PATCH] test reproduce bug 1888 --- .../files/erase-sectors-2-hdd.snapshot2.yaml | 141 ++++++++++++++++++ tests/test_snapshot.py | 28 ++++ 2 files changed, 169 insertions(+) create mode 100644 tests/files/erase-sectors-2-hdd.snapshot2.yaml diff --git a/tests/files/erase-sectors-2-hdd.snapshot2.yaml b/tests/files/erase-sectors-2-hdd.snapshot2.yaml new file mode 100644 index 00000000..9c3da624 --- /dev/null +++ b/tests/files/erase-sectors-2-hdd.snapshot2.yaml @@ -0,0 +1,141 @@ +{ + "version": "11.0a3", + "device": { + "serialNumber": 'fooz', + "manufacturer": 'bar', + "model": 'baz', + "type": "Desktop", + "actions": [], + "chassis": "Tower" + }, + "elapsed": 7631, + "software": "Workbench", + "type": "Snapshot", + "closed": false, + "uuid": "5387668a-8d21-4053-a1ac-36efb97fc4ea", + "components": [ + { + "serialNumber": null, + "threads": 2, + "manufacturer": "Intel Corp.", + "address": 64, + "model": "Intel Core i3-2100 CPU @ 3.10GHz", + "type": "Processor", + "actions": [ + { + "elapsed": 0, + "rate": 6665.7, + "type": "BenchmarkProcessor" + } + ], + "cores": 2, + "speed": 1.6071410000000002 + }, + { + "manufacturer": "Intel Corporation", + "model": "6 Series/C200 Series Chipset Family High Definition Audio Controller", + "type": "SoundCard", + "actions": [], + "serialNumber": null + }, + { + "serialNumber": "8F179435", + "size": 4096, + "manufacturer": "Kingston", + "format": "DIMM", + "model": "9905403-038.A00LF", + "type": "RamModule", + "actions": [], + "interface": "DDR3", + "speed": 1333.0 + }, + { + "manufacturer": "Realtek Semiconductor Co., Ltd.", + "model": "RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller", + "type": "NetworkAdapter", + "actions": [], + "serialNumber": "f4:6d:04:12:9b:85", + "speed": 1000, + "wireless": false + }, + { + "serialNumber": "WD-WCAV29008961", + "size": 305245, + "manufacturer": "Western Digital", + "model": "WDC WD3200AAJS-2", + "type": "HardDrive", + "actions": [ + { + "lifetime": 24658, + "assessment": false, + "elapsed": 131, + "length": "Short", + "offlineUncorrectable": 1, + "severity": "Error", + "currentPendingSectorCount": 1, + "powerCycleCount": 1253, + "reallocatedSectorCount": 15, + "type": "TestDataStorage", + "status": "Completed: read failure" + }, + { + "readSpeed": 63.3, + "type": "BenchmarkDataStorage", + "elapsed": 18, + "writeSpeed": 20.1 + } + ], + "interface": "ATA" + }, + { + "serialNumber": "WD-WCAV27984668", + "size": 305245, + "manufacturer": "Western Digital", + "model": "WDC WD3200AAJS-0", + "type": "HardDrive", + "actions": [ + { + "lifetime": 21979, + "assessment": true, + "elapsed": 115, + "length": "Short", + "offlineUncorrectable": 0, + "severity": "Info", + "currentPendingSectorCount": 0, + "powerCycleCount": 1956, + "reallocatedSectorCount": 0, + "type": "TestDataStorage", + "status": "Completed without error" + }, + { + "readSpeed": 63.3, + "type": "BenchmarkDataStorage", + "elapsed": 18, + "writeSpeed": 20.1 + } + ], + "interface": "ATA" + }, + { + "serialNumber": null, + "manufacturer": "Intel Corporation", + "model": "2nd Generation Core Processor Family Integrated Graphics Controller", + "type": "GraphicCard", + "actions": [], + "memory": 256.0 + }, + { + "pcmcia": 0, + "serial": 1, + "manufacturer": "ASUSTeK Computer INC.", + "model": "P8H61-M LE", + "type": "Motherboard", + "actions": [], + "slots": 2, + "usb": 2, + "firewire": 0, + "serialNumber": "109192430003458" + } + ], + "endTime": "2018-07-13T10:48:36.738398+00:00" +} diff --git a/tests/test_snapshot.py b/tests/test_snapshot.py index c9cf5084..df51eae2 100644 --- a/tests/test_snapshot.py +++ b/tests/test_snapshot.py @@ -13,6 +13,7 @@ from uuid import uuid4 from boltons import urlutils from teal.db import UniqueViolation, DBError from teal.marshmallow import ValidationError +from ereuse_utils.test import ANY from ereuse_devicehub.client import UserClient from ereuse_devicehub.db import db @@ -29,7 +30,9 @@ from ereuse_devicehub.resources.enums import ComputerChassis, SnapshotSoftware from ereuse_devicehub.resources.tag import Tag from ereuse_devicehub.resources.user.models import User from ereuse_devicehub.resources.action.views import save_json +from ereuse_devicehub.resources.documents import documents from tests.conftest import file +from tests import conftest @pytest.mark.mvp @@ -477,6 +480,31 @@ def test_test_data_storage(user: UserClient): assert incidence_test['severity'] == 'Error' +@pytest.mark.usefixtures(conftest.app_context.__name__) +def test_erase(user: UserClient): + """Tests when we erase one device and next change the disk in other device we + want see in the second device the disks erase.""" + s1 = file('erase-sectors-2-hdd.snapshot') + s2 = file('erase-sectors-2-hdd.snapshot2') + snapshot1, _ = user.post(res=Snapshot, data=s1) + snapshot2, _ = user.post(res=Snapshot, data=s2) + dev1 = m.Device.query.filter_by(id=snapshot1['device']['id']).one() + dev2 = m.Device.query.filter_by(id=snapshot2['device']['id']).one() + tag1 = Tag(id='dev1', device=dev1) + tag2 = Tag(id='dev2', device=dev2) + db.session.commit() + + assert dev2.components[1].actions[2].parent == dev2 + doc1, response = user.get(res=documents.DocumentDef.t, + item='erasures/{}'.format(dev1.id), + accept=ANY) + doc2, response = user.get(res=documents.DocumentDef.t, + item='erasures/{}'.format(dev2.id), + accept=ANY) + assert not 'dev1' in doc2 + assert 'dev2' in doc2 + + def assert_similar_device(device1: dict, device2: dict): """Like :class:`ereuse_devicehub.resources.device.models.Device. is_similar()` but adapted for testing.