provisioning: Support older python for tests
authorPhilippe Coval <philippe.coval@osg.samsung.com>
Mon, 10 Jul 2017 10:14:56 +0000 (12:14 +0200)
committerPhil Coval <philippe.coval@osg.samsung.com>
Wed, 23 Aug 2017 11:54:33 +0000 (11:54 +0000)
Call psutil's process name() function if present,
then just access the name property.

It was observed on psutil 1.2.1 (Ubuntu 14.04.5)

  grep __version__ /usr/lib/python2.7/dist-packages/psutil/__init__.py
  __version__ = "1.2.1"

  scons TEST=1 resource/csdk/security/provisioning/
  scons: *** [out/linux/x86_64/release/resource/csdk/security/provisioning/unittest/start] TypeError : 'str' object is not callable
  Traceback (most recent call last):
  File "/usr/lib/scons/SCons/Action.py", line 1062, in execute
  result = self.execfunction(target=target, source=rsources, env=env)
  File ".../resource/csdk/security/provisioning/unittest/SConscript", line 125, in run_test
  kill_all()
  File ".../resource/csdk/security/provisioning/unittest/SConscript", line 118, in kill_all
  if proc.name() == server_bin:
  TypeError: 'str' object is not callable
  scons: building terminated because of errors.

Bug: https://jira.iotivity.org/browse/IOT-1745
Change-Id: I0a9376bb007c49b9b980ed8798ff8a93882015d7
Signed-off-by: Philippe Coval <philippe.coval@osg.samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/21337
Reviewed-by: Mats Wichmann <mats@linux.com>
Reviewed-by: Dan Mihai <Daniel.Mihai@microsoft.com>
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: George Nash <george.nash@intel.com>
(cherry picked from commit ecccbb8206c0498008d023b73497675d2c31d38f)

resource/csdk/security/provisioning/unittest/SConscript

index 2e2279a..f51bdf7 100644 (file)
@@ -115,7 +115,12 @@ def kill_all():
         try:
             from psutil import process_iter
             for proc in process_iter():
-                if proc.name() == server_bin:
+                name = None
+                if callable(getattr(proc, 'name')):
+                    name = proc.name()
+                else:
+                    name = proc.name
+                if name == server_bin:
                     proc.kill()
         except ImportError:
             print "can not process check"