25
25
from vyos .utils .process import process_named_running
26
26
27
27
base_path = ['protocols' , 'rpki' ]
28
+ base_frr_config_args = {'string' : 'rpki' , 'endsection' : '^exit' }
29
+ vrf = 'blue'
30
+ vrf_path = ['vrf' , 'name' , vrf ]
31
+ vrf_frr_config_args = {'string' : f'vrf { vrf } ' , 'endsection' :'^exit-vrf' ,
32
+ 'substring' : ' rpki' , 'endsubsection' : '^ exit' }
28
33
rpki_key_name = 'rpki-smoketest'
29
34
rpki_key_type = 'ssh-rsa'
30
35
@@ -112,14 +117,19 @@ def setUpClass(cls):
112
117
# ensure we can also run this test on a live system - so lets clean
113
118
# out the current configuration :)
114
119
cls .cli_delete (cls , base_path )
120
+ cls .cli_delete (cls , vrf_path )
115
121
# Enable CSTORE guard time required by FRR related tests
116
122
cls ._commit_guard_time = CSTORE_GUARD_TIME
117
123
118
124
def tearDown (self ):
119
125
self .cli_delete (base_path )
126
+ self .cli_delete (vrf_path )
120
127
self .cli_commit ()
121
128
122
- frrconfig = self .getFRRconfig ('rpki' , endsection = '^exit' )
129
+ frrconfig = self .getFRRconfig (** base_frr_config_args )
130
+ self .assertNotIn (f'rpki' , frrconfig )
131
+
132
+ frrconfig = self .getFRRconfig (** vrf_frr_config_args )
123
133
self .assertNotIn (f'rpki' , frrconfig )
124
134
125
135
# check process health and continuity
@@ -144,27 +154,33 @@ def test_rpki(self):
144
154
},
145
155
}
146
156
147
- self .cli_set (base_path + ['expire-interval' , expire_interval ])
148
- self .cli_set (base_path + ['polling-period' , polling_period ])
149
- self .cli_set (base_path + ['retry-interval' , retry_interval ])
157
+ for test_set in [ {'path' : base_path , 'frrargs' : base_frr_config_args },
158
+ {'path' : vrf_path + base_path , 'frrargs' : vrf_frr_config_args } ]:
150
159
151
- for peer , peer_config in cache .items ():
152
- self .cli_set (base_path + ['cache' , peer , 'port' , peer_config ['port' ]])
153
- self .cli_set (base_path + ['cache' , peer , 'preference' , peer_config ['preference' ]])
160
+ if 'vrf' in test_set ['path' ]:
161
+ self .cli_set (vrf_path + ['table' , '1000' ])
154
162
155
- # commit changes
156
- self .cli_commit ()
163
+ self .cli_set (test_set ['path' ] + ['expire-interval' , expire_interval ])
164
+ self .cli_set (test_set ['path' ] + ['polling-period' , polling_period ])
165
+ self .cli_set (test_set ['path' ] + ['retry-interval' , retry_interval ])
166
+
167
+ for peer , peer_config in cache .items ():
168
+ self .cli_set (test_set ['path' ] + ['cache' , peer , 'port' , peer_config ['port' ]])
169
+ self .cli_set (test_set ['path' ] + ['cache' , peer , 'preference' , peer_config ['preference' ]])
170
+
171
+ # commit changes
172
+ self .cli_commit ()
157
173
158
- # Verify FRR configuration
159
- frrconfig = self .getFRRconfig ('rpki' , endsection = '^exit' )
160
- self .assertIn (f'rpki expire_interval { expire_interval } ' , frrconfig )
161
- self .assertIn (f'rpki polling_period { polling_period } ' , frrconfig )
162
- self .assertIn (f'rpki retry_interval { retry_interval } ' , frrconfig )
174
+ # Verify FRR configuration
175
+ frrconfig = self .getFRRconfig (** test_set [ 'frrargs' ] )
176
+ self .assertIn (f'rpki expire_interval { expire_interval } ' , frrconfig )
177
+ self .assertIn (f'rpki polling_period { polling_period } ' , frrconfig )
178
+ self .assertIn (f'rpki retry_interval { retry_interval } ' , frrconfig )
163
179
164
- for peer , peer_config in cache .items ():
165
- port = peer_config ['port' ]
166
- preference = peer_config ['preference' ]
167
- self .assertIn (f'rpki cache tcp { peer } { port } preference { preference } ' , frrconfig )
180
+ for peer , peer_config in cache .items ():
181
+ port = peer_config ['port' ]
182
+ preference = peer_config ['preference' ]
183
+ self .assertIn (f'rpki cache tcp { peer } { port } preference { preference } ' , frrconfig )
168
184
169
185
def test_rpki_ssh (self ):
170
186
polling = '7200'
@@ -185,48 +201,54 @@ def test_rpki_ssh(self):
185
201
self .cli_set (['pki' , 'openssh' , rpki_key_name , 'public' , 'key' , rpki_ssh_pub .replace ('\n ' ,'' )])
186
202
self .cli_set (['pki' , 'openssh' , rpki_key_name , 'public' , 'type' , rpki_key_type ])
187
203
188
- for cache_name , cache_config in cache .items ():
189
- self .cli_set (base_path + ['cache' , cache_name , 'port' , cache_config ['port' ]])
190
- self .cli_set (base_path + ['cache' , cache_name , 'preference' , cache_config ['preference' ]])
191
- self .cli_set (base_path + ['cache' , cache_name , 'ssh' , 'username' , cache_config ['username' ]])
192
- self .cli_set (base_path + ['cache' , cache_name , 'ssh' , 'key' , rpki_key_name ])
204
+ for test_set in [ {'path' : base_path , 'frrargs' : base_frr_config_args },
205
+ {'path' : vrf_path + base_path , 'frrargs' : vrf_frr_config_args } ]:
193
206
194
- # commit changes
195
- self .cli_commit ( )
207
+ if 'vrf' in test_set [ 'path' ]:
208
+ self .cli_set ( vrf_path + [ 'table' , '1000' ] )
196
209
197
- # Verify FRR configuration
198
- frrconfig = self .getFRRconfig ('rpki' , endsection = '^exit' )
199
- for cache_name , cache_config in cache .items ():
200
- port = cache_config ['port' ]
201
- preference = cache_config ['preference' ]
202
- username = cache_config ['username' ]
203
- self .assertIn (f'rpki cache ssh { cache_name } { port } { username } /run/frr/id_rpki_{ cache_name } /run/frr/id_rpki_{ cache_name } .pub preference { preference } ' , frrconfig )
204
-
205
- # Verify content of SSH keys
206
- tmp = read_file (f'/run/frr/id_rpki_{ cache_name } ' )
207
- self .assertIn (rpki_ssh_key .replace ('\n ' ,'' ), tmp )
208
- tmp = read_file (f'/run/frr/id_rpki_{ cache_name } .pub' )
209
- self .assertIn (rpki_ssh_pub .replace ('\n ' ,'' ), tmp )
210
-
211
- # Change OpenSSH key and verify it was properly written to filesystem
212
- self .cli_set (['pki' , 'openssh' , rpki_key_name , 'private' , 'key' , rpki_ssh_key_replacement .replace ('\n ' ,'' )])
213
- self .cli_set (['pki' , 'openssh' , rpki_key_name , 'public' , 'key' , rpki_ssh_pub_replacement .replace ('\n ' ,'' )])
214
- # commit changes
215
- self .cli_commit ()
210
+ for cache_name , cache_config in cache .items ():
211
+ self .cli_set (test_set ['path' ] + ['cache' , cache_name , 'port' , cache_config ['port' ]])
212
+ self .cli_set (test_set ['path' ] + ['cache' , cache_name , 'preference' , cache_config ['preference' ]])
213
+ self .cli_set (test_set ['path' ] + ['cache' , cache_name , 'ssh' , 'username' , cache_config ['username' ]])
214
+ self .cli_set (test_set ['path' ] + ['cache' , cache_name , 'ssh' , 'key' , rpki_key_name ])
215
+
216
+ # commit changes
217
+ self .cli_commit ()
218
+
219
+ # Verify FRR configuration
220
+ frrconfig = self .getFRRconfig (** test_set ['frrargs' ])
221
+ for cache_name , cache_config in cache .items ():
222
+ port = cache_config ['port' ]
223
+ preference = cache_config ['preference' ]
224
+ username = cache_config ['username' ]
225
+ self .assertIn (f'rpki cache ssh { cache_name } { port } { username } /run/frr/id_rpki_{ cache_name } /run/frr/id_rpki_{ cache_name } .pub preference { preference } ' , frrconfig )
226
+
227
+ # Verify content of SSH keys
228
+ tmp = read_file (f'/run/frr/id_rpki_{ cache_name } ' )
229
+ self .assertIn (rpki_ssh_key .replace ('\n ' ,'' ), tmp )
230
+ tmp = read_file (f'/run/frr/id_rpki_{ cache_name } .pub' )
231
+ self .assertIn (rpki_ssh_pub .replace ('\n ' ,'' ), tmp )
232
+
233
+ # Change OpenSSH key and verify it was properly written to filesystem
234
+ self .cli_set (['pki' , 'openssh' , rpki_key_name , 'private' , 'key' , rpki_ssh_key_replacement .replace ('\n ' ,'' )])
235
+ self .cli_set (['pki' , 'openssh' , rpki_key_name , 'public' , 'key' , rpki_ssh_pub_replacement .replace ('\n ' ,'' )])
236
+ # commit changes
237
+ self .cli_commit ()
216
238
217
- for cache_name , cache_config in cache .items ():
218
- port = cache_config ['port' ]
219
- preference = cache_config ['preference' ]
220
- username = cache_config ['username' ]
221
- self .assertIn (f'rpki cache ssh { cache_name } { port } { username } /run/frr/id_rpki_{ cache_name } /run/frr/id_rpki_{ cache_name } .pub preference { preference } ' , frrconfig )
239
+ for cache_name , cache_config in cache .items ():
240
+ port = cache_config ['port' ]
241
+ preference = cache_config ['preference' ]
242
+ username = cache_config ['username' ]
243
+ self .assertIn (f'rpki cache ssh { cache_name } { port } { username } /run/frr/id_rpki_{ cache_name } /run/frr/id_rpki_{ cache_name } .pub preference { preference } ' , frrconfig )
222
244
223
- # Verify content of SSH keys
224
- tmp = read_file (f'/run/frr/id_rpki_{ cache_name } ' )
225
- self .assertIn (rpki_ssh_key_replacement .replace ('\n ' ,'' ), tmp )
226
- tmp = read_file (f'/run/frr/id_rpki_{ cache_name } .pub' )
227
- self .assertIn (rpki_ssh_pub_replacement .replace ('\n ' ,'' ), tmp )
245
+ # Verify content of SSH keys
246
+ tmp = read_file (f'/run/frr/id_rpki_{ cache_name } ' )
247
+ self .assertIn (rpki_ssh_key_replacement .replace ('\n ' ,'' ), tmp )
248
+ tmp = read_file (f'/run/frr/id_rpki_{ cache_name } .pub' )
249
+ self .assertIn (rpki_ssh_pub_replacement .replace ('\n ' ,'' ), tmp )
228
250
229
- self .cli_delete (['pki' , 'openssh' ])
251
+ self .cli_delete (['pki' , 'openssh' ])
230
252
231
253
def test_rpki_verify_preference (self ):
232
254
cache = {
@@ -240,13 +262,19 @@ def test_rpki_verify_preference(self):
240
262
},
241
263
}
242
264
243
- for peer , peer_config in cache .items ():
244
- self .cli_set (base_path + ['cache' , peer , 'port' , peer_config ['port' ]])
245
- self .cli_set (base_path + ['cache' , peer , 'preference' , peer_config ['preference' ]])
265
+ for test_set in [ {'path' : base_path , 'frrargs' : base_frr_config_args },
266
+ {'path' : vrf_path + base_path , 'frrargs' : vrf_frr_config_args } ]:
246
267
247
- # check validate() - preferences must be unique
248
- with self .assertRaises (ConfigSessionError ):
249
- self .cli_commit ()
268
+ if 'vrf' in test_set ['path' ]:
269
+ self .cli_set (vrf_path + ['table' , '1000' ])
270
+
271
+ for peer , peer_config in cache .items ():
272
+ self .cli_set (test_set ['path' ] + ['cache' , peer , 'port' , peer_config ['port' ]])
273
+ self .cli_set (test_set ['path' ] + ['cache' , peer , 'preference' , peer_config ['preference' ]])
274
+
275
+ # check validate() - preferences must be unique
276
+ with self .assertRaises (ConfigSessionError ):
277
+ self .cli_commit ()
250
278
251
279
def test_rpki_source_address (self ):
252
280
peer = '192.0.2.1'
@@ -257,31 +285,38 @@ def test_rpki_source_address(self):
257
285
258
286
self .cli_set (['interfaces' , 'ethernet' , 'eth0' , 'address' , f'{ source_address } /24' ])
259
287
260
- # Configure a TCP cache server
261
- self .cli_set (base_path + ['cache' , peer , 'port' , port ])
262
- self .cli_set (base_path + ['cache' , peer , 'preference' , preference ])
263
- self .cli_set (base_path + ['cache' , peer , 'source-address' , source_address ])
264
- self .cli_commit ()
265
288
266
- # Verify FRR configuration
267
- frrconfig = self .getFRRconfig ('rpki' )
268
- self .assertIn (f'rpki cache tcp { peer } { port } source { source_address } preference { preference } ' , frrconfig )
289
+ for test_set in [ {'path' : base_path , 'frrargs' : base_frr_config_args },
290
+ {'path' : vrf_path + base_path , 'frrargs' : vrf_frr_config_args } ]:
269
291
270
- self .cli_set (['pki' , 'openssh' , rpki_key_name , 'private' , 'key' , rpki_ssh_key .replace ('\n ' , '' )])
271
- self .cli_set (['pki' , 'openssh' , rpki_key_name , 'public' , 'key' , rpki_ssh_pub .replace ('\n ' , '' )])
272
- self .cli_set (['pki' , 'openssh' , rpki_key_name , 'public' , 'type' , rpki_key_type ])
292
+ if 'vrf' in test_set ['path' ]:
293
+ self .cli_set (vrf_path + ['table' , '1000' ])
273
294
274
- # Configure a SSH cache server
275
- self .cli_set (base_path + ['cache' , peer , 'ssh' , 'username' , username ])
276
- self .cli_set (base_path + ['cache' , peer , 'ssh' , 'key' , rpki_key_name ])
277
- self .cli_commit ()
295
+ # Configure a TCP cache server
296
+ self .cli_set (test_set ['path' ] + ['cache' , peer , 'port' , port ])
297
+ self .cli_set (test_set ['path' ] + ['cache' , peer , 'preference' , preference ])
298
+ self .cli_set (test_set ['path' ] + ['cache' , peer , 'source-address' , source_address ])
299
+ self .cli_commit ()
300
+
301
+ # Verify FRR configuration
302
+ frrconfig = self .getFRRconfig (** test_set ['frrargs' ])
303
+ self .assertIn (f'rpki cache tcp { peer } { port } source { source_address } preference { preference } ' , frrconfig )
304
+
305
+ self .cli_set (['pki' , 'openssh' , rpki_key_name , 'private' , 'key' , rpki_ssh_key .replace ('\n ' , '' )])
306
+ self .cli_set (['pki' , 'openssh' , rpki_key_name , 'public' , 'key' , rpki_ssh_pub .replace ('\n ' , '' )])
307
+ self .cli_set (['pki' , 'openssh' , rpki_key_name , 'public' , 'type' , rpki_key_type ])
308
+
309
+ # Configure a SSH cache server
310
+ self .cli_set (test_set ['path' ] + ['cache' , peer , 'ssh' , 'username' , username ])
311
+ self .cli_set (test_set ['path' ] + ['cache' , peer , 'ssh' , 'key' , rpki_key_name ])
312
+ self .cli_commit ()
278
313
279
- # Verify FRR configuration
280
- frrconfig = self .getFRRconfig ('rpki' )
281
- self .assertIn (
282
- f'rpki cache ssh { peer } { port } { username } /run/frr/id_rpki_{ peer } /run/frr/id_rpki_{ peer } .pub source { source_address } preference { preference } ' ,
283
- frrconfig ,
284
- )
314
+ # Verify FRR configuration
315
+ frrconfig = self .getFRRconfig (** test_set [ 'frrargs' ] )
316
+ self .assertIn (
317
+ f'rpki cache ssh { peer } { port } { username } /run/frr/id_rpki_{ peer } /run/frr/id_rpki_{ peer } .pub source { source_address } preference { preference } ' ,
318
+ frrconfig ,
319
+ )
285
320
286
321
287
322
if __name__ == '__main__' :
0 commit comments