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,30 @@ 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
+ self . cli_set ( test_set [ 'path' ] + [ 'expire-interval' , expire_interval ])
161
+ self .cli_set (test_set [ 'path' ] + [ 'polling-period ' , polling_period ])
162
+ self .cli_set (test_set [ 'path' ] + [ 'retry-interval ' , retry_interval ])
154
163
155
- # commit changes
156
- self .cli_commit ()
164
+ for peer , peer_config in cache .items ():
165
+ self .cli_set (test_set ['path' ] + ['cache' , peer , 'port' , peer_config ['port' ]])
166
+ self .cli_set (test_set ['path' ] + ['cache' , peer , 'preference' , peer_config ['preference' ]])
167
+
168
+ # commit changes
169
+ self .cli_commit ()
157
170
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 )
171
+ # Verify FRR configuration
172
+ frrconfig = self .getFRRconfig (** test_set [ 'frrargs' ] )
173
+ self .assertIn (f'rpki expire_interval { expire_interval } ' , frrconfig )
174
+ self .assertIn (f'rpki polling_period { polling_period } ' , frrconfig )
175
+ self .assertIn (f'rpki retry_interval { retry_interval } ' , frrconfig )
163
176
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 )
177
+ for peer , peer_config in cache .items ():
178
+ port = peer_config ['port' ]
179
+ preference = peer_config ['preference' ]
180
+ self .assertIn (f'rpki cache tcp { peer } { port } preference { preference } ' , frrconfig )
168
181
169
182
def test_rpki_ssh (self ):
170
183
polling = '7200'
@@ -185,46 +198,53 @@ def test_rpki_ssh(self):
185
198
self .cli_set (['pki' , 'openssh' , rpki_key_name , 'public' , 'key' , rpki_ssh_pub .replace ('\n ' ,'' )])
186
199
self .cli_set (['pki' , 'openssh' , rpki_key_name , 'public' , 'type' , rpki_key_type ])
187
200
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 ])
201
+ for test_set in [ {'path' : base_path , 'frrargs' : base_frr_config_args },
202
+ {'path' : vrf_path + base_path , 'frrargs' : vrf_frr_config_args } ]:
193
203
194
- # commit changes
195
- self .cli_commit ()
204
+ for cache_name , cache_config in cache .items ():
205
+ self .cli_set (test_set ['path' ] + ['cache' , cache_name , 'port' , cache_config ['port' ]])
206
+ self .cli_set (test_set ['path' ] + ['cache' , cache_name , 'preference' , cache_config ['preference' ]])
207
+ self .cli_set (test_set ['path' ] + ['cache' , cache_name , 'ssh' , 'username' , cache_config ['username' ]])
208
+ self .cli_set (test_set ['path' ] + ['cache' , cache_name , 'ssh' , 'key' , rpki_key_name ])
209
+
210
+ # commit changes
211
+ self .cli_commit ()
196
212
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 )
213
+ # Verify FRR configuration
214
+ frrconfig = self .getFRRconfig (** test_set [ 'frrargs' ] )
215
+ for cache_name , cache_config in cache .items ():
216
+ port = cache_config ['port' ]
217
+ preference = cache_config ['preference' ]
218
+ username = cache_config ['username' ]
219
+ 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
220
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 )
221
+ # Verify content of SSH keys
222
+ tmp = read_file (f'/run/frr/id_rpki_{ cache_name } ' )
223
+ self .assertIn (rpki_ssh_key .replace ('\n ' ,'' ), tmp )
224
+ tmp = read_file (f'/run/frr/id_rpki_{ cache_name } .pub' )
225
+ self .assertIn (rpki_ssh_pub .replace ('\n ' ,'' ), tmp )
210
226
211
227
# Change OpenSSH key and verify it was properly written to filesystem
212
228
self .cli_set (['pki' , 'openssh' , rpki_key_name , 'private' , 'key' , rpki_ssh_key_replacement .replace ('\n ' ,'' )])
213
229
self .cli_set (['pki' , 'openssh' , rpki_key_name , 'public' , 'key' , rpki_ssh_pub_replacement .replace ('\n ' ,'' )])
214
230
# commit changes
215
231
self .cli_commit ()
216
232
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 )
233
+ for test_set in [ {'path' : base_path , 'frrargs' : base_frr_config_args },
234
+ {'path' : vrf_path + base_path , 'frrargs' : vrf_frr_config_args } ]:
222
235
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 )
236
+ frrconfig = self .getFRRconfig (** test_set ['frrargs' ])
237
+ for cache_name , cache_config in cache .items ():
238
+ port = cache_config ['port' ]
239
+ preference = cache_config ['preference' ]
240
+ username = cache_config ['username' ]
241
+ 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 )
242
+
243
+ # Verify content of SSH keys
244
+ tmp = read_file (f'/run/frr/id_rpki_{ cache_name } ' )
245
+ self .assertIn (rpki_ssh_key_replacement .replace ('\n ' ,'' ), tmp )
246
+ tmp = read_file (f'/run/frr/id_rpki_{ cache_name } .pub' )
247
+ self .assertIn (rpki_ssh_pub_replacement .replace ('\n ' ,'' ), tmp )
228
248
229
249
self .cli_delete (['pki' , 'openssh' ])
230
250
@@ -240,13 +260,16 @@ def test_rpki_verify_preference(self):
240
260
},
241
261
}
242
262
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' ]])
263
+ for test_set in [ {'path' : base_path , 'frrargs' : base_frr_config_args },
264
+ {'path' : vrf_path + base_path , 'frrargs' : vrf_frr_config_args } ]:
246
265
247
- # check validate() - preferences must be unique
248
- with self .assertRaises (ConfigSessionError ):
249
- self .cli_commit ()
266
+ for peer , peer_config in cache .items ():
267
+ self .cli_set (test_set ['path' ] + ['cache' , peer , 'port' , peer_config ['port' ]])
268
+ self .cli_set (test_set ['path' ] + ['cache' , peer , 'preference' , peer_config ['preference' ]])
269
+
270
+ # check validate() - preferences must be unique
271
+ with self .assertRaises (ConfigSessionError ):
272
+ self .cli_commit ()
250
273
251
274
def test_rpki_source_address (self ):
252
275
peer = '192.0.2.1'
@@ -257,31 +280,35 @@ def test_rpki_source_address(self):
257
280
258
281
self .cli_set (['interfaces' , 'ethernet' , 'eth0' , 'address' , f'{ source_address } /24' ])
259
282
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
283
266
- # Verify FRR configuration
267
- frrconfig = self .getFRRconfig ('rpki' )
268
- self .assertIn (f'rpki cache tcp { peer } { port } source { source_address } preference { preference } ' , frrconfig )
284
+ for test_set in [ {'path' : base_path , 'frrargs' : base_frr_config_args },
285
+ {'path' : vrf_path + base_path , 'frrargs' : vrf_frr_config_args } ]:
269
286
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 ])
287
+ # Configure a TCP cache server
288
+ self .cli_set (test_set ['path' ] + ['cache' , peer , 'port' , port ])
289
+ self .cli_set (test_set ['path' ] + ['cache' , peer , 'preference' , preference ])
290
+ self .cli_set (test_set ['path' ] + ['cache' , peer , 'source-address' , source_address ])
291
+ self .cli_commit ()
273
292
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 ()
293
+ # Verify FRR configuration
294
+ frrconfig = self .getFRRconfig (** test_set ['frrargs' ])
295
+ self .assertIn (f'rpki cache tcp { peer } { port } source { source_address } preference { preference } ' , frrconfig )
296
+
297
+ self .cli_set (['pki' , 'openssh' , rpki_key_name , 'private' , 'key' , rpki_ssh_key .replace ('\n ' , '' )])
298
+ self .cli_set (['pki' , 'openssh' , rpki_key_name , 'public' , 'key' , rpki_ssh_pub .replace ('\n ' , '' )])
299
+ self .cli_set (['pki' , 'openssh' , rpki_key_name , 'public' , 'type' , rpki_key_type ])
300
+
301
+ # Configure a SSH cache server
302
+ self .cli_set (test_set ['path' ] + ['cache' , peer , 'ssh' , 'username' , username ])
303
+ self .cli_set (test_set ['path' ] + ['cache' , peer , 'ssh' , 'key' , rpki_key_name ])
304
+ self .cli_commit ()
278
305
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
- )
306
+ # Verify FRR configuration
307
+ frrconfig = self .getFRRconfig (** test_set [ 'frrargs' ] )
308
+ self .assertIn (
309
+ f'rpki cache ssh { peer } { port } { username } /run/frr/id_rpki_{ peer } /run/frr/id_rpki_{ peer } .pub source { source_address } preference { preference } ' ,
310
+ frrconfig ,
311
+ )
285
312
286
313
287
314
if __name__ == '__main__' :
0 commit comments