Skip to content

Commit

Permalink
migration: Add capability parsing to analyze-migration.py
Browse files Browse the repository at this point in the history
The script is broken when the configuration/capabilities section is
present. Add support for parsing the capabilities so we can fix it in
the next patch.

Signed-off-by: Fabiano Rosas <farosas@suse.de>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
Message-ID: <20231009184326.15777-4-farosas@suse.de>
  • Loading branch information
Fabiano Rosas authored and Juan Quintela committed Oct 17, 2023
1 parent c36c31c commit 31499a9
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions scripts/analyze-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,13 +264,33 @@ class ConfigurationSection(object):
def __init__(self, file, desc):
self.file = file
self.desc = desc
self.caps = []

def parse_capabilities(self, vmsd_caps):
if not vmsd_caps:
return

ncaps = vmsd_caps.data['caps_count'].data
self.caps = vmsd_caps.data['capabilities']

if type(self.caps) != list:
self.caps = [self.caps]

if len(self.caps) != ncaps:
raise Exception("Number of capabilities doesn't match "
"caps_count field")

def has_capability(self, cap):
return any([str(c) == cap for c in self.caps])

def read(self):
if self.desc:
version_id = self.desc['version']
section = VMSDSection(self.file, version_id, self.desc,
'configuration')
section.read()
self.parse_capabilities(
section.data.get("configuration/capabilities"))
else:
# backward compatibility for older streams that don't have
# the configuration section in the json
Expand All @@ -297,6 +317,23 @@ def read(self):
self.data = self.file.readvar(size)
return self.data

class VMSDFieldCap(object):
def __init__(self, desc, file):
self.file = file
self.desc = desc
self.data = ""

def __repr__(self):
return self.data

def __str__(self):
return self.data

def read(self):
len = self.file.read8()
self.data = self.file.readstr(len)


class VMSDFieldInt(VMSDFieldGeneric):
def __init__(self, desc, file):
super(VMSDFieldInt, self).__init__(desc, file)
Expand Down Expand Up @@ -471,6 +508,7 @@ def getDict(self):
"unused_buffer" : VMSDFieldGeneric,
"bitmap" : VMSDFieldGeneric,
"struct" : VMSDFieldStruct,
"capability": VMSDFieldCap,
"unknown" : VMSDFieldGeneric,
}

Expand Down

0 comments on commit 31499a9

Please sign in to comment.