def do_start_and_return (self, line):
     """Start T-Rex run and once in 'Running' mode, return to cmd prompt"""
     print termstyle.green("*** Starting T-Rex run, wait until in 'Running' state ***")
     try:
         ret = self.trex.start_trex(**self.run_params)
         print termstyle.green("*** End of scenario (T-Rex is probably still running!) ***")
     except TRexException as inst:
         print termstyle.red(inst)
 def do_stop_trex (self, line):
     """Try to stop T-Rex run (if T-Rex is currently running)"""
     print termstyle.green("*** Starting T-Rex termination ***")
     try:
         ret = self.trex.stop_trex()
         print termstyle.green("*** End of scenario (T-Rex is not running now) ***")
     except TRexException as inst:
         print termstyle.red(inst)
 def do_stop_trex(self, line):
     """Try to stop T-Rex run (if T-Rex is currently running)"""
     print termstyle.green("*** Starting T-Rex termination ***")
     try:
         ret = self.trex.stop_trex()
         print termstyle.green(
             "*** End of scenario (T-Rex is not running now) ***")
     except TRexException as inst:
         print termstyle.red(inst)
 def do_kill_indiscriminately (self, line):
     """Force killing of running T-Rex process (if exists) on the server."""
     print termstyle.green("*** Starting T-Rex termination ***")
     ret = self.trex.force_kill()
     if ret:
         print termstyle.green("*** End of scenario (T-Rex is not running now) ***")
     elif ret is None:
         print termstyle.magenta("*** End of scenario (T-Rex termination aborted) ***")
     else:
         print termstyle.red("*** End of scenario (T-Rex termination failed) ***")
 def do_start_and_return(self, line):
     """Start T-Rex run and once in 'Running' mode, return to cmd prompt"""
     print termstyle.green(
         "*** Starting T-Rex run, wait until in 'Running' state ***")
     try:
         ret = self.trex.start_trex(**self.run_params)
         print termstyle.green(
             "*** End of scenario (T-Rex is probably still running!) ***")
     except TRexException as inst:
         print termstyle.red(inst)
 def do_cancel_reservation (self, user):
     """Cancels a current reservation of T-Rex to a certain user"""
     try:
         if not user:
             ret = self.trex.cancel_reservation()
         else:
             ret = self.trex.cancel_reservation(user.split(' ')[0])
         print termstyle.green("*** T-Rex reservation canceled successfully ***")
     except TRexException as inst:
         print termstyle.red(inst)
 def do_reserve_trex(self, user):
     """Reserves the usage of T-Rex to a certain user"""
     try:
         if not user:
             ret = self.trex.reserve_trex()
         else:
             ret = self.trex.reserve_trex(user.split(' ')[0])
         print termstyle.green("*** T-Rex reserved successfully ***")
     except TRexException as inst:
         print termstyle.red(inst)
 def do_reserve_trex (self, user):
     """Reserves the usage of T-Rex to a certain user"""
     try:
         if not user:
             ret = self.trex.reserve_trex()
         else:
             ret = self.trex.reserve_trex(user.split(' ')[0])
         print termstyle.green("*** T-Rex reserved successfully ***")
     except TRexException as inst:
         print termstyle.red(inst)
 def do_cancel_reservation(self, user):
     """Cancels a current reservation of T-Rex to a certain user"""
     try:
         if not user:
             ret = self.trex.cancel_reservation()
         else:
             ret = self.trex.cancel_reservation(user.split(' ')[0])
         print termstyle.green(
             "*** T-Rex reservation canceled successfully ***")
     except TRexException as inst:
         print termstyle.red(inst)
 def do_poll_once (self, line):
     """Performs a single poll of T-Rex current data dump (if T-Rex is running) and prompts and short version of latest result_obj"""
     print termstyle.green("*** Trying T-Rex single poll ***")
     try:
         last_res = dict()
         if self.trex.is_running(dump_out = last_res):
             obj = self.trex.get_result_obj()
             print obj
         else:
             print termstyle.magenta("T-Rex isn't currently running.")
         print termstyle.green("*** End of scenario (T-Rex is posssibly still running!) ***")
     except TRexException as inst:
         print termstyle.red(inst)
 def do_kill_indiscriminately(self, line):
     """Force killing of running T-Rex process (if exists) on the server."""
     print termstyle.green("*** Starting T-Rex termination ***")
     ret = self.trex.force_kill()
     if ret:
         print termstyle.green(
             "*** End of scenario (T-Rex is not running now) ***")
     elif ret is None:
         print termstyle.magenta(
             "*** End of scenario (T-Rex termination aborted) ***")
     else:
         print termstyle.red(
             "*** End of scenario (T-Rex termination failed) ***")
 def do_poll_once(self, line):
     """Performs a single poll of T-Rex current data dump (if T-Rex is running) and prompts and short version of latest result_obj"""
     print termstyle.green("*** Trying T-Rex single poll ***")
     try:
         last_res = dict()
         if self.trex.is_running(dump_out=last_res):
             obj = self.trex.get_result_obj()
             print obj
         else:
             print termstyle.magenta("T-Rex isn't currently running.")
         print termstyle.green(
             "*** End of scenario (T-Rex is posssibly still running!) ***")
     except TRexException as inst:
         print termstyle.red(inst)
    def do_run_until_finish (self, sample_rate):
        """Starts T-Rex and sample server until run is done."""
        print termstyle.green("*** Starting T-Rex run_until_finish scenario ***")

        if not sample_rate: # use default sample rate if not passed
            sample_rate = 5
        try:
            sample_rate = int(sample_rate)
            ret = self.trex.start_trex(**self.run_params)
            self.trex.sample_to_run_finish(sample_rate)
            print termstyle.green("*** End of T-Rex run ***")
        except ValueError as inst:
            print termstyle.magenta("Provided illegal sample rate value. Please try again.\n[", inst,"]")
        except TRexException as inst:
            print termstyle.red(inst)
    def do_run_until_finish(self, sample_rate):
        """Starts T-Rex and sample server until run is done."""
        print termstyle.green(
            "*** Starting T-Rex run_until_finish scenario ***")

        if not sample_rate:  # use default sample rate if not passed
            sample_rate = 5
        try:
            sample_rate = int(sample_rate)
            ret = self.trex.start_trex(**self.run_params)
            self.trex.sample_to_run_finish(sample_rate)
            print termstyle.green("*** End of T-Rex run ***")
        except ValueError as inst:
            print termstyle.magenta(
                "Provided illegal sample rate value. Please try again.\n[",
                inst, "]")
        except TRexException as inst:
            print termstyle.red(inst)
    def do_run_until_condition (self, sample_rate):
        """Starts T-Rex and sample server until condition is satisfied."""
        print termstyle.green("*** Starting T-Rex run until condition is satisfied scenario ***")

        def condition (result_obj):
                return result_obj.get_current_tx_rate()['m_tx_pps'] > 200000

        if not sample_rate: # use default sample rate if not passed
            sample_rate = 5
        try:
            sample_rate = int(sample_rate)
            ret = self.trex.start_trex(**self.run_params)
            ret_val = self.trex.sample_until_condition(condition, sample_rate)
            print ret_val
            print termstyle.green("*** End of T-Rex run ***")
        except ValueError as inst:
            print termstyle.magenta("Provided illegal sample rate value. Please try again.\n[", inst,"]")
        except TRexException as inst:
            print termstyle.red(inst)
 def do_run_and_poll (self, sample_rate):
     """Starts T-Rex and sample server manually until run is done."""
     print termstyle.green("*** Starting T-Rex run and manually poll scenario ***")
     if not sample_rate: # use default sample rate if not passed
         sample_rate = 5
     try:
         sample_rate = int(sample_rate)
         ret = self.trex.start_trex(**self.run_params)
         last_res = dict()
         while self.trex.is_running(dump_out = last_res):
             obj = self.trex.get_result_obj()
             if (self.verbose):
                 print obj
             # do WHATEVER here
             time.sleep(sample_rate)
             
         print termstyle.green("*** End of T-Rex run ***")
     except ValueError as inst:
         print termstyle.magenta("Provided illegal sample rate value. Please try again.\n[", inst,"]")
     except TRexException as inst:
         print termstyle.red(inst)
    def do_run_until_condition(self, sample_rate):
        """Starts T-Rex and sample server until condition is satisfied."""
        print termstyle.green(
            "*** Starting T-Rex run until condition is satisfied scenario ***")

        def condition(result_obj):
            return result_obj.get_current_tx_rate()['m_tx_pps'] > 200000

        if not sample_rate:  # use default sample rate if not passed
            sample_rate = 5
        try:
            sample_rate = int(sample_rate)
            ret = self.trex.start_trex(**self.run_params)
            ret_val = self.trex.sample_until_condition(condition, sample_rate)
            print ret_val
            print termstyle.green("*** End of T-Rex run ***")
        except ValueError as inst:
            print termstyle.magenta(
                "Provided illegal sample rate value. Please try again.\n[",
                inst, "]")
        except TRexException as inst:
            print termstyle.red(inst)
    def do_run_and_poll(self, sample_rate):
        """Starts T-Rex and sample server manually until run is done."""
        print termstyle.green(
            "*** Starting T-Rex run and manually poll scenario ***")
        if not sample_rate:  # use default sample rate if not passed
            sample_rate = 5
        try:
            sample_rate = int(sample_rate)
            ret = self.trex.start_trex(**self.run_params)
            last_res = dict()
            while self.trex.is_running(dump_out=last_res):
                obj = self.trex.get_result_obj()
                if (self.verbose):
                    print obj
                # do WHATEVER here
                time.sleep(sample_rate)

            print termstyle.green("*** End of T-Rex run ***")
        except ValueError as inst:
            print termstyle.magenta(
                "Provided illegal sample rate value. Please try again.\n[",
                inst, "]")
        except TRexException as inst:
            print termstyle.red(inst)
 def _show(self):
     if self.pidfile.is_locked():
         print termstyle.red("T-Rex server daemon is running")
     else:
         print termstyle.red("T-Rex server daemon is NOT running")
Ejemplo n.º 20
0
 def _show (self):
     if self.pidfile.is_locked():
         print termstyle.red("T-Rex server daemon is running")
     else:
         print termstyle.red("T-Rex server daemon is NOT running")