Clean Output Option. 86/72886/2
authorSridhar K. N. Rao <sridhar.rao@spirent.com>
Wed, 1 Sep 2021 05:56:28 +0000 (11:26 +0530)
committerSridhar K. N. Rao <sridhar.rao@spirent.com>
Tue, 7 Sep 2021 04:59:55 +0000 (10:29 +0530)
This patch adds support for clean output - displaying only final
results.

User has to run with --verbosity and level as error or critical.
--verbosity is an existing option.

Remove unnecessary spaces

Signed-off-by: Sridhar K. N. Rao <sridhar.rao@spirent.com>
Change-Id: Id227a4b787c4c7e4dd97f28009946ac6a8a802d3

core/traffic_controller.py
testcases/testcase.py
tools/pkt_gen/trex/trex_client.py
vsperf
vswitches/ovs.py

index 1f21e57..2a5b035 100644 (file)
@@ -164,6 +164,8 @@ class TrafficController(object):
             for(key, value) in list(item.items()):
                 logging.info("         Key: " + str(key) +
                              ", Value: " + str(value))
+                if settings.getValue('CLEAN_OUTPUT'):
+                    print(str(key) + ", " + str(value))
 
     def get_results(self):
         """IResult interface implementation.
index c13754b..7f4ad9a 100644 (file)
@@ -207,7 +207,7 @@ class TestCase(object):
         self._k8s = S.getValue('K8S')
         if self._k8s:
             if S.getValue('EXT_VSWITCH'):
-                self._evfctl = extvswitchfctl.ExtVswitchFlowCtl()
+                self._evfctl = extvswitchflctl.ExtVswitchFlowCtl()
 
 
     def run_initialize(self):
@@ -398,7 +398,8 @@ class TestCase(object):
 
                         # dump vswitch flows before they are affected by VNF termination
                         if not self._vswitch_none:
-                            self._vswitch_ctl.dump_vswitch_connections()
+                            if not S.getValue('CLEAN_OUTPUT'):
+                                self._vswitch_ctl.dump_vswitch_connections()
 
                     # garbage collection for case that TestSteps modify existing deployment
                     self.step_stop_vnfs()
@@ -413,7 +414,11 @@ class TestCase(object):
                                                             self._testcase_start_time))
         logging.info("Testcase execution time: %s", self._testcase_run_time)
         # report test results
+        if S.getValue('CLEAN_OUTPUT'):
+            print('BEGIN OF THE RESULTS')
         self.run_report()
+        if S.getValue('CLEAN_OUTPUT'):
+            print('END OF THE RESULTS')
 
     def _append_results(self, results):
         """
index ff9d5c7..680497e 100644 (file)
@@ -136,7 +136,15 @@ class Trex(ITrafficGenerator):
         else:
             raise RuntimeError('T-Rex: Trex host not defined')
 
-        ping = subprocess.Popen(cmd_ping, shell=True, stderr=subprocess.PIPE)
+        if settings.getValue('CLEAN_OUTPUT'):
+            ping = subprocess.Popen(cmd_ping,
+                                    shell=True,
+                                    stdout=subprocess.DEVNULL,
+                                    stderr=subprocess.PIPE)
+        else:
+            ping = subprocess.Popen(cmd_ping,
+                                    shell=True,
+                                    stderr=subprocess.PIPE)
         output, error = ping.communicate()
 
         if ping.returncode:
@@ -152,9 +160,16 @@ class Trex(ITrafficGenerator):
                           self._trex_base_dir + "t-rex-64"
 
 
-        find_trex = subprocess.Popen(cmd_find_trex,
-                                     shell=True,
-                                     stderr=subprocess.PIPE)
+        if settings.getValue('CLEAN_OUTPUT'):
+            find_trex = subprocess.Popen(cmd_find_trex,
+                                         shell=True,
+                                         stdout=subprocess.DEVNULL,
+                                         stderr=subprocess.PIPE)
+        else:
+            find_trex = subprocess.Popen(cmd_find_trex,
+                                         shell=True,
+                                         stderr=subprocess.PIPE)
+
         output, error = find_trex.communicate()
 
         if find_trex.returncode:
@@ -165,8 +180,12 @@ class Trex(ITrafficGenerator):
                 % (self._trex_host_ip_addr, self._trex_base_dir))
 
         try:
-            self._stlclient = STLClient(username=self._trex_user, server=self._trex_host_ip_addr,
-                                        verbose_level='info')
+            if settings.getValue('CLEAN_OUTPUT'):
+                self._stlclient = STLClient(username=self._trex_user, server=self._trex_host_ip_addr,
+                                            verbose_level='error')
+            else:
+                self._stlclient = STLClient(username=self._trex_user, server=self._trex_host_ip_addr,
+                                            verbose_level='info')
             self._stlclient.connect()
         except STLError:
             raise RuntimeError('T-Rex: Cannot connect to T-Rex server. Please check if it is '
@@ -392,7 +411,8 @@ class Trex(ITrafficGenerator):
             self._stlclient.set_port_attr(my_ports, promiscuous=True)
 
         packet_1, packet_2 = self.create_packets(traffic, ports_info)
-        self.show_packet_info(packet_1, packet_2)
+        if not settings.getValue('CLEAN_OUTPUT'):
+            self.show_packet_info(packet_1, packet_2)
         stream_1, stream_2, stream_1_lat, stream_2_lat = Trex.create_streams(packet_1, packet_2, traffic)
         self._stlclient.add_streams(stream_1, ports=[0])
         self._stlclient.add_streams(stream_2, ports=[1])
diff --git a/vsperf b/vsperf
index 1fb5242..0bc1937 100755 (executable)
--- a/vsperf
+++ b/vsperf
@@ -747,6 +747,13 @@ def main():
     # if required, handle list-* operations
     handle_list_options(args)
 
+    # Using verbosity to run 'clean' test-runs.
+    if args['verbosity']:
+        settings.setValue('VERBOSITY', args['verbosity'])
+        settings.setValue('CLEAN_OUTPUT', True)
+    else:
+        settings.setValue('CLEAN_OUTPUT', False)
+
     configure_logging(settings.getValue('VERBOSITY'))
 
     # CI build support
index 853bef8..a77e898 100644 (file)
@@ -26,9 +26,9 @@ import pexpect
 
 from conf import settings
 from src.ovs import OFBridge, flow_key, flow_match
-from vswitches.vswitch import IVSwitch
 from tools import tasks
 from tools.module_manager import ModuleManager
+from vswitches.vswitch import IVSwitch
 
 # enable caching of flows if their number exceeds given limit
 _CACHE_FLOWS_LIMIT = 10
@@ -100,6 +100,8 @@ class IVSwitchOvs(IVSwitch, tasks.Process):
 
         try:
             tasks.Process.start(self)
+            if settings.getValue('CLEAN_OUTPUT'):
+                self._disable_console_output()
             self.relinquish()
         except (pexpect.EOF, pexpect.TIMEOUT) as exc:
             self._logger.error("Exception during VSwitch start.")
@@ -469,6 +471,15 @@ class IVSwitchOvs(IVSwitch, tasks.Process):
 
         self._logger.info('System reset after last run.')
 
+    def _disable_console_output(self):
+        """
+        Configure vswitch to disable console output
+        """
+        ovsappctl_tool_bin = settings.getValue('TOOLS')['ovs-appctl']
+        tasks.run_task(['sudo', ovsappctl_tool_bin, 'vlog/set', ' console:off'],
+                       self._logger,
+                       'Turning off the logs ...')
+
     def _start_ovsdb(self):
         """Start ``ovsdb-server`` instance.
 
@@ -483,13 +494,22 @@ class IVSwitchOvs(IVSwitch, tasks.Process):
 
         ovsdb_server_bin = settings.getValue('TOOLS')['ovsdb-server']
 
-        tasks.run_background_task(
-            ['sudo', ovsdb_server_bin,
-             '--remote=punix:%s' % os.path.join(settings.getValue('TOOLS')['ovs_var_tmp'], 'db.sock'),
-             '--remote=db:Open_vSwitch,Open_vSwitch,manager_options',
-             '--pidfile=' + self._ovsdb_pidfile_path, '--overwrite-pidfile'],
-            self._logger,
-            'Starting ovsdb-server...')
+        if settings.getValue('CLEAN_OUTPUT'):
+            tasks.run_background_task(
+                ['sudo', ovsdb_server_bin,
+                 '--remote=punix:%s' % os.path.join(settings.getValue('TOOLS')['ovs_var_tmp'], 'db.sock'),
+                 '--remote=db:Open_vSwitch,Open_vSwitch,manager_options',
+                 '--pidfile=' + self._ovsdb_pidfile_path, '--overwrite-pidfile', '--verbose=off'],
+                self._logger,
+                'Starting ovsdb-server...')
+        else:
+            tasks.run_background_task(
+                ['sudo', ovsdb_server_bin,
+                 '--remote=punix:%s' % os.path.join(settings.getValue('TOOLS')['ovs_var_tmp'], 'db.sock'),
+                 '--remote=db:Open_vSwitch,Open_vSwitch,manager_options',
+                 '--pidfile=' + self._ovsdb_pidfile_path, '--overwrite-pidfile'],
+                self._logger,
+                'Starting ovsdb-server...')
 
     def _kill_ovsdb(self):
         """Kill ``ovsdb-server`` instance.