summaryrefslogtreecommitdiffstats
path: root/func/cli.py
blob: 9b140874490b8510b94ff8a60e73c19d88edf993 (plain)
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
##############################################################################
# Copyright (c) 2015 Dell Inc  and others.
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################

import sys
import os
from func.env_setup import Env_setup
from func.driver import Driver
from func.spawn_vm import SpawnVM
import argparse


class cli():

    def _getfile(self, filepath):

        with open('test_list/'+filepath,'r') as finput:
            _benchmarks=finput.readlines()
        for items in range( len(_benchmarks)):
            _benchmarks[items]=_benchmarks[items].rstrip()
        return _benchmarks

    def _getsuite(self, filepath):

        return filepath

    def _checkTestList(self, filename):

        if os.path.isfile('test_list/'+filename):
            return True
        else:
            return False

    def _checkLabName(self, labname):

        if os.path.isdir('test_cases/'+labname):
            return True
        else:
            return False

    def __init__(self):

        suite=[]
        parser = argparse.ArgumentParser()
        parser.add_argument('-l ', '--lab', help='Name of Lab on which being tested, These can' \
                                            'be found in the test_cases/ directory. Please ' \
                                            'ensure that you have edited the respective files '\
                                            'before using them. For testing other than through Jenkins'\
                                            ' The user should list default after -l . all the fields in'\
                                            ' the files are necessary and should be filled')
        parser.add_argument('-f', '--file', help = 'File in test_list with the list of tests. there are three files' \
                                            '\n compute '\
                                            '\n storage '\
                                            '\n network '\
                                            'They contain all the tests that will be run. They are listed by suite.' \
                                            'Please ensure there are no empty lines')
        args = parser.parse_args()

        if not self._checkTestList(args.file):
            print '\n\n ERROR: Test File Does not exist in test_list/ please enter correct file \n\n'
            sys.exit(0)

        if not self._checkLabName(args.lab):
            print '\n\n You have specified a lab that is not present in test_cases/ please enter correct'\
                    ' file. If unsure how to proceed, use -l default.\n\n'
            sys.exit(0)

        benchmarks = self._getfile(args.file)
        suite.append(args.file)
        suite=self._getsuite(suite)
        for items in range (len(benchmarks)):
            if (suite and benchmarks):

                roles=''
                vm_info=''
                benchmark_details=''
                pip=''
                obj=''
                obj = Env_setup()
                if os.path.isfile('./test_cases/'+args.lab.lower()+'/'+suite[0]+'/' +benchmarks[items]):
                    [benchmark, roles, vm_info, benchmark_details, pip] = obj.parse('./test_cases/'
                                                                    +args.lab.lower()+'/'+suite[0]+'/'+benchmarks[items])

                    if len(vm_info) != 0:
                        vmObj =''
                        vmObj = SpawnVM(vm_info)
                    obj.callpingtest()
                    obj.callsshtest()
                    obj.updateAnsible()
                    dvr = Driver()
                    dvr.drive_bench(benchmark, obj.roles_dict.items(), benchmark_details, obj.ip_pw_dict.items())
                else:
                    print (args.benchmark, ' is not a Template in the Directory - \
                                Enter a Valid file name. or use qtip.py -h for list')