From cbe6bb7e90d749f1e1c4cb301b30497e57cefa77 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Tue, 10 Nov 2020 20:45:03 +0100 Subject: [PATCH 01/23] adding mac of networkadapter to hid --- ereuse_devicehub/resources/device/models.py | 32 +++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/ereuse_devicehub/resources/device/models.py b/ereuse_devicehub/resources/device/models.py index 682327bb..b57e32e1 100644 --- a/ereuse_devicehub/resources/device/models.py +++ b/ereuse_devicehub/resources/device/models.py @@ -16,8 +16,10 @@ from sqlalchemy.dialects.postgresql import UUID from sqlalchemy.ext.declarative import declared_attr from sqlalchemy.ext.hybrid import hybrid_property from sqlalchemy.orm import ColumnProperty, backref, relationship, validates +from sqlalchemy.orm.events import AttributeEvents as Events from sqlalchemy.util import OrderedSet from sqlalchemy_utils import ColorType +from sqlalchemy import event from stdnum import imei, meid from teal.db import CASCADE_DEL, POLYMORPHIC_ID, POLYMORPHIC_ON, ResourceNotFound, URL, \ check_lower, check_range, IntEnum @@ -135,8 +137,7 @@ class Device(Thing): def __init__(self, **kw) -> None: super().__init__(**kw) - with suppress(TypeError): - self.hid = Naming.hid(self.type, self.manufacturer, self.model, self.serial_number) + self.set_hid() @property def actions(self) -> list: @@ -269,6 +270,10 @@ class Device(Thing): args[POLYMORPHIC_ON] = cls.type return args + def set_hid(self): + with suppress(TypeError): + self.hid = Naming.hid(self.type, self.manufacturer, self.model, self.serial_number) + def last_action_of(self, *types): """Gets the last action of the given types. @@ -452,6 +457,18 @@ class Computer(Device): if privacy ) + def add_mac_to_hid(self) -> str: + """Returns the Naming.hid with the first mac of network adapter, + following an alphabetical order. + """ + self.set_hid() + if not self.hid: + return + macs_network= [c.serial_number for c in self.components if c.type == 'NetworkAdapter'] + macs_network.sort() + mac = "-"+macs_network[0] if macs_network else '' + self.hid += mac + def __format__(self, format_spec): if not format_spec: return super().__format__(format_spec) @@ -658,6 +675,17 @@ class NetworkAdapter(JoinedComponentTableMixin, NetworkMixin, Component): pass +@event.listens_for(NetworkAdapter.parent, Events.set.__name__, propagate=True) +def update_hid(target: NetworkAdapter, device: Device, _, __): + """Syncs the :attr:`parent.hid` with the parent of the device.""" + target.parent = None + if isinstance(device, Component): + if device.parent: + device.parent.add_mac_to_hid() + + target.parent = device.parent + + class Processor(JoinedComponentTableMixin, Component): """The CPU.""" speed = Column(Float, check_range('speed', 0.1, 15)) From 0a7e805f3e0d09e1808871ab3bceadd41db35b2c Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Wed, 11 Nov 2020 16:52:02 +0100 Subject: [PATCH 02/23] clean events from device models --- ereuse_devicehub/resources/device/models.py | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/ereuse_devicehub/resources/device/models.py b/ereuse_devicehub/resources/device/models.py index b57e32e1..58066798 100644 --- a/ereuse_devicehub/resources/device/models.py +++ b/ereuse_devicehub/resources/device/models.py @@ -16,10 +16,8 @@ from sqlalchemy.dialects.postgresql import UUID from sqlalchemy.ext.declarative import declared_attr from sqlalchemy.ext.hybrid import hybrid_property from sqlalchemy.orm import ColumnProperty, backref, relationship, validates -from sqlalchemy.orm.events import AttributeEvents as Events from sqlalchemy.util import OrderedSet from sqlalchemy_utils import ColorType -from sqlalchemy import event from stdnum import imei, meid from teal.db import CASCADE_DEL, POLYMORPHIC_ID, POLYMORPHIC_ON, ResourceNotFound, URL, \ check_lower, check_range, IntEnum @@ -675,17 +673,6 @@ class NetworkAdapter(JoinedComponentTableMixin, NetworkMixin, Component): pass -@event.listens_for(NetworkAdapter.parent, Events.set.__name__, propagate=True) -def update_hid(target: NetworkAdapter, device: Device, _, __): - """Syncs the :attr:`parent.hid` with the parent of the device.""" - target.parent = None - if isinstance(device, Component): - if device.parent: - device.parent.add_mac_to_hid() - - target.parent = device.parent - - class Processor(JoinedComponentTableMixin, Component): """The CPU.""" speed = Column(Float, check_range('speed', 0.1, 15)) From 17f1ff98e7d623a8b8d61c5f480608c0eb97e3e3 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Wed, 11 Nov 2020 16:53:41 +0100 Subject: [PATCH 03/23] adding update hid when insert one manual or automatic snapshot --- ereuse_devicehub/resources/device/sync.py | 2 ++ ereuse_devicehub/resources/device/views.py | 1 + 2 files changed, 3 insertions(+) diff --git a/ereuse_devicehub/resources/device/sync.py b/ereuse_devicehub/resources/device/sync.py index 5f13d5a0..4efa67bc 100644 --- a/ereuse_devicehub/resources/device/sync.py +++ b/ereuse_devicehub/resources/device/sync.py @@ -52,6 +52,7 @@ class Sync: of the passed-in components. 2. A list of Add / Remove (not yet added to session). """ + db_device = self.execute_register(device) db_components, actions = OrderedSet(), OrderedSet() if components is not None: # We have component info (see above) @@ -71,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 + db_device.add_mac_to_hid() return db_device, actions def execute_register_component(self, diff --git a/ereuse_devicehub/resources/device/views.py b/ereuse_devicehub/resources/device/views.py index 8f16b12d..1b87a426 100644 --- a/ereuse_devicehub/resources/device/views.py +++ b/ereuse_devicehub/resources/device/views.py @@ -230,6 +230,7 @@ class DeviceMergeView(View): base_device.manufacturer = latest_snapshot_device.manufacturer base_device.model = latest_snapshot_device.model base_device.chassis = latest_snapshot_device.chassis + base_device.add_mac_to_hid() class ManufacturerView(View): From 0fb81bea78232c8e688c678a8f94018db14bace2 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Wed, 11 Nov 2020 16:54:13 +0100 Subject: [PATCH 04/23] adding history to shell cli --- ereuse_devicehub/cli.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/ereuse_devicehub/cli.py b/ereuse_devicehub/cli.py index b99c0b5e..4c253235 100644 --- a/ereuse_devicehub/cli.py +++ b/ereuse_devicehub/cli.py @@ -7,6 +7,27 @@ import flask.cli from ereuse_devicehub.config import DevicehubConfig from ereuse_devicehub.devicehub import Devicehub +import sys +sys.ps1 = '\001\033[92m\002>>> \001\033[0m\002' +sys.ps2= '\001\033[94m\002... \001\033[0m\002' + +import os, readline, rlcompleter, atexit +history_file = os.path.join(os.environ['HOME'], '.python_history') +try: + readline.read_history_file(history_file) +except IOError: + pass +readline.parse_and_bind("tab: complete") +readline.parse_and_bind('"\e[5~": history-search-backward') +readline.parse_and_bind('"\e[6~": history-search-forward') +readline.parse_and_bind('"\e[5C": forward-word') +readline.parse_and_bind('"\e[5D": backward-word') +readline.parse_and_bind('"\e\e[C": forward-word') +readline.parse_and_bind('"\e\e[D": backward-word') +readline.parse_and_bind('"\e[1;5C": forward-word') +readline.parse_and_bind('"\e[1;5D": backward-word') +readline.set_history_length(100000) +atexit.register(readline.write_history_file, history_file) class DevicehubGroup(flask.cli.FlaskGroup): # todo users cannot make cli to use a custom db this way! From 554ec254d8ddbd0c3d9c10c26024219e1f1e4d80 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Wed, 11 Nov 2020 16:59:30 +0100 Subject: [PATCH 05/23] identation problem --- ereuse_devicehub/resources/device/sync.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ereuse_devicehub/resources/device/sync.py b/ereuse_devicehub/resources/device/sync.py index 4efa67bc..bb32e7f4 100644 --- a/ereuse_devicehub/resources/device/sync.py +++ b/ereuse_devicehub/resources/device/sync.py @@ -72,7 +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 - db_device.add_mac_to_hid() + db_device.add_mac_to_hid() return db_device, actions def execute_register_component(self, From 82a3344965b4cab0f374047adbf4b289f645b500 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Thu, 12 Nov 2020 20:57:33 +0100 Subject: [PATCH 06/23] centralized in one point the hid --- ereuse_devicehub/resources/device/models.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/ereuse_devicehub/resources/device/models.py b/ereuse_devicehub/resources/device/models.py index 58066798..4efd0189 100644 --- a/ereuse_devicehub/resources/device/models.py +++ b/ereuse_devicehub/resources/device/models.py @@ -455,17 +455,21 @@ class Computer(Device): if privacy ) - def add_mac_to_hid(self) -> str: + def add_mac_to_hid(self, components_snap=None): """Returns the Naming.hid with the first mac of network adapter, following an alphabetical order. """ self.set_hid() if not self.hid: return - macs_network= [c.serial_number for c in self.components if c.type == 'NetworkAdapter'] + components = self.components if components_snap == None else components_snap + macs_network= [c.serial_number for c in components if c.type == 'NetworkAdapter'] macs_network.sort() - mac = "-"+macs_network[0] if macs_network else '' - self.hid += mac + mac = macs_network[0] if macs_network else '' + if not mac or mac in self.hid: + return + mac = f"-{mac}" + self.hid += mac def __format__(self, format_spec): if not format_spec: From a122753e344e7c1a2f006fc1b55d99931d9eaa89 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Thu, 12 Nov 2020 20:58:38 +0100 Subject: [PATCH 07/23] when add or remove components check again the hid --- ereuse_devicehub/resources/action/models.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ereuse_devicehub/resources/action/models.py b/ereuse_devicehub/resources/action/models.py index a0d38e14..f1a6f182 100644 --- a/ereuse_devicehub/resources/action/models.py +++ b/ereuse_devicehub/resources/action/models.py @@ -1510,6 +1510,9 @@ def update_components_action_one(target: ActionWithOneDevice, device: Device, __ target.components.clear() if isinstance(device, Computer): target.components |= device.components + else: + if isinstance(device, Computer): + device.add_mac_to_hid() @event.listens_for(ActionWithMultipleDevices.devices, Events.init_collection.__name__, From 791308d8e88d2f849542f3321b24300d224f6afb Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Thu, 12 Nov 2020 21:00:07 +0100 Subject: [PATCH 08/23] modify hid when create the snapshot --- ereuse_devicehub/resources/action/views.py | 4 ++++ ereuse_devicehub/resources/device/sync.py | 1 - 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/ereuse_devicehub/resources/action/views.py b/ereuse_devicehub/resources/action/views.py index 2d71b4fd..17fd07a0 100644 --- a/ereuse_devicehub/resources/action/views.py +++ b/ereuse_devicehub/resources/action/views.py @@ -13,6 +13,7 @@ from teal.marshmallow import ValidationError from teal.resource import View from ereuse_devicehub.db import db +from ereuse_devicehub.resources.device.models import Device, Computer from ereuse_devicehub.resources.action.models import Action, RateComputer, Snapshot, VisualTest, \ InitTransfer from ereuse_devicehub.resources.action.rate.v1_0 import CannotRate @@ -99,6 +100,7 @@ class ActionView(View): action = Action.query.filter_by(id=id).one() return self.schema.jsonify(action) + def snapshot(self, snapshot_json: dict, resource_def): """Performs a Snapshot. @@ -112,6 +114,8 @@ class ActionView(View): components = None if snapshot_json['software'] == (SnapshotSoftware.Workbench or SnapshotSoftware.WorkbenchAndroid): components = snapshot_json.pop('components', None) # type: List[Component] + if isinstance(device, Computer) and device.hid: + device.add_mac_to_hid(components_snap=components) snapshot = Snapshot(**snapshot_json) # Remove new actions from devices so they don't interfere with sync diff --git a/ereuse_devicehub/resources/device/sync.py b/ereuse_devicehub/resources/device/sync.py index bb32e7f4..32aa8843 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 - db_device.add_mac_to_hid() return db_device, actions def execute_register_component(self, From b56c3d3e0a96347af87cf09abae184751ab62ff3 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Thu, 12 Nov 2020 21:00:33 +0100 Subject: [PATCH 09/23] fixed some tests --- ...removing-processor.snapshot-and-adding-graphic-card.yaml | 5 ----- tests/files/proposal_extended_csv_report.csv | 6 +++--- tests/test_snapshot.py | 6 +++--- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/tests/files/4-first-device-but-removing-processor.snapshot-and-adding-graphic-card.yaml b/tests/files/4-first-device-but-removing-processor.snapshot-and-adding-graphic-card.yaml index ba20cc28..e24131c7 100644 --- a/tests/files/4-first-device-but-removing-processor.snapshot-and-adding-graphic-card.yaml +++ b/tests/files/4-first-device-but-removing-processor.snapshot-and-adding-graphic-card.yaml @@ -5,11 +5,6 @@ device: type: Desktop chassis: Tower components: - - manufacturer: p1c4m - serialNumber: p1c4s - type: NetworkAdapter - speed: 1000 - wireless: False - manufacturer: p1c3m serialNumber: p1c3s type: GraphicCard diff --git a/tests/files/proposal_extended_csv_report.csv b/tests/files/proposal_extended_csv_report.csv index 5bca6df3..2b605615 100644 --- a/tests/files/proposal_extended_csv_report.csv +++ b/tests/files/proposal_extended_csv_report.csv @@ -1,3 +1,3 @@ -System ID;Public Link;Tag 1 Type;Tag 1 ID;Tag 1 Organization;Tag 2 Type;Tag 2 ID;Tag 2 Organization;Tag 3 Type;Tag 3 ID;Tag 3 Organization;Device Hardware ID;Device Type;Device Chassis;Device Serial Number;Device Model;Device Manufacturer;Registered in;Registered (process);Updated in (software);Updated in (web);Physical state;Trading state;Processor;RAM (MB);Data Storage Size (MB);Processor 1;Processor 1 Manufacturer;Processor 1 Model;Processor 1 Serial Number;Processor 1 Number of cores;Processor 1 Speed (GHz);Benchmark Processor 1 (points);Benchmark ProcessorSysbench Processor 1 (points);Processor 2;Processor 2 Manufacturer;Processor 2 Model;Processor 2 Serial Number;Processor 2 Number of cores;Processor 2 Speed (GHz);Benchmark Processor 2 (points);Benchmark ProcessorSysbench Processor 2 (points);RamModule 1;RamModule 1 Manufacturer;RamModule 1 Model;RamModule 1 Serial Number;RamModule 1 Size (MB);RamModule 1 Speed (MHz);RamModule 2;RamModule 2 Manufacturer;RamModule 2 Model;RamModule 2 Serial Number;RamModule 2 Size (MB);RamModule 2 Speed (MHz);RamModule 3;RamModule 3 Manufacturer;RamModule 3 Model;RamModule 3 Serial Number;RamModule 3 Size (MB);RamModule 3 Speed (MHz);RamModule 4;RamModule 4 Manufacturer;RamModule 4 Model;RamModule 4 Serial Number;RamModule 4 Size (MB);RamModule 4 Speed (MHz);DataStorage 1;DataStorage 1 Manufacturer;DataStorage 1 Model;DataStorage 1 Serial Number;DataStorage 1 Size (MB);Erasure DataStorage 1;Erasure DataStorage 1 Serial Number;Erasure DataStorage 1 Size (MB);Erasure DataStorage 1 Software;Erasure DataStorage 1 Result;Erasure DataStorage 1 Type;Erasure DataStorage 1 Method;Erasure DataStorage 1 Elapsed (hours);Erasure DataStorage 1 Date;Erasure DataStorage 1 Steps;Erasure DataStorage 1 Steps Start Time;Erasure DataStorage 1 Steps End Time;Benchmark DataStorage 1 Read Speed (MB/s);Benchmark DataStorage 1 Writing speed (MB/s);Test DataStorage 1 Software;Test DataStorage 1 Type;Test DataStorage 1 Result;Test DataStorage 1 Power on (hours used);Test DataStorage 1 Lifetime remaining (percentage);DataStorage 2;DataStorage 2 Manufacturer;DataStorage 2 Model;DataStorage 2 Serial Number;DataStorage 2 Size (MB);Erasure DataStorage 2;Erasure DataStorage 2 Serial Number;Erasure DataStorage 2 Size (MB);Erasure DataStorage 2 Software;Erasure DataStorage 2 Result;Erasure DataStorage 2 Type;Erasure DataStorage 2 Method;Erasure DataStorage 2 Elapsed (hours);Erasure DataStorage 2 Date;Erasure DataStorage 2 Steps;Erasure DataStorage 2 Steps Start Time;Erasure DataStorage 2 Steps End Time;Benchmark DataStorage 2 Read Speed (MB/s);Benchmark DataStorage 2 Writing speed (MB/s);Test DataStorage 2 Software;Test DataStorage 2 Type;Test DataStorage 2 Result;Test DataStorage 2 Power on (hours used);Test DataStorage 2 Lifetime remaining (percentage);DataStorage 3;DataStorage 3 Manufacturer;DataStorage 3 Model;DataStorage 3 Serial Number;DataStorage 3 Size (MB);Erasure DataStorage 3;Erasure DataStorage 3 Serial Number;Erasure DataStorage 3 Size (MB);Erasure DataStorage 3 Software;Erasure DataStorage 3 Result;Erasure DataStorage 3 Type;Erasure DataStorage 3 Method;Erasure DataStorage 3 Elapsed (hours);Erasure DataStorage 3 Date;Erasure DataStorage 3 Steps;Erasure DataStorage 3 Steps Start Time;Erasure DataStorage 3 Steps End Time;Benchmark DataStorage 3 Read Speed (MB/s);Benchmark DataStorage 3 Writing speed (MB/s);Test DataStorage 3 Software;Test DataStorage 3 Type;Test DataStorage 3 Result;Test DataStorage 3 Power on (hours used);Test DataStorage 3 Lifetime remaining (percentage);DataStorage 4;DataStorage 4 Manufacturer;DataStorage 4 Model;DataStorage 4 Serial Number;DataStorage 4 Size (MB);Erasure DataStorage 4;Erasure DataStorage 4 Serial Number;Erasure DataStorage 4 Size (MB);Erasure DataStorage 4 Software;Erasure DataStorage 4 Result;Erasure DataStorage 4 Type;Erasure DataStorage 4 Method;Erasure DataStorage 4 Elapsed (hours);Erasure DataStorage 4 Date;Erasure DataStorage 4 Steps;Erasure DataStorage 4 Steps Start Time;Erasure DataStorage 4 Steps End Time;Benchmark DataStorage 4 Read Speed (MB/s);Benchmark DataStorage 4 Writing speed (MB/s);Test DataStorage 4 Software;Test DataStorage 4 Type;Test DataStorage 4 Result;Test DataStorage 4 Power on (hours used);Test DataStorage 4 Lifetime remaining (percentage);Motherboard 1;Motherboard 1 Manufacturer;Motherboard 1 Model;Motherboard 1 Serial Number;Display 1;Display 1 Manufacturer;Display 1 Model;Display 1 Serial Number;GraphicCard 1;GraphicCard 1 Manufacturer;GraphicCard 1 Model;GraphicCard 1 Serial Number;GraphicCard 1 Memory (MB);GraphicCard 2;GraphicCard 2 Manufacturer;GraphicCard 2 Model;GraphicCard 2 Serial Number;GraphicCard 2 Memory (MB);NetworkAdapter 1;NetworkAdapter 1 Manufacturer;NetworkAdapter 1 Model;NetworkAdapter 1 Serial Number;NetworkAdapter 2;NetworkAdapter 2 Manufacturer;NetworkAdapter 2 Model;NetworkAdapter 2 Serial Number;SoundCard 1;SoundCard 1 Manufacturer;SoundCard 1 Model;SoundCard 1 Serial Number;SoundCard 2;SoundCard 2 Manufacturer;SoundCard 2 Model;SoundCard 2 Serial Number;Device Rate;Device Range;Processor Rate;Processor Range;RAM Rate;RAM Range;Data Storage Rate;Data Storage Range;Price;Benchmark RamSysbench (points) -1;http://localhost/devices/1;unamed;foo;FooOrg;;;;;;;laptop-asustek_computer_inc-1001pxd-b8oaas048285;Laptop;Netbook;b8oaas048285;1001pxd;asustek computer inc.;Thu Oct 22 13:22:41 2020;Workbench 11.0a2;2020-10-22 13:22:41.206873+02:00;;;;intel atom cpu n455 @ 2.66ghz;1024;238475;Processor 4: model intel atom cpu n455 @ 2.66ghz, S/N None;intel corp.;intel atom cpu n455 @ 2.66ghz;;1;2.667;6666.24;164.0803;;;;;;;;;RamModule 8: model None, S/N None;;;;1024;667;;;;;;;;;;;;;;;;;;;HardDrive 9: model hts54322, S/N e2024242cv86mm;hitachi;hts54322;e2024242cv86mm;238475;harddrive-hitachi-hts54322-e2024242cv86mm;e2024242cv86mm;238475;Workbench 11.0a2;Success;EraseBasic;Shred;1:16:49;2020-10-22 13:22:41.274142+02:00;✓ – StepRandom 1:16:49;2018-07-03 11:15:22.257059+02:00;2018-07-03 12:32:11.843190+02:00;66.2;21.8;Workbench 11.0a2;Short;Failure;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Motherboard 10: model 1001pxd, S/N eee0123456720;asustek computer inc.;1001pxd;eee0123456720;;;;;GraphicCard 5: model atom processor d4xx/d5xx/n4xx/n5xx integrated graphics controller, S/N None;intel corporation;atom processor d4xx/d5xx/n4xx/n5xx integrated graphics controller;;256;;;;;;NetworkAdapter 2: model ar9285 wireless network adapter, S/N 74:2f:68:8b:fd:c9;qualcomm atheros;ar9285 wireless network adapter;74:2f:68:8b:fd:c9;NetworkAdapter 3: model ar8152 v2.0 fast ethernet, S/N 14:da:e9:42:f6:7b;qualcomm atheros;ar8152 v2.0 fast ethernet;14:da:e9:42:f6:7b;SoundCard 6: model nm10/ich7 family high definition audio controller, S/N None;intel corporation;nm10/ich7 family high definition audio controller;;;;;;1.75;LOW;1.55;LOW;1.53;LOW;3.76;HIGH;52.50 €;15.7188 -11;http://localhost/devices/11;;;;;;;;;;laptop-asustek_computer_inc-1001pxd-b8oaas048287;Laptop;Netbook;b8oaas048287;1001pxd;asustek computer inc.;Thu Oct 22 13:22:41 2020;Workbench 11.0b11;2020-10-22 13:22:41.449469+02:00;;;;intel atom cpu n455 @ 1.66ghz;2048;558558;Processor 15: model intel atom cpu n455 @ 1.66ghz, S/N None;intel corp.;intel atom cpu n455 @ 1.66ghz;;1;1.667;6666.24;164.0803;;;;;;;;;RamModule 18: model None, S/N None;;;;1024;667;RamModule 19: model 48594d503131325336344350362d53362020, S/N 4f43487b;hynix semiconductor;48594d503131325336344350362d53362020;4f43487b;1024;667;;;;;;;;;;;;;HardDrive 20: model hts54322, S/N e2024242cv86hj;hitachi;hts54322;e2024242cv86hj;238475;harddrive-hitachi-hts54322-e2024242cv86hj;e2024242cv86hj;238475;Workbench 11.0b11;Success;EraseBasic;Shred;1:16:49;2020-10-22 13:22:41.462162+02:00;✓ – StepRandom 1:16:49;2018-07-03 11:15:22.257059+02:00;2018-07-03 12:32:11.843190+02:00;66.2;21.8;Workbench 11.0b11;Extended;Failure;;;DataStorage 21: model wdc wd1600bevt-2, S/N wd-wx11a80w7430;western digital;wdc wd1600bevt-2;wd-wx11a80w7430;160041;datastorage-western_digital-wdc_wd1600bevt-2-wd-wx11a80w7430;wd-wx11a80w7430;160041;Workbench 11.0b11;Failure;EraseBasic;Shred;0:45:36;2020-10-22 13:22:41.463826+02:00;✓ – StepRandom 0:45:36;2019-10-23 09:49:54.410830+02:00;2019-10-23 10:35:31.400587+02:00;41.6;17.3;Workbench 11.0b11;Short;Success;5293;195 days, 12:00:00;SolidStateDrive 22: model wdc wd1600bevt-2, S/N wd-wx11a80w7430;western digital;wdc wd1600bevt-2;wd-wx11a80w7430;160042;solidstatedrive-western_digital-wdc_wd1600bevt-2-wd-wx11a80w7430;wd-wx11a80w7430;160042;Workbench 11.0b11;Success;EraseSectors;Badblocks;1:46:03;2020-10-22 13:22:41.466798+02:00;✓ – StepRandom 0:46:03,✓ – StepZero 1:00:00;2019-08-19 18:48:19.690458+02:00,2019-08-19 19:34:22.690458+02:00;2019-08-19 19:34:22.930562+02:00,2019-08-19 20:34:22.930562+02:00;41.1;17.1;Workbench 11.0b11;Short;Success;5231;194 days, 17:00:00;;;;;;;;;;;;;;;;;;;;;;;;;Motherboard 23: model 1001pxd, S/N eee0123456789;asustek computer inc.;1001pxd;eee0123456789;;auo "auo";auo lcd monitor;;GraphicCard 16: model atom processor d4xx/d5xx/n4xx/n5xx integrated graphics controller, S/N None;intel corporation;atom processor d4xx/d5xx/n4xx/n5xx integrated graphics controller;;256;;;;;;NetworkAdapter 13: model ar9285 wireless network adapter, S/N 74:2f:68:8b:fd:c8;qualcomm atheros;ar9285 wireless network adapter;74:2f:68:8b:fd:c8;NetworkAdapter 14: model ar8152 v2.0 fast ethernet, S/N 14:da:e9:42:f6:7c;qualcomm atheros;ar8152 v2.0 fast ethernet;14:da:e9:42:f6:7c;SoundCard 7: model usb 2.0 uvc vga webcam, S/N 0x0001;azurewave;usb 2.0 uvc vga webcam;0x0001;SoundCard 17: model nm10/ich7 family high definition audio controller, S/N None;intel corporation;nm10/ich7 family high definition audio controller;;1.72;LOW;1.31;LOW;1.99;LOW;3.97;HIGH;51.60 €;15.7188 +System ID;Public Link;Tag 1 Type;Tag 1 ID;Tag 1 Organization;Tag 2 Type;Tag 2 ID;Tag 2 Organization;Tag 3 Type;Tag 3 ID;Tag 3 Organization;Device Hardware ID;Device Type;Device Chassis;Device Serial Number;Device Model;Device Manufacturer;Registered in;Registered (process);Updated in (software);Updated in (web);Physical state;Trading state;Processor;RAM (MB);Data Storage Size (MB);Processor 1;Processor 1 Manufacturer;Processor 1 Model;Processor 1 Serial Number;Processor 1 Number of cores;Processor 1 Speed (GHz);Benchmark Processor 1 (points);Benchmark ProcessorSysbench Processor 1 (points);Processor 2;Processor 2 Manufacturer;Processor 2 Model;Processor 2 Serial Number;Processor 2 Number of cores;Processor 2 Speed (GHz);Benchmark Processor 2 (points);Benchmark ProcessorSysbench Processor 2 (points);RamModule 1;RamModule 1 Manufacturer;RamModule 1 Model;RamModule 1 Serial Number;RamModule 1 Size (MB);RamModule 1 Speed (MHz);RamModule 2;RamModule 2 Manufacturer;RamModule 2 Model;RamModule 2 Serial Number;RamModule 2 Size (MB);RamModule 2 Speed (MHz);RamModule 3;RamModule 3 Manufacturer;RamModule 3 Model;RamModule 3 Serial Number;RamModule 3 Size (MB);RamModule 3 Speed (MHz);RamModule 4;RamModule 4 Manufacturer;RamModule 4 Model;RamModule 4 Serial Number;RamModule 4 Size (MB);RamModule 4 Speed (MHz);DataStorage 1;DataStorage 1 Manufacturer;DataStorage 1 Model;DataStorage 1 Serial Number;DataStorage 1 Size (MB);Erasure DataStorage 1;Erasure DataStorage 1 Serial Number;Erasure DataStorage 1 Size (MB);Erasure DataStorage 1 Software;Erasure DataStorage 1 Result;Erasure DataStorage 1 Type;Erasure DataStorage 1 Method;Erasure DataStorage 1 Elapsed (hours);Erasure DataStorage 1 Date;Erasure DataStorage 1 Steps;Erasure DataStorage 1 Steps Start Time;Erasure DataStorage 1 Steps End Time;Benchmark DataStorage 1 Read Speed (MB/s);Benchmark DataStorage 1 Writing speed (MB/s);Test DataStorage 1 Software;Test DataStorage 1 Type;Test DataStorage 1 Result;Test DataStorage 1 Power on (hours used);Test DataStorage 1 Lifetime remaining (percentage);DataStorage 2;DataStorage 2 Manufacturer;DataStorage 2 Model;DataStorage 2 Serial Number;DataStorage 2 Size (MB);Erasure DataStorage 2;Erasure DataStorage 2 Serial Number;Erasure DataStorage 2 Size (MB);Erasure DataStorage 2 Software;Erasure DataStorage 2 Result;Erasure DataStorage 2 Type;Erasure DataStorage 2 Method;Erasure DataStorage 2 Elapsed (hours);Erasure DataStorage 2 Date;Erasure DataStorage 2 Steps;Erasure DataStorage 2 Steps Start Time;Erasure DataStorage 2 Steps End Time;Benchmark DataStorage 2 Read Speed (MB/s);Benchmark DataStorage 2 Writing speed (MB/s);Test DataStorage 2 Software;Test DataStorage 2 Type;Test DataStorage 2 Result;Test DataStorage 2 Power on (hours used);Test DataStorage 2 Lifetime remaining (percentage);DataStorage 3;DataStorage 3 Manufacturer;DataStorage 3 Model;DataStorage 3 Serial Number;DataStorage 3 Size (MB);Erasure DataStorage 3;Erasure DataStorage 3 Serial Number;Erasure DataStorage 3 Size (MB);Erasure DataStorage 3 Software;Erasure DataStorage 3 Result;Erasure DataStorage 3 Type;Erasure DataStorage 3 Method;Erasure DataStorage 3 Elapsed (hours);Erasure DataStorage 3 Date;Erasure DataStorage 3 Steps;Erasure DataStorage 3 Steps Start Time;Erasure DataStorage 3 Steps End Time;Benchmark DataStorage 3 Read Speed (MB/s);Benchmark DataStorage 3 Writing speed (MB/s);Test DataStorage 3 Software;Test DataStorage 3 Type;Test DataStorage 3 Result;Test DataStorage 3 Power on (hours used);Test DataStorage 3 Lifetime remaining (percentage);DataStorage 4;DataStorage 4 Manufacturer;DataStorage 4 Model;DataStorage 4 Serial Number;DataStorage 4 Size (MB);Erasure DataStorage 4;Erasure DataStorage 4 Serial Number;Erasure DataStorage 4 Size (MB);Erasure DataStorage 4 Software;Erasure DataStorage 4 Result;Erasure DataStorage 4 Type;Erasure DataStorage 4 Method;Erasure DataStorage 4 Elapsed (hours);Erasure DataStorage 4 Date;Erasure DataStorage 4 Steps;Erasure DataStorage 4 Steps Start Time;Erasure DataStorage 4 Steps End Time;Benchmark DataStorage 4 Read Speed (MB/s);Benchmark DataStorage 4 Writing speed (MB/s);Test DataStorage 4 Software;Test DataStorage 4 Type;Test DataStorage 4 Result;Test DataStorage 4 Power on (hours used);Test DataStorage 4 Lifetime remaining (percentage);Motherboard 1;Motherboard 1 Manufacturer;Motherboard 1 Model;Motherboard 1 Serial Number;Display 1;Display 1 Manufacturer;Display 1 Model;Display 1 Serial Number;GraphicCard 1;GraphicCard 1 Manufacturer;GraphicCard 1 Model;GraphicCard 1 Serial Number;GraphicCard 1 Memory (MB);GraphicCard 2;GraphicCard 2 Manufacturer;GraphicCard 2 Model;GraphicCard 2 Serial Number;GraphicCard 2 Memory (MB);NetworkAdapter 1;NetworkAdapter 1 Manufacturer;NetworkAdapter 1 Model;NetworkAdapter 1 Serial Number;NetworkAdapter 2;NetworkAdapter 2 Manufacturer;NetworkAdapter 2 Model;NetworkAdapter 2 Serial Number;SoundCard 1;SoundCard 1 Manufacturer;SoundCard 1 Model;SoundCard 1 Serial Number;SoundCard 2;SoundCard 2 Manufacturer;SoundCard 2 Model;SoundCard 2 Serial Number;Device Rate;Device Range;Processor Rate;Processor Range;RAM Rate;RAM Range;Data Storage Rate;Data Storage Range;Price;Benchmark RamSysbench (points) +1;http://localhost/devices/1;unamed;foo;FooOrg;;;;;;;laptop-asustek_computer_inc-1001pxd-b8oaas048285-14:da:e9:42:f6:7b;Laptop;Netbook;b8oaas048285;1001pxd;asustek computer inc.;Thu Nov 12 19:53:01 2020;Workbench 11.0a2;2020-11-12 19:54:03.959185+01:00;;;;intel atom cpu n455 @ 2.66ghz;1024;238475;Processor 4: model intel atom cpu n455 @ 2.66ghz, S/N None;intel corp.;intel atom cpu n455 @ 2.66ghz;;1;2.667;6666.24;164.0803;;;;;;;;;RamModule 8: model None, S/N None;;;;1024;667;;;;;;;;;;;;;;;;;;;HardDrive 9: model hts54322, S/N e2024242cv86mm;hitachi;hts54322;e2024242cv86mm;238475;harddrive-hitachi-hts54322-e2024242cv86mm;e2024242cv86mm;238475;Workbench 11.0a2;Success;EraseBasic;Shred;1:16:49;2020-11-12 19:53:01.899092+01:00;✓ – StepRandom 1:16:49;2018-07-03 11:15:22.257059+02:00;2018-07-03 12:32:11.843190+02:00;66.2;21.8;Workbench 11.0a2;Short;Failure;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Motherboard 10: model 1001pxd, S/N eee0123456720;asustek computer inc.;1001pxd;eee0123456720;;;;;GraphicCard 5: model atom processor d4xx/d5xx/n4xx/n5xx integrated graphics controller, S/N None;intel corporation;atom processor d4xx/d5xx/n4xx/n5xx integrated graphics controller;;256;;;;;;NetworkAdapter 2: model ar9285 wireless network adapter, S/N 74:2f:68:8b:fd:c9;qualcomm atheros;ar9285 wireless network adapter;74:2f:68:8b:fd:c9;NetworkAdapter 3: model ar8152 v2.0 fast ethernet, S/N 14:da:e9:42:f6:7b;qualcomm atheros;ar8152 v2.0 fast ethernet;14:da:e9:42:f6:7b;SoundCard 6: model nm10/ich7 family high definition audio controller, S/N None;intel corporation;nm10/ich7 family high definition audio controller;;;;;;1.75;LOW;1.55;LOW;1.53;LOW;3.76;HIGH;52.50 €;15.7188 +11;http://localhost/devices/11;;;;;;;;;;laptop-asustek_computer_inc-1001pxd-b8oaas048287-14:da:e9:42:f6:7c;Laptop;Netbook;b8oaas048287;1001pxd;asustek computer inc.;Thu Nov 12 19:53:02 2020;Workbench 11.0b11;2020-11-12 19:53:02.225373+01:00;;;;intel atom cpu n455 @ 1.66ghz;2048;558558;Processor 15: model intel atom cpu n455 @ 1.66ghz, S/N None;intel corp.;intel atom cpu n455 @ 1.66ghz;;1;1.667;6666.24;164.0803;;;;;;;;;RamModule 18: model None, S/N None;;;;1024;667;RamModule 19: model 48594d503131325336344350362d53362020, S/N 4f43487b;hynix semiconductor;48594d503131325336344350362d53362020;4f43487b;1024;667;;;;;;;;;;;;;HardDrive 20: model hts54322, S/N e2024242cv86hj;hitachi;hts54322;e2024242cv86hj;238475;harddrive-hitachi-hts54322-e2024242cv86hj;e2024242cv86hj;238475;Workbench 11.0b11;Success;EraseBasic;Shred;1:16:49;2020-11-12 19:53:02.175189+01:00;✓ – StepRandom 1:16:49;2018-07-03 11:15:22.257059+02:00;2018-07-03 12:32:11.843190+02:00;66.2;21.8;Workbench 11.0b11;Extended;Failure;;;DataStorage 21: model wdc wd1600bevt-2, S/N wd-wx11a80w7430;western digital;wdc wd1600bevt-2;wd-wx11a80w7430;160041;datastorage-western_digital-wdc_wd1600bevt-2-wd-wx11a80w7430;wd-wx11a80w7430;160041;Workbench 11.0b11;Failure;EraseBasic;Shred;0:45:36;2020-11-12 19:53:02.176882+01:00;✓ – StepRandom 0:45:36;2019-10-23 09:49:54.410830+02:00;2019-10-23 10:35:31.400587+02:00;41.6;17.3;Workbench 11.0b11;Short;Success;5293;195 days, 12:00:00;SolidStateDrive 22: model wdc wd1600bevt-2, S/N wd-wx11a80w7430;western digital;wdc wd1600bevt-2;wd-wx11a80w7430;160042;solidstatedrive-western_digital-wdc_wd1600bevt-2-wd-wx11a80w7430;wd-wx11a80w7430;160042;Workbench 11.0b11;Success;EraseSectors;Badblocks;1:46:03;2020-11-12 19:53:02.180043+01:00;✓ – StepRandom 0:46:03,✓ – StepZero 1:00:00;2019-08-19 18:48:19.690458+02:00,2019-08-19 19:34:22.690458+02:00;2019-08-19 19:34:22.930562+02:00,2019-08-19 20:34:22.930562+02:00;41.1;17.1;Workbench 11.0b11;Short;Success;5231;194 days, 17:00:00;;;;;;;;;;;;;;;;;;;;;;;;;Motherboard 23: model 1001pxd, S/N eee0123456789;asustek computer inc.;1001pxd;eee0123456789;;"auo ""auo""";auo lcd monitor;;GraphicCard 16: model atom processor d4xx/d5xx/n4xx/n5xx integrated graphics controller, S/N None;intel corporation;atom processor d4xx/d5xx/n4xx/n5xx integrated graphics controller;;256;;;;;;NetworkAdapter 13: model ar9285 wireless network adapter, S/N 74:2f:68:8b:fd:c8;qualcomm atheros;ar9285 wireless network adapter;74:2f:68:8b:fd:c8;NetworkAdapter 14: model ar8152 v2.0 fast ethernet, S/N 14:da:e9:42:f6:7c;qualcomm atheros;ar8152 v2.0 fast ethernet;14:da:e9:42:f6:7c;SoundCard 7: model usb 2.0 uvc vga webcam, S/N 0x0001;azurewave;usb 2.0 uvc vga webcam;0x0001;SoundCard 17: model nm10/ich7 family high definition audio controller, S/N None;intel corporation;nm10/ich7 family high definition audio controller;;1.72;LOW;1.31;LOW;1.99;LOW;3.97;HIGH;51.60 €;15.7188 diff --git a/tests/test_snapshot.py b/tests/test_snapshot.py index 0c4bbf1d..aaa902ed 100644 --- a/tests/test_snapshot.py +++ b/tests/test_snapshot.py @@ -241,7 +241,7 @@ def test_snapshot_component_add_remove(user: UserClient): # We register the first device but without the processor, # adding a graphic card and adding a new component s4 = file('4-first-device-but-removing-processor.snapshot-and-adding-graphic-card') - snapshot_and_check(user, s4, ('RateComputer',), perform_second_snapshot=False) + snapshot4 = snapshot_and_check(user, s4, ('RateComputer',), perform_second_snapshot=False) pc1, _ = user.get(res=m.Device, item=pc1_id) pc2, _ = user.get(res=m.Device, item=pc2_id) # Check if the update_timestamp is updated @@ -250,10 +250,10 @@ def test_snapshot_component_add_remove(user: UserClient): assert not update4_pc1 in [update1_pc1, update2_pc1, update3_pc1] assert update3_pc2 == update2_pc2 # PC 0: p1c3s, p1c4s. PC1: p2c1s - assert {c['serialNumber'] for c in pc1['components']} == {'p1c3s', 'p1c4s'} + assert {c['serialNumber'] for c in pc1['components']} == {'p1c3s'} assert all(c['parent'] == pc1_id for c in pc1['components']) # This last Action only - assert get_actions_info(pc1['actions'])[-1] == ('RateComputer', ['p1c3s', 'p1c4s']) + assert get_actions_info(pc1['actions'])[-1] == ('RateComputer', ['p1c3s']) # PC2 # We haven't changed PC2 assert tuple(c['serialNumber'] for c in pc2['components']) == ('p2c1s',) From 0ab8a36832616d65b85f4b085d2dcebee5090284 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Fri, 13 Nov 2020 11:05:00 +0100 Subject: [PATCH 10/23] bugfix with none in the mac serial --- ereuse_devicehub/resources/device/models.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ereuse_devicehub/resources/device/models.py b/ereuse_devicehub/resources/device/models.py index 4efd0189..2983e2ec 100644 --- a/ereuse_devicehub/resources/device/models.py +++ b/ereuse_devicehub/resources/device/models.py @@ -462,14 +462,15 @@ class Computer(Device): self.set_hid() if not self.hid: return - components = self.components if components_snap == None else components_snap - macs_network= [c.serial_number for c in components if c.type == 'NetworkAdapter'] + components = self.components if components_snap is None else components_snap + macs_network = [c.serial_number for c in components + if c.type == 'NetworkAdapter' and c.serial_number is not None] macs_network.sort() mac = macs_network[0] if macs_network else '' if not mac or mac in self.hid: return mac = f"-{mac}" - self.hid += mac + self.hid += mac def __format__(self, format_spec): if not format_spec: From 0883b4384a1c8f4e6f612a7692c50bff105d7a20 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Fri, 13 Nov 2020 11:11:35 +0100 Subject: [PATCH 11/23] bugfix test workbench --- tests/test_workbench.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_workbench.py b/tests/test_workbench.py index cefd294e..e2d5ce9a 100644 --- a/tests/test_workbench.py +++ b/tests/test_workbench.py @@ -52,7 +52,7 @@ def test_workbench_server_condensed(user: UserClient): device, _ = user.get(res=Device, item=snapshot['device']['id']) assert device['dataStorageSize'] == 1100 assert device['chassis'] == 'Tower' - assert device['hid'] == 'desktop-d1mr-d1ml-d1s' + assert device['hid'] == 'desktop-d1mr-d1ml-d1s-na1-s' assert device['graphicCardModel'] == device['components'][0]['model'] == 'gc1-1ml' assert device['networkSpeeds'] == [1000, 58] assert device['processorModel'] == device['components'][3]['model'] == 'p1-1ml' @@ -138,7 +138,7 @@ def test_real_hp_11(user: UserClient): s = file('real-hp.snapshot.11') snapshot, _ = user.post(res=em.Snapshot, data=s) pc = snapshot['device'] - assert pc['hid'] == 'desktop-hewlett-packard-hp_compaq_8100_elite_sff-czc0408yjg' + assert pc['hid'] == 'desktop-hewlett-packard-hp_compaq_8100_elite_sff-czc0408yjg-6c:62:6d:81:22:9f' assert pc['chassis'] == 'Tower' assert set(e['type'] for e in snapshot['actions']) == { 'EreusePrice', @@ -179,7 +179,7 @@ def test_snapshot_real_eee_1001pxd_with_rate(user: UserClient): assert pc['model'] == '1001pxd' assert pc['serialNumber'] == 'b8oaas048286' assert pc['manufacturer'] == 'asustek computer inc.' - assert pc['hid'] == 'laptop-asustek_computer_inc-1001pxd-b8oaas048286' + assert pc['hid'] == 'laptop-asustek_computer_inc-1001pxd-b8oaas048286-14:da:e9:42:f6:7c' assert pc['tags'] == [] assert pc['networkSpeeds'] == [100, 0], 'Although it has WiFi we do not know the speed' assert pc['rate'] From 2587b365e35b7624bd7850abc31e8a50eceab46a Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Fri, 13 Nov 2020 12:29:37 +0100 Subject: [PATCH 12/23] test for requirements of new hid --- tests/test_device.py | 108 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 107 insertions(+), 1 deletion(-) diff --git a/tests/test_device.py b/tests/test_device.py index 60389d8f..4ceb06a3 100644 --- a/tests/test_device.py +++ b/tests/test_device.py @@ -1,8 +1,10 @@ import datetime +import copy +import pytest + from uuid import UUID from flask import g -import pytest from colour import Color from ereuse_utils.naming import Naming from ereuse_utils.test import ANY @@ -596,3 +598,107 @@ def test_cooking_mixer_api(user: UserClient): mixer, _ = user.get(res=d.Device, item=snapshot['device']['id']) assert mixer['type'] == 'Mixer' assert mixer['serialNumber'] == 'foo' + + +@pytest.mark.mvp +def test_hid_with_mac(app: Devicehub, user: UserClient): + """Checks hid with mac.""" + snapshot = file('asus-eee-1000h.snapshot.11') + s, _ = user.post(snapshot, res=m.Snapshot) + pc, _ = user.get(res=d.Device, item=1) + assert pc['hid'] == 'laptop-asustek_computer_inc-1000h-94oaaq021116-00:24:8c:7f:cf:2d' + + +@pytest.mark.mvp +def test_hid_without_mac(app: Devicehub, user: UserClient): + """Checks hid without mac.""" + snapshot = file('asus-eee-1000h.snapshot.11') + snapshot['components'] = [c for c in snapshot['components'] if c['type'] != 'NetworkAdapter'] + s, _ = user.post(snapshot, res=m.Snapshot) + pc, _ = user.get(res=d.Device, item=1) + assert pc['hid'] == 'laptop-asustek_computer_inc-1000h-94oaaq021116' + + +@pytest.mark.mvp +def test_hid_with_mac_none(app: Devicehub, user: UserClient): + """Checks hid with mac = None.""" + snapshot = file('asus-eee-1000h.snapshot.11') + network = [c for c in snapshot['components'] if c['type'] == 'NetworkAdapter'][0] + network['serialNumber'] = None + s, _ = user.post(snapshot, res=m.Snapshot) + pc, _ = user.get(res=d.Device, item=1) + assert pc['hid'] == 'laptop-asustek_computer_inc-1000h-94oaaq021116' + + +@pytest.mark.mvp +def test_hid_with_2networkadapters(app: Devicehub, user: UserClient): + """Checks hid with 2 networks adapters""" + snapshot = file('asus-eee-1000h.snapshot.11') + network = [c for c in snapshot['components'] if c['type'] == 'NetworkAdapter'][0] + network2 = copy.copy(network) + snapshot['components'].append(network2) + network['serialNumber'] = 'a0:24:8c:7f:cf:2d' + s, _ = user.post(snapshot, res=m.Snapshot) + pc, _ = user.get(res=d.Device, item=1) + assert pc['hid'] == 'laptop-asustek_computer_inc-1000h-94oaaq021116-00:24:8c:7f:cf:2d' + + +@pytest.mark.mvp +def test_hid_with_2network_and_drop_no_mac_in_hid(app: Devicehub, user: UserClient): + """Checks hid with 2 networks adapters and next drop the network is not used in hid""" + snapshot = file('asus-eee-1000h.snapshot.11') + network = [c for c in snapshot['components'] if c['type'] == 'NetworkAdapter'][0] + network2 = copy.copy(network) + snapshot['components'].append(network2) + network['serialNumber'] = 'a0:24:8c:7f:cf:2d' + s, _ = user.post(snapshot, res=m.Snapshot) + pc, _ = user.get(res=d.Device, item=1) + assert pc['hid'] == 'laptop-asustek_computer_inc-1000h-94oaaq021116-00:24:8c:7f:cf:2d' + + snapshot['uuid'] = 'd1b70cb8-8929-4f36-99b7-fe052cec0abb' + snapshot['components'] = [c for c in snapshot['components'] if c != network] + s, _ = user.post(snapshot, res=m.Snapshot) + pc, _ = user.get(res=d.Device, item=1) + assert pc['hid'] == 'laptop-asustek_computer_inc-1000h-94oaaq021116-00:24:8c:7f:cf:2d' + devices, _ = user.get(res=d.Device) + assert len([c for c in devices['items'] if c['type'] == 'Laptop']) == 1 + + +@pytest.mark.mvp +def test_hid_with_2network_and_drop_mac_in_hid(app: Devicehub, user: UserClient): + """Checks hid with 2 networks adapters and next drop the network is used in hid""" + # One tipical snapshot with 2 network cards + snapshot = file('asus-eee-1000h.snapshot.11') + network = [c for c in snapshot['components'] if c['type'] == 'NetworkAdapter'][0] + network2 = copy.copy(network) + snapshot['components'].append(network2) + network['serialNumber'] = 'a0:24:8c:7f:cf:2d' + s, _ = user.post(snapshot, res=m.Snapshot) + pc, _ = user.get(res=d.Device, item=1) + assert pc['hid'] == 'laptop-asustek_computer_inc-1000h-94oaaq021116-00:24:8c:7f:cf:2d' + + # we drop the network card then is used for to build the hid + snapshot['uuid'] = 'd1b70cb8-8929-4f36-99b7-fe052cec0abb' + snapshot['components'] = [c for c in snapshot['components'] if c != network2] + s, _ = user.post(snapshot, res=m.Snapshot) + devices, _ = user.get(res=d.Device) + laptops = [c for c in devices['items'] if c['type'] == 'Laptop'] + assert len(laptops) == 2 + hids = [h['hid'] for h in laptops] + proof_hid = ['laptop-asustek_computer_inc-1000h-94oaaq021116-a0:24:8c:7f:cf:2d', + 'laptop-asustek_computer_inc-1000h-94oaaq021116-00:24:8c:7f:cf:2d'] + assert all([h in proof_hid for h in hids]) + + # we drop all network cards + snapshot['uuid'] = 'd1b70cb8-8929-4f36-99b7-fe052cec0abc' + snapshot['components'] = [c for c in snapshot['components'] if not c in [network, network2]] + s, _ = user.post(snapshot, res=m.Snapshot) + devices, _ = user.get(res=d.Device) + laptops = [c for c in devices['items'] if c['type'] == 'Laptop'] + assert len(laptops) == 3 + hids = [h['hid'] for h in laptops] + proof_hid = ['laptop-asustek_computer_inc-1000h-94oaaq021116-a0:24:8c:7f:cf:2d', + 'laptop-asustek_computer_inc-1000h-94oaaq021116-00:24:8c:7f:cf:2d', + 'laptop-asustek_computer_inc-1000h-94oaaq021116'] + assert all([h in proof_hid for h in hids]) + From 62e52f145ff03673cdf4ed0b13f306f026d64e11 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Fri, 13 Nov 2020 12:44:20 +0100 Subject: [PATCH 13/23] fixed bug in test --- tests/test_device.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/tests/test_device.py b/tests/test_device.py index 4ceb06a3..50e7c147 100644 --- a/tests/test_device.py +++ b/tests/test_device.py @@ -638,9 +638,11 @@ def test_hid_with_2networkadapters(app: Devicehub, user: UserClient): network2 = copy.copy(network) snapshot['components'].append(network2) network['serialNumber'] = 'a0:24:8c:7f:cf:2d' - s, _ = user.post(snapshot, res=m.Snapshot) - pc, _ = user.get(res=d.Device, item=1) + user.post(snapshot, res=m.Snapshot) + # pc, _ = user.get(res=d.Device, item=1) assert pc['hid'] == 'laptop-asustek_computer_inc-1000h-94oaaq021116-00:24:8c:7f:cf:2d' + devices, _ = user.get(res=d.Device) + assert len([c for c in devices['items'] if c['type'] == 'Laptop']) == 1 @pytest.mark.mvp @@ -651,17 +653,16 @@ def test_hid_with_2network_and_drop_no_mac_in_hid(app: Devicehub, user: UserClie network2 = copy.copy(network) snapshot['components'].append(network2) network['serialNumber'] = 'a0:24:8c:7f:cf:2d' - s, _ = user.post(snapshot, res=m.Snapshot) + user.post(snapshot, res=m.Snapshot) pc, _ = user.get(res=d.Device, item=1) assert pc['hid'] == 'laptop-asustek_computer_inc-1000h-94oaaq021116-00:24:8c:7f:cf:2d' snapshot['uuid'] = 'd1b70cb8-8929-4f36-99b7-fe052cec0abb' snapshot['components'] = [c for c in snapshot['components'] if c != network] - s, _ = user.post(snapshot, res=m.Snapshot) - pc, _ = user.get(res=d.Device, item=1) - assert pc['hid'] == 'laptop-asustek_computer_inc-1000h-94oaaq021116-00:24:8c:7f:cf:2d' + user.post(snapshot, res=m.Snapshot) devices, _ = user.get(res=d.Device) assert len([c for c in devices['items'] if c['type'] == 'Laptop']) == 1 + assert devices['items'][0]['hid'] == 'laptop-asustek_computer_inc-1000h-94oaaq021116-00:24:8c:7f:cf:2d' @pytest.mark.mvp @@ -673,14 +674,14 @@ def test_hid_with_2network_and_drop_mac_in_hid(app: Devicehub, user: UserClient) network2 = copy.copy(network) snapshot['components'].append(network2) network['serialNumber'] = 'a0:24:8c:7f:cf:2d' - s, _ = user.post(snapshot, res=m.Snapshot) + user.post(snapshot, res=m.Snapshot) pc, _ = user.get(res=d.Device, item=1) assert pc['hid'] == 'laptop-asustek_computer_inc-1000h-94oaaq021116-00:24:8c:7f:cf:2d' # we drop the network card then is used for to build the hid snapshot['uuid'] = 'd1b70cb8-8929-4f36-99b7-fe052cec0abb' snapshot['components'] = [c for c in snapshot['components'] if c != network2] - s, _ = user.post(snapshot, res=m.Snapshot) + user.post(snapshot, res=m.Snapshot) devices, _ = user.get(res=d.Device) laptops = [c for c in devices['items'] if c['type'] == 'Laptop'] assert len(laptops) == 2 @@ -692,7 +693,7 @@ def test_hid_with_2network_and_drop_mac_in_hid(app: Devicehub, user: UserClient) # we drop all network cards snapshot['uuid'] = 'd1b70cb8-8929-4f36-99b7-fe052cec0abc' snapshot['components'] = [c for c in snapshot['components'] if not c in [network, network2]] - s, _ = user.post(snapshot, res=m.Snapshot) + user.post(snapshot, res=m.Snapshot) devices, _ = user.get(res=d.Device) laptops = [c for c in devices['items'] if c['type'] == 'Laptop'] assert len(laptops) == 3 From 34be1df7a294da491db7b80095e71d1c0e41a6c3 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Fri, 13 Nov 2020 12:48:44 +0100 Subject: [PATCH 14/23] fixed bug in test --- tests/test_device.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_device.py b/tests/test_device.py index 50e7c147..76cf4de6 100644 --- a/tests/test_device.py +++ b/tests/test_device.py @@ -663,6 +663,7 @@ def test_hid_with_2network_and_drop_no_mac_in_hid(app: Devicehub, user: UserClie devices, _ = user.get(res=d.Device) assert len([c for c in devices['items'] if c['type'] == 'Laptop']) == 1 assert devices['items'][0]['hid'] == 'laptop-asustek_computer_inc-1000h-94oaaq021116-00:24:8c:7f:cf:2d' + assert len([c for c in devices['items'][0]['components'] if c['type'] == 'NetworkAdapter']) == 1 @pytest.mark.mvp From fcfd2f549daddd5b1a4bb52cf2c8374b9d280324 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Fri, 13 Nov 2020 13:05:25 +0100 Subject: [PATCH 15/23] fixed bug in test --- tests/test_device.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/tests/test_device.py b/tests/test_device.py index 76cf4de6..8c68077c 100644 --- a/tests/test_device.py +++ b/tests/test_device.py @@ -604,7 +604,7 @@ def test_cooking_mixer_api(user: UserClient): def test_hid_with_mac(app: Devicehub, user: UserClient): """Checks hid with mac.""" snapshot = file('asus-eee-1000h.snapshot.11') - s, _ = user.post(snapshot, res=m.Snapshot) + user.post(snapshot, res=m.Snapshot) pc, _ = user.get(res=d.Device, item=1) assert pc['hid'] == 'laptop-asustek_computer_inc-1000h-94oaaq021116-00:24:8c:7f:cf:2d' @@ -614,7 +614,7 @@ def test_hid_without_mac(app: Devicehub, user: UserClient): """Checks hid without mac.""" snapshot = file('asus-eee-1000h.snapshot.11') snapshot['components'] = [c for c in snapshot['components'] if c['type'] != 'NetworkAdapter'] - s, _ = user.post(snapshot, res=m.Snapshot) + user.post(snapshot, res=m.Snapshot) pc, _ = user.get(res=d.Device, item=1) assert pc['hid'] == 'laptop-asustek_computer_inc-1000h-94oaaq021116' @@ -625,7 +625,7 @@ def test_hid_with_mac_none(app: Devicehub, user: UserClient): snapshot = file('asus-eee-1000h.snapshot.11') network = [c for c in snapshot['components'] if c['type'] == 'NetworkAdapter'][0] network['serialNumber'] = None - s, _ = user.post(snapshot, res=m.Snapshot) + user.post(snapshot, res=m.Snapshot) pc, _ = user.get(res=d.Device, item=1) assert pc['hid'] == 'laptop-asustek_computer_inc-1000h-94oaaq021116' @@ -639,9 +639,10 @@ def test_hid_with_2networkadapters(app: Devicehub, user: UserClient): snapshot['components'].append(network2) network['serialNumber'] = 'a0:24:8c:7f:cf:2d' user.post(snapshot, res=m.Snapshot) - # pc, _ = user.get(res=d.Device, item=1) - assert pc['hid'] == 'laptop-asustek_computer_inc-1000h-94oaaq021116-00:24:8c:7f:cf:2d' devices, _ = user.get(res=d.Device) + + laptop = devices['items'][0] + assert laptop['hid'] == 'laptop-asustek_computer_inc-1000h-94oaaq021116-00:24:8c:7f:cf:2d' assert len([c for c in devices['items'] if c['type'] == 'Laptop']) == 1 @@ -661,9 +662,10 @@ def test_hid_with_2network_and_drop_no_mac_in_hid(app: Devicehub, user: UserClie snapshot['components'] = [c for c in snapshot['components'] if c != network] user.post(snapshot, res=m.Snapshot) devices, _ = user.get(res=d.Device) + laptop = devices['items'][0] + assert laptop['hid'] == 'laptop-asustek_computer_inc-1000h-94oaaq021116-00:24:8c:7f:cf:2d' assert len([c for c in devices['items'] if c['type'] == 'Laptop']) == 1 - assert devices['items'][0]['hid'] == 'laptop-asustek_computer_inc-1000h-94oaaq021116-00:24:8c:7f:cf:2d' - assert len([c for c in devices['items'][0]['components'] if c['type'] == 'NetworkAdapter']) == 1 + assert len([c for c in laptop['components'] if c['type'] == 'NetworkAdapter']) == 1 @pytest.mark.mvp From 2f761f338a670899356609b6eedeababfa7bc55d Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Fri, 13 Nov 2020 13:25:51 +0100 Subject: [PATCH 16/23] drop facilities in a shell --- ereuse_devicehub/cli.py | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/ereuse_devicehub/cli.py b/ereuse_devicehub/cli.py index 4c253235..b99c0b5e 100644 --- a/ereuse_devicehub/cli.py +++ b/ereuse_devicehub/cli.py @@ -7,27 +7,6 @@ import flask.cli from ereuse_devicehub.config import DevicehubConfig from ereuse_devicehub.devicehub import Devicehub -import sys -sys.ps1 = '\001\033[92m\002>>> \001\033[0m\002' -sys.ps2= '\001\033[94m\002... \001\033[0m\002' - -import os, readline, rlcompleter, atexit -history_file = os.path.join(os.environ['HOME'], '.python_history') -try: - readline.read_history_file(history_file) -except IOError: - pass -readline.parse_and_bind("tab: complete") -readline.parse_and_bind('"\e[5~": history-search-backward') -readline.parse_and_bind('"\e[6~": history-search-forward') -readline.parse_and_bind('"\e[5C": forward-word') -readline.parse_and_bind('"\e[5D": backward-word') -readline.parse_and_bind('"\e\e[C": forward-word') -readline.parse_and_bind('"\e\e[D": backward-word') -readline.parse_and_bind('"\e[1;5C": forward-word') -readline.parse_and_bind('"\e[1;5D": backward-word') -readline.set_history_length(100000) -atexit.register(readline.write_history_file, history_file) class DevicehubGroup(flask.cli.FlaskGroup): # todo users cannot make cli to use a custom db this way! From 0c1e5b8307313d1a9710af8124c384fc0449ad2c Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Wed, 25 Nov 2020 18:42:36 +0100 Subject: [PATCH 17/23] changes from review --- ereuse_devicehub/resources/action/models.py | 3 +-- ereuse_devicehub/resources/action/views.py | 1 - ereuse_devicehub/resources/device/sync.py | 1 - tests/test_device.py | 2 +- 4 files changed, 2 insertions(+), 5 deletions(-) diff --git a/ereuse_devicehub/resources/action/models.py b/ereuse_devicehub/resources/action/models.py index f1a6f182..bffd2a13 100644 --- a/ereuse_devicehub/resources/action/models.py +++ b/ereuse_devicehub/resources/action/models.py @@ -1510,8 +1510,7 @@ def update_components_action_one(target: ActionWithOneDevice, device: Device, __ target.components.clear() if isinstance(device, Computer): target.components |= device.components - else: - if isinstance(device, Computer): + elif isinstance(device, Computer): device.add_mac_to_hid() diff --git a/ereuse_devicehub/resources/action/views.py b/ereuse_devicehub/resources/action/views.py index 17fd07a0..3f21f0bf 100644 --- a/ereuse_devicehub/resources/action/views.py +++ b/ereuse_devicehub/resources/action/views.py @@ -100,7 +100,6 @@ class ActionView(View): action = Action.query.filter_by(id=id).one() return self.schema.jsonify(action) - def snapshot(self, snapshot_json: dict, resource_def): """Performs a Snapshot. diff --git a/ereuse_devicehub/resources/device/sync.py b/ereuse_devicehub/resources/device/sync.py index 32aa8843..5f13d5a0 100644 --- a/ereuse_devicehub/resources/device/sync.py +++ b/ereuse_devicehub/resources/device/sync.py @@ -52,7 +52,6 @@ class Sync: of the passed-in components. 2. A list of Add / Remove (not yet added to session). """ - db_device = self.execute_register(device) db_components, actions = OrderedSet(), OrderedSet() if components is not None: # We have component info (see above) diff --git a/tests/test_device.py b/tests/test_device.py index 8c68077c..b0dcd1d7 100644 --- a/tests/test_device.py +++ b/tests/test_device.py @@ -1,5 +1,5 @@ -import datetime import copy +import datetime import pytest from uuid import UUID From 09d92e818cec96fc9e6330cb3be6527897c43952 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Wed, 9 Dec 2020 13:28:50 +0100 Subject: [PATCH 18/23] fixed the TODO of live action --- ereuse_devicehub/resources/action/views.py | 25 +++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/ereuse_devicehub/resources/action/views.py b/ereuse_devicehub/resources/action/views.py index ee7b9d20..50637ad8 100644 --- a/ereuse_devicehub/resources/action/views.py +++ b/ereuse_devicehub/resources/action/views.py @@ -239,15 +239,30 @@ class ActionView(View): raise ResourceNotFound("There aren't any disk in this device {}".format(device)) return usage_time_hdd, serial_number + def get_hid(self, snapshot): + device = snapshot.get('device') # type: Computer + components = snapshot.get('components') + if not device: + return None + macs = [c.serial_number for c in components + if c.type == 'NetworkAdapter' and c.serial_number is not None] + macs.sort() + mac = '' + hid = device.hid + if macs: + mac = "-{mac}".format(mac=macs[0]) + hid += mac + return hid + def live(self, snapshot): """If the device.allocated == True, then this snapshot create an action live.""" - device = snapshot.get('device') # type: Computer - # TODO @cayop dependency of pulls 85 and 83 - # if the pr/85 and pr/83 is merged, then you need change this way for get the device - if not device.hid or not Device.query.filter(Device.hid==device.hid).count(): + # TODO @cayop dependency of pulls 83 + # if the pr/83 is merged, then you need change this way for get the device + hid = self.get_hid(snapshot) + if not hid or not Device.query.filter(Device.hid==hid).count(): return None - device = Device.query.filter(Device.hid==device.hid).one() + device = Device.query.filter(Device.hid==hid).one() if not device.allocated: return None From 14e974781ecfa5bbd07347842e7ca55c9e2cea8f Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Wed, 9 Dec 2020 19:54:24 +0100 Subject: [PATCH 19/23] fixing bugs --- ereuse_devicehub/resources/action/views.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ereuse_devicehub/resources/action/views.py b/ereuse_devicehub/resources/action/views.py index 50637ad8..3847fd06 100644 --- a/ereuse_devicehub/resources/action/views.py +++ b/ereuse_devicehub/resources/action/views.py @@ -244,11 +244,15 @@ class ActionView(View): components = snapshot.get('components') if not device: return None + if not components: + return device.hid macs = [c.serial_number for c in components - if c.type == 'NetworkAdapter' and c.serial_number is not None] + if c.type == 'NetworkAdapter' and c.serial_number is not None] macs.sort() mac = '' hid = device.hid + if not hid: + return hid if macs: mac = "-{mac}".format(mac=macs[0]) hid += mac From 73a08d67704a797f68769414e4a12bab6547c2a2 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Thu, 10 Dec 2020 10:41:02 +0100 Subject: [PATCH 20/23] CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ba9a808..15512058 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,3 +15,4 @@ ml). - [addend] #87 allocate, deallocate and live actions - [fixed] #89 save json on disk only for shapshots - [addend] #83 add owner_id in all kind of device +- [addend] #85 add mac of network adapter to device hid From b23b4d9e2a49f4e1f2322dee89eca4643659a70f Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Thu, 10 Dec 2020 11:15:12 +0100 Subject: [PATCH 21/23] change version in this branch --- CHANGELOG.md | 4 +++- ereuse_devicehub/__init__.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4916c2bd..0390d365 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,9 +11,11 @@ ml). ## testing [1.0.2-beta] +## [1.0.3-beta] +- [addend] #85 add mac of network adapter to device hid + ## [1.0.2-beta] - [addend] #87 allocate, deallocate and live actions - [fixed] #89 save json on disk only for shapshots - [addend] #83 add owner_id in all kind of device -- [addend] #85 add mac of network adapter to device hid - [fixed] #91 The most old time allow is 1970-01-01 diff --git a/ereuse_devicehub/__init__.py b/ereuse_devicehub/__init__.py index feee2d99..35bf5f4a 100644 --- a/ereuse_devicehub/__init__.py +++ b/ereuse_devicehub/__init__.py @@ -1 +1 @@ -__version__ = "1.0.2-beta" +__version__ = "1.0.3-beta" From de2539091caa64e21883c4667fabeb5340af9446 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Tue, 15 Dec 2020 20:45:47 +0100 Subject: [PATCH 22/23] allembic for upgrade datas for actual hid's computers --- .../versions/bf600ca861a4_adding_hid.py | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 ereuse_devicehub/migrations/versions/bf600ca861a4_adding_hid.py diff --git a/ereuse_devicehub/migrations/versions/bf600ca861a4_adding_hid.py b/ereuse_devicehub/migrations/versions/bf600ca861a4_adding_hid.py new file mode 100644 index 00000000..662671c6 --- /dev/null +++ b/ereuse_devicehub/migrations/versions/bf600ca861a4_adding_hid.py @@ -0,0 +1,65 @@ +"""empty message + +Revision ID: bf600ca861a4 +Revises: 68a5c025ab8e +Create Date: 2020-12-15 15:58:41.545563 + +""" +from alembic import context +from alembic import op +import sqlalchemy as sa +import sqlalchemy_utils +import citext +import teal + + +# revision identifiers, used by Alembic. +revision = 'bf600ca861a4' +down_revision = '68a5c025ab8e' +branch_labels = None +depends_on = None + + +def get_inv(): + INV = context.get_x_argument(as_dictionary=True).get('inventory') + if not INV: + raise ValueError("Inventory value is not specified") + return INV + +def upgrade(): + con = op.get_bind() + sql = f""" + select d.id, d.hid, dd.serial_number from {get_inv()}.computer as c + join {get_inv()}.device as d on c.id=d.id + inner join {get_inv()}.component as cmp on cmp.parent_id=c.id + inner join {get_inv()}.network_adapter as net on net.id=cmp.id + join {get_inv()}.device as dd on net.id=dd.id; + """ + computers = con.execute(sql) + hids = {} + macs = {} + for c in computers: + hids[c.id] = c.hid + try: + macs[c.id].append(c.serial_number) + macs[c.id].sort() + except: + macs[c.id] = [c.serial_number] + + for id_dev, hid in hids.items(): + if not (id_dev and hid): + continue + if not id_dev in macs: + continue + mac = macs[id_dev][0] + if not mac: + continue + new_hid = "{}-{}".format(hid, mac) + + sql = f"update {get_inv()}.device set hid='{new_hid}' where id={id_dev};" + con.execute(sql) + + + +def downgrade(): + pass From 48d866b2d52c8aa22d3b80ff8193d71d9a7da4e1 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Tue, 15 Dec 2020 20:52:41 +0100 Subject: [PATCH 23/23] allembic for upgrade datas for actual hid's computers --- .../migrations/versions/bf600ca861a4_adding_hid.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ereuse_devicehub/migrations/versions/bf600ca861a4_adding_hid.py b/ereuse_devicehub/migrations/versions/bf600ca861a4_adding_hid.py index 662671c6..ae68e3ed 100644 --- a/ereuse_devicehub/migrations/versions/bf600ca861a4_adding_hid.py +++ b/ereuse_devicehub/migrations/versions/bf600ca861a4_adding_hid.py @@ -40,6 +40,8 @@ def upgrade(): macs = {} for c in computers: hids[c.id] = c.hid + if not c.serial_number: + continue try: macs[c.id].append(c.serial_number) macs[c.id].sort() @@ -52,8 +54,6 @@ def upgrade(): if not id_dev in macs: continue mac = macs[id_dev][0] - if not mac: - continue new_hid = "{}-{}".format(hid, mac) sql = f"update {get_inv()}.device set hid='{new_hid}' where id={id_dev};"