Beispiel #1
0
 def _send(self, cmd):
     """Append LF and send command to the PROX instance."""
     if self._sock is None:
         raise RuntimeError("PROX socket closed, cannot send '%s'" % cmd)
     try:
         self._sock.sendall(cmd.encode() + b'\n')
     except ConnectionResetError as e:
         RapidLog.error('Pipe reset by Prox instance: traffic too high?')
         raise
Beispiel #2
0
 def _recv(self):
     """Receive response from PROX instance, return it with LF removed."""
     if self._sock is None:
         raise RuntimeError("PROX socket closed, cannot receive anymore")
     try:
         pos = self._rcvd.find(b'\n')
         while pos == -1:
             self._rcvd += self._sock.recv(256)
             pos = self._rcvd.find(b'\n')
         rsp = self._rcvd[:pos]
         self._rcvd = self._rcvd[pos + 1:]
     except ConnectionResetError as e:
         RapidLog.error('Pipe reset by Prox instance: traffic too high?')
         raise
     return rsp.decode()
Beispiel #3
0
 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
     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['password'], 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['password'],
                                    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)
     try:
         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()
         socket_executor = concurrent.futures.ThreadPoolExecutor(
             max_workers=len(self.machines))
         future_to_connect_prox = {
             socket_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,
                     test_params['sleep_time'])
             elif test_param['test'] in ['corestatstest']:
                 test = CoreStatsTest(test_param, test_params['runtime'],
                                      test_params['TestName'],
                                      test_params['environment_file'],
                                      self.machines)
             elif test_param['test'] in ['portstatstest']:
                 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, background_machines)
             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)
     except (ConnectionError, KeyboardInterrupt) as e:
         result = result_details = None
         socket_executor.shutdown(wait=False)
         socket_executor._threads.clear()
         prox_executor.shutdown(wait=False)
         prox_executor._threads.clear()
         concurrent.futures.thread._threads_queues.clear()
         RapidLog.error("Test interrupted: {} {}".format(
             type(e).__name__, e))
     return (result, result_details)