From c3b860b69c18794ee7ee14b7d67d376fb9239d7b Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Mon, 25 Jan 2021 15:38:09 +0100 Subject: [PATCH 1/5] 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. From 1e50386b93c0dfaf567f1e3841ef12368fd53c29 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Mon, 25 Jan 2021 16:10:23 +0100 Subject: [PATCH 2/5] fixed test --- ereuse_devicehub/resources/device/sync.py | 8 ++++++++ tests/test_snapshot.py | 23 +++++++++++++++-------- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/ereuse_devicehub/resources/device/sync.py b/ereuse_devicehub/resources/device/sync.py index 81c57657..1b7cd724 100644 --- a/ereuse_devicehub/resources/device/sync.py +++ b/ereuse_devicehub/resources/device/sync.py @@ -72,6 +72,7 @@ class Sync: # We only want to perform Add/Remove to not new components actions = self.add_remove(db_device, not_new_components) db_device.components = db_components + self.change_parent_actions_components(db_device) return db_device, actions def execute_register_component(self, @@ -245,6 +246,13 @@ class Sync: actions.add(Remove(device=parent, components=set_components)) return actions + @staticmethod + def change_parent_actions_components(device: Computer): + # import pdb; pdb.set_trace() + for c in set(device.components): + for act in c.actions: + act.parent = device + class MismatchBetweenTags(ValidationError): def __init__(self, diff --git a/tests/test_snapshot.py b/tests/test_snapshot.py index df51eae2..775a3d5d 100644 --- a/tests/test_snapshot.py +++ b/tests/test_snapshot.py @@ -201,11 +201,13 @@ def test_snapshot_component_add_remove(user: UserClient): # PC1 assert tuple(c['serialNumber'] for c in pc1['components']) == ('p1c1s', 'p1c3s') assert all(c['parent'] == pc1_id for c in pc1['components']) - assert tuple(e['type'] for e in pc1['actions']) == ('BenchmarkProcessor', 'Snapshot', 'RateComputer', 'Remove') + assert tuple(e['type'] for e in pc1['actions']) == ('Snapshot', 'RateComputer', 'Remove') # PC2 assert tuple(c['serialNumber'] for c in pc2['components']) == ('p1c2s', 'p2c1s') assert all(c['parent'] == pc2_id for c in pc2['components']) - assert tuple(e['type'] for e in pc2['actions']) == ('Snapshot', 'RateComputer') + assert tuple(e['type'] for e in pc2['actions']) == ( + 'BenchmarkProcessor', 'Snapshot', 'RateComputer', 'Snapshot', 'Remove', 'RateComputer' + ) # p1c2s has two Snapshots, a Remove and an Add p1c2s, _ = user.get(res=m.Device, item=pc2['components'][0]['id']) assert tuple(e['type'] for e in p1c2s['actions']) == ( @@ -230,12 +232,16 @@ def test_snapshot_component_add_remove(user: UserClient): assert {c['serialNumber'] for c in pc1['components']} == {'p1c2s', 'p1c3s'} assert all(c['parent'] == pc1_id for c in pc1['components']) assert tuple(get_actions_info(pc1['actions'])) == ( - # id, type, components, snapshot - ('BenchmarkProcessor', []), # first BenchmarkProcessor - ('Snapshot', ['p1c1s', 'p1c2s', 'p1c3s']), # first Snapshot1 + ('BenchmarkProcessor', []), + ('Snapshot', ['p1c1s', 'p1c2s', 'p1c3s']), + ('Snapshot', ['p1c1s', 'p1c2s', 'p1c3s']), + ('RateComputer', ['p1c1s', 'p1c2s', 'p1c3s']), ('RateComputer', ['p1c1s', 'p1c2s', 'p1c3s']), - ('Remove', ['p1c2s']), # Remove Processor in Snapshot2 - ('Snapshot', ['p1c2s', 'p1c3s']), # This Snapshot3 + ('Snapshot', ['p1c2s', 'p2c1s']), + ('Remove', ['p1c2s']), ('Remove', ['p1c2s']), + ('RateComputer', ['p1c2s', 'p2c1s']), + ('Snapshot', ['p1c2s', 'p1c3s']), + ('Remove', ['p1c2s']), ('RateComputer', ['p1c2s', 'p1c3s']) ) # PC2 @@ -480,8 +486,9 @@ def test_test_data_storage(user: UserClient): assert incidence_test['severity'] == 'Error' +@pytest.mark.mvp @pytest.mark.usefixtures(conftest.app_context.__name__) -def test_erase(user: UserClient): +def test_erase_changing_hdd_between_pcs(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') From 9cc82e7a82eff494a401f19707d5c598e3d160fa Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Tue, 26 Jan 2021 12:24:02 +0100 Subject: [PATCH 3/5] return to previus state --- ereuse_devicehub/resources/device/sync.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/ereuse_devicehub/resources/device/sync.py b/ereuse_devicehub/resources/device/sync.py index 1b7cd724..81c57657 100644 --- a/ereuse_devicehub/resources/device/sync.py +++ b/ereuse_devicehub/resources/device/sync.py @@ -72,7 +72,6 @@ class Sync: # We only want to perform Add/Remove to not new components actions = self.add_remove(db_device, not_new_components) db_device.components = db_components - self.change_parent_actions_components(db_device) return db_device, actions def execute_register_component(self, @@ -246,13 +245,6 @@ class Sync: actions.add(Remove(device=parent, components=set_components)) return actions - @staticmethod - def change_parent_actions_components(device: Computer): - # import pdb; pdb.set_trace() - for c in set(device.components): - for act in c.actions: - act.parent = device - class MismatchBetweenTags(ValidationError): def __init__(self, From 6ca37e348cc7210bb14931bc199bd60bb8878454 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Tue, 26 Jan 2021 13:52:23 +0100 Subject: [PATCH 4/5] change erasure.html template --- .../templates/documents/erasure.html | 29 +++++++++---------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/ereuse_devicehub/resources/documents/templates/documents/erasure.html b/ereuse_devicehub/resources/documents/templates/documents/erasure.html index b2556500..d8170767 100644 --- a/ereuse_devicehub/resources/documents/templates/documents/erasure.html +++ b/ereuse_devicehub/resources/documents/templates/documents/erasure.html @@ -5,8 +5,6 @@ - - @@ -16,16 +14,6 @@ {% for erasure in erasures %} - {% if erasure.parent.serial_number %} - - {% else %} - - {% endif %} - @@ -51,10 +39,19 @@
Data storage:
{{ erasure.device.__format__('ts') }}
-
Computer:
-
{{ erasure.parent.__format__('ts') }}
-
Tags:
-
{{ erasure.parent.tags }}
+ +
Computer where was erase:
+
Title: {{ erasure.parent.__format__('ts') }}
+
SystemId: {{ erasure.parent.id }}
+
Hid: {{ erasure.parent.hid }}
+
Tags: {{ erasure.parent.tags }}
+ +
Computer where it resides:
+
Title: {{ erasure.device.parent.__format__('ts') }}
+
SystemId: {{ erasure.device.parent.id }}
+
Hid: {{ erasure.device.parent.hid }}
+
Tags: {{ erasure.device.parent.tags }}
+
Erasure:
{{ erasure.__format__('ts') }}
{% if erasure.steps %} From fd7920b3f946cf26e4bf13900918ef8d3cfc7241 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Tue, 26 Jan 2021 15:35:42 +0100 Subject: [PATCH 5/5] fixed test --- tests/test_snapshot.py | 73 ++++++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 39 deletions(-) diff --git a/tests/test_snapshot.py b/tests/test_snapshot.py index 775a3d5d..9de3c1a4 100644 --- a/tests/test_snapshot.py +++ b/tests/test_snapshot.py @@ -201,13 +201,11 @@ def test_snapshot_component_add_remove(user: UserClient): # PC1 assert tuple(c['serialNumber'] for c in pc1['components']) == ('p1c1s', 'p1c3s') assert all(c['parent'] == pc1_id for c in pc1['components']) - assert tuple(e['type'] for e in pc1['actions']) == ('Snapshot', 'RateComputer', 'Remove') + assert tuple(e['type'] for e in pc1['actions']) == ('BenchmarkProcessor', 'Snapshot', 'RateComputer', 'Remove') # PC2 assert tuple(c['serialNumber'] for c in pc2['components']) == ('p1c2s', 'p2c1s') assert all(c['parent'] == pc2_id for c in pc2['components']) - assert tuple(e['type'] for e in pc2['actions']) == ( - 'BenchmarkProcessor', 'Snapshot', 'RateComputer', 'Snapshot', 'Remove', 'RateComputer' - ) + assert tuple(e['type'] for e in pc2['actions']) == ('Snapshot', 'RateComputer') # p1c2s has two Snapshots, a Remove and an Add p1c2s, _ = user.get(res=m.Device, item=pc2['components'][0]['id']) assert tuple(e['type'] for e in p1c2s['actions']) == ( @@ -232,16 +230,12 @@ def test_snapshot_component_add_remove(user: UserClient): assert {c['serialNumber'] for c in pc1['components']} == {'p1c2s', 'p1c3s'} assert all(c['parent'] == pc1_id for c in pc1['components']) assert tuple(get_actions_info(pc1['actions'])) == ( - ('BenchmarkProcessor', []), - ('Snapshot', ['p1c1s', 'p1c2s', 'p1c3s']), - ('Snapshot', ['p1c1s', 'p1c2s', 'p1c3s']), - ('RateComputer', ['p1c1s', 'p1c2s', 'p1c3s']), + # id, type, components, snapshot + ('BenchmarkProcessor', []), # first BenchmarkProcessor + ('Snapshot', ['p1c1s', 'p1c2s', 'p1c3s']), # first Snapshot1 ('RateComputer', ['p1c1s', 'p1c2s', 'p1c3s']), - ('Snapshot', ['p1c2s', 'p2c1s']), - ('Remove', ['p1c2s']), ('Remove', ['p1c2s']), - ('RateComputer', ['p1c2s', 'p2c1s']), - ('Snapshot', ['p1c2s', 'p1c3s']), - ('Remove', ['p1c2s']), + ('Remove', ['p1c2s']), # Remove Processor in Snapshot2 + ('Snapshot', ['p1c2s', 'p1c3s']), # This Snapshot3 ('RateComputer', ['p1c2s', 'p1c3s']) ) # PC2 @@ -486,32 +480,6 @@ def test_test_data_storage(user: UserClient): assert incidence_test['severity'] == 'Error' -@pytest.mark.mvp -@pytest.mark.usefixtures(conftest.app_context.__name__) -def test_erase_changing_hdd_between_pcs(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. @@ -577,6 +545,32 @@ def snapshot_and_check(user: UserClient, return snapshot +@pytest.mark.mvp +@pytest.mark.usefixtures(conftest.app_context.__name__) +def test_erase_changing_hdd_between_pcs(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 == dev1 + 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 'dev1' in doc2 + assert 'dev2' in doc2 + + @pytest.mark.mvp @pytest.mark.xfail(reason='Debug and rewrite it') def test_pc_rating_rate_none(user: UserClient): @@ -592,6 +586,7 @@ def test_pc_2(user: UserClient): snapshot, _ = user.post(res=Snapshot, data=s) + @pytest.mark.mvp def test_save_snapshot_in_file(app: Devicehub, user: UserClient): """ This test check if works the function save_snapshot_in_file """
S/NTags S/N Data Storage Type of erasure Result
- {{ erasure.parent.serial_number.upper() }} - - {{ erasure.parent.tags.__format__('') }} - {{ erasure.device.serial_number.upper() }}