Skip to content

Commit 7d827c4

Browse files
Wei Liuwenlingz
authored andcommitted
acrn-config: remove the same parameters and functions from scenario_cfg_lib
Scenario config should relay on library/common.py and scenario_cfg_lib, then remove the duplicate parameters and functions. Tracked-On: #3854 Signed-off-by: Wei Liu <weix.w.liu@intel.com> Acked-by: Victor Sun <victor.sun@intel.com> Acked-by: Terry Zou <terry.zou@intel.com>
1 parent 8e3ede1 commit 7d827c4

File tree

7 files changed

+81
-274
lines changed

7 files changed

+81
-274
lines changed

misc/acrn-config/library/common.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,6 @@ def get_vm_num(config_file):
267267
if item.tag == "vm":
268268
vm_count += 1
269269
VM_COUNT = vm_count
270-
return vm_count
271270

272271

273272
# TODO: This will be abandonment in future
@@ -382,7 +381,7 @@ def get_sub_value(tmp, tag_str, vm_id):
382381
tmp.tag[vm_id] = tmp.multi.vir_network
383382

384383

385-
def get_leaf_tag_map(config_file, branch_tag, tag_str):
384+
def get_leaf_tag_map(config_file, branch_tag, tag_str=''):
386385
"""
387386
This is get tag value by tag_str from config file
388387
:param config_file: it is a file what contains information for script to read from

misc/acrn-config/library/scenario_cfg_lib.py

Lines changed: 8 additions & 201 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@
66
import common
77
import board_cfg_lib
88

9-
SOURCE_ROOT_DIR = common.SOURCE_ROOT_DIR
109
HEADER_LICENSE = common.open_license()
11-
BOARD_INFO_FILE = "board_info.txt"
12-
SCENARIO_INFO_FILE = ""
1310

1411
LOAD_ORDER_TYPE = ['PRE_LAUNCHED_VM', 'SOS_VM', 'POST_LAUNCHED_VM']
1512
START_HPA_LIST = ['0', '0x100000000', '0x120000000']
@@ -39,7 +36,6 @@
3936

4037
ERR_LIST = {}
4138

42-
VM_COUNT = 0
4339
DEFAULT_VM_COUNT = {
4440
'sdc':2,
4541
'sdc2':4,
@@ -49,152 +45,10 @@
4945
}
5046
KATA_VM_COUNT = 0
5147

52-
LEGACY_TTYS = {
53-
'ttyS0':'0x3F8',
54-
'ttyS1':'0x2F8',
55-
'ttyS2':'0x3E8',
56-
'ttyS3':'0x2E8',
57-
}
58-
59-
def prepare():
60-
""" Check environment """
61-
return common.prepare()
62-
63-
64-
def print_yel(msg, warn=False):
65-
"""
66-
Print the message with color of yellow
67-
:param msg: the stings which will be output to STDOUT
68-
:param warn: the condition if needs to be output the color of yellow with 'Warning'
69-
"""
70-
common.print_yel(msg, warn)
71-
72-
73-
def print_red(msg, err=False):
74-
"""
75-
Print the message with color of red
76-
:param msg: the stings which will be output to STDOUT
77-
:param err: the condition if needs to be output the color of red with 'Error'
78-
"""
79-
common.print_red(msg, err)
80-
81-
82-
def usage(file_name):
83-
""" This is usage for how to use this tool """
84-
common.usage(file_name)
85-
86-
87-
def get_param(args):
88-
"""
89-
Get the script parameters from command line
90-
:param args: this the command line of string for the script without script name
91-
"""
92-
return common.get_param(args)
93-
94-
95-
def get_scenario_name():
96-
"""
97-
Get board name from scenario.xml at fist line
98-
:param scenario_file: it is a file what contains scenario information for script to read from
99-
"""
100-
return common.get_scenario_name()
101-
102-
103-
def is_config_file_match():
104-
105-
return common.is_config_file_match()
106-
107-
108-
def get_info(board_info, msg_s, msg_e):
109-
"""
110-
Get information which specify by argument
111-
:param board_info: it is a file what contains board information for script to read from
112-
:param msg_s: it is a pattern of key stings what start to match from board information
113-
:param msg_e: it is a pattern of key stings what end to match from board information
114-
"""
115-
info_lines = board_cfg_lib.get_info(board_info, msg_s, msg_e)
116-
return info_lines
117-
118-
119-
def get_processor_info(board_info):
120-
"""
121-
Get cpu core list
122-
:param board_info: it is a file what contains board information for script to read from
123-
:return: cpu processor which one cpu has
124-
"""
125-
processor_list = []
126-
tmp_list = []
127-
processor_info = board_cfg_lib.get_info(board_info, "<CPU_PROCESSOR_INFO>", "</CPU_PROCESSOR_INFO>")
128-
129-
if not processor_info:
130-
key = "vm:id=0,vcpu_affinity"
131-
ERR_LIST[key] = "CPU core is not exists"
132-
return processor_list
133-
134-
for processor_line in processor_info:
135-
if not processor_line:
136-
break
137-
138-
processor_list = processor_line.strip().split(',')
139-
for processor in processor_list:
140-
tmp_list.append(processor.strip())
141-
break
142-
143-
return tmp_list
144-
145-
146-
def get_rootdev_info(board_info):
147-
"""
148-
Get root devices from board info
149-
:param board_info: it is a file what contains board information for script to read from
150-
:return: root devices list
151-
"""
152-
rootdev_list = []
153-
rootdev_info = board_cfg_lib.get_info(board_info, "<BLOCK_DEVICE_INFO>", "</BLOCK_DEVICE_INFO>")
154-
155-
# none 'BLOCK_DEVICE_INFO' tag
156-
if rootdev_info == None:
157-
return rootdev_list
158-
159-
for rootdev_line in rootdev_info:
160-
if not rootdev_line:
161-
break
162-
163-
if not board_cfg_lib.handle_root_dev(rootdev_line):
164-
continue
165-
166-
root_dev = rootdev_line.strip().split(':')[0]
167-
rootdev_list.append(root_dev)
168-
169-
return rootdev_list
170-
171-
172-
def get_ttys_info(board_info):
173-
"""
174-
Get ttySn from board info
175-
:param board_info: it is a file what contains board information for script to read from
176-
:return: serial console list
177-
"""
178-
ttys_list = []
179-
ttys_info = board_cfg_lib.get_info(board_info, "<TTYS_INFO>", "</TTYS_INFO>")
180-
181-
for ttys_line in ttys_info:
182-
if not ttys_line:
183-
break
184-
185-
ttys_dev = ttys_line.split()[0].split(':')[1]
186-
ttysn = ttys_dev.split('/')[-1]
187-
# currently SOS console can only support legacy serial port
188-
if ttysn not in list(LEGACY_TTYS.keys()):
189-
continue
190-
ttys_list.append(ttys_dev)
191-
192-
return ttys_list
193-
19448

19549
def get_board_private_info(config_file):
19650

197-
(err_dic, scenario_name) = get_scenario_name()
51+
(err_dic, scenario_name) = common.get_scenario_name()
19852

19953
if scenario_name == "logical_partition":
20054
branch_tag = "os_config"
@@ -204,7 +58,7 @@ def get_board_private_info(config_file):
20458
private_info = {}
20559
dev_private_tags = ['rootfs', 'console']
20660
for tag_str in dev_private_tags:
207-
dev_setting = get_sub_leaf_tag(config_file, branch_tag, tag_str)
61+
dev_setting = common.get_sub_leaf_tag(config_file, branch_tag, tag_str)
20862
if not dev_setting and tag_str == "console":
20963
continue
21064

@@ -215,41 +69,21 @@ def get_board_private_info(config_file):
21569

21670
def check_board_private_info():
21771

218-
(err_dic, private_info) = get_board_private_info(SCENARIO_INFO_FILE)
72+
(err_dic, private_info) = get_board_private_info(common.SCENARIO_INFO_FILE)
21973

22074
if not private_info['rootfs'] and err_dic:
22175
ERR_LIST['vm:id=0,boot_private,rootfs'] = "The board have to chose one rootfs partition"
22276
ERR_LIST.update(err_dic)
22377

22478

225-
def get_vm_num(config_file):
226-
"""
227-
This is get vm count
228-
:param config_file: it is a file what contains vm information for script to read from
229-
:return: number of vm
230-
"""
231-
return common.get_vm_num(config_file)
232-
233-
234-
def get_sub_leaf_tag(config_file, branch_tag, tag_str=''):
235-
"""
236-
This is get tag value by tag_str from config file
237-
:param config_file: it is a file what contains information for script to read from
238-
:param branch_tag: it is key of patter to config file branch tag item
239-
:param tag_str: it is key of pattern to config file leaf tag item
240-
:return: value of tag_str item
241-
"""
242-
return common.get_sub_leaf_tag(config_file, branch_tag, tag_str)
243-
244-
24579
def get_order_type_by_vmid(idx):
24680
"""
24781
Get load order by vm id
24882
24983
:param idx: index of vm id
25084
:return: load order type of index to vmid
25185
"""
252-
(err_dic, order_type) = common.get_load_order_by_vmid(SCENARIO_INFO_FILE, VM_COUNT, idx)
86+
(err_dic, order_type) = common.get_load_order_by_vmid(common.SCENARIO_INFO_FILE, common.VM_COUNT, idx)
25387
if err_dic:
25488
ERR_LIST.update(err_dic)
25589

@@ -375,17 +209,6 @@ def uuid_format_check(uuid_dic, item):
375209
ERR_LIST[key] = "VM uuid format unknown"
376210

377211

378-
def get_leaf_tag_map(info_file, prime_item, item=''):
379-
"""
380-
:param info_file: some configurations in the info file
381-
:param prime_item: the prime item in xml file
382-
:param item: the item in xml file
383-
:return: dictionary which item value could be indexed by vmid
384-
"""
385-
vmid_item_dic = common.get_leaf_tag_map(info_file, prime_item, item)
386-
return vmid_item_dic
387-
388-
389212
def cpus_per_vm_check(id_cpus_per_vm_dic, item):
390213
"""
391214
Check cpu number of per vm
@@ -618,7 +441,7 @@ def get_vuart1_vmid(vm_vuart1):
618441
:return: dictionary of vmid:vuart1
619442
"""
620443
vm_id_dic = {}
621-
for i in range(VM_COUNT):
444+
for i in range(common.VM_COUNT):
622445
for key in vm_vuart1[i].keys():
623446
if key == "target_vm_id":
624447
vm_id_dic[i] = vm_vuart1[i][key]
@@ -685,21 +508,10 @@ def clos_assignment(clos_per_vm, index):
685508
vm_clos_bmp['clos_map'] = clos_str
686509
return vm_clos_bmp
687510

688-
def get_vuart_info_id(config_file, idx):
689-
"""
690-
Get vuart information by vuart id indexx
691-
:param config_file: it is a file what contains information for script to read from
692-
:param idx: vuart index in range: [0,1]
693-
:return: dictionary which stored the vuart-id
694-
"""
695-
tmp_tag = board_cfg_lib.get_vuart_info_id(config_file, idx)
696-
return tmp_tag
697-
698511

699512
def avl_vuart_ui_select(scenario_info):
700-
vm_num = get_vm_num(scenario_info)
701513
tmp_vuart = {}
702-
for vm_i in range(vm_num):
514+
for vm_i in range(common.VM_COUNT):
703515
vm_type = get_order_type_by_vmid(vm_i)
704516

705517
if vm_type == "SOS_VM":
@@ -718,14 +530,9 @@ def avl_vuart_ui_select(scenario_info):
718530

719531
def get_first_post_vm():
720532

721-
for i in range(VM_COUNT):
722-
(err_dic, vm_type) = common.get_load_order_by_vmid(SCENARIO_INFO_FILE, VM_COUNT, i)
533+
for i in range(common.VM_COUNT):
534+
(err_dic, vm_type) = common.get_load_order_by_vmid(common.SCENARIO_INFO_FILE, common.VM_COUNT, i)
723535
if vm_type == "POST_LAUNCHED_VM":
724536
break
725537

726538
return (err_dic, i)
727-
728-
729-
def mkdir(path):
730-
731-
common.mkdir(path)

misc/acrn-config/scenario_config/pci_dev_c.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
# SPDX-License-Identifier: BSD-3-Clause
44
#
55

6+
import common
67
import scenario_cfg_lib
8+
79
PCI_DEV_TYPE = ['PCI_DEV_TYPE_HVEMUL', 'PCI_DEV_TYPE_PTDEV']
810

911

@@ -27,7 +29,7 @@ def generate_file(config):
2729
print(" * The memory range of vBAR should exactly match with the e820 layout of VM.",
2830
file=config)
2931
print(" */", file=config)
30-
for i in range(scenario_cfg_lib.VM_COUNT):
32+
for i in range(common.VM_COUNT):
3133
print("", file=config)
3234
print("struct acrn_vm_pci_dev_config " +
3335
"vm{}_pci_devs[VM{}_CONFIG_PCI_DEV_NUM] = {{".format(i, i), file=config)

0 commit comments

Comments
 (0)