From 9a7845f6d160748abd5b11ee97f327c904d40c87 Mon Sep 17 00:00:00 2001 From: junboli Date: Tue, 10 Oct 2017 16:57:03 +0800 Subject: [PATCH] Make 'utils.monkey_patch' py3 compatible 'utils.monkey_patch' function uses py2-specific thing - 'inspect.ismethod' for getting list of class method members. But the concept of 'unbound methods' has been removed from the python 3.x and 'methods' now are the same type as standalone functions. So, add such distinguish to 'utils.monkey_patch' function to make it py 2/3 compatible. Change-Id: Iff9ae135486eb82f0873c3cf0f59b92bea4b169d Closes-bug: #1722485 --- contrib/nova-docker/nova/virt/zun/client.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/contrib/nova-docker/nova/virt/zun/client.py b/contrib/nova-docker/nova/virt/zun/client.py index fcca1cd23..9cfc4a328 100644 --- a/contrib/nova-docker/nova/virt/zun/client.py +++ b/contrib/nova-docker/nova/virt/zun/client.py @@ -76,7 +76,14 @@ class DockerHTTPClient(docker.APIClient): self._setup_decorators() def _setup_decorators(self): - for name, member in inspect.getmembers(self, inspect.ismethod): + # NOTE(junbo.li): we need to distinguish class methods types + # for py2 and py3, because the concept of 'unbound methods' has + # been removed from the python3.x + if six.PY3: + member_type = inspect.isfunction + else: + member_type = inspect.ismethod + for name, member in inspect.getmembers(self, member_type): if not name.startswith('_'): setattr(self, name, filter_data(member))