If a session object is not provided to keystoneauth1.session.Session, the session that is created ends up not being properly closed. This leads to a ResourceWarning about an unclosed socket:
sys:1: ResourceWarning: unclosed <ssl.SSLSocket fd=3, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6, laddr=('192.168.24.2', 51102), raddr=('192.168.24.2', 13000)>
$ cat keystoneauth.py
#!/usr/bin/python3 -Wd
import keystoneauth1.identity.generic as auth_plugin
from keystoneauth1 import session as ks_session
auth = auth_plugin.Token(
auth_url='https://192.168.24.2:13000',
project_domain_id='default',
project_domain_name='Default',
project_id='d25c0720341c499f981d4ddbcd2b6354',
project_name='admin',
token='<my magical token>'
)
session = ks_session.Session(auth=auth, verify=False)
print(session.get_endpoint(service_type='network', endpoint_type='public', region_name='regionOne'))
This results in:
$ ./keystoneauth.py
/usr/lib64/python3.6/importlib/_bootstrap_external.py:426: ImportWarning: Not importing directory /usr/lib/python3.6/site-packages/repoze: missing __init__
_warnings.warn(msg.format(portions[0]), ImportWarning)
/usr/lib64/python3.6/importlib/_bootstrap_external.py:426: ImportWarning: Not importing directory /usr/lib/python3.6/site-packages/paste: missing __init__
_warnings.warn(msg.format(portions[0]), ImportWarning)
/usr/lib/python3.6/site-packages/pytz/__init__.py:499: ResourceWarning: unclosed file <_io.TextIOWrapper name='/usr/share/zoneinfo/zone.tab' mode='r' encoding='UTF-8'>
for l in open(os.path.join(_tzinfo_dir, 'zone.tab'))
/usr/lib/python3.6/site-packages/eventlet/patcher.py:1: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
import imp
/usr/lib/python3.6/site-packages/urllib3/connectionpool.py:857: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
InsecureRequestWarning)
https://192.168.24.2:13696
sys:1: ResourceWarning: unclosed <ssl.SSLSocket fd=3, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6, laddr=('192.168.24.2', 51102), raddr=('192.168.24.2', 13000)>
This can be mitigated by properly cleaning up the created requests.Session when the keystoneauth1.session.Session is destroyed
Fix proposed to branch: master /review. opendev. org/674139
Review: https:/