Unittest test_distributed_port_binding_deleted_by_port_deletion fails: DeprecationWarning('ssl.PROTOCOL_TLS is deprecated')

Bug #1998343 reported by Anton Kurbatov
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
neutron
Fix Released
Critical
Anton Kurbatov

Bug Description

I got an error in the test_distributed_port_binding_deleted_by_port_deletion test on my CI run [1].
Also I found the same failure in another CI run [2]

FAIL: neutron.tests.unit.plugins.ml2.test_db.Ml2DvrDBTestCase.test_distributed_port_binding_deleted_by_port_deletion
tags: worker-0
----------------------------------------------------------------------
stderr: {{{
/home/zuul/src/opendev.org/openstack/neutron/.tox/shared/lib/python3.10/site-packages/ovs/stream.py:794: DeprecationWarning: ssl.PROTOCOL_TLS is deprecated
  ctx = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
/home/zuul/src/opendev.org/openstack/neutron/.tox/shared/lib/python3.10/site-packages/ovs/stream.py:794: DeprecationWarning: ssl.PROTOCOL_TLS is deprecated
  ctx = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
}}}

Traceback (most recent call last):
  File "/home/zuul/src/opendev.org/openstack/neutron/neutron/tests/base.py", line 182, in func
    return f(self, *args, **kwargs)
  File "/home/zuul/src/opendev.org/openstack/neutron/neutron/tests/unit/plugins/ml2/test_db.py", line 535, in test_distributed_port_binding_deleted_by_port_deletion
    self.assertEqual(
  File "/home/zuul/src/opendev.org/openstack/neutron/.tox/shared/lib/python3.10/site-packages/testtools/testcase.py", line 393, in assertEqual
    self.assertThat(observed, matcher, message)
  File "/home/zuul/src/opendev.org/openstack/neutron/.tox/shared/lib/python3.10/site-packages/testtools/testcase.py", line 480, in assertThat
    raise mismatch_error
testtools.matchers._impl.MismatchError: [] != [<warnings.WarningMessage object at 0x7f65a6cdd3c0>]: Warnings: {message : DeprecationWarning('ssl.PROTOCOL_TLS is deprecated'), category : 'DeprecationWarning', filename : '/home/zuul/src/opendev.org/openstack/neutron/.tox/shared/lib/python3.10/site-packages/ovs/stream.py', lineno : 794, line : None}

I have spent some time and seem to have found the reason for this behavior on python 3.10.
First of all, since python3.10 we get a warning when using ssl.PROTOCOL_TLS [3]:

[root@node0 neutron]# python
Python 3.10.8+ (heads/3.10-dirty:ca3c480, Nov 30 2022, 12:16:40) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ssl
>>> ssl.SSLContext(ssl.PROTOCOL_SSLv23)
<stdin>:1: DeprecationWarning: ssl.PROTOCOL_TLS is deprecated
<ssl.SSLContext object at 0x7f98620223c0>
>>>

I also found that the `test_ssl_connection` test case affects catching warnings in the test_distributed_port_binding_deleted_by_port_deletion test case.
I was then able to reproduce the issue like this:

[root@node0 neutron]# cat run_list.txt
neutron.tests.unit.agent.ovsdb.native.test_connection.ConfigureSslConnTestCase.test_ssl_connection
neutron.tests.unit.plugins.ml2.test_db.Ml2DvrDBTestCase.test_distributed_port_binding_deleted_by_port_deletion
[root@node0 neutron]# git diff
diff --git a/neutron/tests/unit/plugins/ml2/test_db.py b/neutron/tests/unit/plugins/ml2/test_db.py
index 578a01a..d837871 100644
--- a/neutron/tests/unit/plugins/ml2/test_db.py
+++ b/neutron/tests/unit/plugins/ml2/test_db.py
@@ -531,6 +531,8 @@ class Ml2DvrDBTestCase(testlib_api.SqlTestCase):
             router_id='router_id',
             status=constants.PORT_STATUS_DOWN).create()
         with warnings.catch_warnings(record=True) as warning_list:
+ import time
+ time.sleep(0.1)
             port.delete()
             self.assertEqual(
                 [], warning_list,
[root@node0 neutron]# source .tox/shared/bin/activate
(shared) [root@node0 neutron]# stestr run --concurrency=1 --load-list ./run_list.txt
...
neutron.tests.unit.plugins.ml2.test_db.Ml2DvrDBTestCase.test_distributed_port_binding_deleted_by_port_deletion
--------------------------------------------------------------------------------------------------------------
Captured traceback:
~~~~~~~~~~~~~~~~~~~
    Traceback (most recent call last):
      File "/root/github/neutron/neutron/tests/base.py", line 182, in func
    return f(self, *args, **kwargs)
      File "/root/github/neutron/neutron/tests/unit/plugins/ml2/test_db.py", line 537, in test_distributed_port_binding_deleted_by_port_deletion
    self.assertEqual(
      File "/root/github/neutron/.tox/shared/lib/python3.10/site-packages/testtools/testcase.py", line 393, in assertEqual
    self.assertThat(observed, matcher, message)
      File "/root/github/neutron/.tox/shared/lib/python3.10/site-packages/testtools/testcase.py", line 480, in assertThat
    raise mismatch_error
    testtools.matchers._impl.MismatchError: [] != [<warnings.WarningMessage object at 0x7f701cb5f640>]: Warnings: {message : DeprecationWarning('ssl.PROTOCOL_TLS is deprecated'), category : 'DeprecationWarning', filename : '/root/github/neutron/.tox/shared/lib/python3.10/site-packages/ovs/stream.py', lineno : 794, line : None}

======
Totals
======
Ran: 2 tests in 1.3571 sec.
 - Passed: 1
 - Skipped: 0
 - Expected Fail: 0
 - Unexpected Success: 0
 - Failed: 1
Sum of execute time for each test: 1.3053 sec.

[1] https://zuul.opendev.org/t/openstack/build/8e0dd6e817394911aa0baffe07798b13
[2] https://zuul.opendev.org/t/openstack/build/9f7881818f7842b38d31ed44ffa8a4f3
[3] https://github.com/python/cpython/blob/3.10/Modules/_ssl.c#L3038

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to neutron (master)

Fix proposed to branch: master
Review: https://review.opendev.org/c/openstack/neutron/+/866178

Changed in neutron:
status: New → In Progress
Changed in neutron:
assignee: nobody → Anton Kurbatov (akurbatov)
tags: added: gate-failure unittest
Changed in neutron:
importance: Undecided → Critical
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to neutron (master)

Reviewed: https://review.opendev.org/c/openstack/neutron/+/866178
Committed: https://opendev.org/openstack/neutron/commit/26c55efe34f317409e4277154bac4617db0d57cc
Submitter: "Zuul (22348)"
Branch: master

commit 26c55efe34f317409e4277154bac4617db0d57cc
Author: Anton Kurbatov <email address hidden>
Date: Wed Nov 30 15:04:34 2022 +0000

    Do not emit ssl warnings in the test_ssl_connection test

    Since python3.10 we get a warning inside the ovs.stream module:

    Warnings: {message : DeprecationWarning('ssl.PROTOCOL_TLS is
    deprecated'), category : 'DeprecationWarning', filename :
    'python3.10/site-packages/ovs/stream.py', lineno : 794, line : None}

    or using python console:

    >>> ssl.SSLContext(ssl.PROTOCOL_SSLv23)
    <stdin>:1: DeprecationWarning: ssl.PROTOCOL_TLS is deprecated
    <ssl.SSLContext object at 0x7f98620223c0>
    >>>

    This patch mocks the 'Connection.run' method that emits this warning
    inside a thread. This patch also fixes a failure in the
    test_distributed_port_binding_deleted_by_port_deletion test that was
    catching the ssl warning from test_ssl_connection and therefore
    failing.

    Closes-Bug: #1998343
    Signed-off-by: Anton Kurbatov <email address hidden>
    Change-Id: I6a4b9222a63a0d0271069eb12d0c97dd3821a2cc

Changed in neutron:
status: In Progress → Fix Released
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix included in openstack/neutron 22.0.0.0rc1

This issue was fixed in the openstack/neutron 22.0.0.0rc1 release candidate.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.