def test_delete_non_existing_route(self, execute_command): execute_command.return_value = self.ip_route_list_output route = Route('1.2.3.4', 'wlo1') route.gateway = '192.168.0.254' with self.assertRaises(ObjectNotFoundException): route.delete() execute_command.assert_called_with('ip route del 1.2.3.4', namespace=None)
def test_add_existing_route(self, execute_command): execute_command.return_value = self.ip_route_list_output route = Route('default', 'wlo1') route.gateway = '192.168.0.254' with self.assertRaises(ObjectAlreadyExistsException): route.create() execute_command.assert_called_once_with('ip route list', namespace=None)
def step_impl(context, destination, device): route = Route(destination, device) route.refresh() assert not route.is_reachable() response = None try: response = os.system('ping -c 1 %s 2>/dev/null' % destination.split('/')[0]) except: assert response == 2 assert response is not None
def test_refresh_route(self, execute_command): execute_command.return_value = self.ip_route_list_output route = Route('default', 'wlo1') route.refresh() execute_command.assert_called_once_with("ip route list", namespace=None) self.assertEqual(route.metric, '600') self.assertEqual(route.gateway, '192.168.0.254') self.assertIsNone(route.source) self.assertIsNone(route.scope) self.assertIsNone(route.namespace)
def test_route_discovery(self, destination, device, scope, source, metric, gateway, default, prohibit, reachable, execute_command): execute_command.return_value = self.ip_route_list_output route = Route(destination, device) route.scope = scope route.source = source route.gateway = gateway route.metric = metric routes = Route.discover() self.assertEqual(len(routes), 6) found_route = routes[routes.index(route)] self.assertTrue(self.deep_equality(route, found_route)) self.assertEqual(found_route.is_default(), default) self.assertEqual(found_route.is_prohibited(), prohibit) self.assertEqual(found_route.is_reachable(), reachable)
def step_impl(context, destination, device): route = Route(destination, device) assert route.exists()
def step_impl(context, destination, device): route = Route(destination, device) try: route.unreachable() except Exception as e: context.exception = e
def step_impl(context, destination, device): route = Route(destination, device) try: route.prohibit() except Exception as e: context.exception = e
def step_impl(context): context.routes = Route.discover()
def test_delete_existing_route(self, execute_command): execute_command.return_value = self.ip_route_list_output route = Route('default', 'wlo1') route.gateway = '192.168.0.254' route.delete() execute_command.assert_called_with('ip route del default', namespace=None)
def test_prohibit_non_existing_route(self, execute_command): execute_command.return_value = self.ip_route_list_output route = Route('10.10.10.10/24', 'wlo1') route.prohibit() execute_command.assert_called_with('ip route add prohibit 10.10.10.10/24', namespace=None)
def test_contains_route(self, execute_command): execute_command.return_value = self.ip_route_list_output route = Route('default', 'wlo1') route.gateway = '192.168.0.254' self.assertTrue(route.exists()) execute_command.assert_called_once_with('ip route list', namespace=None)
def test_refresh_non_existing_route(self, execute_command): execute_command.return_value = self.ip_route_list_output route = Route('destination', 'device') with self.assertRaises(ObjectNotFoundException): route.refresh() execute_command.assert_called_once_with("ip route list", namespace=None)
def test_unreachable_existing_route(self, execute_command): execute_command.return_value = self.ip_route_list_output route = Route('1.2.3.4/30', None) with self.assertRaises(ObjectAlreadyExistsException): route.unreachable() execute_command.assert_called_with('ip route del 1.2.3.4', namespace=None)
def test_unreachable_non_existing_route(self, execute_command): execute_command.return_value = self.ip_route_list_output route = Route('10.10.10.10/24', 'wlo1') route.unreachable() execute_command.assert_called_with('ip route add unreachable 10.10.10.10/24', namespace=None)
def step_impl(context, destination, device): route = Route(destination, device) if route.exists(): route.delete()
def step_impl(context, destination, device): route = Route(destination, device) if route not in Route.discover(): route.create()
def test_add_non_existing_route(self, execute_command): execute_command.return_value = self.ip_route_list_output route = Route('1.2.3.4', 'wlo1') route.gateway = '192.168.0.254' route.create() execute_command.assert_called_with('ip route add 1.2.3.4 dev wlo1 via 192.168.0.254', namespace=None)