# About nova-client bug.
The nova-client bug occurred only pythn3.5.0. Other python versions don't relate.
This bug is novaclient version 10.1.0 or more.
I occurred by the version of pip and novaclient.
- python 3.5.0
- pip version 7.1.2
- novaclient 10.1.0
- pip version 10.0.1
- novaclient 10.1.1
[markdown version is here:](https://gist.github.com/hirosetakahito/13c02b9a91e9567cc901098e283f2f72)
## Error Message
When I try to update the quota, this error happened and I got the below error message.
```
Traceback (most recent call last):
File "nova_client_bug_report_script.py", line 37, in <module>
update_quota(sess, '81be1886-cf7b-4b11-9208-e847fe5a9fe9')
File "nova_client_bug_report_script.py", line 29, in update_quota
nova.quotas.update(project_id, instances=90)
File "/home/www/.pyenv/versions/3.5.0/lib/python3.5/site-packages/novaclient/api_versions.py", line 398, in substitution
obj.api_version.get_string(), name)
novaclient.exceptions.VersionNotFoundForAPIMethod: API version '2.1' is not supported on 'novaclient.v2.quotas.[server_group_members=None):].update' method.
```
## executed script
```
# -*- coding: utf-8 -*-
import sys
from novaclient import client as nova_client
from keystoneclient.v3 import client
from keystoneauth1 import session
from keystoneauth1.identity import v3
def get_keystone_session():
params = {
'auth_url': KEYSTONE_ENDPOINT,
'username': USERNAME,
'password': PASSWORD,
'user_domain_name': 'default',
'project_name': PROJECT_NAME,
'project_domain_name': 'default',
}
auth = v3.Password(**params)
sess = session.Session(auth=auth)
return sess
def update_quota(sess, server):
project_id = PROJECT_ID
nova = nova_client.Client('2.1', session=sess)
print(nova.quotas.get(project_id))
nova.quotas.update(project_id, instances=100)
print(nova.quotas.get(project_id))
return 'success'
if __name__ == '__main__':
argvs = sys.argv
sess = get_keystone_session()
update_quota(sess, INSTANCE_ID)
```
## Cause
[api_version.py in line 348.](https://github.com/openstack/python-novaclient/blob/master/novaclient/api_versions.py#L348)
It is due to specifying `-4` at this line. I don't know the reason, but only python3.5.0 is in necessary data at `-5` in the list.(It doesn't matter python3.5.1 or more).
So It can't check the api_version at only python3.5.0.
## Solution
`_name` argument at 348th line need `<module>`. But the case of Python 3.5.0 isn't into `-4` but into `-5`.
This case, `_get_function_name` method can't return the data, because `filename` has incorrect data.
For the solution of this problem, it better is using 'for loops'.
If below patch use, you can become the using `_get_function_name` method by all python versions.
Why reason I do the loop from behind, this calculation amount of loop is less than the loop from the top.(Please read the below the data.)
```
$ cat api_version.patch
--- api_version.py 2018-04-25 13:19:11.999263977 +0900
+++ api_version.py.change 2018-04-25 13:21:52.732243109 +0900
@@ -346,7 +346,11 @@
# ("im_class" property does not exist at that moment)
# we need to write own logic to obtain the full function name which
# include module name, owner name(optional) and just function name.
- filename, _lineno, _name, line = traceback.extract_stack()[-4]
+ traceback_data = traceback.extract_stack()
+ for tl in traceback_list[::-1]:
+ if tl[2] == '<module>':
+ filename, _lineno, _name, line = tl
+ break
module, _file_extension = os.path.splitext(filename)
module = module.replace("/", ".")
if module.endswith(func.__module__):
```
## traceback.extract data of each python versions.
These are getting data of traceback.extract_stack().
### python2.7.14
```
[('nova_script.py', 60, '<module>', "print(get_instance(sess, '81be1886-cf7b-4b11-9208-e847fe5a9fe9'))"), ('nova_script.py', 39, 'get_instance', "nova = nova_client.Client('2.1', session=sess)"), ('/home/www/.pyenv/versions/2.7.14/lib/python2.7/site-packages/novaclient/client.py', 330, 'Client', 'api_version, client_class = _get_client_class_and_version(version)'), ('/home/www/.pyenv/versions/2.7.14/lib/python2.7/site-packages/novaclient/client.py', 224, '_get_client_class_and_version', '"novaclient.v%s.client.Client" % version.ver_major)'), ('/home/www/.pyenv/versions/2.7.14/lib/python2.7/site-packages/oslo_utils/importutils.py', 30, 'import_class', '__import__(mod_str)'),
('/home/www/.pyenv/versions/2.7.14/lib/python2.7/site-packages/novaclient/v2/__init__.py', 16, '<module>', 'from novaclient.v2.client import Client # noqa'),
('/home/www/.pyenv/versions/2.7.14/lib/python2.7/site-packages/novaclient/v2/client.py', 47, '<module>', 'from novaclient.v2 import volumes'),
('/home/www/.pyenv/versions/2.7.14/lib/python2.7/site-packages/novaclient/v2/volumes.py', 36, '<module>', 'class VolumeManager(base.Manager):'),
('/home/www/.pyenv/versions/2.7.14/lib/python2.7/site-packages/novaclient/v2/volumes.py', 60, 'VolumeManager', 'tag=None):'),
('/home/www/.pyenv/versions/2.7.14/lib/python2.7/site-packages/novaclient/api_versions.py', 382, 'decor', 'name = _get_function_name(func)'),
('/home/www/.pyenv/versions/2.7.14/lib/python2.7/site-packages/novaclient/api_versions.py', 350, '_get_function_name', 'print traceback.extract_stack()')]
```
### python3.4.0
```
[('nova_script.py', 60, '<module>', "print(get_instance(sess, '81be1886-cf7b-4b11-9208-e847fe5a9fe9'))"), ('nova_script.py', 39, 'get_instance', "nova = nova_client.Client('2.1', session=sess)"), ('/home/www/.pyenv/versions/3.4.0/lib/python3.4/site-packages/novaclient/client.py', 330, 'Client', 'api_version, client_class = _get_client_class_and_version(version)'), ('/home/www/.pyenv/versions/3.4.0/lib/python3.4/site-packages/novaclient/client.py', 224, '_get_client_class_and_version', '"novaclient.v%s.client.Client" % version.ver_major)'), ('/home/www/.pyenv/versions/3.4.0/lib/python3.4/site-packages/oslo_utils/importutils.py', 30, 'import_class', '__import__(mod_str)'), ('<frozen importlib._bootstrap>', 2214, '_find_and_load', None), ('<frozen importlib._bootstrap>', 2189, '_find_and_load_unlocked', None), ('<frozen importlib._bootstrap>', 321, '_call_with_frames_removed', None), ('<frozen importlib._bootstrap>', 2214, '_find_and_load', None), ('<frozen importlib._bootstrap>', 2203, '_find_and_load_unlocked', None), ('<frozen importlib._bootstrap>', 1200, '_load_unlocked', None), ('<frozen importlib._bootstrap>', 1129, '_exec', None), ('<frozen importlib._bootstrap>', 1448, 'exec_module', None), ('<frozen importlib._bootstrap>', 321, '_call_with_frames_removed', None), ('/home/www/.pyenv/versions/3.4.0/lib/python3.4/site-packages/novaclient/v2/__init__.py', 16, '<module>', 'from novaclient.v2.client import Client # noqa'), ('<frozen importlib._bootstrap>', 2214, '_find_and_load', None), ('<frozen importlib._bootstrap>', 2203, '_find_and_load_unlocked', None), ('<frozen importlib._bootstrap>', 1200, '_load_unlocked', None), ('<frozen importlib._bootstrap>', 1129, '_exec', None), ('<frozen importlib._bootstrap>', 1448, 'exec_module', None), ('<frozen importlib._bootstrap>', 321, '_call_with_frames_removed', None), ('/home/www/.pyenv/versions/3.4.0/lib/python3.4/site-packages/novaclient/v2/client.py', 47, '<module>', 'from novaclient.v2 import volumes'), ('<frozen importlib._bootstrap>', 2261, '_handle_fromlist', None), ('<frozen importlib._bootstrap>', 321, '_call_with_frames_removed', None), ('<frozen importlib._bootstrap>', 2214, '_find_and_load', None), ('<frozen importlib._bootstrap>', 2203, '_find_and_load_unlocked', None), ('<frozen importlib._bootstrap>', 1200, '_load_unlocked', None), ('<frozen importlib._bootstrap>', 1129, '_exec', None), ('<frozen importlib._bootstrap>', 1448, 'exec_module', None), ('<frozen importlib._bootstrap>', 321, '_call_with_frames_removed', None),
('/home/www/.pyenv/versions/3.4.0/lib/python3.4/site-packages/novaclient/v2/volumes.py', 36, '<module>', 'class VolumeManager(base.Manager):'),
('/home/www/.pyenv/versions/3.4.0/lib/python3.4/site-packages/novaclient/v2/volumes.py', 60, 'VolumeManager', 'tag=None):'),
('/home/www/.pyenv/versions/3.4.0/lib/python3.4/site-packages/novaclient/api_versions.py', 382, 'decor', 'name = _get_function_name(func)'),
('/home/www/.pyenv/versions/3.4.0/lib/python3.4/site-packages/novaclient/api_versions.py', 350, '_get_function_name', 'print(traceback.extract_stack())')]
```
### python3.5.0
```
[<FrameSummary file nova_script.py, line 60 in <module>>, <FrameSummary file nova_script.py, line 39 in get_instance>, <FrameSummary file /home/www/.pyenv/versions/3.5.0/lib/python3.5/site-packages/novaclient/client.py, line 330 in Client>, <FrameSummary file /home/www/.pyenv/versions/3.5.0/lib/python3.5/site-packages/novaclient/client.py, line 224 in _get_client_class_and_version>, <FrameSummary file /home/www/.pyenv/versions/3.5.0/lib/python3.5/site-packages/oslo_utils/importutils.py, line 30 in import_class>, <FrameSummary file <frozen importlib._bootstrap>, line 969 in _find_and_load>, <FrameSummary file <frozen importlib._bootstrap>, line 944 in _find_and_load_unlocked>, <FrameSummary file <frozen importlib._bootstrap>, line 222 in _call_with_frames_removed>, <FrameSummary file <frozen importlib._bootstrap>, line 969 in _find_and_load>, <FrameSummary file <frozen importlib._bootstrap>, line 958 in _find_and_load_unlocked>, <FrameSummary file <frozen importlib._bootstrap>, line 673 in _load_unlocked>, <FrameSummary file <frozen importlib._bootstrap_external>, line 662 in exec_module>, <FrameSummary file <frozen importlib._bootstrap>, line 222 in _call_with_frames_removed>, <FrameSummary file /home/www/.pyenv/versions/3.5.0/lib/python3.5/site-packages/novaclient/v2/__init__.py, line 16 in <module>>, <FrameSummary file <frozen importlib._bootstrap>, line 969 in _find_and_load>, <FrameSummary file <frozen importlib._bootstrap>, line 958 in _find_and_load_unlocked>, <FrameSummary file <frozen importlib._bootstrap>, line 673 in _load_unlocked>, <FrameSummary file <frozen importlib._bootstrap_external>, line 662 in exec_module>, <FrameSummary file <frozen importlib._bootstrap>, line 222 in _call_with_frames_removed>, <FrameSummary file /home/www/.pyenv/versions/3.5.0/lib/python3.5/site-packages/novaclient/v2/client.py, line 47 in <module>>, <FrameSummary file <frozen importlib._bootstrap>, line 1016 in _handle_fromlist>, <FrameSummary file <frozen importlib._bootstrap>, line 222 in _call_with_frames_removed>, <FrameSummary file <frozen importlib._bootstrap>, line 969 in _find_and_load>, <FrameSummary file <frozen importlib._bootstrap>, line 958 in _find_and_load_unlocked>, <FrameSummary file <frozen importlib._bootstrap>, line 673 in _load_unlocked>, <FrameSummary file <frozen importlib._bootstrap_external>, line 662 in exec_module>, <FrameSummary file <frozen importlib._bootstrap>, line 222 in _call_with_frames_removed>,
<FrameSummary file /home/www/.pyenv/versions/3.5.0/lib/python3.5/site-packages/novaclient/v2/volumes.py, line 36 in <module>>,
<FrameSummary file /home/www/.pyenv/versions/3.5.0/lib/python3.5/site-packages/novaclient/v2/volumes.py, line 60 in VolumeManager>,
<FrameSummary file /home/www/.pyenv/versions/3.5.0/lib/python3.5/site-packages/novaclient/api_versions.py, line 386 in decor>,
<FrameSummary file /home/www/.pyenv/versions/3.5.0/lib/python3.5/site-packages/novaclient/api_versions.py, line 349 in _get_function_name>,
<FrameSummary file /home/www/.pyenv/versions/3.5.0/lib/python3.5/traceback.py, line 201 in extract_stack>]
```
### python3.5.1
```
[<FrameSummary file nova_script.py, line 60 in <module>>, <FrameSummary file nova_script.py, line 39 in get_instance>, <FrameSummary file /home/www/.pyenv/versions/3.5.1/lib/python3.5/site-packages/novaclient/client.py, line 330 in Client>, <FrameSummary file /home/www/.pyenv/versions/3.5.1/lib/python3.5/site-packages/novaclient/client.py, line 224 in _get_client_class_and_version>, <FrameSummary file /home/www/.pyenv/versions/3.5.1/lib/python3.5/site-packages/oslo_utils/importutils.py, line 30 in import_class>, <FrameSummary file <frozen importlib._bootstrap>, line 969 in _find_and_load>, <FrameSummary file <frozen importlib._bootstrap>, line 944 in _find_and_load_unlocked>, <FrameSummary file <frozen importlib._bootstrap>, line 222 in _call_with_frames_removed>, <FrameSummary file <frozen importlib._bootstrap>, line 969 in _find_and_load>, <FrameSummary file <frozen importlib._bootstrap>, line 958 in _find_and_load_unlocked>, <FrameSummary file <frozen importlib._bootstrap>, line 673 in _load_unlocked>, <FrameSummary file <frozen importlib._bootstrap_external>, line 662 in exec_module>, <FrameSummary file <frozen importlib._bootstrap>, line 222 in _call_with_frames_removed>, <FrameSummary file /home/www/.pyenv/versions/3.5.1/lib/python3.5/site-packages/novaclient/v2/__init__.py, line 16 in <module>>, <FrameSummary file <frozen importlib._bootstrap>, line 969 in _find_and_load>, <FrameSummary file <frozen importlib._bootstrap>, line 958 in _find_and_load_unlocked>, <FrameSummary file <frozen importlib._bootstrap>, line 673 in _load_unlocked>, <FrameSummary file <frozen importlib._bootstrap_external>, line 662 in exec_module>, <FrameSummary file <frozen importlib._bootstrap>, line 222 in _call_with_frames_removed>, <FrameSummary file /home/www/.pyenv/versions/3.5.1/lib/python3.5/site-packages/novaclient/v2/client.py, line 47 in <module>>, <FrameSummary file <frozen importlib._bootstrap>, line 1016 in _handle_fromlist>, <FrameSummary file <frozen importlib._bootstrap>, line 222 in _call_with_frames_removed>, <FrameSummary file <frozen importlib._bootstrap>, line 969 in _find_and_load>, <FrameSummary file <frozen importlib._bootstrap>, line 958 in _find_and_load_unlocked>, <FrameSummary file <frozen importlib._bootstrap>, line 673 in _load_unlocked>, <FrameSummary file <frozen importlib._bootstrap_external>, line 662 in exec_module>,
<FrameSummary file <frozen importlib._bootstrap>, line 222 in _call_with_frames_removed>,
<FrameSummary file /home/www/.pyenv/versions/3.5.1/lib/python3.5/site-packages/novaclient/v2/volumes.py, line 36 in <module>>,
<FrameSummary file /home/www/.pyenv/versions/3.5.1/lib/python3.5/site-packages/novaclient/v2/volumes.py, line 60 in VolumeManager>,
<FrameSummary file /home/www/.pyenv/versions/3.5.1/lib/python3.5/site-packages/novaclient/api_versions.py, line 382 in decor>,
<FrameSummary file /home/www/.pyenv/versions/3.5.1/lib/python3.5/site-packages/novaclient/api_versions.py, line 350 in _get_function_name>]
```
### python3.5.5
```
[<FrameSummary file nova_script.py, line 60 in <module>>, <FrameSummary file nova_script.py, line 39 in get_instance>, <FrameSummary file /home/www/.pyenv/versions/3.5.5/lib/python3.5/site-packages/novaclient/client.py, line 330 in Client>, <FrameSummary file /home/www/.pyenv/versions/3.5.5/lib/python3.5/site-packages/novaclient/client.py, line 224 in _get_client_class_and_version>, <FrameSummary file /home/www/.pyenv/versions/3.5.5/lib/python3.5/site-packages/oslo_utils/importutils.py, line 30 in import_class>, <FrameSummary file <frozen importlib._bootstrap>, line 968 in _find_and_load>, <FrameSummary file <frozen importlib._bootstrap>, line 943 in _find_and_load_unlocked>, <FrameSummary file <frozen importlib._bootstrap>, line 222 in _call_with_frames_removed>, <FrameSummary file <frozen importlib._bootstrap>, line 968 in _find_and_load>, <FrameSummary file <frozen importlib._bootstrap>, line 957 in _find_and_load_unlocked>, <FrameSummary file <frozen importlib._bootstrap>, line 673 in _load_unlocked>, <FrameSummary file <frozen importlib._bootstrap_external>, line 697 in exec_module>, <FrameSummary file <frozen importlib._bootstrap>, line 222 in _call_with_frames_removed>, <FrameSummary file /home/www/.pyenv/versions/3.5.5/lib/python3.5/site-packages/novaclient/v2/__init__.py, line 16 in <module>>, <FrameSummary file <frozen importlib._bootstrap>, line 968 in _find_and_load>, <FrameSummary file <frozen importlib._bootstrap>, line 957 in _find_and_load_unlocked>, <FrameSummary file <frozen importlib._bootstrap>, line 673 in _load_unlocked>, <FrameSummary file <frozen importlib._bootstrap_external>, line 697 in exec_module>, <FrameSummary file <frozen importlib._bootstrap>, line 222 in _call_with_frames_removed>, <FrameSummary file /home/www/.pyenv/versions/3.5.5/lib/python3.5/site-packages/novaclient/v2/client.py, line 47 in <module>>, <FrameSummary file <frozen importlib._bootstrap>, line 1015 in _handle_fromlist>, <FrameSummary file <frozen importlib._bootstrap>, line 222 in _call_with_frames_removed>, <FrameSummary file <frozen importlib._bootstrap>, line 968 in _find_and_load>,
<FrameSummary file <frozen importlib._bootstrap>, line 957 in _find_and_load_unlocked>,
<FrameSummary file <frozen importlib._bootstrap>, line 673 in _load_unlocked>,
<FrameSummary file <frozen importlib._bootstrap_external>, line 697 in exec_module>,
<FrameSummary file <frozen importlib._bootstrap>, line 222 in _call_with_frames_removed>,
<FrameSummary file /home/www/.pyenv/versions/3.5.5/lib/python3.5/site-packages/novaclient/v2/volumes.py, line 36 in <module>>,
<FrameSummary file /home/www/.pyenv/versions/3.5.5/lib/python3.5/site-packages/novaclient/v2/volumes.py, line 60 in VolumeManager>,
<FrameSummary file /home/www/.pyenv/versions/3.5.5/lib/python3.5/site-packages/novaclient/api_versions.py, line 382 in decor>,
<FrameSummary file /home/www/.pyenv/versions/3.5.5/lib/python3.5/site-packages/novaclient/api_versions.py, line 350 in _get_function_name>]
```
### python3.6.4
```
[<FrameSummary file nova_script.py, line 60 in <module>>, <FrameSummary file nova_script.py, line 39 in get_instance>, <FrameSummary file /home/www/.pyenv/versions/3.6.4/lib/python3.6/site-packages/novaclient/client.py, line 330 in Client>, <FrameSummary file /home/www/.pyenv/versions/3.6.4/lib/python3.6/site-packages/novaclient/client.py, line 224 in _get_client_class_and_version>, <FrameSummary file /home/www/.pyenv/versions/3.6.4/lib/python3.6/site-packages/oslo_utils/importutils.py, line 30 in import_class>, <FrameSummary file <frozen importlib._bootstrap>, line 971 in _find_and_load>, <FrameSummary file <frozen importlib._bootstrap>, line 941 in _find_and_load_unlocked>, <FrameSummary file <frozen importlib._bootstrap>, line 219 in _call_with_frames_removed>, <FrameSummary file <frozen importlib._bootstrap>, line 971 in _find_and_load>, <FrameSummary file <frozen importlib._bootstrap>, line 955 in _find_and_load_unlocked>, <FrameSummary file <frozen importlib._bootstrap>, line 665 in _load_unlocked>, <FrameSummary file <frozen importlib._bootstrap_external>, line 678 in exec_module>, <FrameSummary file <frozen importlib._bootstrap>, line 219 in _call_with_frames_removed>, <FrameSummary file /home/www/.pyenv/versions/3.6.4/lib/python3.6/site-packages/novaclient/v2/__init__.py, line 16 in <module>>, <FrameSummary file <frozen importlib._bootstrap>, line 971 in _find_and_load>, <FrameSummary file <frozen importlib._bootstrap>, line 955 in _find_and_load_unlocked>, <FrameSummary file <frozen importlib._bootstrap>, line 665 in _load_unlocked>, <FrameSummary file <frozen importlib._bootstrap_external>, line 678 in exec_module>, <FrameSummary file <frozen importlib._bootstrap>, line 219 in _call_with_frames_removed>, <FrameSummary file /home/www/.pyenv/versions/3.6.4/lib/python3.6/site-packages/novaclient/v2/client.py, line 46 in <module>>, <FrameSummary file <frozen importlib._bootstrap>, line 1023 in _handle_fromlist>, <FrameSummary file <frozen importlib._bootstrap>, line 219 in _call_with_frames_removed>, <FrameSummary file <frozen importlib._bootstrap>, line 971 in _find_and_load>, <FrameSummary file <frozen importlib._bootstrap>, line 955 in _find_and_load_unlocked>, <FrameSummary file <frozen importlib._bootstrap>, line 665 in _load_unlocked>, <FrameSummary file <frozen importlib._bootstrap_external>, line 678 in exec_module>,
<FrameSummary file <frozen importlib._bootstrap>, line 219 in _call_with_frames_removed>,
<FrameSummary file /home/www/.pyenv/versions/3.6.4/lib/python3.6/site-packages/novaclient/v2/volumes.py, line 36 in <module>>,
<FrameSummary file /home/www/.pyenv/versions/3.6.4/lib/python3.6/site-packages/novaclient/v2/volumes.py, line 60 in VolumeManager>,
<FrameSummary file /home/www/.pyenv/versions/3.6.4/lib/python3.6/site-packages/novaclient/api_versions.py, line 382 in decor>,
<FrameSummary file /home/www/.pyenv/versions/3.6.4/lib/python3.6/site-packages/novaclient/api_versions.py, line 350 in _get_function_name>]
```
Thank you for reading my poor English report.
The data log was too long. because data deleted some versions.
And adding the 'cause'