python-psutil compatibility patch
According to [1] there have been backwards incompatible changes in psutil module. This patch makes amqp oscheck be compatible with all versions of the module. [1] https://pyup.io/changelogs/psutil/ Change-Id: I7af6c25d58b327011013bdea990ccf7ea2f3002e
This commit is contained in:
parent
62160d1068
commit
01e2d34a58
|
@ -52,13 +52,22 @@ def ok(msg):
|
|||
|
||||
|
||||
def check_process_name(name, p):
|
||||
if p.name == name:
|
||||
try:
|
||||
len(p.cmdline)
|
||||
except TypeError:
|
||||
pname = p.name()
|
||||
pcmdline = p.cmdline()
|
||||
else:
|
||||
pname = p.name
|
||||
pcmdline = p.cmdline
|
||||
|
||||
if pname == name:
|
||||
return True
|
||||
# name can be truncated and a script so check also if it can be an
|
||||
# argument to an interpreter
|
||||
if len(p.cmdline) > 0 and os.path.basename(p.cmdline[0]) == name:
|
||||
if len(pcmdline) > 0 and os.path.basename(pcmdline[0]) == name:
|
||||
return True
|
||||
if len(p.cmdline) > 1 and os.path.basename(p.cmdline[1]) == name:
|
||||
if len(pcmdline) > 1 and os.path.basename(pcmdline[1]) == name:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
@ -70,13 +79,14 @@ def check_process_exists_and_amqp_connected(name):
|
|||
critical("%s is not running" % name)
|
||||
for p in processes:
|
||||
try:
|
||||
connections = p.get_connections(kind='inet')
|
||||
conn_func = getattr(p, 'get_connections', p.connections)
|
||||
connections = conn_func(kind='inet')
|
||||
except psutil.NoSuchProcess:
|
||||
continue
|
||||
found_amqp = (
|
||||
len(list(itertools.takewhile(lambda c:
|
||||
len(c.remote_address) <= 1 or
|
||||
c.remote_address[1] != AMQP_PORT,
|
||||
len(getattr(c, 'remote_address', c.raddr)) <= 1 or
|
||||
getattr(c, 'remote_address', c.raddr)[1] != AMQP_PORT,
|
||||
connections))) != len(connections))
|
||||
if found_amqp:
|
||||
ok("%s is working." % name)
|
||||
|
|
Loading…
Reference in New Issue