Skip to content

Commit bb2218e

Browse files
szhen11wenlingz
authored andcommitted
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>
1 parent 31d023e commit bb2218e

File tree

4 files changed

+78
-3
lines changed

4 files changed

+78
-3
lines changed

misc/acrn-config/config_app/controller.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,19 @@ def add_curr_value(self, key, desc, value, *args):
202202
new_node = ElementTree.SubElement(dest_node, key, attrib={'desc': desc})
203203
new_node.text = value
204204

205+
def clone_curr_elem(self, elem, *args):
206+
"""
207+
clone elements for current path.
208+
:param elem: the element to clone.
209+
:param args: the path of the element.
210+
:return: None.
211+
"""
212+
if self._curr_xml_tree is None:
213+
return
214+
215+
dest_node = self._get_dest_node(*args)
216+
dest_node.append(elem)
217+
205218
def delete_curr_key(self, *args):
206219
"""
207220
delete the element by its path.

misc/acrn-config/config_app/static/main.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,17 @@ $().ready(function(){
323323
config_item.remove();
324324
});
325325

326+
$('#remove_vm_kata').on('click', function() {
327+
if(confirm("Do you want to remove the VM?")) {
328+
save_scenario("remove_vm_kata");
329+
}
330+
});
331+
332+
$('#add_vm_kata').on('click', function() {
333+
if(confirm("Do you want to add the Kata VM based on generic config?")) {
334+
save_scenario("add_vm_kata");
335+
}
336+
});
326337
})
327338

328339

@@ -362,7 +373,8 @@ function save_scenario(generator=null){
362373

363374
scenario_config = {
364375
old_scenario_name: $("#old_scenario_name").text(),
365-
new_scenario_name: $("#new_scenario_name").val()
376+
new_scenario_name: $("#new_scenario_name").val(),
377+
generator: generator
366378
}
367379

368380
$("input").each(function(){
@@ -425,7 +437,7 @@ function save_scenario(generator=null){
425437
validate_message = 'Scenario setting existed, saved successfully with a new name: '
426438
+file_name+'\ninto acrn-hypervisor/misc/acrn-config/xmls/config-xmls/'+board_info+'/user_defined/.';
427439
}
428-
if(generator != null) {
440+
if(generator=="generate_board_src" || generator=="generate_scenario_src") {
429441
commit_confirm_message = validate_message+'\n\nGenerate source codes from scenario setting.'
430442
+'\n\nDo you want to commit changes to local tree?'
431443
commit_confirm = 'no'

misc/acrn-config/config_app/templates/scenario.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,24 @@ <h4 class="modal-title" id="myModalLabel">Save as</h4>
8787

8888
{% if board_info != None and root != None and scenario_item_values %}
8989
<table class="table table-hover" id="tab">
90+
{% set vm_kata = [] %}
9091
{% for vm in root.getchildren() %}
92+
{% if 'desc' in vm.attrib and vm.attrib['desc'] == 'specific for Kata' %}
93+
{% do vm_kata.append(1) %}
94+
{% endif %}
9195
{% if 'configurable' not in vm.attrib or vm.attrib['configurable'] != '0'%}
9296
<tr>
9397
<td>
9498
<div class="form-group">
9599
<label class="col-sm-1 control-label">VM: </label>
96100
<label class="col-sm-1 control-label" id="vm">{{vm.attrib['id']}}</label>
101+
102+
</div>
103+
{% if 'desc' in vm.attrib or vm.attrib['desc'] == 'specific for Kata' %}
104+
<div class="form-group">
105+
<button type="button" class="btn" id="remove_vm_kata">Remove Kata VM</button>
97106
</div>
107+
{% endif %}
98108
</td>
99109
<td>
100110
{% for elem in vm.getchildren() %}
@@ -321,6 +331,11 @@ <h4 class="modal-title" id="myModalLabel">Save as</h4>
321331
</tr>
322332
{% endif %}
323333
{% endfor %}
334+
{% if not vm_kata and ('scenario' in root.attrib and root.attrib['scenario'] == 'sdc') %}
335+
<tr><td>
336+
<button type="button" class="btn" id="add_vm_kata">Add Kata VM</button>
337+
</td></tr>
338+
{% endif %}
324339
</table>
325340
{% else %}
326341
<text class="form-control" id="err_msg">No setting available. Select one board info and make sure the scenario xml

misc/acrn-config/config_app/views.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,26 @@ def save_scenario():
169169
scenario_config.set_curr(old_scenario_name)
170170
for key in scenario_config_data:
171171
if key not in ['old_scenario_name', 'new_scenario_name', 'board_info_file',
172-
'board_info_upload']:
172+
'board_info_upload', 'generator']:
173173
if isinstance(scenario_config_data[key], list):
174174
scenario_config.set_curr_list(scenario_config_data[key], *tuple(key.split(',')))
175175
else:
176176
scenario_config.set_curr_value(scenario_config_data[key], *tuple(key.split(',')))
177177

178+
if scenario_config_data['generator'] == 'remove_vm_kata':
179+
scenario_config.delete_curr_key('vm:desc=specific for Kata')
180+
elif scenario_config_data['generator'] == 'add_vm_kata':
181+
# clone vm kata from generic config
182+
generic_scenario_config = get_generic_scenario_config(scenario_config)
183+
generic_scenario_config_root = generic_scenario_config.get_curr_root()
184+
elem_kata = None
185+
for vm in generic_scenario_config_root.getchildren():
186+
if 'desc' in vm.attrib and vm.attrib['desc'] == 'specific for Kata':
187+
elem_kata = vm
188+
break
189+
if elem_kata is not None:
190+
scenario_config.clone_curr_elem(elem_kata)
191+
178192
tmp_scenario_file = os.path.join(scenario_path, 'user_defined',
179193
'tmp_'+scenario_config_data['new_scenario_name']+'.xml')
180194
# if os.path.isfile(tmp_scenario_file):
@@ -191,6 +205,8 @@ def save_scenario():
191205
tmp_scenario_file)
192206
print('vm_info: ', vm_info)
193207
except Exception as error:
208+
if os.path.isfile(tmp_scenario_file):
209+
os.remove(tmp_scenario_file)
194210
return {'status': 'fail', 'file_name': new_scenario_name,
195211
'rename': rename, 'error_list': {'error': str(error)}}
196212

@@ -280,6 +296,8 @@ def save_launch():
280296
tmp_launch_file)
281297
print(pthru_sel, dm_value)
282298
except Exception as error:
299+
if os.path.isfile(tmp_launch_file):
300+
os.remove(tmp_launch_file)
283301
return {'status': 'fail', 'file_name': launch_config_data['new_launch_name'],
284302
'rename': rename, 'error_list': {'launch config error': str(error)}}
285303

@@ -663,6 +681,23 @@ def get_xml_configs(user_defined=False):
663681
return board_info, board_type, scenario_config, launch_config
664682

665683

684+
def get_generic_scenario_config(scenario_config):
685+
config_path = os.path.join(current_app.config.get('CONFIG_PATH'), 'generic')
686+
generic_scenario_config = XmlConfig(config_path)
687+
for file in os.listdir(config_path):
688+
if os.path.isfile(os.path.join(config_path, file)) and \
689+
os.path.splitext(file)[1] == '.xml':
690+
generic_scenario_config.set_curr(os.path.splitext(file)[0])
691+
generic_scenario_config_root = generic_scenario_config.get_curr_root()
692+
if 'scenario' in generic_scenario_config_root.attrib \
693+
and 'uos_launcher' not in generic_scenario_config_root.attrib \
694+
and generic_scenario_config_root.attrib['scenario'] == \
695+
scenario_config.get_curr_root().attrib['scenario']:
696+
return generic_scenario_config
697+
698+
return None
699+
700+
666701
def get_board_info_type(board_info):
667702
"""
668703
get board info type

0 commit comments

Comments
 (0)