acrn-config: refinement for library config

Some API calls have the same function in library config,
the patch refines the API calls.

Tracked-On: #3854
Signed-off-by: Wei Liu <weix.w.liu@intel.com>
Acked-by: Victor Sun <victor.sun@intel.com>
This commit is contained in:
Wei Liu
2019-11-26 09:43:12 +08:00
committed by wenlingz
parent 502e60237c
commit 78b2f73703
7 changed files with 148 additions and 196 deletions

View File

@@ -155,16 +155,6 @@ def get_tree_tag(config_file, tag_str):
return common.get_tree_tag_val(config_file, tag_str)
def get_sub_tree_tag(config_file, tag_str):
"""
This is get tag value by tag_str from config file
:param config_file: it is a file what contains information for script to read from
:param tag_str: it is key of pattern to config file item
:return: value of tag_str item
"""
return common.get_branch_tag_val(config_file, tag_str)
def get_sub_leaf_tag(config_file, branch_tag, tag_str):
"""
This is get tag value by tag_str from config file

View File

@@ -23,6 +23,23 @@ GUEST_FLAG = ["0UL", "GUEST_FLAG_SECURE_WORLD_ENABLED", "GUEST_FLAG_LAPIC_PASSTH
START_HPA_SIZE_LIST = ['0x20000000', '0x40000000', '0x80000000', 'CONFIG_SOS_RAM_SIZE', 'VM0_MEM_SIZE']
MULTI_ITEM = ["guest_flag", "pcpu_id"]
class MultiItem():
def __init__(self):
self.guest_flag = []
self.pcpu_id = []
self.vir_console = []
self.vir_net = []
class TmpItem():
def __init__(self):
self.tag = {}
self.multi = MultiItem
def open_license():
""" Get the license """
with open(HV_LICENSE_FILE, 'r') as f_licence:
@@ -331,84 +348,8 @@ def get_tree_tag_val(config_file, tag_str):
return False
def get_branch_tag_val(config_file, tag_str):
"""
This is get tag value by tag_str from config file
:param config_file: it is a file what contains information for script to read from
:param tag_str: it is key of pattern to config file item
:return: value of tag_str item list
"""
tmp_tag = []
root = get_config_root(config_file)
for item in root:
for sub in item:
if sub.tag == tag_str:
tmp_tag.append(sub.text)
return tmp_tag
def get_spec_branch_tag_val(config_file, tag_str):
"""
This is get tag value by tag_str from config file
:param config_file: it is a file what contains information for script to read from
:param tag_str: it is key of pattern to config file item
:return: value of tag_str item list
"""
tmp_tag = {}
root = get_config_root(config_file)
for item in root:
id_i = int(item.attrib['id'])
for sub in item:
if sub.tag == tag_str:
if sub.text == None or not sub.text:
tmp_tag[id_i] = ''
else:
tmp_tag[id_i] = sub.text
return tmp_tag
def get_branch_tag_map(config_file, tag_str):
"""
This is get tag value by tag_str from config file
:param config_file: it is a file what contains information for script to read from
:param tag_str: it is key of pattern to config file item
:return: value of tag_str item dictionary
"""
tmp_tag = {}
root = get_config_root(config_file)
for item in root:
vm_id = int(item.attrib['id'])
for sub in item:
if sub.tag == tag_str:
tmp_tag[vm_id] = sub.text
#if item.tag == "vm":
# vm_id += 1
return tmp_tag
def get_spec_leaf_tag_val(config_file, branch_tag, tag_str):
tmp_tag = {}
root = get_config_root(config_file)
for item in root:
id_i = int(item.attrib['id'])
for sub in item:
if sub.tag == branch_tag:
for leaf in sub:
if leaf.tag == tag_str and tag_str != "guest_flag" and tag_str != "pcpu_id" and\
sub.tag != "vuart":
if leaf.text == None or not leaf.text:
tmp_tag[id_i] = ''
else:
tmp_tag[id_i] = leaf.text
continue
return tmp_tag
def get_leaf_tag_val(config_file, branch_tag, tag_str):
# TODO: This will be abandonment in future
def get_leaf_tag_val(config_file, branch_tag, tag_str=''):
"""
This is get tag value by tag_str from config file
:param config_file: it is a file what contains information for script to read from
@@ -419,13 +360,18 @@ def get_leaf_tag_val(config_file, branch_tag, tag_str):
tmp_tag = []
root = get_config_root(config_file)
for item in root:
# for each 2th level item
for sub in item:
tmp_flag = []
tmp_cpus = []
if sub.tag == branch_tag:
if not tag_str:
tmp_tag.append(sub.text)
continue
# for each 3rd level item
for leaf in sub:
if leaf.tag == tag_str and tag_str != "guest_flag" and tag_str != "pcpu_id" and\
sub.tag != "vuart":
if leaf.tag == tag_str and tag_str not in MULTI_ITEM and sub.tag != "vuart":
tmp_tag.append(leaf.text)
continue
@@ -450,10 +396,33 @@ def get_leaf_tag_val(config_file, branch_tag, tag_str):
tmp_tag.append(tmp_cpus)
continue
return tmp_tag
def get_leaf_value(tmp, tag_str, leaf):
# get guest flag for logical partition vm1
if leaf.tag == "guest_flag" and tag_str == "guest_flag":
t_flag = find_tmp_flag(leaf.text)
tmp.multi.guest_flag.append(t_flag)
# get cpu for vm
if leaf.tag == "pcpu_id" and tag_str == "pcpu_id":
tmp.multi.pcpu_id.append(leaf.text)
def get_sub_value(tmp, tag_str, vm_id):
# append guest flags for each vm
if tmp.multi.guest_flag and tag_str == "guest_flag":
tmp.tag[vm_id] = tmp.multi.guest_flag
tmp.tag.append(tmp.multi.guest_flag)
# append cpus for vm
if tmp.multi.pcpu_id and tag_str == "pcpu_id":
tmp.tag[vm_id] = tmp.multi.pcpu_id
def get_leaf_tag_map(config_file, branch_tag, tag_str):
"""
This is get tag value by tag_str from config file
@@ -462,45 +431,35 @@ def get_leaf_tag_map(config_file, branch_tag, tag_str):
:param tag_str: it is key of pattern to config file leaf tag item
:return: value of tag_str item map
"""
tmp_tag = {}
vm_id = 0
tmp = TmpItem()
root = get_config_root(config_file)
for item in root:
vm_id = int(item.attrib['id'])
# for each 2th level item
for sub in item:
tmp_flag = []
tmp_cpus = []
tmp.multi = MultiItem()
if sub.tag == branch_tag:
if not tag_str:
if sub.text == None or not sub.text:
tmp.tag[vm_id] = ''
else:
tmp.tag[vm_id] = sub.text
continue
# for each 3rd level item
for leaf in sub:
if leaf.tag == tag_str and tag_str != "guest_flag" and tag_str != "pcpu_id"\
and sub.tag != "vuart":
tmp_tag[vm_id] = leaf.text
if leaf.tag == tag_str and tag_str not in MULTI_ITEM and sub.tag != "vuart":
if leaf.text == None or not leaf.text:
tmp.tag[vm_id] = ''
else:
tmp.tag[vm_id] = leaf.text
continue
# get guest flag for logical partition vm1
if leaf.tag == "guest_flag" and tag_str == "guest_flag":
tmp_flag = find_tmp_flag(tmp_flag, leaf.text)
continue
get_leaf_value(tmp, tag_str, leaf)
# get cpu for vm
if leaf.tag == "pcpu_id" and tag_str == "pcpu_id":
tmp_cpus.append(leaf.text)
continue
get_sub_value(tmp, tag_str, vm_id)
# append guest flags for each vm
if tmp_flag and tag_str == "guest_flag":
tmp_tag[vm_id] = tmp_flag
continue
# append cpus for vm
if tmp_cpus and tag_str == "pcpu_id":
tmp_tag[vm_id] = tmp_cpus
continue
if item.tag == "vm":
vm_id += 1
return tmp_tag
return tmp.tag
def order_type_map_vmid(config_file, vm_count):
@@ -511,7 +470,7 @@ def order_type_map_vmid(config_file, vm_count):
:return: table of id:order type dictionary
"""
order_id_dic = {}
load_type_list = get_branch_tag_val(config_file, "load_order")
load_type_list = get_leaf_tag_val(config_file, "load_order")
for i in range(vm_count):
order_id_dic[i] = load_type_list[i]
@@ -570,7 +529,7 @@ def vm_pre_launch_cnt(config_file):
:return: number of pre launched vm
"""
pre_launch_cnt = 0
load_type_list = get_branch_tag_val(config_file, "load_order")
load_type_list = get_leaf_tag_val(config_file, "load_order")
for vm_type in load_type_list:
if vm_type == "PRE_LAUNCHED_VM":
@@ -586,7 +545,7 @@ def post_vm_cnt(config_file):
:return: number of post launched vm
"""
post_launch_cnt = 0
load_type_list = get_branch_tag_val(config_file, "load_order")
load_type_list = get_leaf_tag_val(config_file, "load_order")
for vm_type in load_type_list:
if vm_type == "POST_LAUNCHED_VM":

View File

@@ -150,13 +150,6 @@ def get_param(args):
return (err_dic, board_info_file, scenario_info_file, launch_info_file, int(vm_th), enable_commit)
def get_scenario_uuid():
# {id_num:uuid} (id_num:0~max)
scenario_uuid_dic = {}
scenario_uuid_dic = common.get_branch_tag_map(SCENARIO_INFO_FILE, 'uuid')
return scenario_uuid_dic
def get_post_num_list():
"""
Get board name from launch.xml at fist line
@@ -314,35 +307,40 @@ def is_config_file_match():
return (err_dic, match)
def get_leaf_tag_map(info_file, prime_item, item=''):
"""
:param info_file: some configurations in the info file
:param prime_item: the prime item in xml file
:param item: the item in xml file
:return: dictionary which item value could be indexed by vmid
"""
vmid_item_dic = common.get_leaf_tag_map(info_file, prime_item, item)
return vmid_item_dic
def get_scenario_uuid():
# {id_num:uuid} (id_num:0~max)
scenario_uuid_dic = {}
scenario_uuid_dic = get_leaf_tag_map(SCENARIO_INFO_FILE, 'uuid')
return scenario_uuid_dic
def get_sos_vmid():
load_list = common.get_branch_tag_val(SCENARIO_INFO_FILE, "load_order")
load_dic = get_leaf_tag_map(SCENARIO_INFO_FILE, "load_order")
sos_id = 0
for load_order in load_list:
sos_id = ''
for idx,load_order in load_dic.items():
if load_order == "SOS_VM":
sos_id = idx
break
sos_id += 1
return sos_id
def get_sub_tree_tag(config_file, tag_str):
"""
This is get tag value by tag_str from config file
:param config_file: it is a file what contains information for script to read from
:param tag_str: it is key of pattern to config file item
:return: value of tag_str item
"""
arg = common.get_spec_branch_tag_val(config_file, tag_str)
return arg
def get_bdf_from_tag(config_file, branch_tag, tag_str):
bdf_list = {}
bdf_list = common.get_spec_leaf_tag_val(config_file, branch_tag, tag_str)
bdf_list = get_leaf_tag_map(config_file, branch_tag, tag_str)
# split b:d:f from pci description
for idx, bdf_v in bdf_list.items():
@@ -382,7 +380,7 @@ def get_uos_type():
"""
Get uos name from launch.xml at fist line
"""
uos_types = get_sub_tree_tag(LAUNCH_INFO_FILE, "uos_type")
uos_types = get_leaf_tag_map(LAUNCH_INFO_FILE, "uos_type")
return uos_types

View File

@@ -215,7 +215,7 @@ def get_vm_num(config_file):
return common.get_vm_count(config_file)
def get_sub_leaf_tag(config_file, branch_tag, tag_str):
def get_sub_leaf_tag(config_file, branch_tag, tag_str=''):
"""
This is get tag value by tag_str from config file
:param config_file: it is a file what contains information for script to read from
@@ -361,7 +361,7 @@ def uuid_format_check(uuid_dic, item):
ERR_LIST[key] = "VM uuid format unknown"
def get_leaf_tag_map(info_file, prime_item, item):
def get_leaf_tag_map(info_file, prime_item, item=''):
"""
:param info_file: some configurations in the info file
:param prime_item: the prime item in xml file
@@ -387,9 +387,10 @@ def cpus_per_vm_check(id_cpus_per_vm_dic, item):
ERR_LIST[key] = "VM have no assignment cpus"
def mem_start_hpa_check(id_start_hpa_dic, item):
def mem_start_hpa_check(id_start_hpa_dic, prime_item, item):
"""
Check host physical address
:param prime_item: the prime item in xml file
:param item: vm start_hpa item in xml
:return: None
"""
@@ -409,9 +410,10 @@ def mem_start_hpa_check(id_start_hpa_dic, item):
ERR_LIST[key] = "Address should be Hex format"
def mem_size_check(id_hpa_size_dic, item):
def mem_size_check(id_hpa_size_dic, prime_item, item):
"""
Check host physical size
:param prime_item: the prime item in xml file
:param item: vm size item in xml
:return: None
"""
@@ -435,9 +437,10 @@ def mem_size_check(id_hpa_size_dic, item):
ERR_LIST[key] = "Mem size should less than 2GB"
def os_kern_name_check(id_kern_name_dic, item):
def os_kern_name_check(id_kern_name_dic, prime_item, item):
"""
Check os kernel name
:param prime_item: the prime item in xml file
:param item: vm os config name item in xml
:return: None
"""
@@ -448,9 +451,10 @@ def os_kern_name_check(id_kern_name_dic, item):
ERR_LIST[key] = "VM os config kernel name length should be in range [1,32] bytes"
def os_kern_type_check(id_kern_type_dic, item):
def os_kern_type_check(id_kern_type_dic, prime_item, item):
"""
Check os kernel type
:param prime_item: the prime item in xml file
:param item: vm os config type item in xml
:return: None
"""
@@ -467,9 +471,10 @@ def os_kern_type_check(id_kern_type_dic, item):
ERR_LIST[key] = "VM os config kernel type unknown"
def os_kern_mod_check(id_kern_mod_dic, item):
def os_kern_mod_check(id_kern_mod_dic, prime_item, item):
"""
Check os kernel mod
:param prime_item: the prime item in xml file
:param item: vm os config mod item in xml
:return: None
"""
@@ -480,9 +485,10 @@ def os_kern_mod_check(id_kern_mod_dic, item):
ERR_LIST[key] = "VM os config kernel mod tag should be in range [1,32] bytes"
def os_kern_args_check(id_kern_args_dic, item):
def os_kern_args_check(id_kern_args_dic, prime_item, item):
"""
Check os kernel args
:param prime_item: the prime item in xml file
:param item: vm os config args item in xml
:return: None
"""
@@ -495,9 +501,10 @@ def os_kern_args_check(id_kern_args_dic, item):
ERR_LIST[key] = "VM os config kernel service os should be SOS_VM_BOOTARGS"
def os_kern_console_check(id_kern_console_dic, item):
def os_kern_console_check(id_kern_console_dic, prime_item, item):
"""
Check os kernel console
:param prime_item: the prime item in xml file
:param item: vm os config console item in xml
:return: None
"""
@@ -508,9 +515,10 @@ def os_kern_console_check(id_kern_console_dic, item):
ERR_LIST[key] = "VM os config kernel console should be ttyS[0..3]"
def os_kern_load_addr_check(id_kern_load_addr_dic, item):
def os_kern_load_addr_check(id_kern_load_addr_dic, prime_item, item):
"""
Check os kernel load address
:param prime_item: the prime item in xml file
:param item: vm os config load address item in xml
:return: None
"""
@@ -527,9 +535,10 @@ def os_kern_load_addr_check(id_kern_load_addr_dic, item):
ERR_LIST[key] = "VM os config kernel load address should Hex format"
def os_kern_entry_addr_check(id_kern_entry_addr_dic, item):
def os_kern_entry_addr_check(id_kern_entry_addr_dic, prime_item, item):
"""
Check os kernel entry address
:param prime_item: the prime item in xml file
:param item: vm os config entry address item in xml
:return: None
"""
@@ -546,9 +555,10 @@ def os_kern_entry_addr_check(id_kern_entry_addr_dic, item):
ERR_LIST[key] = "VM os config kernel entry address should Hex format"
def os_kern_root_dev_check(id_kern_rootdev_dic, item):
def os_kern_root_dev_check(id_kern_rootdev_dic, prime_item, item):
"""
Check os kernel rootfs partitions
:param prime_item: the prime item in xml file
:param item: vm os config rootdev item in xml
:return: None
"""
@@ -559,16 +569,6 @@ def os_kern_root_dev_check(id_kern_rootdev_dic, item):
ERR_LIST[key] = "VM os config kernel root device should not empty"
def get_branch_tag_map(info_file, item):
"""
:param info_file: some configurations in the info file
:param item: the item in xml file
:return: dictionary which item value could be indexed by vmid
"""
vmid_item_dic = common.get_branch_tag_map(info_file, item)
return vmid_item_dic
def pci_dev_num_check(id_dev_num_dic, item):
"""
Check vm pci device number