From abe2a37e561286feddb48090985b3ab93404e07f Mon Sep 17 00:00:00 2001 From: Weiyi Feng Date: Tue, 9 Nov 2021 12:03:13 +0800 Subject: [PATCH] config_tool: let common.MAX_VM_NUM controlled by scenario data let common.MAX_VM_NUM controlled by scenario data Tracked-On: #6685 Signed-off-by: Weiyi Feng --- .../board_config/board_cfg_gen.py | 3 ++- misc/config_tools/config_app/views.py | 24 ++++++++++++------- misc/config_tools/library/common.py | 5 ++-- .../scenario_config/scenario_cfg_gen.py | 3 ++- misc/config_tools/schema/config.xsd | 5 ++++ .../xforms/vm_configurations.h.xsl | 3 ++- 6 files changed, 30 insertions(+), 13 deletions(-) diff --git a/misc/config_tools/board_config/board_cfg_gen.py b/misc/config_tools/board_config/board_cfg_gen.py index 170347ad2..73ffd7f80 100755 --- a/misc/config_tools/board_config/board_cfg_gen.py +++ b/misc/config_tools/board_config/board_cfg_gen.py @@ -45,7 +45,8 @@ def main(args): common.get_vm_types() if common.VM_COUNT > common.MAX_VM_NUM: - err_dic['vm count'] = "The vm count in config xml should be less or equal {}!".format(common.MAX_VM_NUM) + err_dic['vm count'] = "The number of VMs in the scenario XML file should be no greater than " \ + "hv.CAPACITIES.MAX_VM_NUM. Its current value is {}.".format(common.MAX_VM_NUM) return err_dic # check if this is the scenario config which matched board info diff --git a/misc/config_tools/config_app/views.py b/misc/config_tools/config_app/views.py index ac7802dc5..6163f2139 100644 --- a/misc/config_tools/config_app/views.py +++ b/misc/config_tools/config_app/views.py @@ -19,12 +19,12 @@ from flask import request, render_template, Blueprint, redirect, url_for, curren # Refer to https://github.com/pallets/werkzeug/blob/master/LICENSE.rst for the permission notice. from werkzeug.utils import secure_filename +import common from controller import * from scenario_config.scenario_cfg_gen import get_scenario_item_values from scenario_config.scenario_cfg_gen import validate_scenario_setting from launch_config.launch_cfg_gen import get_launch_item_values from launch_config.launch_cfg_gen import validate_launch_setting -from library.common import MAX_VM_NUM import scenario_config.default_populator as default_populator @@ -245,6 +245,7 @@ def save_scenario(): board_type = xml_configs[1] scenario_config = xml_configs[3] + common.MAX_VM_NUM = int(scenario_config_data['hv,CAPACITIES,MAX_VM_NUM']) if board_type is None or xml_configs[0] is None: return {'status': 'fail', 'error_list': {'error': 'Please select the board info before this operation.'}} @@ -304,9 +305,9 @@ def save_scenario(): for vm in list(scenario_config.get_curr_root()): if vm.tag == 'vm': vm_list.append(vm.attrib['id']) - if len(vm_list) >= MAX_VM_NUM: + if len(vm_list) >= common.MAX_VM_NUM: return {'status': 'fail', - 'error_list': {'error': 'Can not add a new VM. Max VM number is {}.'.format(MAX_VM_NUM)}} + 'error_list': {'error': 'Cannot add a new VM. hv.CAPACITIES.MAX_VM_NUM is currently set to {}.'.format(common.MAX_VM_NUM)}} curr_vm_id = generator.split(':')[1] add_vm_type = scenario_config_data['add_vm_type'] add_scenario_config = get_generic_scenario_config(scenario_config, add_vm_type) @@ -320,7 +321,7 @@ def save_scenario(): curr_vm_index = i + 2 break if add_scenario_config is not None and add_scenario_config.tag == 'vm': - for i in range(0, MAX_VM_NUM): + for i in range(0, common.MAX_VM_NUM): if str(i) not in vm_list: break add_scenario_config.attrib['id'] = str(i) @@ -394,6 +395,8 @@ def save_launch(): scenario_file_path = os.path.join(current_app.config.get('CONFIG_PATH'), current_app.config.get('BOARD_TYPE'), scenario_name + '.xml') + # update VM_COUNT and MAX_VM_NUM + common.get_vm_num(scenario_file_path) for key in launch_config_data: if launch_config_data[key] in [None, 'None']: @@ -411,9 +414,14 @@ def save_launch(): for vm in list(launch_config.get_curr_root()): if vm.tag == 'user_vm': vm_list.append(vm.attrib['id']) - if len(vm_list) >= MAX_VM_NUM: - return {'status': 'fail', - 'error_list': {'error': 'Can not add a new VM. Max VM number is {}.'.format(MAX_VM_NUM)}} + if len(vm_list) >= common.MAX_VM_NUM: + return { + 'status': 'fail', + 'error_list': { + 'error': 'Cannot add a new VM. hv.CAPACITIES.MAX_VM_NUM ' + 'is currently set to {}.'.format(common.MAX_VM_NUM) + } + } curr_vm_id = generator.split(':')[1].strip() add_launch_type = launch_config_data['add_launch_type'] if add_launch_type is None or len(add_launch_type.split('ID :')) < 2: @@ -440,7 +448,7 @@ def save_launch(): curr_vm_index = i + 1 break if add_launch_config is not None and add_launch_config.tag == 'user_vm': - for i in range(1, MAX_VM_NUM): + for i in range(1, common.MAX_VM_NUM): if str(i) not in vm_list: break add_launch_config.attrib['id'] = str(add_launch_id) diff --git a/misc/config_tools/library/common.py b/misc/config_tools/library/common.py index 091970d50..f15e8111a 100644 --- a/misc/config_tools/library/common.py +++ b/misc/config_tools/library/common.py @@ -38,7 +38,7 @@ BOARD_INFO_FILE = "" SCENARIO_INFO_FILE = "" LAUNCH_INFO_FILE = "" VM_TYPES = {} -MAX_VM_NUM = 32 +MAX_VM_NUM = 16 MAX_VUART_NUM = 8 @@ -291,7 +291,7 @@ def get_vm_num(config_file): :param config_file: it is a file what contains information for script to read from :return: total vm number """ - global VM_COUNT + global VM_COUNT, MAX_VM_NUM vm_count = 0 root = get_config_root(config_file) for item in root: @@ -299,6 +299,7 @@ def get_vm_num(config_file): if item.tag == "vm": vm_count += 1 VM_COUNT = vm_count + MAX_VM_NUM = int(root.find(".//MAX_VM_NUM").text) def get_leaf_value(tmp, tag_str, leaf): diff --git a/misc/config_tools/scenario_config/scenario_cfg_gen.py b/misc/config_tools/scenario_config/scenario_cfg_gen.py index 31ccfd9a1..97d75c985 100755 --- a/misc/config_tools/scenario_config/scenario_cfg_gen.py +++ b/misc/config_tools/scenario_config/scenario_cfg_gen.py @@ -217,7 +217,8 @@ def main(args): return err_dic if common.VM_COUNT > common.MAX_VM_NUM: - err_dic['vm count'] = "Number of VMs in scenario xml file should be no greater than {}!".format(common.MAX_VM_NUM) + err_dic['vm count'] = "Number of VMs in scenario xml file should be no greater than hv/CAPACITIES/MAX_VM_NUM ! " \ + "Now this value is {}.".format(common.MAX_VM_NUM) return err_dic # check if this is the scenario config which matches board info diff --git a/misc/config_tools/schema/config.xsd b/misc/config_tools/schema/config.xsd index 9a3cca093..cfcb69238 100644 --- a/misc/config_tools/schema/config.xsd +++ b/misc/config_tools/schema/config.xsd @@ -222,6 +222,11 @@ value ``0x400000000``. maximum supported resource. + + + Maximum number of User VMs allowed. + + Highest PCI bus ID used during IOMMU diff --git a/misc/config_tools/xforms/vm_configurations.h.xsl b/misc/config_tools/xforms/vm_configurations.h.xsl index 61ddc5223..d7a0a37e2 100644 --- a/misc/config_tools/xforms/vm_configurations.h.xsl +++ b/misc/config_tools/xforms/vm_configurations.h.xsl @@ -41,7 +41,8 @@ - + +