diff --git a/module_utils/network_lsr/argument_validator.py b/module_utils/network_lsr/argument_validator.py index 06a07041..78ae2b53 100644 --- a/module_utils/network_lsr/argument_validator.py +++ b/module_utils/network_lsr/argument_validator.py @@ -2771,6 +2771,11 @@ def _parse_route_tables_mapping_from_file(cls, filename, mapping): def get_route_tables_mapping(cls): if not hasattr(cls, "_cached_rt_tables"): mapping = {} + # look in static built-in route tables file first + cls._parse_route_tables_mapping_from_file( + "/usr/share/iproute2/rt_tables", mapping + ) + # then look in the user-defined route tables file cls._parse_route_tables_mapping_from_file( "/etc/iproute2/rt_tables", mapping ) diff --git a/tests/playbooks/tests_route_table.yml b/tests/playbooks/tests_route_table.yml index 251e489d..4a7f1df2 100644 --- a/tests/playbooks/tests_route_table.yml +++ b/tests/playbooks/tests_route_table.yml @@ -49,6 +49,11 @@ metric: 50 table: 30200 src: 198.51.100.3 + - network: 198.51.101.128 + prefix: 26 + gateway: 198.51.101.1 + metric: 2 + table: main - name: Get the routes from the route table 30200 command: ip route show table 30200 @@ -62,6 +67,12 @@ ignore_errors: true changed_when: false + - name: Get the routes from the route table main + command: ip route show table main + register: route_table_main + ignore_errors: true + changed_when: false + - name: Assert that the route table 30200 contains the specified route assert: that: @@ -81,6 +92,14 @@ msg: "the route table 30400 does not exist or does not contain the specified route" + - name: Assert that the route table main contains the specified route + assert: + that: + - route_table_main.stdout is search("198.51.101.128/26 via + 198.51.101.1 dev ethtest0 proto static metric 2") + msg: "the route table main does not exist or does not contain the + specified route" + - name: Create a dedicated test file in `/etc/iproute2/rt_tables.d/` and add a new routing table lineinfile: @@ -121,6 +140,11 @@ metric: 50 table: custom src: 198.51.100.3 + - network: 198.51.101.128 + prefix: 26 + gateway: 198.51.101.1 + metric: 2 + table: custom - name: Get the routes from the named route table 'custom' command: ip route show table custom @@ -139,6 +163,8 @@ - route_table_custom.stdout is search("192.0.2.64/26 via 198.51.100.8 dev ethtest0 proto static src 198.51.100.3 metric 50") + - route_table_custom.stdout is search("198.51.101.128/26 via + 198.51.101.1 dev ethtest0 proto static metric 2") msg: "the named route table 'custom' does not exist or does not contain the specified route"