Skip to content

Commit 6f35e4f

Browse files
committed
Test for disabling greendns
In commit 7c1d964 we fixed how we disable greendns. This patch adds a test for this. It also lays down the groundwork for future tests of how we manage eventlet's monkeypatching. How and what eventlet monkeypatches can be controlled by environment variables that are processed by eventlet at import-time (for exmaple, EVENTLET_NO_GREENDNS). Nova manages all of this in nova.monkey_patch. Therefore, nova.monkey_patch must be the first thing to import eventlet. As nova.tests.functional.__init__ imports nova.monkey_patch, our new test can go in the functional tree. Related-bug: 1895322 Change-Id: I5b6c45b7b9a9eca3c13ecfaa5f50942922b69270
1 parent b5330a9 commit 6f35e4f

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Copyright 2020 Red Hat, Inc. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
4+
# not use this file except in compliance with the License. You may obtain
5+
# a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12+
# License for the specific language governing permissions and limitations
13+
# under the License.
14+
15+
# NOTE(artom) This file exists to test eventlet monkeypatching. How and what
16+
# eventlet monkeypatches can be controlled by environment variables that
17+
# are processed by eventlet at import-time (for exmaple, EVENTLET_NO_GREENDNS).
18+
# Nova manages all of this in nova.monkey_patch. Therefore, nova.monkey_patch
19+
# must be the first thing to import eventlet. As nova.tests.functional.__init__
20+
# imports nova.monkey_patch, we're OK here.
21+
22+
import socket
23+
import traceback
24+
25+
from nova import test
26+
27+
28+
class TestMonkeyPatch(test.TestCase):
29+
30+
def test_greendns_is_disabled(self):
31+
"""Try to resolve a fake fqdn. If we see greendns mentioned in the
32+
traceback of the raised exception, it means we've not actually disabled
33+
greendns. See the TODO and NOTE in nova.monkey_patch to understand why
34+
greendns needs to be disabled.
35+
"""
36+
raised = False
37+
try:
38+
socket.gethostbyname('goat.fake')
39+
except Exception:
40+
tb = traceback.format_exc()
41+
# NOTE(artom) If we've correctly disabled greendns, we expect the
42+
# traceback to not contain any reference to it.
43+
self.assertNotIn('greendns.py', tb)
44+
raised = True
45+
self.assertTrue(raised)

0 commit comments

Comments
 (0)