]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
iptables_manager: Fix get_binary_name for eventlet
authorYAMAMOTO Takashi <yamamoto@valinux.co.jp>
Tue, 9 Sep 2014 03:20:23 +0000 (12:20 +0900)
committerYAMAMOTO Takashi <yamamoto@valinux.co.jp>
Tue, 2 Dec 2014 03:40:03 +0000 (12:40 +0900)
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

neutron/agent/linux/iptables_manager.py
neutron/tests/unit/test_iptables_manager.py

index c9a2b894b0329b994afaefe920ae823045d8d493..11b275d3d75c7a2ae64ed0aa0f0e32cd472dbeda 100644 (file)
@@ -18,9 +18,9 @@
 
 """Implements iptables rules using linux utilities."""
 
-import inspect
 import os
 import re
+import sys
 
 from oslo.config import cfg
 from oslo.utils import excutils
@@ -42,7 +42,7 @@ LOG = logging.getLogger(__name__)
 #             (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()
 
index 54380401d748e74e2a45a6a0a069d02db0b110cf..e96309fec3d6b608fc0406cc39bd8d7f6605b7e1 100644 (file)
@@ -13,8 +13,8 @@
 #    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
@@ -190,8 +190,8 @@ class IptablesManagerStateFulTestCase(base.BaseTestCase):
         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