Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,13 @@ $ ./avocado-setup.py -h
>It contains 1 yaml file,namely [ioping.yaml](https://github.com/avocado-framework-tests/avocado-misc-tests/blob/master/io/disk/ioping.py.data/ioping.yaml)
Now, it has yaml parameters like mode, count, deadline, period, disk, etc.
Suppose user wants to change only 3 of those values, say disk, wsize and period, user can have that alone in our input file.
Refer [input_example.txt](input_example.txt) for this example.
User must specify config key value matching the branch of the yaml through "/" notation (matching yaml_to_mux.parameter_paths).
Optinally users can also provide input with '*' as part of config key, if the config key needs to be matched irrespective for multiple branches.
Please note that only strings where you want to enforce strictly as string must be enclosed in double-quotes only, like numbers, expressions, lists, etc. Normal strings need not be enclosed in double-quotes.
Example:
"1", if 1 needs to be strictly read as string
1, if 1 needs to be read as integer
Refer [input_example.txt](input_example.txt) for details.


5. `--verbose`:
Expand Down
67 changes: 45 additions & 22 deletions avocado-setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,42 @@ def env_clean():
helper.remove_file(postscript, postscript_dir)


def edit_mux_file(test_config_name, mux_file_path, tmp_mux_path):
def get_mux_inject_list(output, inp_dict):
inj_list = []
for key, value in inp_dict.items():
if "/" not in key:
full_key = "/run:%s" % key
else:
full_key = "/run/%s" % ':'.join(key.rsplit("/", 1))
multi = False
if "*" in full_key:
st_list = full_key.split("*")
prefix = st_list[0]
suffix = st_list[1]
multi = True
for line in output.splitlines():
key_to_check = full_key
if multi:
if prefix in line and suffix in line and "=>" in line:
key_to_check = line.split()[0]
key_exist = False
if " %s " % key_to_check in line:
for item in inj_list:
if key_to_check in item.keys():
key_exist = True
break
if not key_exist:
val_to_write = value
if '"' in value:
val_to_write = value.replace('"', '\\"')
val_to_write = '"%s"' % val_to_write
inj_list.append({key_to_check: val_to_write})
if not multi:
break
return inj_list


def process_mux_file(avocado_bin, test_config_name, mux_path):
"""
Edit the mux file with input given in input config file.
"""
Expand All @@ -441,26 +476,10 @@ def edit_mux_file(test_config_name, mux_file_path, tmp_mux_path):
input_dic[input_line[0]] = input_line[1]
else:
logger.debug("Section %s not found in input file", test_config_name)
shutil.copyfile(mux_file_path, tmp_mux_path)
return

with open(mux_file_path) as mux_fp:
mux_str = mux_fp.read()

mux_str_edited = []
for line in mux_str.splitlines():
if len(line) == 0 or line.lstrip()[0] == '#':
continue
for key, value in input_dic.items():
temp_line = line.split(":")
mux_key = temp_line[0]
mux_value = temp_line[1]
if key == mux_key.strip():
line = line.replace('%s' % line.strip(), '%s: %s' % (key, value))
mux_str_edited.append(line)

with open(tmp_mux_path, 'w') as mux_fp:
mux_fp.write(str("\n".join(mux_str_edited)))
_, out = helper.runcmd("%s variants --variants max -m %s" % (avocado_bin, mux_path))
return get_mux_inject_list(out, input_dic)


def parse_test_config(test_config_file, avocado_bin, enable_kvm):
Expand Down Expand Up @@ -536,9 +555,13 @@ def parse_test_config(test_config_file, avocado_bin, enable_kvm):
if not os.path.isfile(mux_file):
logger.debug("%s does not exist", mux_file)
continue
tmp_mux_path = os.path.join('/tmp/mux/', "%s_%s.yaml" % (test_config_name, test_dic['name']))
edit_mux_file(test_config_name, mux_file, tmp_mux_path)
test_dic['mux'] = tmp_mux_path
test_dic['mux'] = mux_file
inj_list = process_mux_file(avocado_bin, test_config_name, mux_file)
if inj_list:
test_dic['mux'] += " --mux-inject"
for inj_dic in inj_list:
for key, value in inj_dic.items():
test_dic['mux'] += " %s:%s" % (key, value)
# Handling additional args from second param
else:
arg_flag = 1
Expand Down
9 changes: 6 additions & 3 deletions input_example.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
[example]
disk = '/home'
wsize = '1m'
period = '5'
disk = /home
wsize = 1m
period = 5
setup/fs_type/fs_xfs/exclude = "83,113,136"
setup/fs_type/*/gen_exclude = 232
config/preserve_change = False