summaryrefslogtreecommitdiffstats
path: root/VNFs/DPPD-PROX/helper-scripts/rapid/runrapid.py
blob: 3bdb91d1e9db80609e39fcce21054ca434b7f419 (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
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
#!/usr/bin/python3

##
## Copyright (c) 2010-2020 Intel Corporation
##
## Licensed under the Apache License, Version 2.0 (the "License");
## you may not use this file except in compliance with the License.
## You may obtain a copy of the License at
##
##     http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
##
from __future__ import print_function
from __future__ import print_function
from __future__ import division

from future import standard_library
standard_library.install_aliases()
from builtins import object
import sys
import concurrent.futures
from concurrent.futures import ALL_COMPLETED
from rapid_cli import RapidCli
from rapid_log import RapidLog
from rapid_parser import RapidConfigParser
from rapid_defaults import RapidDefaults
from rapid_machine import RapidMachine
from rapid_generator_machine import RapidGeneratorMachine
from rapid_flowsizetest import FlowSizeTest
from rapid_corestatstest import CoreStatsTest
from rapid_portstatstest import PortStatsTest
from rapid_impairtest import ImpairTest
from rapid_irqtest import IrqTest
from rapid_warmuptest import WarmupTest

class RapidTestManager(object):
    """
    RapidTestManager Class
    """
    def __del__(self):
        for machine in self.machines:
            machine.close_prox()

    @staticmethod
    def get_defaults():
        return (RapidDefaults.test_params)

    def run_tests(self, test_params):
        test_params = RapidConfigParser.parse_config(test_params)
        RapidLog.debug(test_params)
        monitor_gen = monitor_sut = False
        background_machines = []
        sut_machine = gen_machine = None
        self.machines = []
        configonly = test_params['configonly']
        for machine_params in test_params['machines']:
            if 'gencores' in machine_params.keys():
                machine = RapidGeneratorMachine(test_params['key'],
                        test_params['user'], test_params['vim_type'],
                        test_params['rundir'], test_params['resultsdir'],
                        machine_params, configonly, test_params['ipv6'])
                if machine_params['monitor']:
                    if monitor_gen:
                        RapidLog.exception("Can only monitor 1 generator")
                        raise Exception("Can only monitor 1 generator")
                    else:
                        monitor_gen = True
                        gen_machine = machine
                else:
                    background_machines.append(machine)
            else:
                machine = RapidMachine(test_params['key'], test_params['user'],
                        test_params['vim_type'], test_params['rundir'],
                        test_params['resultsdir'], machine_params, configonly)
                if machine_params['monitor']:
                    if monitor_sut:
                        RapidLog.exception("Can only monitor 1 sut")
                        raise Exception("Can only monitor 1 sut")
                    else:
                        monitor_sut = True
                        if machine_params['prox_socket']:
                            sut_machine = machine
            self.machines.append(machine)
        prox_executor = concurrent.futures.ThreadPoolExecutor(max_workers=len(self.machines))
        self.future_to_prox = {prox_executor.submit(machine.start_prox): machine for machine in self.machines}
        if configonly:
            concurrent.futures.wait(self.future_to_prox,return_when=ALL_COMPLETED)
            sys.exit()
        with concurrent.futures.ThreadPoolExecutor(max_workers=len(self.machines)) as executor:
            future_to_connect_prox = {executor.submit(machine.connect_prox): machine for machine in self.machines}
            concurrent.futures.wait(future_to_connect_prox,return_when=ALL_COMPLETED)
        result = 0
        for test_param in test_params['tests']:
            RapidLog.info(test_param['test'])
            if test_param['test'] in ['flowsizetest', 'TST009test',
                    'fixed_rate', 'increment_till_fail']:
                test = FlowSizeTest(test_param, test_params['lat_percentile'],
                        test_params['runtime'], 
                        test_params['TestName'], 
                        test_params['environment_file'], gen_machine,
                        sut_machine, background_machines)
            elif test_param['test'] in ['corestats']:
                test = CoreStatsTest(test_param, test_params['runtime'],
                        test_params['TestName'], 
                        test_params['environment_file'], self.machines)
            elif test_param['test'] in ['portstats']:
                test = PortStatsTest(test_param, test_params['runtime'],
                        test_params['TestName'], 
                        test_params['environment_file'], self.machines)
            elif test_param['test'] in ['impairtest']:
                test = ImpairTest(test_param, test_params['lat_percentile'],
                        test_params['runtime'],
                        test_params['TestName'], 
                        test_params['environment_file'], gen_machine,
                        sut_machine)
            elif test_param['test'] in ['irqtest']:
                test = IrqTest(test_param, test_params['runtime'],
                        test_params['TestName'], 
                        test_params['environment_file'], self.machines)
            elif test_param['test'] in ['warmuptest']:
                test = WarmupTest(test_param, gen_machine)
            else:
                RapidLog.debug('Test name ({}) is not valid:'.format(
                    test_param['test']))
            single_test_result, result_details = test.run()
            result = result + single_test_result
        for machine in self.machines:
            machine.close_prox()
        concurrent.futures.wait(self.future_to_prox,return_when=ALL_COMPLETED)
        return (result, result_details)

def main():
    """Main function.
    """
    test_params = RapidTestManager.get_defaults()
    # When no cli is used, the process_cli can be replaced by code modifying
    # test_params
    test_params = RapidCli.process_cli(test_params)
    log_file = 'RUN{}.{}.log'.format(test_params['environment_file'],
            test_params['test_file'])
    RapidLog.log_init(log_file, test_params['loglevel'],
            test_params['screenloglevel'] , test_params['version']  )
    test_manager = RapidTestManager()
    test_result, _ = test_manager.run_tests(test_params)
    RapidLog.log_close()

if __name__ == "__main__":
    main()