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
# (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()
'# 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):