Skip to content

Commit 65b5d1a

Browse files
committed
fix: allow use of built-in routing tables
Cause: The user is trying to specify the routing table to use by the name of a built-in routing table defined in /usr/share/iproute2/rt_tables such as `main`. Consequence: The network role gives an error: "cannot find route table main in `/etc/iproute2/rt_tables` or `/etc/iproute2/rt_tables.d/`" The workaround is that the user must specify the table by number instead of name e.g `table: 254` instead of `table: main` Fix: Look for table mappings in /usr/share/iproute2/rt_tables as well as the other paths. Result: The user can use built-in route table names. Signed-off-by: Rich Megginson <[email protected]>
1 parent 79fb5cd commit 65b5d1a

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

module_utils/network_lsr/argument_validator.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2771,6 +2771,11 @@ def _parse_route_tables_mapping_from_file(cls, filename, mapping):
27712771
def get_route_tables_mapping(cls):
27722772
if not hasattr(cls, "_cached_rt_tables"):
27732773
mapping = {}
2774+
# look in static built-in route tables file first
2775+
cls._parse_route_tables_mapping_from_file(
2776+
"/usr/share/iproute2/rt_tables", mapping
2777+
)
2778+
# then look in the user-defined route tables file
27742779
cls._parse_route_tables_mapping_from_file(
27752780
"/etc/iproute2/rt_tables", mapping
27762781
)

tests/playbooks/tests_route_table.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@
4949
metric: 50
5050
table: 30200
5151
src: 198.51.100.3
52+
- network: 198.51.101.128
53+
prefix: 26
54+
gateway: 198.51.101.1
55+
metric: 2
56+
table: main
5257

5358
- name: Get the routes from the route table 30200
5459
command: ip route show table 30200
@@ -62,6 +67,12 @@
6267
ignore_errors: true
6368
changed_when: false
6469

70+
- name: Get the routes from the route table main
71+
command: ip route show table main
72+
register: route_table_main
73+
ignore_errors: true
74+
changed_when: false
75+
6576
- name: Assert that the route table 30200 contains the specified route
6677
assert:
6778
that:
@@ -81,6 +92,14 @@
8192
msg: "the route table 30400 does not exist or does not contain the
8293
specified route"
8394

95+
- name: Assert that the route table main contains the specified route
96+
assert:
97+
that:
98+
- route_table_main.stdout is search("198.51.101.128/26 via
99+
198.51.101.1 dev ethtest0 proto static metric 2")
100+
msg: "the route table main does not exist or does not contain the
101+
specified route"
102+
84103
- name: Create a dedicated test file in `/etc/iproute2/rt_tables.d/` and
85104
add a new routing table
86105
lineinfile:
@@ -121,6 +140,11 @@
121140
metric: 50
122141
table: custom
123142
src: 198.51.100.3
143+
- network: 198.51.101.128
144+
prefix: 26
145+
gateway: 198.51.101.1
146+
metric: 2
147+
table: custom
124148

125149
- name: Get the routes from the named route table 'custom'
126150
command: ip route show table custom
@@ -139,6 +163,8 @@
139163
- route_table_custom.stdout is search("192.0.2.64/26 via
140164
198.51.100.8 dev ethtest0 proto static src 198.51.100.3
141165
metric 50")
166+
- route_table_custom.stdout is search("198.51.101.128/26 via
167+
198.51.101.1 dev ethtest0 proto static metric 2")
142168
msg: "the named route table 'custom' does not exist or does not contain
143169
the specified route"
144170

0 commit comments

Comments
 (0)