]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
get_binary_name should returns strings without spaces
authorCedric Brandily <zzelle@gmail.com>
Fri, 19 Dec 2014 14:05:53 +0000 (15:05 +0100)
committerCedric Brandily <zzelle@gmail.com>
Tue, 23 Dec 2014 18:50:08 +0000 (18:50 +0000)
Iptables does not support chain names with spaces. It implies
get_binary_name should return strings without spaces (they are used as
chain name prefix). But currently 'python -m unittest $module' implies
spaces in get_binary_name() result, it disallows to use it when $module
is a functional test module. This change replaces spaces with
underscores in get_binary_name results.

Change-Id: Ie7c8518b92be46a4eea4e9345713fdeba844126d
Closes-Bug: #1404250

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

index 11b275d3d75c7a2ae64ed0aa0f0e32cd472dbeda..4b2988ceec9800675cf99c7f7cc249410bc64b0c 100644 (file)
@@ -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(sys.argv[0])[:16]
+    return os.path.basename(sys.argv[0])[:16].replace(' ', '_')
 
 binary_name = get_binary_name()
 
index e96309fec3d6b608fc0406cc39bd8d7f6605b7e1..2991fbf082ae8ab64e63000bbdb14df70c605ba9 100644 (file)
@@ -84,6 +84,15 @@ COMMENTED_NAT_DUMP = (
     '# Completed by iptables_manager\n' % IPTABLES_ARG)
 
 
+class IptablesTestCase(base.BaseTestCase):
+
+    def test_get_binary_name_in_unittest(self):
+        # Corresponds to sys.argv content when running python -m unittest class
+        with mock.patch('sys.argv', ['python -m unittest', 'class']):
+            binary_name = iptables_manager.get_binary_name()
+            self.assertEqual('python_-m_unitte', binary_name)
+
+
 class IptablesCommentsTestCase(base.BaseTestCase):
 
     def setUp(self):