From bb2218effc32b33fcb766a8afab0e3b49c12fdd7 Mon Sep 17 00:00:00 2001 From: Shuang Zheng Date: Mon, 25 Nov 2019 16:09:46 +0800 Subject: [PATCH] acrn-config: add UI to add or remove Kata VM for sdc scenario add UI to add or remove Kata VM for sdc scenario, the added Kata VM is based on the generic config xml. Tracked-On: 4145 Signed-off-by: Shuang Zheng Reviewed-by: Victor Sun --- misc/acrn-config/config_app/controller.py | 13 +++++++ misc/acrn-config/config_app/static/main.js | 16 +++++++- .../config_app/templates/scenario.html | 15 ++++++++ misc/acrn-config/config_app/views.py | 37 ++++++++++++++++++- 4 files changed, 78 insertions(+), 3 deletions(-) diff --git a/misc/acrn-config/config_app/controller.py b/misc/acrn-config/config_app/controller.py index e764ee92e..b49ba97c5 100644 --- a/misc/acrn-config/config_app/controller.py +++ b/misc/acrn-config/config_app/controller.py @@ -202,6 +202,19 @@ class XmlConfig: new_node = ElementTree.SubElement(dest_node, key, attrib={'desc': desc}) new_node.text = value + def clone_curr_elem(self, elem, *args): + """ + clone elements for current path. + :param elem: the element to clone. + :param args: the path of the element. + :return: None. + """ + if self._curr_xml_tree is None: + return + + dest_node = self._get_dest_node(*args) + dest_node.append(elem) + def delete_curr_key(self, *args): """ delete the element by its path. diff --git a/misc/acrn-config/config_app/static/main.js b/misc/acrn-config/config_app/static/main.js index f0093cf4f..f5b89623d 100644 --- a/misc/acrn-config/config_app/static/main.js +++ b/misc/acrn-config/config_app/static/main.js @@ -323,6 +323,17 @@ $().ready(function(){ config_item.remove(); }); + $('#remove_vm_kata').on('click', function() { + if(confirm("Do you want to remove the VM?")) { + save_scenario("remove_vm_kata"); + } + }); + + $('#add_vm_kata').on('click', function() { + if(confirm("Do you want to add the Kata VM based on generic config?")) { + save_scenario("add_vm_kata"); + } + }); }) @@ -362,7 +373,8 @@ function save_scenario(generator=null){ scenario_config = { old_scenario_name: $("#old_scenario_name").text(), - new_scenario_name: $("#new_scenario_name").val() + new_scenario_name: $("#new_scenario_name").val(), + generator: generator } $("input").each(function(){ @@ -425,7 +437,7 @@ function save_scenario(generator=null){ validate_message = 'Scenario setting existed, saved successfully with a new name: ' +file_name+'\ninto acrn-hypervisor/misc/acrn-config/xmls/config-xmls/'+board_info+'/user_defined/.'; } - if(generator != null) { + if(generator=="generate_board_src" || generator=="generate_scenario_src") { commit_confirm_message = validate_message+'\n\nGenerate source codes from scenario setting.' +'\n\nDo you want to commit changes to local tree?' commit_confirm = 'no' diff --git a/misc/acrn-config/config_app/templates/scenario.html b/misc/acrn-config/config_app/templates/scenario.html index 0f8f922b4..75f0001f6 100644 --- a/misc/acrn-config/config_app/templates/scenario.html +++ b/misc/acrn-config/config_app/templates/scenario.html @@ -87,14 +87,24 @@ {% if board_info != None and root != None and scenario_item_values %} + {% set vm_kata = [] %} {% for vm in root.getchildren() %} + {% if 'desc' in vm.attrib and vm.attrib['desc'] == 'specific for Kata' %} + {% do vm_kata.append(1) %} + {% endif %} {% if 'configurable' not in vm.attrib or vm.attrib['configurable'] != '0'%} {% endif %} {% endfor %} + {% if not vm_kata and ('scenario' in root.attrib and root.attrib['scenario'] == 'sdc') %} + + {% endif %}
+
+ {% if 'desc' in vm.attrib or vm.attrib['desc'] == 'specific for Kata' %} +
+ +
+ {% endif %}
{% for elem in vm.getchildren() %} @@ -321,6 +331,11 @@
+ +
{% else %} No setting available. Select one board info and make sure the scenario xml diff --git a/misc/acrn-config/config_app/views.py b/misc/acrn-config/config_app/views.py index 7cfd39764..4214e17bb 100644 --- a/misc/acrn-config/config_app/views.py +++ b/misc/acrn-config/config_app/views.py @@ -169,12 +169,26 @@ def save_scenario(): scenario_config.set_curr(old_scenario_name) for key in scenario_config_data: if key not in ['old_scenario_name', 'new_scenario_name', 'board_info_file', - 'board_info_upload']: + 'board_info_upload', 'generator']: if isinstance(scenario_config_data[key], list): scenario_config.set_curr_list(scenario_config_data[key], *tuple(key.split(','))) else: scenario_config.set_curr_value(scenario_config_data[key], *tuple(key.split(','))) + if scenario_config_data['generator'] == 'remove_vm_kata': + scenario_config.delete_curr_key('vm:desc=specific for Kata') + elif scenario_config_data['generator'] == 'add_vm_kata': + # clone vm kata from generic config + generic_scenario_config = get_generic_scenario_config(scenario_config) + generic_scenario_config_root = generic_scenario_config.get_curr_root() + elem_kata = None + for vm in generic_scenario_config_root.getchildren(): + if 'desc' in vm.attrib and vm.attrib['desc'] == 'specific for Kata': + elem_kata = vm + break + if elem_kata is not None: + scenario_config.clone_curr_elem(elem_kata) + tmp_scenario_file = os.path.join(scenario_path, 'user_defined', 'tmp_'+scenario_config_data['new_scenario_name']+'.xml') # if os.path.isfile(tmp_scenario_file): @@ -191,6 +205,8 @@ def save_scenario(): tmp_scenario_file) print('vm_info: ', vm_info) except Exception as error: + if os.path.isfile(tmp_scenario_file): + os.remove(tmp_scenario_file) return {'status': 'fail', 'file_name': new_scenario_name, 'rename': rename, 'error_list': {'error': str(error)}} @@ -280,6 +296,8 @@ def save_launch(): tmp_launch_file) print(pthru_sel, dm_value) except Exception as error: + if os.path.isfile(tmp_launch_file): + os.remove(tmp_launch_file) return {'status': 'fail', 'file_name': launch_config_data['new_launch_name'], 'rename': rename, 'error_list': {'launch config error': str(error)}} @@ -663,6 +681,23 @@ def get_xml_configs(user_defined=False): return board_info, board_type, scenario_config, launch_config +def get_generic_scenario_config(scenario_config): + config_path = os.path.join(current_app.config.get('CONFIG_PATH'), 'generic') + generic_scenario_config = XmlConfig(config_path) + for file in os.listdir(config_path): + if os.path.isfile(os.path.join(config_path, file)) and \ + os.path.splitext(file)[1] == '.xml': + generic_scenario_config.set_curr(os.path.splitext(file)[0]) + generic_scenario_config_root = generic_scenario_config.get_curr_root() + if 'scenario' in generic_scenario_config_root.attrib \ + and 'uos_launcher' not in generic_scenario_config_root.attrib \ + and generic_scenario_config_root.attrib['scenario'] == \ + scenario_config.get_curr_root().attrib['scenario']: + return generic_scenario_config + + return None + + def get_board_info_type(board_info): """ get board info type