From b85191e2cdde8f472e1956274afe155c63eff58d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C5=82awek=20Kap=C5=82o=C5=84ski?= Date: Fri, 23 Mar 2018 16:35:22 +0100 Subject: [PATCH] [Functional tests] Add gateway add/delete/flush tests This commit adds functional tests for add/delete/flush/get gateway IP methods from ip_lib.IpRouteCommand class. Change-Id: I59d2361a849660a6a67ed56a5be52ee0e88d6e4a --- .../functional/agent/linux/test_ip_lib.py | 54 +++++++++++++++++++ 1 file changed, 54 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..89faf987501 100644 --- a/neutron/tests/functional/agent/linux/test_ip_lib.py +++ b/neutron/tests/functional/agent/linux/test_ip_lib.py @@ -201,6 +201,60 @@ class IpLibTestCase(IpLibTestFramework): device.link.delete() + def test_gateway_lifecycle(self): + attr = self.generate_device_details( + ip_cidrs=["%s/24" % TEST_IP, "fd00::1/64"] + ) + metric = 1000 + device = self.manage_device(attr) + gateways = { + constants.IP_VERSION_4: attr.ip_cidrs[0].split('/')[0], + constants.IP_VERSION_6: "fd00::ff" + } + expected_gateways = { + constants.IP_VERSION_4: { + 'metric': metric, + 'gateway': gateways[constants.IP_VERSION_4]}, + constants.IP_VERSION_6: { + 'metric': metric, + 'gateway': gateways[constants.IP_VERSION_6]}} + + for ip_version, gateway_ip in gateways.items(): + device.route.add_gateway(gateway_ip, metric) + + self.assertEqual( + expected_gateways[ip_version], + device.route.get_gateway(ip_version=ip_version)) + + device.route.delete_gateway(gateway_ip) + self.assertIsNone( + device.route.get_gateway(ip_version=ip_version)) + + def test_gateway_flush(self): + attr = self.generate_device_details( + ip_cidrs=["%s/24" % TEST_IP, "fd00::1/64"] + ) + device = self.manage_device(attr) + + gateways = { + constants.IP_VERSION_4: attr.ip_cidrs[0].split('/')[0], + constants.IP_VERSION_6: "fd00::ff" + } + for ip_version, gateway_ip in gateways.items(): + # Ensure that there is no gateway configured + self.assertIsNone( + device.route.get_gateway(ip_version=ip_version)) + + # Now lets add gateway + device.route.add_gateway(gateway_ip, table="main") + self.assertIsNotNone( + device.route.get_gateway(ip_version=ip_version)) + + # Flush gateway and check that there is no any gateway configured + device.route.flush(ip_version, table="main") + self.assertIsNone( + device.route.get_gateway(ip_version=ip_version)) + def test_get_routing_table(self): attr = self.generate_device_details( ip_cidrs=["%s/24" % TEST_IP, "fd00::1/64"]