From 15e83758d6817857d59207decca99871ed35ff4c Mon Sep 17 00:00:00 2001 From: Kunhui-Li Date: Wed, 20 Apr 2022 23:28:03 +0800 Subject: [PATCH] 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 Reviewed-by: Junjie Mao --- .../cfl-k700-i7/hybrid_launch_2user_vm.xml | 2 - .../cfl-k700-i7/shared_launch_6user_vm.xml | 6 -- .../generic_board/hybrid_launch_2user_vm.xml | 2 - .../generic_board/shared_launch_6user_vm.xml | 6 -- .../nuc11tnbi5/hybrid_launch_2user_vm.xml | 2 - .../nuc11tnbi5/shared_launch_6user_vm.xml | 18 ++-- .../shared_launch_2user_vm.xml | 2 - .../hybrid_rt_launch_1user_vm_waag.xml | 1 - .../shared_launch_1user_vm_hardrt.xml | 1 - .../shared_launch_1user_vm_waag.xml | 1 - .../whl-ipc-i5/shared_launch_2user_vm.xml | 2 - .../whl-ipc-i5/shared_launch_6user_vm.xml | 2 - misc/config_tools/scenario_config/upgrader.py | 99 ++++++++++++------- 13 files changed, 71 insertions(+), 73 deletions(-) diff --git a/misc/config_tools/data/cfl-k700-i7/hybrid_launch_2user_vm.xml b/misc/config_tools/data/cfl-k700-i7/hybrid_launch_2user_vm.xml index 39d011f23..018889e62 100644 --- a/misc/config_tools/data/cfl-k700-i7/hybrid_launch_2user_vm.xml +++ b/misc/config_tools/data/cfl-k700-i7/hybrid_launch_2user_vm.xml @@ -147,7 +147,6 @@ - WaaG @@ -181,7 +180,6 @@ stdio - YaaG diff --git a/misc/config_tools/data/cfl-k700-i7/shared_launch_6user_vm.xml b/misc/config_tools/data/cfl-k700-i7/shared_launch_6user_vm.xml index 93d431e15..9ff217f93 100644 --- a/misc/config_tools/data/cfl-k700-i7/shared_launch_6user_vm.xml +++ b/misc/config_tools/data/cfl-k700-i7/shared_launch_6user_vm.xml @@ -102,7 +102,6 @@ - WaaG @@ -143,7 +142,6 @@ stdio - RT @@ -181,7 +179,6 @@ stdio - YaaG3 @@ -219,7 +216,6 @@ stdio - YaaG4 @@ -257,7 +253,6 @@ stdio - YaaG5 @@ -295,7 +290,6 @@ stdio - YaaG6 diff --git a/misc/config_tools/data/generic_board/hybrid_launch_2user_vm.xml b/misc/config_tools/data/generic_board/hybrid_launch_2user_vm.xml index aa1792b9c..5f4befa6f 100644 --- a/misc/config_tools/data/generic_board/hybrid_launch_2user_vm.xml +++ b/misc/config_tools/data/generic_board/hybrid_launch_2user_vm.xml @@ -147,7 +147,6 @@ - WaaG @@ -181,7 +180,6 @@ stdio - YaaG diff --git a/misc/config_tools/data/generic_board/shared_launch_6user_vm.xml b/misc/config_tools/data/generic_board/shared_launch_6user_vm.xml index 1b05c0401..db94c8475 100644 --- a/misc/config_tools/data/generic_board/shared_launch_6user_vm.xml +++ b/misc/config_tools/data/generic_board/shared_launch_6user_vm.xml @@ -102,7 +102,6 @@ - WaaG @@ -143,7 +142,6 @@ stdio - RT @@ -181,7 +179,6 @@ stdio - YaaG3 @@ -219,7 +216,6 @@ stdio - YaaG4 @@ -257,7 +253,6 @@ stdio - YaaG5 @@ -295,7 +290,6 @@ stdio - YaaG6 diff --git a/misc/config_tools/data/nuc11tnbi5/hybrid_launch_2user_vm.xml b/misc/config_tools/data/nuc11tnbi5/hybrid_launch_2user_vm.xml index aa1792b9c..5f4befa6f 100644 --- a/misc/config_tools/data/nuc11tnbi5/hybrid_launch_2user_vm.xml +++ b/misc/config_tools/data/nuc11tnbi5/hybrid_launch_2user_vm.xml @@ -147,7 +147,6 @@ - WaaG @@ -181,7 +180,6 @@ stdio - YaaG diff --git a/misc/config_tools/data/nuc11tnbi5/shared_launch_6user_vm.xml b/misc/config_tools/data/nuc11tnbi5/shared_launch_6user_vm.xml index 75c368af1..9c053add1 100644 --- a/misc/config_tools/data/nuc11tnbi5/shared_launch_6user_vm.xml +++ b/misc/config_tools/data/nuc11tnbi5/shared_launch_6user_vm.xml @@ -114,8 +114,7 @@ - - WaaG + WaaG ./win10-ltsc.img @@ -155,8 +154,7 @@ stdio - - RT + RT ./core-image-weston-intel-corei7-64.wic @@ -193,8 +191,7 @@ stdio - - YaaG3 + YaaG3 ./YaaG.img @@ -231,8 +228,7 @@ stdio - - YaaG4 + YaaG4 ./YaaG.img @@ -269,8 +265,7 @@ stdio - - YaaG5 + YaaG5 ./YaaG.img @@ -307,8 +302,7 @@ stdio - - YaaG6 + YaaG6 ./YaaG.img diff --git a/misc/config_tools/data/tgl-vecow-spc-7100-Corei7/shared_launch_2user_vm.xml b/misc/config_tools/data/tgl-vecow-spc-7100-Corei7/shared_launch_2user_vm.xml index 664774a74..10193bdeb 100644 --- a/misc/config_tools/data/tgl-vecow-spc-7100-Corei7/shared_launch_2user_vm.xml +++ b/misc/config_tools/data/tgl-vecow-spc-7100-Corei7/shared_launch_2user_vm.xml @@ -119,7 +119,6 @@ stdio - WaaG @@ -161,7 +160,6 @@ stdio - RT diff --git a/misc/config_tools/data/whl-ipc-i5/hybrid_rt_launch_1user_vm_waag.xml b/misc/config_tools/data/whl-ipc-i5/hybrid_rt_launch_1user_vm_waag.xml index 20858ac3d..50416fc94 100644 --- a/misc/config_tools/data/whl-ipc-i5/hybrid_rt_launch_1user_vm_waag.xml +++ b/misc/config_tools/data/whl-ipc-i5/hybrid_rt_launch_1user_vm_waag.xml @@ -175,7 +175,6 @@ - WaaG diff --git a/misc/config_tools/data/whl-ipc-i5/shared_launch_1user_vm_hardrt.xml b/misc/config_tools/data/whl-ipc-i5/shared_launch_1user_vm_hardrt.xml index 52a79d18e..59b29bb1b 100644 --- a/misc/config_tools/data/whl-ipc-i5/shared_launch_1user_vm_hardrt.xml +++ b/misc/config_tools/data/whl-ipc-i5/shared_launch_1user_vm_hardrt.xml @@ -123,7 +123,6 @@ stdio - RT diff --git a/misc/config_tools/data/whl-ipc-i5/shared_launch_1user_vm_waag.xml b/misc/config_tools/data/whl-ipc-i5/shared_launch_1user_vm_waag.xml index ac732c2e7..7d6e105ce 100644 --- a/misc/config_tools/data/whl-ipc-i5/shared_launch_1user_vm_waag.xml +++ b/misc/config_tools/data/whl-ipc-i5/shared_launch_1user_vm_waag.xml @@ -103,7 +103,6 @@ - WaaG diff --git a/misc/config_tools/data/whl-ipc-i5/shared_launch_2user_vm.xml b/misc/config_tools/data/whl-ipc-i5/shared_launch_2user_vm.xml index b20a90e29..61a57cb4c 100644 --- a/misc/config_tools/data/whl-ipc-i5/shared_launch_2user_vm.xml +++ b/misc/config_tools/data/whl-ipc-i5/shared_launch_2user_vm.xml @@ -103,7 +103,6 @@ - WaaG @@ -144,7 +143,6 @@ stdio - RT diff --git a/misc/config_tools/data/whl-ipc-i5/shared_launch_6user_vm.xml b/misc/config_tools/data/whl-ipc-i5/shared_launch_6user_vm.xml index 6c9b0f215..c49bd5d9d 100644 --- a/misc/config_tools/data/whl-ipc-i5/shared_launch_6user_vm.xml +++ b/misc/config_tools/data/whl-ipc-i5/shared_launch_6user_vm.xml @@ -103,7 +103,6 @@ - WaaG @@ -144,7 +143,6 @@ stdio - RT diff --git a/misc/config_tools/scenario_config/upgrader.py b/misc/config_tools/scenario_config/upgrader.py index ee4cf0dde..ae28cb446 100755 --- a/misc/config_tools/scenario_config/upgrader.py +++ b/misc/config_tools/scenario_config/upgrader.py @@ -233,45 +233,52 @@ class SharedMemoryRegions: return node class VirtioDevices(object): - def __init__(self, old_xml_etree): + self.gpus = [] self.blocks = [] self.inputs = [] self.networks = [] - self.console = namedtuple("console", ["use_type", "backend_type", "file_path"]) - self.old_xml_etree = old_xml_etree + self.consoles = [] - def console_encoding(self, text): - if text is not None: - self.console.use_type = "Virtio console" if text.startswith("@") else "Virtio serial port" - self.console.backend_type = text.split(":")[0].replace("@", "") - self.console.file_path = text.split("=")[1].split(":")[0] if "=" in text else None + def console_encoding(self, console): + if console.text is not None: + use_type = "Virtio console" if console.text.startswith("@") else "Virtio serial port" + backend_type = console.text.split(":")[0].replace("@", "") + file_path = console.text.split("=")[1].split(":")[0] if "=" in console.text else None else: - self.console = self.console(use_type=None, backend_type=None, file_path=None) - return self.console + use_type = console.xpath("./use_type")[0].text if console.xpath("./use_type") else None + 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") - etree.SubElement(node, "use_type").text = self.console.use_type - etree.SubElement(node, "backend_type").text = self.console.backend_type - if self.console.backend_type == "socket": - etree.SubElement(node, "sock_file_path").text = self.console.file_path - if self.console.backend_type == "tty": - etree.SubElement(node, "tty_device_path").text = self.console.file_path - if self.console.backend_type == "file": - etree.SubElement(node, "output_file_path").text = self.console.file_path + if console[0] is not None: + etree.SubElement(node, "use_type").text = console[0] + if console[1] is not None: + etree.SubElement(node, "backend_type").text = console[1] + if console[1] == "socket": + etree.SubElement(node, "sock_file_path").text = console[2] + if console[1] == "tty": + etree.SubElement(node, "tty_device_path").text = console[2] + if console[1] == "file": + etree.SubElement(node, "output_file_path").text = console[2] return node def format_network_element(self, network): node = etree.Element("network") - etree.SubElement(node, "virtio_framework") - etree.SubElement(node, "interface_name").text = network + if network[0] is not None: + etree.SubElement(node, "virtio_framework").text = network[0] + if network[1] is not None: + etree.SubElement(node, "interface_name").text = network[1] return node def format_input_element(self, input): node = etree.Element("input") - etree.SubElement(node, "backend_device_file").text = input - etree.SubElement(node, "id") + if input[0] is not None: + etree.SubElement(node, "backend_device_file").text = input[0] + if input[1] is not None: + etree.SubElement(node, "id").text = input[1] return node def format_block_element(self, block): @@ -279,25 +286,51 @@ class VirtioDevices(object): node.text = block 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): 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: node.append(self.format_network_element(network)) for input in self.inputs: node.append(self.format_input_element(input)) for block in self.blocks: node.append(self.format_block_element(block)) + for gpu in self.gpus: + node.append(self.format_gpu_element(gpu)) return node def add_virtio_devices(self, virtio_device_node): - self.console = self.console_encoding(virtio_device_node.xpath("./console")[0].text) - for virtio_network in virtio_device_node.xpath("./network"): - self.networks.append(virtio_network.text) - for virtio_input in virtio_device_node.xpath("./input"): - self.inputs.append(virtio_input.text) - for virtio_block in virtio_device_node.xpath("./block"): - self.blocks.append(virtio_block.text) + if virtio_device_node.xpath("./network")[0].text is not None: + for network in virtio_device_node.xpath("./network"): + self.networks.append((None, network.text)) + else: + for network in virtio_device_node.xpath("./network"): + virtio_framework = network.xpath("./virtio_framework")[0].text if network.xpath("./virtio_framework") else None + 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): @classmethod @@ -364,17 +397,15 @@ class ScenarioUpgrader(ScenarioTransformer): def move_virtio_devices(self, xsd_element_node, xml_parent_node, new_nodes): virtio = VirtioDevices(self.old_xml_etree) - try: old_data_virtio = self.get_from_old_data(xml_parent_node, ".//virtio_devices").pop() except IndexError as e: logging.debug(e) return - old_data_virtio = self.get_from_old_data(xml_parent_node, ".//virtio_devices").pop() + virtio.add_virtio_devices(old_data_virtio) for child in old_data_virtio.iter(): self.old_data_nodes.discard(child) - new_nodes.append(virtio.format_xml_element()) return False