docs: refresh & structure overhaul
[nfvbench.git] / nfvbench / traffic_server.py
index 629cb3d..5111b32 100644 (file)
@@ -34,27 +34,12 @@ class TRexTrafficServer(TrafficServer):
         assert len(contents) == 1
         self.trex_dir = os.path.join(trex_base_dir, contents[0])
 
-    def __apply_trex_patches(self):
-        parent_dir = os.path.dirname(os.path.realpath(__file__))
-        patches_dir = os.path.join(parent_dir, "trex_patches")
-        patches = os.listdir(patches_dir)
-        for patch in patches:
-            patch = os.path.join(patches_dir, patch)
-            command = (
-                "patch --directory=" + self.trex_dir + " --strip=0"
-                " --forward --no-backup-if-mismatch --reject-file=-"
-                " --force --input=" + patch + " >&-")
-            os.system(command)
-
     def run_server(self, generator_config, filename='/etc/trex_cfg.yaml'):
         """Run TRex server for specified traffic profile.
 
         :param traffic_profile: traffic profile object based on config file
         :param filename: path where to save TRex config file
         """
-        # in order to allow for customized behaviors, let's apply some patches
-        # this scheme keeps acceptable since we have only simple modifications
-        self.__apply_trex_patches()
         cfg = self.__save_config(generator_config, filename)
         cores = generator_config.cores
         vtep_vlan = generator_config.gen_config.get('vtep_vlan')
@@ -87,13 +72,13 @@ class TRexTrafficServer(TrafficServer):
                                                                  hdrh_opt,
                                                                  mbuf_opt, cfg)]
         LOG.info(' '.join(cmd))
-        subprocess.Popen(cmd, cwd=self.trex_dir)
-        LOG.info('TRex server is running...')
+        with subprocess.Popen(cmd, cwd=self.trex_dir) as trex_process:
+            LOG.info('TRex server is running (PID: %s)...', trex_process.pid)
 
     def __load_config(self, filename):
         result = {}
         if os.path.exists(filename):
-            with open(filename, 'r') as stream:
+            with open(filename, 'r', encoding="utf-8") as stream:
                 try:
                     result = yaml.safe_load(stream)
                 except yaml.YAMLError as exc:
@@ -105,7 +90,7 @@ class TRexTrafficServer(TrafficServer):
         yaml.safe_load(result)
         if os.path.exists(filename):
             os.remove(filename)
-        with open(filename, 'w') as f:
+        with open(filename, 'w', encoding="utf-8") as f:
             f.write(result)
         return filename