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 = self.snapshot.settings_version or ''
settings_version = "".join([x[0] for x in settings_version.split(' ') if x]) settings_version = "".join([x[0] for x in settings_version.split(' ') if x])
if settings_version:
return "{} ({})".format(self.version, settings_version) return "{} ({})".format(self.version, settings_version)
return "{}".format(self.version)
class PlaceholdersLog(Thing): class PlaceholdersLog(Thing):

View File

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

View File

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

View File

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

View File

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