config_tools: update upgrader.py script for virtio

1. add virtio gpu logic in upgrader.py script.
2. fix the upgraded virtio elements issue.
3. add the logic to remove the element with empty value in xml file
to use the default value.

Tracked-On: #7301
Signed-off-by: Kunhui-Li <kunhuix.li@intel.com>
Reviewed-by: Junjie Mao <junjie.mao@intel.com>
This commit is contained in:
Kunhui-Li 2022-04-20 23:28:03 +08:00 committed by acrnsi-robot
parent 68f88a4bc9
commit 15e83758d6
13 changed files with 71 additions and 73 deletions

View File

@ -147,7 +147,6 @@
<virtio_devices> <virtio_devices>
<console/> <console/>
<network> <network>
<virtio_framework/>
<interface_name>WaaG</interface_name> <interface_name>WaaG</interface_name>
</network> </network>
<input/> <input/>
@ -181,7 +180,6 @@
<backend_type>stdio</backend_type> <backend_type>stdio</backend_type>
</console> </console>
<network> <network>
<virtio_framework/>
<interface_name>YaaG</interface_name> <interface_name>YaaG</interface_name>
</network> </network>
<input/> <input/>

View File

@ -102,7 +102,6 @@
<virtio_devices> <virtio_devices>
<console/> <console/>
<network> <network>
<virtio_framework/>
<interface_name>WaaG</interface_name> <interface_name>WaaG</interface_name>
</network> </network>
<input/> <input/>
@ -143,7 +142,6 @@
<backend_type>stdio</backend_type> <backend_type>stdio</backend_type>
</console> </console>
<network> <network>
<virtio_framework/>
<interface_name>RT</interface_name> <interface_name>RT</interface_name>
</network> </network>
<input/> <input/>
@ -181,7 +179,6 @@
<backend_type>stdio</backend_type> <backend_type>stdio</backend_type>
</console> </console>
<network> <network>
<virtio_framework/>
<interface_name>YaaG3</interface_name> <interface_name>YaaG3</interface_name>
</network> </network>
<input/> <input/>
@ -219,7 +216,6 @@
<backend_type>stdio</backend_type> <backend_type>stdio</backend_type>
</console> </console>
<network> <network>
<virtio_framework/>
<interface_name>YaaG4</interface_name> <interface_name>YaaG4</interface_name>
</network> </network>
<input/> <input/>
@ -257,7 +253,6 @@
<backend_type>stdio</backend_type> <backend_type>stdio</backend_type>
</console> </console>
<network> <network>
<virtio_framework/>
<interface_name>YaaG5</interface_name> <interface_name>YaaG5</interface_name>
</network> </network>
<input/> <input/>
@ -295,7 +290,6 @@
<backend_type>stdio</backend_type> <backend_type>stdio</backend_type>
</console> </console>
<network> <network>
<virtio_framework/>
<interface_name>YaaG6</interface_name> <interface_name>YaaG6</interface_name>
</network> </network>
<input/> <input/>

View File

@ -147,7 +147,6 @@
<virtio_devices> <virtio_devices>
<console/> <console/>
<network> <network>
<virtio_framework/>
<interface_name>WaaG</interface_name> <interface_name>WaaG</interface_name>
</network> </network>
<input/> <input/>
@ -181,7 +180,6 @@
<backend_type>stdio</backend_type> <backend_type>stdio</backend_type>
</console> </console>
<network> <network>
<virtio_framework/>
<interface_name>YaaG</interface_name> <interface_name>YaaG</interface_name>
</network> </network>
<input/> <input/>

View File

@ -102,7 +102,6 @@
<virtio_devices> <virtio_devices>
<console/> <console/>
<network> <network>
<virtio_framework/>
<interface_name>WaaG</interface_name> <interface_name>WaaG</interface_name>
</network> </network>
<input/> <input/>
@ -143,7 +142,6 @@
<backend_type>stdio</backend_type> <backend_type>stdio</backend_type>
</console> </console>
<network> <network>
<virtio_framework/>
<interface_name>RT</interface_name> <interface_name>RT</interface_name>
</network> </network>
<input/> <input/>
@ -181,7 +179,6 @@
<backend_type>stdio</backend_type> <backend_type>stdio</backend_type>
</console> </console>
<network> <network>
<virtio_framework/>
<interface_name>YaaG3</interface_name> <interface_name>YaaG3</interface_name>
</network> </network>
<input/> <input/>
@ -219,7 +216,6 @@
<backend_type>stdio</backend_type> <backend_type>stdio</backend_type>
</console> </console>
<network> <network>
<virtio_framework/>
<interface_name>YaaG4</interface_name> <interface_name>YaaG4</interface_name>
</network> </network>
<input/> <input/>
@ -257,7 +253,6 @@
<backend_type>stdio</backend_type> <backend_type>stdio</backend_type>
</console> </console>
<network> <network>
<virtio_framework/>
<interface_name>YaaG5</interface_name> <interface_name>YaaG5</interface_name>
</network> </network>
<input/> <input/>
@ -295,7 +290,6 @@
<backend_type>stdio</backend_type> <backend_type>stdio</backend_type>
</console> </console>
<network> <network>
<virtio_framework/>
<interface_name>YaaG6</interface_name> <interface_name>YaaG6</interface_name>
</network> </network>
<input/> <input/>

View File

@ -147,7 +147,6 @@
<virtio_devices> <virtio_devices>
<console/> <console/>
<network> <network>
<virtio_framework/>
<interface_name>WaaG</interface_name> <interface_name>WaaG</interface_name>
</network> </network>
<input/> <input/>
@ -181,7 +180,6 @@
<backend_type>stdio</backend_type> <backend_type>stdio</backend_type>
</console> </console>
<network> <network>
<virtio_framework/>
<interface_name>YaaG</interface_name> <interface_name>YaaG</interface_name>
</network> </network>
<input/> <input/>

View File

@ -114,7 +114,6 @@
<virtio_devices> <virtio_devices>
<console/> <console/>
<network> <network>
<virtio_framework/>
<interface_name>WaaG</interface_name> <interface_name>WaaG</interface_name>
</network> </network>
<input/> <input/>
@ -155,7 +154,6 @@
<backend_type>stdio</backend_type> <backend_type>stdio</backend_type>
</console> </console>
<network> <network>
<virtio_framework/>
<interface_name>RT</interface_name> <interface_name>RT</interface_name>
</network> </network>
<input/> <input/>
@ -193,7 +191,6 @@
<backend_type>stdio</backend_type> <backend_type>stdio</backend_type>
</console> </console>
<network> <network>
<virtio_framework/>
<interface_name>YaaG3</interface_name> <interface_name>YaaG3</interface_name>
</network> </network>
<input/> <input/>
@ -231,7 +228,6 @@
<backend_type>stdio</backend_type> <backend_type>stdio</backend_type>
</console> </console>
<network> <network>
<virtio_framework/>
<interface_name>YaaG4</interface_name> <interface_name>YaaG4</interface_name>
</network> </network>
<input/> <input/>
@ -269,7 +265,6 @@
<backend_type>stdio</backend_type> <backend_type>stdio</backend_type>
</console> </console>
<network> <network>
<virtio_framework/>
<interface_name>YaaG5</interface_name> <interface_name>YaaG5</interface_name>
</network> </network>
<input/> <input/>
@ -307,7 +302,6 @@
<backend_type>stdio</backend_type> <backend_type>stdio</backend_type>
</console> </console>
<network> <network>
<virtio_framework/>
<interface_name>YaaG6</interface_name> <interface_name>YaaG6</interface_name>
</network> </network>
<input/> <input/>

View File

@ -119,7 +119,6 @@
<backend_type>stdio</backend_type> <backend_type>stdio</backend_type>
</console> </console>
<network> <network>
<virtio_framework/>
<interface_name>WaaG</interface_name> <interface_name>WaaG</interface_name>
</network> </network>
<input/> <input/>
@ -161,7 +160,6 @@
<backend_type>stdio</backend_type> <backend_type>stdio</backend_type>
</console> </console>
<network> <network>
<virtio_framework/>
<interface_name>RT</interface_name> <interface_name>RT</interface_name>
</network> </network>
<input/> <input/>

View File

@ -175,7 +175,6 @@
<virtio_devices> <virtio_devices>
<console/> <console/>
<network> <network>
<virtio_framework/>
<interface_name>WaaG</interface_name> <interface_name>WaaG</interface_name>
</network> </network>
<input/> <input/>

View File

@ -123,7 +123,6 @@
<backend_type>stdio</backend_type> <backend_type>stdio</backend_type>
</console> </console>
<network> <network>
<virtio_framework/>
<interface_name>RT</interface_name> <interface_name>RT</interface_name>
</network> </network>
<input/> <input/>

View File

@ -103,7 +103,6 @@
<virtio_devices> <virtio_devices>
<console/> <console/>
<network> <network>
<virtio_framework/>
<interface_name>WaaG</interface_name> <interface_name>WaaG</interface_name>
</network> </network>
<input/> <input/>

View File

@ -103,7 +103,6 @@
<virtio_devices> <virtio_devices>
<console/> <console/>
<network> <network>
<virtio_framework/>
<interface_name>WaaG</interface_name> <interface_name>WaaG</interface_name>
</network> </network>
<input/> <input/>
@ -144,7 +143,6 @@
<backend_type>stdio</backend_type> <backend_type>stdio</backend_type>
</console> </console>
<network> <network>
<virtio_framework/>
<interface_name>RT</interface_name> <interface_name>RT</interface_name>
</network> </network>
<input/> <input/>

View File

@ -103,7 +103,6 @@
<virtio_devices> <virtio_devices>
<console/> <console/>
<network> <network>
<virtio_framework/>
<interface_name>WaaG</interface_name> <interface_name>WaaG</interface_name>
</network> </network>
<input/> <input/>
@ -144,7 +143,6 @@
<backend_type>stdio</backend_type> <backend_type>stdio</backend_type>
</console> </console>
<network> <network>
<virtio_framework/>
<interface_name>RT</interface_name> <interface_name>RT</interface_name>
</network> </network>
<input/> <input/>

View File

@ -233,45 +233,52 @@ class SharedMemoryRegions:
return node return node
class VirtioDevices(object): class VirtioDevices(object):
def __init__(self, old_xml_etree): def __init__(self, old_xml_etree):
self.gpus = []
self.blocks = [] self.blocks = []
self.inputs = [] self.inputs = []
self.networks = [] self.networks = []
self.console = namedtuple("console", ["use_type", "backend_type", "file_path"]) self.consoles = []
self.old_xml_etree = old_xml_etree
def console_encoding(self, text): def console_encoding(self, console):
if text is not None: if console.text is not None:
self.console.use_type = "Virtio console" if text.startswith("@") else "Virtio serial port" use_type = "Virtio console" if console.text.startswith("@") else "Virtio serial port"
self.console.backend_type = text.split(":")[0].replace("@", "") backend_type = console.text.split(":")[0].replace("@", "")
self.console.file_path = text.split("=")[1].split(":")[0] if "=" in text else None file_path = console.text.split("=")[1].split(":")[0] if "=" in console.text else None
else: else:
self.console = self.console(use_type=None, backend_type=None, file_path=None) use_type = console.xpath("./use_type")[0].text if console.xpath("./use_type") else None
return self.console backend_type = console.xpath("./backend_type")[0].text if console.xpath("./backend_type") else None
file_path = console.xpath("./file_path")[0].text if console.xpath("./file_path") else None
self.consoles.append((use_type, backend_type, file_path))
def format_console_element(self): def format_console_element(self, console):
node = etree.Element("console") node = etree.Element("console")
etree.SubElement(node, "use_type").text = self.console.use_type if console[0] is not None:
etree.SubElement(node, "backend_type").text = self.console.backend_type etree.SubElement(node, "use_type").text = console[0]
if self.console.backend_type == "socket": if console[1] is not None:
etree.SubElement(node, "sock_file_path").text = self.console.file_path etree.SubElement(node, "backend_type").text = console[1]
if self.console.backend_type == "tty": if console[1] == "socket":
etree.SubElement(node, "tty_device_path").text = self.console.file_path etree.SubElement(node, "sock_file_path").text = console[2]
if self.console.backend_type == "file": if console[1] == "tty":
etree.SubElement(node, "output_file_path").text = self.console.file_path etree.SubElement(node, "tty_device_path").text = console[2]
if console[1] == "file":
etree.SubElement(node, "output_file_path").text = console[2]
return node return node
def format_network_element(self, network): def format_network_element(self, network):
node = etree.Element("network") node = etree.Element("network")
etree.SubElement(node, "virtio_framework") if network[0] is not None:
etree.SubElement(node, "interface_name").text = network etree.SubElement(node, "virtio_framework").text = network[0]
if network[1] is not None:
etree.SubElement(node, "interface_name").text = network[1]
return node return node
def format_input_element(self, input): def format_input_element(self, input):
node = etree.Element("input") node = etree.Element("input")
etree.SubElement(node, "backend_device_file").text = input if input[0] is not None:
etree.SubElement(node, "id") etree.SubElement(node, "backend_device_file").text = input[0]
if input[1] is not None:
etree.SubElement(node, "id").text = input[1]
return node return node
def format_block_element(self, block): def format_block_element(self, block):
@ -279,25 +286,51 @@ class VirtioDevices(object):
node.text = block node.text = block
return node return node
def format_gpu_element(self, gpu):
if gpu is not None:
node = etree.Element("gpu")
node.text = gpu
return node
def format_xml_element(self): def format_xml_element(self):
node = etree.Element("virtio_devices") node = etree.Element("virtio_devices")
node.append(self.format_console_element()) for console in self.consoles:
node.append(self.format_console_element(console))
for network in self.networks: for network in self.networks:
node.append(self.format_network_element(network)) node.append(self.format_network_element(network))
for input in self.inputs: for input in self.inputs:
node.append(self.format_input_element(input)) node.append(self.format_input_element(input))
for block in self.blocks: for block in self.blocks:
node.append(self.format_block_element(block)) node.append(self.format_block_element(block))
for gpu in self.gpus:
node.append(self.format_gpu_element(gpu))
return node return node
def add_virtio_devices(self, virtio_device_node): def add_virtio_devices(self, virtio_device_node):
self.console = self.console_encoding(virtio_device_node.xpath("./console")[0].text) if virtio_device_node.xpath("./network")[0].text is not None:
for virtio_network in virtio_device_node.xpath("./network"): for network in virtio_device_node.xpath("./network"):
self.networks.append(virtio_network.text) self.networks.append((None, network.text))
for virtio_input in virtio_device_node.xpath("./input"): else:
self.inputs.append(virtio_input.text) for network in virtio_device_node.xpath("./network"):
for virtio_block in virtio_device_node.xpath("./block"): virtio_framework = network.xpath("./virtio_framework")[0].text if network.xpath("./virtio_framework") else None
self.blocks.append(virtio_block.text) interface_name = network.xpath("./interface_name")[0].text if network.xpath("./interface_name") else None
self.networks.append((virtio_framework, interface_name))
if virtio_device_node.xpath("./input")[0].text is not None:
for input in virtio_device_node.xpath("./input"):
self.inputs.append((None, input.text))
else:
for input in virtio_device_node.xpath("./input"):
backend_device_file = input.xpath("./backend_device_file")[0].text if input.xpath("./backend_device_file") else None
id = input.xpath("./id")[0].text if input.xpath("./id") else None
self.inputs.append((backend_device_file, id))
for console in virtio_device_node.xpath("./console"):
self.console_encoding(console)
for block in virtio_device_node.xpath("./block"):
self.blocks.append(block.text)
for gpu in virtio_device_node.xpath("./gpu"):
self.gpus.append(gpu.text)
class ScenarioUpgrader(ScenarioTransformer): class ScenarioUpgrader(ScenarioTransformer):
@classmethod @classmethod
@ -364,17 +397,15 @@ class ScenarioUpgrader(ScenarioTransformer):
def move_virtio_devices(self, xsd_element_node, xml_parent_node, new_nodes): def move_virtio_devices(self, xsd_element_node, xml_parent_node, new_nodes):
virtio = VirtioDevices(self.old_xml_etree) virtio = VirtioDevices(self.old_xml_etree)
try: try:
old_data_virtio = self.get_from_old_data(xml_parent_node, ".//virtio_devices").pop() old_data_virtio = self.get_from_old_data(xml_parent_node, ".//virtio_devices").pop()
except IndexError as e: except IndexError as e:
logging.debug(e) logging.debug(e)
return return
old_data_virtio = self.get_from_old_data(xml_parent_node, ".//virtio_devices").pop()
virtio.add_virtio_devices(old_data_virtio) virtio.add_virtio_devices(old_data_virtio)
for child in old_data_virtio.iter(): for child in old_data_virtio.iter():
self.old_data_nodes.discard(child) self.old_data_nodes.discard(child)
new_nodes.append(virtio.format_xml_element()) new_nodes.append(virtio.format_xml_element())
return False return False