fix settings_version

This commit is contained in:
Cayo Puigdefabregas 2022-12-15 10:18:22 +01:00
parent 30474fa7e6
commit 0f7c9504b0
5 changed files with 13 additions and 26 deletions

View File

@ -90,7 +90,9 @@ class SnapshotsLog(Thing):
settings_version = self.snapshot.settings_version or ''
settings_version = "".join([x[0] for x in settings_version.split(' ') if x])
return "{} ({})".format(self.version, settings_version)
if settings_version:
return "{} ({})".format(self.version, settings_version)
return "{}".format(self.version)
class PlaceholdersLog(Thing):

View File

@ -343,6 +343,7 @@ class ParseSnapshotLsHw:
"components": self.components,
"uuid": snapshot['uuid'],
"version": "14.0.0",
"settings_version": snapshot.get("settings_version"),
"endTime": snapshot["timestamp"],
"elapsed": 1,
"sid": snapshot["sid"],

View File

@ -22,6 +22,7 @@ class Snapshot_lite(Thing):
sid = String(required=True)
type = String(required=True)
timestamp = String(required=True)
settings_version = String(required=False)
data = Nested(Snapshot_lite_data, required=True)
@validates_schema

View File

@ -6,6 +6,7 @@
"software": "Workbench",
"version": "2022.03.00",
"schema_api": "1.0.0",
"settings_version": "Basic Metadata",
"data": {
"lspci": "",
"lshw": {

View File

@ -1420,29 +1420,11 @@ def test_bug_4028_components(user: UserClient):
def test_settings_version(user: UserClient):
"""Tests when we have one computer and then we change the disk, then
the new disk need to have placeholder too."""
s = yaml2json('real-eee-1001pxd.snapshot.12')
s['settings_version'] = 'Basic Metadata (BM)'
snap1, _ = user.post(s, res=Snapshot)
dev1 = m.Device.query.filter_by(id=snap1['device']['id']).one()
assert m.Placeholder.query.count() * 2 == m.Device.query.count()
components1 = [c for c in dev1.components]
for c in s['components']:
if c['type'] == 'HardDrive':
c['serialNumber'] = 'E2024242CV86MF'
s = file_json("2022-03-31_17h18m51s_ZQMPKKX51K67R68VO2X9RNZL08JPL_snapshot.json")
body, res = user.post(s, uri="/api/inventory/")
assert m.Computer.query.first().dhid == body['dhid']
snapshot = Snapshot.query.first()
log = SnapshotsLog.query.first()
s['uuid'] = str(uuid4())
snap2, _ = user.post(s, res=Snapshot)
dev2 = m.Device.query.filter_by(id=snap2['device']['id']).one()
components2 = [c for c in dev2.components]
assert '' not in [c.phid() for c in components1]
assert '' not in [c.phid() for c in components2]
assert len(components1) == len(components2)
assert m.Placeholder.query.count() == 16
assert m.Placeholder.query.count() * 2 == m.Device.query.count()
for c in m.Placeholder.query.filter():
assert c.binding
assert c.device
for c in m.Device.query.filter():
assert c.binding or c.placeholder
assert log.get_version() == "14.0 (BM)"
assert snapshot.settings_version == "Basic Metadata"