From 94817a5a5d5c044d4266583a1e9503aaa5f780b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C5=82awek=20Kap=C5=82o=C5=84ski?= Date: Mon, 26 Mar 2018 16:08:51 +0200 Subject: [PATCH] [Functional] Add test for ip_lib.IPRule lifecycle This patch adds functional test for basic create/list/delete of routing policy rules. Change-Id: I3a9447bb89642269c370ea6dbf8bf9166bde2ca1 --- .../functional/agent/linux/test_ip_lib.py | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/neutron/tests/functional/agent/linux/test_ip_lib.py b/neutron/tests/functional/agent/linux/test_ip_lib.py index c8aa749b262..5e7ed35b23d 100644 --- a/neutron/tests/functional/agent/linux/test_ip_lib.py +++ b/neutron/tests/functional/agent/linux/test_ip_lib.py @@ -91,6 +91,89 @@ class IpLibTestFramework(functional_base.BaseSudoTestCase): class IpLibTestCase(IpLibTestFramework): + + def test_rules_lifecycle(self): + PRIORITY = 32768 + TABLE = 16 + attr = self.generate_device_details() + device = self.manage_device(attr) + + test_cases = { + constants.IP_VERSION_4: [ + { + 'ip': '1.1.1.1', + 'to': '8.8.8.0/24' + }, + { + 'ip': '1.1.1.1', + 'iif': device.name, + 'to': '7.7.7.0/24' + } + ], + constants.IP_VERSION_6: [ + { + 'ip': 'abcd::1', + 'to': '1234::/64' + }, + { + 'ip': 'abcd::1', + 'iif': device.name, + 'to': '4567::/64' + } + ] + } + expected_rules = { + constants.IP_VERSION_4: [ + { + 'from': '1.1.1.1', + 'to': '8.8.8.0/24', + 'priority': str(PRIORITY), + 'table': str(TABLE), + 'type': 'unicast' + }, { + 'from': '0.0.0.0/0', + 'to': '7.7.7.0/24', + 'iif': device.name, + 'priority': str(PRIORITY), + 'table': str(TABLE), + 'type': 'unicast' + } + ], + constants.IP_VERSION_6: [ + { + 'from': 'abcd::1', + 'to': '1234::/64', + 'priority': str(PRIORITY), + 'table': str(TABLE), + 'type': 'unicast' + }, + { + 'from': '::/0', + 'to': '4567::/64', + 'iif': device.name, + 'priority': str(PRIORITY), + 'table': str(TABLE), + 'type': 'unicast', + } + ] + } + + ip_rule = ip_lib.IPRule(namespace=device.namespace) + for ip_version, test_case in test_cases.items(): + for rule in test_case: + ip_rule.rule.add(table=TABLE, priority=PRIORITY, **rule) + + rules = ip_rule.rule.list_rules(ip_version) + for expected_rule in expected_rules[ip_version]: + self.assertIn(expected_rule, rules) + + for rule in test_case: + ip_rule.rule.delete(table=TABLE, priority=PRIORITY, **rule) + + rules = ip_rule.rule.list_rules(ip_version) + for expected_rule in expected_rules[ip_version]: + self.assertNotIn(expected_rule, rules) + def test_device_exists(self): attr = self.generate_device_details()