The inspect trick used by get_binary_name does not work for
eventlet non-main threads. It's actually the case for ofagent
and in that case it yields something like "greenthread.py",
which is not desirable because this module assumes it different
for each programs. This commit fixes the problem by switching
to use sys.argv.
Closes-Bug: #
1367075
Change-Id: I8e765882c58d9991a37f0bbb52cdccc406e287bd
"""Implements iptables rules using linux utilities."""
-import inspect
import os
import re
+import sys
from oslo.config import cfg
from oslo.utils import excutils
# (max_chain_name_length - len('-POSTROUTING') == 16)
def get_binary_name():
"""Grab the name of the binary we're running in."""
- return os.path.basename(inspect.stack()[-1][1])[:16]
+ return os.path.basename(sys.argv[0])[:16]
binary_name = get_binary_name()
# See the License for the specific language governing permissions and
# limitations under the License.
-import inspect
import os
+import sys
import mock
from oslo.config import cfg
self.execute = mock.patch.object(self.iptables, "execute").start()
def test_binary_name(self):
- self.assertEqual(iptables_manager.binary_name,
- os.path.basename(inspect.stack()[-1][1])[:16])
+ expected = os.path.basename(sys.argv[0])[:16]
+ self.assertEqual(expected, iptables_manager.binary_name)
def test_get_chain_name(self):
name = '0123456789' * 5