neutron/neutron/tests/functional/agent/linux/bin/ipt_binname.py
Rodolfo Alonso Hernandez bc99e56515 Import "oslo_config.cfg" before "eventlet"
Eventlet will patch the "os" library and how it works.

If "oslo_config.cfg" is called after "eventlet":
- "oslo_config.cfg" imports "stevedore"
- "stevedore" imports "importlib_metadata"
- this library will try to use "os.open" library, but patched
- "eventlet" imports "oslo_service"
- "oslo_service" imports "oslo_logging"
- "oslo_logging" imports "oslo_config.cfg", but at this point,
  the instance cfg.CONF does not exist yet

If "oslo_config.cfg" is imported before calling eventlet,
"oslo_logging" is not called and there is no circular import.

Closes-Bug: #1888213

[1]I8b08f289d446f4775eac1e1a91997fa96f25f641

Change-Id: Idcc04f46b2a01e24dfd56cef8121694439e0339e
2020-07-20 15:55:46 +00:00

41 lines
1.2 KiB
Python
Executable File

#! /usr/bin/env python
# Copyright (C) 2014 VA Linux Systems Japan K.K.
# Copyright (C) 2014 YAMAMOTO Takashi <yamamoto at valinux co jp>
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import sys
from oslo_config import cfg # noqa
def print_binary_name():
# NOTE(yamamoto): Don't move this import to module-level.
# The aim is to test importing from eventlet non-main thread.
# See Bug #1367075 for details.
from neutron.agent.linux import iptables_manager
print(iptables_manager.binary_name)
if __name__ == "__main__":
import eventlet
if 'spawn' in sys.argv:
eventlet.spawn(print_binary_name).wait()
else:
print_binary_name()