vhost_affin_fixup: Change vhost thread from regex to pgrep usage 07/20107/1
authorChristian Trautman <ctrautma@redhat.com>
Thu, 1 Sep 2016 06:44:35 +0000 (02:44 -0400)
committerChristian Trautman <ctrautma@redhat.com>
Thu, 1 Sep 2016 06:44:35 +0000 (02:44 -0400)
Change vhost affinity process lookup to use pgrep instead of
ugly error prone regex method as suggested.

Change-Id: I8cac00a7f2d26ba1ce1815535a198f578159222c
Signed-off-by: Christian Trautman <ctrautma@redhat.com>
vnfs/qemu/qemu.py

index dd9ad81..2093cb3 100644 (file)
@@ -247,14 +247,13 @@ class IVnfQemu(IVnf):
         :return: None
         """
         self._logger.info('Affinitizing VHOST Net threads.')
-        args1 = ['ps', 'ax']
+        args1 = ['pgrep', 'vhost-']
         process1 = subprocess.Popen(args1, stdout=subprocess.PIPE,
                                     shell=False)
         out = process1.communicate()[0]
-        processes = list()
-        for line in out.decode(locale.getdefaultlocale()[1]).split('\n'):
-            if re.search('\[vhost-(\d+)', line):
-                processes.append(re.match('\s*(\d+)', line).group(1))
+        processes = out.decode(locale.getdefaultlocale()[1]).split('\n')
+        if processes[-1] == '':
+            processes.pop() # pgrep may return an extra line with no data
         self._logger.info('Found %s vhost net threads...', len(processes))
 
         cpumap = S.getValue('VSWITCH_VHOST_CPU_MAP')