forked from lop-devops/tests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
avocado-setup.py
789 lines (728 loc) · 33.4 KB
/
avocado-setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
#!/usr/bin/env python3
# Copyright (C) IBM Corp. 2016.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Python wrapper for avocado
# Author: Satheesh Rajendran<[email protected]>
import os
import shutil
import time
import json
import sys
import shlex
import argparse
import configparser
import binascii
from lib.logger import logger_init
from lib import helper
AVOCADO_CONFIG_DIR = "%s/.config/avocado" % os.environ['HOME']
BASE_PATH = os.path.dirname(os.path.abspath(__file__))
CONFIG_PATH = "%s/config/wrapper/env.conf" % BASE_PATH
prescript = "%s/config/prescript" % BASE_PATH
postscript = "%s/config/postscript" % BASE_PATH
NORUNTEST_PATH = "%s/config/wrapper/no_run_tests.conf" % BASE_PATH
TEST_CONF_PATH = "%s/config/tests/" % BASE_PATH
CONFIGFILE = configparser.ConfigParser()
CONFIGFILE.read(CONFIG_PATH)
NORUNTESTFILE = configparser.ConfigParser()
NORUNTESTFILE.read(NORUNTEST_PATH)
INPUTFILE = configparser.ConfigParser()
INPUTFILE.optionxform = str
BASE_FRAMEWORK = eval(CONFIGFILE.get('framework', 'base'))
KVM_FRAMEWORK = eval(CONFIGFILE.get('framework', 'kvm'))
OPTIONAL_FRAMEWORK = eval(CONFIGFILE.get('framework', 'optional'))
TEST_REPOS = eval(CONFIGFILE.get('tests', 'name'))
TEST_DIR = "%s/tests" % BASE_PATH
DATA_DIR = "%s/data" % BASE_PATH
LOG_DIR = "%s/results" % BASE_PATH
logger = logger_init(filepath=BASE_PATH).getlogger()
prescript_dir = CONFIGFILE.get('script-dir', 'prescriptdir')
postscript_dir = CONFIGFILE.get('script-dir', 'postscriptdir')
class TestSuite():
"""
Class for Testsuite
"""
guest_add_args = ""
host_add_args = ""
def __init__(self, name, resultdir, vt_type, test=None, mux=None, args=None,
use_test_dir=False):
self.jobid = binascii.b2a_hex(os.urandom(20)).decode()
self.name = str(name)
self.shortname = "_".join(self.name.split('_')[1:])
self.job_dir = None
self.type = str(name.split('_')[0])
self.resultdir = resultdir
self.conf = None
self.test = test
self.mux = mux
self.args = args
self.run = "Not_Run"
self.runsummary = None
self.runlink = None
if use_test_dir:
self.resultdir = os.path.join(self.resultdir, self.name)
if self.type == 'guest':
self.vt_type = vt_type
else:
self.vt_type = None
def jobdir(self):
cmd = 'grep %s %s/*/id|grep job-' % (self.jobid, self.resultdir)
status, self.job_dir = helper.runcmd(cmd, ignore_status=True)
if status != 0:
return ''
self.job_dir = self.job_dir.split(':')[0]
return os.path.dirname(self.job_dir)
def config(self):
if self.type == 'guest':
local_cfg = "%s/%s/%s/%s.cfg" % (TEST_CONF_PATH,
self.type, self.vt_type,
self.shortname)
if not os.path.isfile(local_cfg):
return self.conf
cfg = "%s/avocado-vt/backends/%s/cfg/%s.cfg" % (DATA_DIR,
self.vt_type,
self.shortname)
cmd = 'cp -f %s %s' % (local_cfg, cfg)
os.system(cmd)
self.conf = cfg
elif self.type == 'host':
local_cfg = "%s/%s/%s.cfg" % (TEST_CONF_PATH,
self.type,
self.shortname)
if not os.path.isfile(local_cfg):
return self.conf
self.conf = local_cfg
return self.conf
def runstatus(self, status, summary="Tests Executed", link=''):
self.run = status
self.runsummary = summary
self.runlink = link
def env_check(enable_kvm):
"""
Check if the environment is proper
"""
logger.info("Check for environment")
not_found = []
(env_ver, env_type, cmd_pat) = helper.get_env_type(enable_kvm)
# try to check base packages using major version numbers
env_ver = env_ver.split('.')[0]
env_deps = []
if not CONFIGFILE.has_section('deps_%s' % env_ver):
# Fallback to base name if specific version is not found
dist = helper.get_dist()
env_ver = dist[0]
if CONFIGFILE.has_section('deps_%s' % env_ver):
packages = CONFIGFILE.get('deps_%s' % env_ver, 'packages')
if packages != '':
env_deps = packages.split(',')
for dep in env_deps:
if helper.runcmd(cmd_pat % dep, ignore_status=True)[0] != 0:
not_found.append(dep)
env_deps = []
# try to check env specific packages
if CONFIGFILE.has_section('deps_%s_%s' % (env_ver, env_type)):
packages = CONFIGFILE.get('deps_%s_%s' %
(env_ver, env_type), 'packages')
if packages != '':
env_deps = packages.split(',')
for dep in env_deps:
if helper.runcmd(cmd_pat % dep, ignore_status=True)[0] != 0:
not_found.append(dep)
if not_found:
if args.install_deps:
logger.warning("Installing missing packages %s",
" ".join(not_found))
if helper.install_packages(not_found):
logger.error("Some packages not installed")
sys.exit(1)
else:
logger.error("Please install following "
"dependancy packages %s", " ".join(not_found))
sys.exit(1)
def is_avocado_plugin_avl(plugin):
"""
Check if the given avocado plugin installed
"""
cmd = 'avocado plugins|grep %s' % plugin
if helper.runcmd(cmd, ignore_status=True)[0] != 0:
logger.warning("Avocado %s plugin not installed", plugin)
return False
return True
def need_bootstrap(enable_kvm=False):
"""
Check if bootstrap required
:return: True if bootstrap is needed
"""
logger.debug("Check if bootstrap required")
needs_bootstrap = False
# Check for avocado
if 'no avocado ' in helper.get_avocado_bin(ignore_status=True):
logger.debug("Avocado needs to be installed")
needs_bootstrap = True
if enable_kvm:
# Check for avocado-vt
for plugin in ['vt', 'vt-list', 'vt-bootstrap']:
if not is_avocado_plugin_avl(plugin):
logger.debug("Avocado %s plugin needs to installed", plugin)
needs_bootstrap = True
# Check for avocado-tests
for repo in TEST_REPOS:
repo_name = repo[0].split('/')[-1].split('.')[0]
if not os.path.isdir(os.path.join(TEST_DIR, repo_name)):
logger.debug("Test needs to be downloaded/updated")
needs_bootstrap = True
return needs_bootstrap
def get_repo(repo, basepath):
"""
To get given repo cloned/updated and install
:param repo: tuple of repo link and branch(optional)
:param basepath: base path where the repository has to be downloaded
"""
if not repo[1]:
branch = "master"
else:
branch = repo[1]
cmd_update = "b=%s;git reset --hard && git checkout master && git remote update && (git branch|grep $b||(git checkout $b && git switch -c $b))" % branch
repo_name = repo[0].split('/')[-1].split('.git')[0]
repo_path = os.path.join(basepath, repo_name)
cmd_clone = "git clone %s %s" % (repo[0], repo_path)
if os.path.isdir(repo_path):
cmd = "cd %s && %s" % (repo_path, cmd_update)
else:
cmd = "%s && cd %s && %s" % (cmd_clone, repo_path, cmd_update)
helper.runcmd(cmd,
info_str="\t3. Cloning/Updating the repo: %s with branch %s under %s" % (
repo_name, branch, repo_path),
err_str="Failed to clone/update %s repository:" % repo_name)
def create_config(logdir):
"""
Create the local avocado config file
:param logdir: Log directory
"""
logger.info("\t1. Creating Avocado Config")
config = configparser.ConfigParser()
os.makedirs(AVOCADO_CONFIG_DIR, exist_ok=True)
avocado_conf = os.path.join(AVOCADO_CONFIG_DIR, "avocado.conf")
config.add_section('datadir.paths')
config.set('datadir.paths', 'base_dir', BASE_PATH)
config.set('datadir.paths', 'test_dir', TEST_DIR)
config.set('datadir.paths', 'data_dir', DATA_DIR)
config.set('datadir.paths', 'logs_dir', logdir)
config.add_section('sysinfo.collect')
config.set('sysinfo.collect', 'enabled', 'on')
config.set('sysinfo.collect', 'profiler', 'True')
config.set('sysinfo.collect', 'per_test', 'True')
config.set('sysinfo.collect', 'optimize', 'True')
config.add_section('sysinfo.collectibles')
config.set('sysinfo.collectibles', 'commands',
os.path.join(BASE_PATH, "config/sysinfo/commands"))
config.set('sysinfo.collectibles', 'fail_commands',
os.path.join(BASE_PATH, "config/sysinfo/fail_commands"))
config.set('sysinfo.collectibles', 'files',
os.path.join(BASE_PATH, "config/sysinfo/files"))
config.set('sysinfo.collectibles', 'fail_files',
os.path.join(BASE_PATH, "config/sysinfo/fail_files"))
config.set('sysinfo.collectibles', 'profilers',
os.path.join(BASE_PATH, "config/sysinfo/profilers"))
with open(avocado_conf, 'w+') as conf:
config.write(conf)
def guest_download(guestos):
"""
Guest image downloading
"""
avocado_bin = helper.get_avocado_bin()
cmd = '%s vt-bootstrap --vt-guest-os %s --yes-to-all' % (avocado_bin,
guestos)
helper.runcmd(cmd, err_str="Failed to Download Guest OS. Error:",
info_str="Downloading the guest OS(%s) image" % guestos)
def kvm_bootstrap(guest_os):
"""
Prepare KVM Test environment
"""
avocado_bin = helper.get_avocado_bin()
libvirt_cmd = '%s vt-bootstrap --vt-type libvirt \
--vt-update-providers --vt-skip-verify-download-assets \
--yes-to-all' % avocado_bin
helper.runcmd(libvirt_cmd, err_str="Failed to bootstrap vt libvirt. Error:",
info_str="\t\ti) Bootstrapping VT libvirt")
qemu_cmd = '%s vt-bootstrap --vt-type qemu --vt-update-providers \
--vt-skip-verify-download-assets --yes-to-all' % avocado_bin
helper.runcmd(qemu_cmd, err_str="Failed to bootstrap vt qemu. Error:",
info_str="\t\tii) Bootstrapping VT qemu")
if guest_os:
guestos_cmd = '%s vt-bootstrap --vt-guest-os %s --yes-to-all' % (avocado_bin,
guest_os)
helper.runcmd(guestos_cmd, err_str="Failed to Download Guest OS. Error:",
info_str="\t\tiii) Downloading guest OS(%s) image" % guest_os)
def bootstrap(enable_kvm=False, guest_os=None):
"""
Prepare the environment for execution
:params enable_kvm: Flag to enable kvm environment bootstrap
"""
env_clean()
logger.info("Bootstrapping Framework")
create_config(outputdir)
if enable_kvm:
install_str = "\t2. Installing Avocado and Avocado-VT(KVM) Framework"
else:
install_str = "\t2. Installing Avocado Framework"
logger.info(install_str)
pipManager.install()
if enable_kvm:
logger.info("\t2a.Bootstrapping Avocado-VT(KVM) Framework")
# Copy if any isos present in the local folder
dst_iso_path = "%s/avocado-vt/isos/linux/" % DATA_DIR
os.makedirs(dst_iso_path, exist_ok=True)
for fle in os.listdir("%s/isos" % BASE_PATH):
if fle.endswith(".iso"):
file_path = os.path.join(BASE_PATH, 'isos', fle)
dst_file = os.path.join(dst_iso_path, fle)
shutil.copyfile(file_path, dst_file)
kvm_bootstrap(guest_os)
helper.runcmd('mkdir -p %s' % TEST_DIR,
debug_str="Creating test repo dir %s" % TEST_DIR,
err_str="Failed to create test repo dir. Error: ")
for repo in TEST_REPOS:
get_repo(repo, TEST_DIR)
if os.path.isdir(prescript):
if len(os.listdir(prescript)):
if not os.path.exists(prescript_dir):
os.makedirs(prescript_dir)
helper.copy_dir_file(prescript, prescript_dir)
if os.path.isdir(postscript):
if len(os.listdir(postscript)):
if not os.path.exists(postscript_dir):
os.makedirs(postscript_dir)
helper.copy_dir_file(postscript, postscript_dir)
def run_test(testsuite, avocado_bin, nrunner):
"""
To run given testsuite
:param testsuite: Testsuite object which has details about the tests
:param avocado_bin: Executable path of avocado
"""
if not nrunner:
nrunner = '--test-runner runner'
else:
nrunner = ''
logger.info('')
if 'guest' in testsuite.type:
guest_args = TestSuite.guest_add_args
logger.info("Running Guest Tests Suite %s", testsuite.shortname)
if "sanity" in testsuite.shortname:
guest_args = " --vt-only-filter %s " % args.guest_os
cmd = "%s run --vt-type %s --vt-config %s \
--force-job-id %s \
--job-results-dir %s %s" % (avocado_bin, testsuite.vt_type,
testsuite.config(),
testsuite.jobid,
testsuite.resultdir, guest_args)
if 'host' in testsuite.type:
logger.info("Running Host Tests Suite %s", testsuite.shortname)
cmd = "%s run %s %s" % (avocado_bin, nrunner, testsuite.test)
if testsuite.mux:
cmd += " -m %s" % os.path.join(TEST_DIR, testsuite.mux)
cmd += " --force-job-id %s \
--job-results-dir %s %s" % (testsuite.jobid,
testsuite.resultdir,
TestSuite.host_add_args)
if testsuite.args:
cmd += testsuite.args
try:
logger.info("Running: %s", cmd)
status = os.system(cmd)
status = int(bin(int(status))[2:].zfill(16)[:-8], 2)
if status >= 2:
testsuite.runstatus("Not_Run", "Command execution failed")
return
except Exception as error:
logger.error("Running testsuite %s failed with error\n%s",
testsuite.name, error)
testsuite.runstatus("Not_Run", "Command execution failed")
return
logger.info('')
result_link = testsuite.jobdir()
if result_link:
result_json = result_link + "/results.json"
result_link += "/job.log\n"
with open(result_json, encoding="utf-8") as filep:
result_state = json.load(filep)
for state in ['pass', 'cancel', 'errors', 'failures', 'skip', 'warn', 'interrupt']:
if state in result_state.keys():
result_link += "| %s %s |" % (state.upper(),
str(result_state[state]))
testsuite.runstatus("Run", "Successfully executed", result_link)
else:
testsuite.runstatus("Not_Run", "Unable to find job log file")
return
def env_clean(deep=False):
"""
Clean/uninstall avocado and autotest
"""
logger.info("Cleaning the Environment")
pipManager.uninstall()
if os.path.isdir(prescript):
helper.remove_file(prescript, prescript_dir)
if os.path.isdir(postscript):
helper.remove_file(postscript, postscript_dir)
if deep:
# Remove Data dir if present
if os.path.isdir(DATA_DIR):
shutil.rmtree(DATA_DIR)
# Remove local avocado config if present
if os.path.isdir(AVOCADO_CONFIG_DIR):
shutil.rmtree(AVOCADO_CONFIG_DIR)
# Remove tests folder
if os.path.isdir(TEST_DIR):
shutil.rmtree(TEST_DIR)
def edit_mux_file(test_config_name, mux_file_path, tmp_mux_path):
"""
Edit the mux file with input given in input config file.
"""
INPUTFILE.read(args.inputfile)
if INPUTFILE.has_section(test_config_name):
input_dic = {}
for input_line in INPUTFILE.items(test_config_name):
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)))
def parse_test_config(test_config_file, avocado_bin, enable_kvm):
"""
Parses Test Config file and returns list of indivual tests dictionaries,
with test path and yaml file path.
"""
test_config_type = test_config_file[:test_config_file.find("_")]
test_config_name = test_config_file[test_config_file.find("_") + 1:]
test_config_file = "%s/%s/%s.cfg" % (TEST_CONF_PATH, test_config_type,
test_config_name)
if os.path.isfile(test_config_file):
(env_ver, env_type, _) = helper.get_env_type(enable_kvm)
norun_tests = []
# Get common set of not needed tests
env = 'norun_%s' % env_type
dist = 'norun_%s' % helper.get_dist()[0]
major = 'norun_%s' % env_ver.split('.')[0]
minor = 'norun_%s' % env_ver
minor_env = 'norun_%s_%s' % (env_ver, env_type)
for section in [env, dist, major, minor, minor_env]:
if NORUNTESTFILE.has_section(section):
norun_tests.extend(NORUNTESTFILE.get(
section, 'tests').split(','))
norun_tests = list(filter(None, norun_tests))
with open(test_config_file, 'r') as filep:
test_config_contents = filep.read()
test_list = []
mux_flag = 0
arg_flag = 0
for line in test_config_contents.splitlines():
norun_flag = False
test_dic = {}
# Comment line or Empty line filtering
if line.startswith("#") or not line:
norun_flag = True
# Filtering <test yaml> combination
elif line in norun_tests:
norun_flag = True
# Filtering <string*> pattern
else:
for norun_test in norun_tests:
if norun_test.endswith('*') and line.startswith(norun_test[:-1]):
norun_flag = True
break
if norun_flag:
continue
# split line ignoring quotes used for additional args
line = shlex.split(line)
test_dic['test'] = line[0].strip('$')
test_dic['name'] = test_dic['test'].split("/")[-1]
if ":" in test_dic['test'].split("/")[-1]:
test_dic['name'] = "%s_%s" % (test_dic['name'].split(".")[0],
test_dic['name'].split(":")[-1].replace(".", "_"))
test_dic['test'] = "%s$" % test_dic['test']
else:
test_dic['name'] = test_dic['name'].split(".")[0]
cmd = "%s list %s 2> /dev/null" % (avocado_bin, test_dic['test'])
if helper.runcmd(cmd, ignore_status=True)[0] != 0:
logger.debug("%s does not exist", test_dic['test'])
continue
# Handling parameters after test from cfg
if len(line) > 1:
# Handling yaml file from second param
if '.yaml' in line[1]:
test_dic['mux'] = line[1]
mux_flag = 1
test_dic['name'] = "%s_%s" % (test_dic['name'],
test_dic['mux'].split("/")[-1].split(".")[0])
if args.inputfile:
mux_file = os.path.join(TEST_DIR, test_dic['mux'])
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
# Handling additional args from second param
else:
arg_flag = 1
test_dic['args'] = " %s" % line[1]
count = 0
for list_dic in test_list:
if test_dic['name'] == list_dic['name'].split('.')[0]:
count += 1
if count:
test_dic['name'] += ".%d" % (count + 1)
# Handle additional args after yaml(second arg) from third param
if len(line) > 2:
arg_flag = 1
test_dic['args'] = " %s" % line[2]
test_list.append(test_dic)
if mux_flag == 0 and arg_flag == 0:
single_test_dic = {}
single_test_dic['name'] = test_config_name
single_test_dic['test'] = ''
for test in test_list:
single_test_dic['test'] += " %s" % test['test']
return [single_test_dic]
return test_list
logger.error("Test Config %s not present", test_config_file)
return []
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--bootstrap', dest='bootstrap',
action='store_true', default=False,
help='Prepare the environment for test')
parser.add_argument('--run-suite', dest='run_suite',
action='store', default=None,
help='Indicate which test suite(s) to run')
parser.add_argument('--output-dir', dest='outputdir',
action='store', default=None,
help='Specify the custom test results directory')
parser.add_argument('--use-test-dir', dest='testdir',
action='store_true', default=False,
help='Use corresponding test-name dir for storing job results')
parser.add_argument('--input-file', dest='inputfile',
action='store', default=None,
help='Specify input file for custom mux values for host tests')
parser.add_argument('--interval-time', dest='interval',
action='store', default=None,
help='Specify the interval time between tests')
parser.add_argument('--verbose', dest='verbose',
action='store_true', default=False,
help='Enable verbose output on the console')
parser.add_argument('--only-filter', dest='only_filter',
action='store', default="",
help='Add filters to include specific avocado tests,'
'features from the guest test suite')
parser.add_argument('--no-filter', dest='no_filter',
action='store', default="",
help='Add filters to exclude specific avocado tests,'
'features from the guest test suite')
parser.add_argument('--additional-args', dest='add_args',
action='store', default="",
help='Pass additional arguments to the command')
parser.add_argument('--guest-os', dest='guest_os',
action='store', default='JeOS.27.ppc64le',
help='Provide Guest os: Default: JeOS.27.ppc64le')
parser.add_argument('--vt', dest='vt_type',
action='store', choices=['qemu', 'libvirt'],
default='libvirt',
help='Provide VT: qemu or libvirt Default: libvirt')
parser.add_argument('--install', dest='install_guest',
action='store_true', default=False,
help='Install the Guest VM, if needed.')
parser.add_argument('--no-download', dest='no_guest_download',
action='store_true', default=False,
help='To download the preinstalled guest image')
parser.add_argument('--no-deps-check', dest="no_deps_check",
action='store_true', default=False,
help='To force wrapper not to check for dependancy packages')
parser.add_argument('--install-deps', dest="install_deps",
action='store_true', default=False,
help="To force wrapper to install dependancy packages "
"(Only for Ubuntu, SLES and yum based OS)")
parser.add_argument('--clean', dest="clean",
action='store_true', default=False,
help='To remove/uninstall autotest, avocado from system')
parser.add_argument('--enable-kvm', dest="enable_kvm", action='store_true',
default=False, help='enable bootstrap kvm tests')
parser.add_argument('--nrunner', dest="nrunner", action='store_true',
default=False, help='enable Parallel run')
parser.add_argument('--run-tests', dest="run_tests", action='store',
default=None,
help="To run the host tests provided in the option and publish result [Note: test names(full path) and separated by comma]")
args = parser.parse_args()
if helper.get_machine_type() == 'pHyp':
args.enable_kvm = False
if args.run_suite:
if "guest_" in args.run_suite:
logger.error("Not suitable platform to run kvm tests, "
"please check the commandline, exiting...")
sys.exit(-1)
else:
if args.run_suite:
if "guest_" in args.run_suite:
logger.warning("Overriding user setting and enabling kvm bootstrap "
"as guest tests are requested")
args.enable_kvm = True
pipManager = helper.PipMagager(BASE_FRAMEWORK, OPTIONAL_FRAMEWORK,
KVM_FRAMEWORK, args.enable_kvm)
if not (args.run_suite and args.install_deps
and args.bootstrap and args.install) and args.clean:
# honor the spl condition, just to deep clean the environment incase needed
env_clean(deep=True)
sys.exit(0)
if not args.no_deps_check:
env_check(args.enable_kvm)
additional_args = " %s" % args.add_args
if args.verbose:
additional_args += ' --show-job-log'
if args.outputdir:
# Check if it valid path
if not os.path.isdir(os.path.abspath(args.outputdir)):
raise ValueError("No output dir")
outputdir = os.path.join(args.outputdir, 'results')
else:
outputdir = os.path.join(BASE_PATH, 'results')
bootstraped = False
if (args.bootstrap or need_bootstrap(args.enable_kvm)):
if not args.no_guest_download and args.enable_kvm:
bootstrap(args.enable_kvm, args.guest_os)
else:
bootstrap(args.enable_kvm)
bootstraped = True
if args.run_tests:
with open("%s/host/dynamic_test_suite" % TEST_CONF_PATH+".cfg","w+") as fp:
fp.write('\n'.join(args.run_tests.split(",")))
args.run_suite = str(args.run_suite)+","+"host_dynamic_test_suite"
if args.inputfile:
if not os.path.isfile(args.inputfile):
logger.debug(
"Input file %s not found. Continuing without input file", args.inputfile)
args.inputfile = None
if args.run_suite:
# create a folder to store all edited multiplexer files
if not os.path.isdir("/tmp/mux/"):
logger.info("Creating temporary mux dir")
os.makedirs("/tmp/mux/")
if "guest_" in args.run_suite:
# Make sure we download guest image once
if not args.no_guest_download and not bootstraped:
guest_download(args.guest_os)
only_filter = args.only_filter
if only_filter:
only_filter += ' %s' % args.guest_os
else:
only_filter = args.guest_os
if only_filter:
TestSuite.guest_add_args += ' --vt-only-filter \
"%s"' % only_filter
if args.no_filter:
TestSuite.guest_add_args += ' --vt-no-filter \
"%s"' % args.no_filter
if additional_args:
TestSuite.guest_add_args += additional_args
if "host_" in args.run_suite:
TestSuite.host_add_args = additional_args
test_suites = args.run_suite.split(',')
if args.install_guest:
test_suites.insert(0, 'guest_install')
avocado_bin = helper.get_avocado_bin()
Testsuites = {}
# Validate if given test suite is available
# and init TestSuite object for each test suite
Testsuites_list = []
for test_suite in test_suites:
if 'host' in test_suite:
test_list = parse_test_config(
test_suite, avocado_bin, args.enable_kvm)
if not test_list:
Testsuites[test_suite] = TestSuite(test_suite, outputdir,
args.vt_type,
use_test_dir=args.testdir)
Testsuites[test_suite].runstatus("Cant_Run",
"Config file not present")
continue
for test in test_list:
for l_key in ['mux', 'args']:
if l_key not in test:
test[l_key] = ''
test_suite_name = "%s_%s" % (test_suite, test['name'])
Testsuites[test_suite_name] = TestSuite(test_suite_name,
outputdir, args.vt_type,
test['test'], test['mux'],
test['args'],
use_test_dir=args.testdir)
Testsuites_list.append(test_suite_name)
if 'guest' in test_suite:
guest_additional_args = ""
Testsuites[test_suite] = TestSuite(str(test_suite),
outputdir, args.vt_type,
use_test_dir=args.testdir)
Testsuites_list.append(str(test_suite))
if not Testsuites[test_suite].config():
Testsuites[test_suite].runstatus("Cant_Run",
"Config file not present")
continue
# Run Tests
for test_suite in Testsuites_list:
if not Testsuites[test_suite].run == "Cant_Run":
run_test(Testsuites[test_suite], avocado_bin, args.nrunner)
if args.interval:
time.sleep(int(args.interval))
# Finding the space needed for formatting result summary
test_name_list = []
for test_suite in Testsuites_list:
test_name_list.append(Testsuites[test_suite].name)
if Testsuites[test_suite].runlink:
test_name_list.extend(
Testsuites[test_suite].runlink.split('\n'))
if test_name_list:
lg_name_len = len((sorted(test_name_list, key=len)[-1])) + 5
else:
lg_name_len = 10
# List the final output
output_str = "Summary of test results can be found below:"
output_str += "\n%s %s %s" % ('TestSuite'.ljust(lg_name_len),
'TestRun'.ljust(10), 'Summary')
summary_output = [output_str]
for test_suite in Testsuites_list:
summary_output.append(' ')
summary_output.append('%s %s %s' % (Testsuites[test_suite].name.ljust(lg_name_len),
Testsuites[test_suite].run.ljust(
10),
Testsuites[test_suite].runsummary))
summary_output.append(Testsuites[test_suite].runlink)
logger.info("\n".join(summary_output))
if os.path.isdir("/tmp/mux/"):
logger.info("Removing temporary mux dir")
shutil.rmtree("/tmp/mux/")
if args.clean:
env_clean()