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 <shuang.zheng@intel.com>
Reviewed-by: Victor Sun <victor.sun@intel.com>
This commit is contained in:
Shuang Zheng 2019-11-25 16:09:46 +08:00 committed by wenlingz
parent 31d023e8f9
commit bb2218effc
4 changed files with 78 additions and 3 deletions

View File

@ -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.

View File

@ -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'

View File

@ -87,14 +87,24 @@
{% if board_info != None and root != None and scenario_item_values %}
<table class="table table-hover" id="tab">
{% 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'%}
<tr>
<td>
<div class="form-group">
<label class="col-sm-1 control-label">VM: </label>
<label class="col-sm-1 control-label" id="vm">{{vm.attrib['id']}}</label>
</div>
{% if 'desc' in vm.attrib or vm.attrib['desc'] == 'specific for Kata' %}
<div class="form-group">
<button type="button" class="btn" id="remove_vm_kata">Remove Kata VM</button>
</div>
{% endif %}
</td>
<td>
{% for elem in vm.getchildren() %}
@ -321,6 +331,11 @@
</tr>
{% endif %}
{% endfor %}
{% if not vm_kata and ('scenario' in root.attrib and root.attrib['scenario'] == 'sdc') %}
<tr><td>
<button type="button" class="btn" id="add_vm_kata">Add Kata VM</button>
</td></tr>
{% endif %}
</table>
{% else %}
<text class="form-control" id="err_msg">No setting available. Select one board info and make sure the scenario xml

View File

@ -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