[functional]Fix remaining greenlet leaks

We leak due to running background operations like server create, rebuild
and in one case a sleeping claim. So this patch removes the leaks by
making sure that the background operations stop before the test
finishes.

As there is no more leak in functional test too this patch makes the
leak an error there too.

Change-Id: I6905999050e8d09b772837034a212c534e9c3226
This commit is contained in:
Balazs Gibizer
2023-08-25 16:15:29 +02:00
parent 0ae1802db6
commit bc58c1d2fb
4 changed files with 19 additions and 5 deletions

View File

@@ -10,9 +10,11 @@
# License for the specific language governing permissions and limitations
# under the License.
import threading
import time
from unittest import mock
from nova import context as nova_context
from nova import objects
from nova.tests.functional import integrated_helpers
@@ -151,8 +153,10 @@ class TestComputeRestartInstanceStuckInBuild(
image_uuid='155d900f-4e14-4e4c-a73d-069cbf4541e6',
networks='none')
stop = threading.Event()
def sleep_forever(*args, **kwargs):
time.sleep(1000000)
stop.wait(1000000)
with mock.patch('nova.compute.resource_tracker.ResourceTracker.'
'instance_claim') as mock_instance_claim:
@@ -176,3 +180,5 @@ class TestComputeRestartInstanceStuckInBuild(
'Instance spawn was interrupted before instance_claim, setting '
'instance to ERROR state',
instance=mock.ANY)
stop.set()

View File

@@ -80,3 +80,4 @@ class LegacyV2CompatibleTestBase(integrated_helpers._IntegratedTestBase):
'x' * 300: 'y',
'h' * 300: 'i'})
self.assertEqual(exc.response.status_code, 400)
self.api.delete_server(created_server['id'])

View File

@@ -1086,7 +1086,8 @@ class ServersTestV219(integrated_helpers._IntegratedTestBase):
# Update and rebuild servers with invalid descriptions.
# These throw 400.
server_id = self._create_server(True, "desc")[1]['id']
server = self._create_server(True, "desc")[1]
server_id = server['id']
# Invalid unicode with non-printable control char
self._update_assertRaisesRegex(server_id, u'invalid\u0604string')
self._rebuild_assertRaisesRegex(server_id, u'invalid\u0604string')
@@ -1094,6 +1095,8 @@ class ServersTestV219(integrated_helpers._IntegratedTestBase):
self._update_assertRaisesRegex(server_id, 'x' * 256)
self._rebuild_assertRaisesRegex(server_id, 'x' * 256)
self._delete_server(server)
class ServerTestV220(integrated_helpers._IntegratedTestBase):
api_major_version = 'v2.1'

10
tox.ini
View File

@@ -36,9 +36,8 @@ passenv =
# greenlet leaks will be annotated in the test details but will not cause a
# failure. if you want to make them raise set
# NOVA_RAISE_ON_GREENLET_LEAK=1|true|yes
# All simiple leaks of green threads have been resolved the remaining 7
# functional test failures where greenlet leaks happen are non trivial
# to address as there is no obvious cause so they are ignored for now.
# All leaks of green threads have been resolved in the unit and functional
# suite
NOVA_RAISE_ON_GREENLET_LEAK
# NOTE(sean-k-mooney) optimization is enabled by default and when enabled
# asserts are complied out. Disable optimization to allow asserts in
@@ -62,6 +61,11 @@ setenv =
[testenv:functional{,-py38,-py39,-py310,-py311}]
description =
Run functional tests.
setenv =
{[testenv]setenv}
# we do not have any greenlet leaks in functional tests so enforce that
# by making greenlet leaks a failure.
NOVA_RAISE_ON_GREENLET_LEAK=True
# As nova functional tests import the PlacementFixture from the placement
# repository these tests are, by default, set up to run with openstack-placement
# from pypi. In the gate, Zuul will use the installed version of placement (stable