diff options
author | Suraj Deshmukh <surajssd009005@gmail.com> | 2015-10-31 18:37:45 +0530 |
---|---|---|
committer | Suraj Deshmukh <surajssd009005@gmail.com> | 2015-11-10 23:50:17 +0530 |
commit | e77d38ca3330f09a1aa65027c17816eefe7ef7df (patch) | |
tree | 36c249d03a3289b0706bbeb29d92fd92a3f4c6ac /oslo_utils/tests/test_netutils.py | |
parent | 7da2a5ba647cb2b222be0682d0c0ec707fbda131 (diff) | |
download | oslo-utils-e77d38ca3330f09a1aa65027c17816eefe7ef7df.tar.gz |
Added ICMP 'type' and 'code' checking capability to 'netutils' module
ICMP has 'type' and 'code' fields which are used while adding a security
group rule using Horizon. I have written functions in 'netutils' module
which validate ICMP 'type' and 'code' fields.
Change-Id: Ie1a67ea1afd69d5de4326f9e9a7243362b912582
Closes-Bug: #1511940
Diffstat (limited to 'oslo_utils/tests/test_netutils.py')
-rw-r--r-- | oslo_utils/tests/test_netutils.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/oslo_utils/tests/test_netutils.py b/oslo_utils/tests/test_netutils.py index afec104..06a930d 100644 --- a/oslo_utils/tests/test_netutils.py +++ b/oslo_utils/tests/test_netutils.py @@ -199,6 +199,44 @@ class NetworkUtilsTest(test_base.BaseTestCase): addr = netutils.get_my_ipv4() self.assertEqual(addr, '1.2.3.4') + def test_is_int_in_range(self): + valid_inputs = [(1, -100, 100), + ('1', -100, 100), + (100, -100, 100), + ('100', -100, 100), + (-100, -100, 100), + ('-100', -100, 100)] + for input_value in valid_inputs: + self.assertTrue(netutils._is_int_in_range(*input_value)) + + def test_is_int_not_in_range(self): + invalid_inputs = [(None, 1, 100), + ('ten', 1, 100), + (-1, 0, 255), + ('None', 1, 100)] + for input_value in invalid_inputs: + self.assertFalse(netutils._is_int_in_range(*input_value)) + + def test_valid_icmp_type(self): + valid_inputs = [1, '1', 0, '0', 255, '255'] + for input_value in valid_inputs: + self.assertTrue(netutils.is_valid_icmp_type(input_value)) + + def test_invalid_icmp_type(self): + invalid_inputs = [-1, '-1', 256, '256', None, 'None', 'five'] + for input_value in invalid_inputs: + self.assertFalse(netutils.is_valid_icmp_type(input_value)) + + def test_valid_icmp_code(self): + valid_inputs = [1, '1', 0, '0', 255, '255', None] + for input_value in valid_inputs: + self.assertTrue(netutils.is_valid_icmp_code(input_value)) + + def test_invalid_icmp_code(self): + invalid_inputs = [-1, '-1', 256, '256', 'None', 'zero'] + for input_value in invalid_inputs: + self.assertFalse(netutils.is_valid_icmp_code(input_value)) + @mock.patch('socket.socket') @mock.patch('oslo_utils.netutils._get_my_ipv4_address') def test_get_my_ip_socket_error(self, ip, mock_socket): |