|
| 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