kanrisuru 0.14.0 → 0.15.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,814 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe Kanrisuru::Core::IP do
6
+ before(:all) do
7
+ StubNetwork.stub!
8
+ end
9
+
10
+ after(:all) do
11
+ StubNetwork.unstub!
12
+ end
13
+
14
+ let(:host) do
15
+ Kanrisuru::Remote::Host.new(
16
+ host: 'localhost',
17
+ username: 'ubuntu',
18
+ keys: ['id_rsa']
19
+ )
20
+ end
21
+
22
+ %w[link l].each do |object_variant|
23
+ context "with ip #{object_variant}" do
24
+ context 'with json support' do
25
+ before(:all) do
26
+ StubNetwork.stub_command!(:ip_version) do
27
+ Kanrisuru::Core::IP::IPROUTE2_JSON_VERSION
28
+ end
29
+ end
30
+
31
+ after(:all) do
32
+ StubNetwork.unstub_command!(:ip_version)
33
+ end
34
+
35
+ %w[show list].each do |action_variant|
36
+ it "prepares #{action_variant} command" do
37
+ expect_command(host.ip(object_variant, action_variant), 'ip -json link show')
38
+ expect_command(host.ip(object_variant, action_variant, {
39
+ stats: true,
40
+ family: 'inet',
41
+ dev: 'eth0',
42
+ up: true
43
+ }), 'ip -json -s -family inet link show dev eth0 up')
44
+
45
+ expect_command(host.ip(object_variant, action_variant, {
46
+ dev: 'eth0.10',
47
+ group: '0',
48
+ master: 'eth0',
49
+ vrf: 'red',
50
+ type: 'vlan'
51
+ }), 'ip -json link show dev eth0.10 group 0 master eth0 type vlan vrf red')
52
+ end
53
+ end
54
+ end
55
+
56
+ context 'without json support' do
57
+ before(:all) do
58
+ StubNetwork.stub_command!(:ip_version) do
59
+ Kanrisuru::Core::IP::IPROUTE2_JSON_VERSION - 1
60
+ end
61
+ end
62
+
63
+ after(:all) do
64
+ StubNetwork.unstub_command!(:ip_version)
65
+ end
66
+
67
+ %w[show list].each do |action_variant|
68
+ it "prepares #{action_variant} command" do
69
+ expect_command(host.ip(object_variant, action_variant), 'ip link show')
70
+ expect_command(host.ip(object_variant, action_variant, {
71
+ stats: true,
72
+ family: 'inet',
73
+ dev: 'eth0',
74
+ up: true
75
+ }), 'ip -s -family inet link show dev eth0 up')
76
+
77
+ expect_command(host.ip(object_variant, action_variant, {
78
+ dev: 'eth0.10',
79
+ group: '0',
80
+ master: 'eth0',
81
+ vrf: 'red',
82
+ type: 'vlan'
83
+ }), 'ip link show dev eth0.10 group 0 master eth0 type vlan vrf red')
84
+ end
85
+ end
86
+ end
87
+
88
+ %w[delete del].each do |action_variant|
89
+ it "prepares #{action_variant} command" do
90
+ expect_command(host.ip(object_variant, action_variant, {
91
+ dev: 'eth2'
92
+ }), 'ip link delete dev eth2')
93
+
94
+ expect_command(host.ip(object_variant, action_variant, {
95
+ group: '0'
96
+ }), 'ip link delete group 0')
97
+
98
+ expect_command(host.ip(object_variant, action_variant, {
99
+ type: 'vxlan'
100
+ }), 'ip link delete type vxlan')
101
+ end
102
+ end
103
+
104
+ %w[add a].each do |action_variant|
105
+ it "prepares #{action_variant} command" do
106
+ expect_command(host.ip(object_variant, action_variant, {
107
+ dev: 'eth0',
108
+ name: 'eth0',
109
+ mtu: 9000,
110
+ index: 1,
111
+ numttxqueues: 1000,
112
+ numrxqueues: 1000,
113
+ gso_max_size: 32,
114
+ gso_max_segs: 64
115
+ }), 'ip link add dev eth0 name eth0 mtu 9000 index 1 numrxqueues 1000 gso_max_size 32 gso_max_segs 64')
116
+ end
117
+
118
+ it "prepares #{action_variant} command with vlan" do
119
+ expect_command(host.ip(object_variant, action_variant, {
120
+ dev: 'eth0',
121
+ name: 'eth0.10',
122
+ type: 'vlan',
123
+ type_opts: {
124
+ id: 10,
125
+ protocol: '802.1Q',
126
+ reorder_hdr: 'off',
127
+ gvrp: 'off',
128
+ mvrp: 'on',
129
+ loose_binding: 'on',
130
+ ingress_qos_map: '1:2',
131
+ egress_qos_map: '2:1'
132
+ }
133
+ }), 'ip link add dev eth0 name eth0.10 type vlan protocol 802.1Q id 10 reorder_hdr off gvrp off mvrp on loose_binding on ingress-qos-map 1:2 egress-qos-map 2:1')
134
+ end
135
+
136
+ it "prepares #{action_variant} command with vxlan" do
137
+ expect_command(host.ip(object_variant, action_variant, {
138
+ name: 'eth0.5',
139
+ type: 'vxlan',
140
+ type_opts: {
141
+ id: 5,
142
+ remote: '172.0.0.12',
143
+ dev: 'eth0',
144
+ local: '10.0.0.1',
145
+ ttl: '300',
146
+ tos: '0x28',
147
+ df: 'set',
148
+ flowlabel: 'vxlan-label',
149
+ dstport: 6082,
150
+ srcport: '6085 6086',
151
+ learning: true,
152
+ rsc: true,
153
+ proxy: true,
154
+ l2miss: true,
155
+ l3miss: true,
156
+ external: true,
157
+ udpcsum: true,
158
+ udp6zerocsumtx: true,
159
+ udp6zerocsumrx: true,
160
+ ageing: 3600,
161
+ maxaddress: 128,
162
+ gbp: true,
163
+ gpe: true
164
+ }
165
+ }), 'ip link add name eth0.5 type vxlan id 5 dev eth0 remote 172.0.0.12 local 10.0.0.1 ttl 300 tos 0x28 df set flowlabel vxlan-label dstport 6082 srcport 6085 6086 learning rsc proxy l2miss l3miss udpcsum udp6zerocsumtx udp6zerocsumrx ageing 3600 maxaddress 128 gbp gpe')
166
+
167
+ expect_command(host.ip(object_variant, action_variant, {
168
+ name: 'eth0.5',
169
+ type: 'vxlan',
170
+ type_opts: {
171
+ id: 5,
172
+ remote: '172.0.0.12',
173
+ dev: 'eth0',
174
+ learning: false,
175
+ rsc: false,
176
+ proxy: false,
177
+ l2miss: false,
178
+ l3miss: false,
179
+ external: false,
180
+ udpcsum: false,
181
+ udp6zerocsumtx: false,
182
+ udp6zerocsumrx: false,
183
+ gbp: false
184
+ }
185
+ }), 'ip link add name eth0.5 type vxlan id 5 dev eth0 remote 172.0.0.12 nolearning norsc noproxy nol2miss nol3miss noudpcsum noudp6zerocsumtx noudp6zerocsumrx')
186
+ end
187
+
188
+ it "prepares #{action_variant} command with veth" do
189
+ expect_command(host.ip(object_variant, action_variant, {
190
+ dev: 'eth0',
191
+ name: 'eth0.10',
192
+ type: 'veth',
193
+ type_opts: {
194
+ peer_name: 'veth-tunnel-connect'
195
+ }
196
+ }), 'ip link add dev eth0 name eth0.10 type veth peer name veth-tunnel-connect')
197
+ end
198
+
199
+ it "prepares #{action_variant} command with vxcan" do
200
+ expect_command(host.ip(object_variant, action_variant, {
201
+ dev: 'eth0',
202
+ name: 'eth0.10',
203
+ type: 'vxcan',
204
+ type_opts: {
205
+ peer_name: 'vxcan-tunnel-connect'
206
+ }
207
+ }), 'ip link add dev eth0 name eth0.10 type vxcan peer name vxcan-tunnel-connect')
208
+ end
209
+
210
+ %w[ipip sit].each do |type|
211
+ it "prepares #{action_variant} command with #{type}" do
212
+ expect_command(host.ip(object_variant, action_variant, {
213
+ dev: 'eth0',
214
+ name: 'eth0.10',
215
+ type: type,
216
+ type_opts: {
217
+ remote: '172.0.0.1',
218
+ local: '10.0.0.2',
219
+ encap: 'gue',
220
+ encap_support: 'auto',
221
+ encap_csum: true,
222
+ encap_remcsum: true,
223
+ mode: 'any',
224
+ external: true
225
+ }
226
+ }), "ip link add dev eth0 name eth0.10 type #{type} remote 172.0.0.1 local 10.0.0.2 encap gue encap-csum encap-remcsum external mode any")
227
+
228
+ expect_command(host.ip(object_variant, action_variant, {
229
+ dev: 'eth0',
230
+ name: 'eth0.10',
231
+ type: type,
232
+ type_opts: {
233
+ remote: '172.0.0.1',
234
+ local: '10.0.0.2',
235
+ encap: 'gue',
236
+ encap_support: 'auto',
237
+ encap_csum: false,
238
+ encap_remcsum: false,
239
+ mode: 'any'
240
+ }
241
+ }), "ip link add dev eth0 name eth0.10 type #{type} remote 172.0.0.1 local 10.0.0.2 encap gue noencap-csum noencap-remcsum mode any")
242
+ end
243
+ end
244
+
245
+ %w[gre gretap].each do |type|
246
+ it "prepares #{action_variant} command with #{type}" do
247
+ expect_command(host.ip(object_variant, action_variant, {
248
+ name: 'eth0.10',
249
+ type: type,
250
+ type_opts: {
251
+ remote: '172.0.0.1',
252
+ local: '10.0.0.2',
253
+ iseq: true,
254
+ oseq: true,
255
+ icsum: true,
256
+ ocsum: true,
257
+ ikey: 10,
258
+ okey: 10,
259
+ ttl: 300,
260
+ tos: '0x28',
261
+ pmtudisc: true,
262
+ ignore_df: true,
263
+ dev: 'eth0',
264
+ encap: 'none',
265
+ encap_sport: 'auto',
266
+ encap_csum: true,
267
+ encap_remcsum: true,
268
+ external: true
269
+ }
270
+ }), "ip link add name eth0.10 type #{type} remote 172.0.0.1 local 10.0.0.2 encap none encap-sport auto encap-csum encap-remcsum external iseq oseq icsum ocsum okey 10 ikey 10 ttl 300 tos 0x28 pmtudisc ignore-df dev eth0")
271
+
272
+ expect_command(host.ip(object_variant, action_variant, {
273
+ name: 'eth0.10',
274
+ type: type,
275
+ type_opts: {
276
+ remote: '172.0.0.1',
277
+ local: '10.0.0.2',
278
+ iseq: false,
279
+ oseq: false,
280
+ icsum: false,
281
+ ocsum: false,
282
+ ikey: false,
283
+ okey: false,
284
+ tos: '0x28',
285
+ pmtudisc: false,
286
+ ignore_df: false,
287
+ dev: 'eth0',
288
+ encap: 'none',
289
+ encap_sport: 'auto',
290
+ encap_csum: false,
291
+ encap_remcsum: false
292
+ }
293
+ }), "ip link add name eth0.10 type #{type} remote 172.0.0.1 local 10.0.0.2 encap none encap-sport auto noencap-csum noencap-remcsum noiseq nooseq noicsum noocsum tos 0x28 nopmtudisc noignore-df dev eth0")
294
+ end
295
+ end
296
+
297
+ %w[ip6gre ip6gretap].each do |type|
298
+ it "prepares #{action_variant} command with #{type}" do
299
+ expect_command(host.ip(object_variant, action_variant, {
300
+ dev: 'eth0',
301
+ name: 'eth0.10',
302
+ type: type,
303
+ type_opts: {
304
+ external: true
305
+ }
306
+ }), "ip link add dev eth0 name eth0.10 type #{type} external true")
307
+
308
+ expect_command(host.ip(object_variant, action_variant, {
309
+ dev: 'eth0',
310
+ name: 'eth0.10',
311
+ type: type,
312
+ type_opts: {
313
+ remote: '172.0.0.1',
314
+ local: '10.0.0.3',
315
+ iseq: true,
316
+ oseq: true,
317
+ icsum: true,
318
+ ocsum: true,
319
+ ikey: 10,
320
+ okey: 10,
321
+ hoplimit: 300,
322
+ encaplimit: 5,
323
+ flowlabel: 'gre-flow-label',
324
+ allow_localremote: true,
325
+ tclass: 'internet'
326
+ }
327
+ }), "ip link add dev eth0 name eth0.10 type #{type} remote 172.0.0.1 local 10.0.0.3 iseq oseq icsum ocsum okey 10 ikey 10 hoplimit 300 encaplimit 5 flowlabel gre-flow-label allow-localremote tclass internet")
328
+
329
+ expect_command(host.ip(object_variant, action_variant, {
330
+ dev: 'eth0',
331
+ name: 'eth0.10',
332
+ type: type,
333
+ type_opts: {
334
+ remote: '172.0.0.1',
335
+ local: '10.0.0.3',
336
+ iseq: false,
337
+ oseq: false,
338
+ icsum: false,
339
+ ocsum: false,
340
+ ikey: false,
341
+ okey: false,
342
+ allow_localremote: false
343
+ }
344
+ }), "ip link add dev eth0 name eth0.10 type #{type} remote 172.0.0.1 local 10.0.0.3 noiseq nooseq noicsum noocsum noallow-localremote")
345
+ end
346
+ end
347
+
348
+ it "prepares #{action_variant} command with ipoib" do
349
+ expect_command(host.ip(object_variant, action_variant, {
350
+ dev: 'eth0',
351
+ name: 'eth0.10',
352
+ type: 'ipoib',
353
+ type_opts: {
354
+ pkey: '0x8003',
355
+ mode: 'connected'
356
+ }
357
+ }), 'ip link add dev eth0 name eth0.10 type ipoib pkey 0x8003 mode connected')
358
+ end
359
+
360
+ it "prepares #{action_variant} command with erspan" do
361
+ expect_command(host.ip(object_variant, action_variant, {
362
+ dev: 'erspan1',
363
+ name: 'erspan1',
364
+ type: 'erspan',
365
+ type_opts: {
366
+ remote: '172.0.0.1',
367
+ local: '10.0.0.4',
368
+ erspan_ver: 2,
369
+ erspan: '1',
370
+ erspan_dir: 'ingress',
371
+ erspan_hwid: '17',
372
+ allow_localremote: true
373
+ }
374
+ }), 'ip link add dev erspan1 name erspan1 type erspan remote 172.0.0.1 local 10.0.0.4 erspan_ver 2 erspan 1 erspan_dir ingress erspan_hwid 17 allow-localremote')
375
+
376
+ expect_command(host.ip(object_variant, action_variant, {
377
+ dev: 'erspan2',
378
+ name: 'erspan2',
379
+ type: 'erspan',
380
+ type_opts: {
381
+ remote: '172.0.0.1',
382
+ local: '10.0.0.4',
383
+ allow_localremote: false
384
+ }
385
+ }), 'ip link add dev erspan2 name erspan2 type erspan remote 172.0.0.1 local 10.0.0.4 noallow-localremote')
386
+
387
+ expect_command(host.ip(object_variant, action_variant, {
388
+ dev: 'erspan3',
389
+ name: 'erspan3',
390
+ type: 'erspan',
391
+ type_opts: {
392
+ external: true
393
+ }
394
+ }), 'ip link add dev erspan3 name erspan3 type erspan external')
395
+ end
396
+
397
+ it "prepares #{action_variant} command with ip6erspan" do
398
+ expect_command(host.ip(object_variant, action_variant, {
399
+ dev: 'ip6erspan1',
400
+ name: 'ip6erspan1',
401
+ type: 'ip6erspan',
402
+ type_opts: {
403
+ remote: 'fc00:100::1',
404
+ local: 'fc00:100::1',
405
+ erspan_ver: 2,
406
+ erspan: '1',
407
+ erspan_dir: 'ingress',
408
+ erspan_hwid: '17',
409
+ allow_localremote: true
410
+ }
411
+ }), 'ip link add dev ip6erspan1 name ip6erspan1 type ip6erspan remote fc00:100::1 local fc00:100::1 erspan_ver 2 erspan 1 erspan_dir ingress erspan_hwid 17 allow-localremote')
412
+
413
+ expect_command(host.ip(object_variant, action_variant, {
414
+ dev: 'ip6erspan2',
415
+ name: 'ip6erspan2',
416
+ type: 'ip6erspan',
417
+ type_opts: {
418
+ remote: 'fc00:100::1',
419
+ local: 'fc00:100::1',
420
+ allow_localremote: false
421
+ }
422
+ }), 'ip link add dev ip6erspan2 name ip6erspan2 type ip6erspan remote fc00:100::1 local fc00:100::1 noallow-localremote')
423
+
424
+ expect_command(host.ip(object_variant, action_variant, {
425
+ dev: 'ip6erspan3',
426
+ name: 'ip6erspan3',
427
+ type: 'ip6erspan',
428
+ type_opts: {
429
+ external: true
430
+ }
431
+ }), 'ip link add dev ip6erspan3 name ip6erspan3 type ip6erspan external')
432
+ end
433
+
434
+ it "prepares #{action_variant} command with geneve" do
435
+ expect_command(host.ip(object_variant, action_variant, {
436
+ dev: 'eth0',
437
+ name: 'geneve0',
438
+ type: 'geneve',
439
+ type_opts: {
440
+ external: true
441
+ }
442
+ }), 'ip link add dev eth0 name geneve0 type geneve external')
443
+
444
+ expect_command(host.ip(object_variant, action_variant, {
445
+ dev: 'eth0',
446
+ name: 'geneve0',
447
+ type: 'geneve',
448
+ type_opts: {
449
+ external: false
450
+ }
451
+ }), 'ip link add dev eth0 name geneve0 type geneve noexternal')
452
+
453
+ expect_command(host.ip(object_variant, action_variant, {
454
+ dev: 'eth0',
455
+ name: 'geneve0',
456
+ type: 'geneve',
457
+ type_opts: {
458
+ id: 1,
459
+ remote: '172.0.0.1',
460
+ ttl: 300,
461
+ tos: '0x28',
462
+ df: 'unset',
463
+ flowlabel: 'geneve-flow-label',
464
+ dstport: 6082,
465
+ udpcsum: true,
466
+ udp6zerocsumtx: true,
467
+ udp6zerocsumrx: true
468
+ }
469
+ }), 'ip link add dev eth0 name geneve0 type geneve id 1 remote 172.0.0.1 ttl 300 tos 0x28 df unset flowlabel geneve-flow-label dstport 6082 udpcsum udp6zerocsumtx udp6zerocsumrx')
470
+
471
+ expect_command(host.ip(object_variant, action_variant, {
472
+ dev: 'eth0',
473
+ name: 'geneve0',
474
+ type: 'geneve',
475
+ type_opts: {
476
+ id: 1,
477
+ remote: '172.0.0.1',
478
+ ttl: 300,
479
+ tos: '0x28',
480
+ df: 'unset',
481
+ flowlabel: 'geneve-flow-label',
482
+ dstport: 6082,
483
+ udpcsum: false,
484
+ udp6zerocsumtx: false,
485
+ udp6zerocsumrx: false
486
+ }
487
+ }), 'ip link add dev eth0 name geneve0 type geneve id 1 remote 172.0.0.1 ttl 300 tos 0x28 df unset flowlabel geneve-flow-label dstport 6082 noudpcsum noudp6zerocsumtx noudp6zerocsumrx')
488
+ end
489
+
490
+ it "prepares #{action_variant} command with bareudp" do
491
+ expect_command(host.ip(object_variant, action_variant, {
492
+ dev: 'bareudp0',
493
+ name: 'bareudp0',
494
+ type: 'bareudp',
495
+ type_opts: {
496
+ dstport: 6635,
497
+ ethertype: 'mpls_uc',
498
+ srcportmin: 100,
499
+ multiproto: true
500
+ }
501
+ }), 'ip link add dev bareudp0 name bareudp0 type bareudp dstport 6635 ethertype mpls_uc srcportmin 100 multiproto')
502
+ end
503
+
504
+ %w[macvlan macvtap].each do |type|
505
+ it "prepares #{action_variant} command with #{type}" do
506
+ expect_command(host.ip(object_variant, action_variant, {
507
+ dev: 'bareudp0',
508
+ name: 'bareudp0',
509
+ type: type,
510
+ type_opts: {
511
+ mode: 'bridge'
512
+ }
513
+ }), "ip link add dev bareudp0 name bareudp0 type #{type} mode bridge")
514
+ end
515
+ end
516
+
517
+ it "prepares #{action_variant} command with hsr" do
518
+ expect_command(host.ip(object_variant, action_variant, {
519
+ dev: 'hsr1',
520
+ name: 'hsr1',
521
+ type: 'hsr',
522
+ type_opts: {
523
+ slave1: 'eth1',
524
+ slave2: 'eth2',
525
+ supervision: '254',
526
+ version: '1',
527
+ proto: '1'
528
+ }
529
+ }), 'ip link add dev hsr1 name hsr1 type hsr slave1 eth1 slave2 eth2 supervision 254 version 1 proto 1')
530
+ end
531
+
532
+ it "prepares #{action_variant} command with bridge" do
533
+ expect_command(host.ip(object_variant, action_variant, {
534
+ dev: 'br0',
535
+ name: 'br0',
536
+ type: 'bridge',
537
+ type_opts: {
538
+ ageing_time: 29_999,
539
+ group_fwd_mask: 0,
540
+ group_address: '01:80:c2:00:00:00',
541
+ forward_delay: 0,
542
+ hello_time: 199,
543
+ max_age: 1999,
544
+ stp_state: 0,
545
+ priority: 32_768,
546
+ vlan_filtering: 0,
547
+ vlan_protocol: '802.1Q',
548
+ vlan_default_pvid: 1,
549
+ vlan_stats_enabled: 1,
550
+ vlan_stats_per_port: 1,
551
+ mcast_snooping: 1,
552
+ mcast_router: 1,
553
+ mcast_query_use_ifaddr: 0,
554
+ mcast_querier: 0,
555
+ mcast_hash_elasticity: 4,
556
+ mcast_hash_max: 512,
557
+ mcast_last_member_count: 2,
558
+ mcast_startup_query_count: 2,
559
+ mcast_last_member_interval: 99,
560
+ mcast_membership_interval: 25_999,
561
+ mcast_querier_interval: 25_499,
562
+ mcast_query_interval: 12_499,
563
+ mcast_query_response_interval: 999,
564
+ mcast_startup_query_interval: 3124,
565
+ mcast_stats_enabled: 0,
566
+ mcast_igmp_version: 2,
567
+ mcast_mld_version: 1,
568
+ nf_call_iptables: 0,
569
+ nf_call_ip6tables: 0,
570
+ nf_call_arptables: 0
571
+ }
572
+ }), 'ip link add dev br0 name br0 type bridge ageing_time 29999 group_fwd_mask 0 group_address 01:80:c2:00:00:00 forward_delay 0 hello_time 199 max_age 1999 stp_state 0 priority 32768 vlan_filtering 0 vlan_protocol 802.1Q vlan_default_pvid 1 vlan_stats_enabled 1 vlan_stats_per_port 1 mcast_snooping 1 mcast_router 1 mcast_query_use_ifaddr 0 mcast_querier 0 mcast_querier_interval 25499 mcast_hash_elasticity 4 mcast_hash_max 512 mcast_last_member_count 2 mcast_last_member_interval 99 mcast_startup_query_count 2 mcast_startup_query_interval 3124 mcast_query_interval 12499 mcast_query_response_interval 999 mcast_membership_interval 25999 mcast_stats_enabled 0 mcast_igmp_version 2 mcast_mld_version 1 nf_call_iptables 0 nf_call_ip6tables 0 nf_call_arptables 0')
573
+ end
574
+
575
+ it "prepares #{action_variant} command with macsec" do
576
+ expect_command(host.ip(object_variant, action_variant, {
577
+ dev: 'eth0',
578
+ name: 'macsec0',
579
+ type: 'macsec',
580
+ type_opts: {
581
+ address: '32:53:41:bd:7c:27',
582
+ port: 11,
583
+ send_sci: 'on',
584
+ sci: '1',
585
+ cipher: 'GCM-AES-128',
586
+ icvlen: 16,
587
+ encrypt: 'on',
588
+ end_station: 'on',
589
+ scb: 'on',
590
+ protect: 'on',
591
+ replay: 'on',
592
+ window: 1,
593
+ validate: 'check',
594
+ encodingsa: '3'
595
+ }
596
+ }), 'ip link add dev eth0 name macsec0 type macsec address 32:53:41:bd:7c:27 port 11 sci 1 cipher GCM-AES-128 icvlen 16 encrypt on send_sci on end_station on scb on protect on replay on window 1 validate check encodingsa 3')
597
+ end
598
+
599
+ it "prepares #{action_variant} command with vrf" do
600
+ expect_command(host.ip(object_variant, action_variant, {
601
+ dev: 'vrf1',
602
+ name: 'vrf1',
603
+ type: 'vrf',
604
+ type_opts: {
605
+ table: 10
606
+ }
607
+ }), 'ip link add dev vrf1 name vrf1 type vrf table 10')
608
+ end
609
+
610
+ it "prepares #{action_variant} command with rmnet" do
611
+ expect_command(host.ip(object_variant, action_variant, {
612
+ dev: 'rmnet0',
613
+ name: 'rmnet0',
614
+ type: 'rmnet',
615
+ type_opts: {
616
+ mux_id: 254
617
+ }
618
+ }), 'ip link add dev rmnet0 name rmnet0 type rmnet mux_id 254')
619
+ end
620
+
621
+ it "prepares #{action_variant} command with xfrm" do
622
+ expect_command(host.ip(object_variant, action_variant, {
623
+ name: 'xfrm3',
624
+ type: 'xfrm',
625
+ type_opts: {
626
+ dev: 'xfrm3',
627
+ if_id: 0
628
+ }
629
+ }), 'ip link add name xfrm3 type xfrm if_id 0')
630
+ end
631
+ end
632
+
633
+ it 'prepares set command' do
634
+ expect_command(host.ip(object_variant, 'set', {
635
+ dev: 'eth10.10',
636
+ direction: 'down'
637
+ }), 'ip link set dev eth10.10 down')
638
+
639
+ expect_command(host.ip(object_variant, 'set', {
640
+ dev: 'eno1.10',
641
+ mtu: 1400,
642
+ direction: 'up',
643
+ arp: 'on',
644
+ multicast: 'on',
645
+ allmulticast: 'on',
646
+ promisc: 'on',
647
+ trailers: 'on',
648
+ protodown: 'on',
649
+ protodown_reason: 30,
650
+ dynamic: 'on',
651
+ name: 'eno1-vlan.10',
652
+ txqueuelen: 256,
653
+ txqlen: 4,
654
+ master: 'eno1',
655
+ address: '172.16.0.2',
656
+ broadcast: 'ff:ff:ff:ff:ff:ff',
657
+ brd: 'ff:ff:ff:ff:ff:ff',
658
+ peer: 'ae:14:7e:e4:6c:64',
659
+ netns: 1154,
660
+ alias: 'eno1-alias',
661
+ group: 0
662
+ }), 'ip link set dev eno1.10 group 0 up arp on multicast on allmulticast on promisc on protodown on protodown_reason 30 dynamic on name eno1-vlan.10 txqueuelen 256 txqlen 4 mtu 1400 address 172.16.0.2 broadcast ff:ff:ff:ff:ff:ff brd ff:ff:ff:ff:ff:ff peer ae:14:7e:e4:6c:64 netns 1154 alias eno1-alias master eno1')
663
+
664
+ expect_command(host.ip(object_variant, 'set', {
665
+ dev: 'eno1.10',
666
+ master: false
667
+ }), 'ip link set dev eno1.10 nomaster')
668
+
669
+ expect do
670
+ host.ip(object_variant, 'set')
671
+ end.to raise_error(ArgumentError)
672
+ end
673
+
674
+ it 'prepares set command with vf' do
675
+ expect_command(host.ip(object_variant, 'set', {
676
+ dev: 'eth0',
677
+ vf: 5,
678
+ mac: 'AD:D9:01:ED:0B:13',
679
+ vlan: 10,
680
+ qos: 1,
681
+ proto: '802.1ad',
682
+ rate: 0,
683
+ max_tx_rate: 0,
684
+ min_tx_rate: 0,
685
+ spoofchk: 'on',
686
+ query_rss: 'on',
687
+ state: 'enable',
688
+ trust: 'on',
689
+ node_guid: 100,
690
+ port_guid: 100
691
+ }), 'ip link set dev eth0 vf 5 mac AD:D9:01:ED:0B:13 vlan 10 qos 1 proto 802.1ad rate 0 max_tx_rate 0 min_tx_rate 0 spoofchk on query_rss on state enable trust on node_guid 100 port_guid 100')
692
+ end
693
+
694
+ it 'prepares set command with xdp' do
695
+ expect_command(host.ip(object_variant, 'set', {
696
+ dev: 'vethcaf7146',
697
+ xdp: 'object',
698
+ object: 'udp.o',
699
+ section: 'dropper_main',
700
+ verbose: true
701
+ }), 'ip link set dev vethcaf7146 xdp object udp.o section dropper_main verbose')
702
+
703
+ expect_command(host.ip(object_variant, 'set', {
704
+ dev: 'vethcaf7146',
705
+ xdp: 'pinned',
706
+ pinned: 'udp.o'
707
+ }), 'ip link set dev vethcaf7146 xdp pinned udp.o')
708
+
709
+ expect_command(host.ip(object_variant, 'set', {
710
+ dev: 'vethcaf7146',
711
+ xdp: 'off'
712
+ }), 'ip link set dev vethcaf7146 xdp off')
713
+ end
714
+
715
+ it 'prepares set command with type opts' do
716
+ expect do
717
+ host.ip(object_variant, 'set', {
718
+ dev: 'eno10.10',
719
+ type: 'bridge_'
720
+ })
721
+ end.to raise_error(ArgumentError)
722
+
723
+ expect_command(host.ip(object_variant, 'set', {
724
+ dev: 'eth0bridge',
725
+ type: 'bridge_slave',
726
+ type_opts: {
727
+ fdb_flush: true,
728
+ state: 1,
729
+ priority: 63,
730
+ cost: 1,
731
+ guard: 'on',
732
+ hairpin: 'off',
733
+ fastleave: 'off',
734
+ root_block: 'on',
735
+ learning: 'on',
736
+ flood: 'on',
737
+ proxy_arp: 'on',
738
+ proxy_arp_wifi: 'off',
739
+ mcast_router: 3,
740
+ mcast_fast_leave: 'on',
741
+ mcast_flood: 'on',
742
+ mcast_to_unicast: 'off',
743
+ group_fwd_mask: 0,
744
+ neigh_suppress: 'on',
745
+ vlan_tunnel: 'on',
746
+ backup_port: 'eth0backup'
747
+ }
748
+ }), 'ip link set dev eth0bridge type bridge_slave fdb_flush state 1 priority 63 cost 1 guard on hairpin off fastleave off root_block on learning on flood on proxy_arp on proxy_arp_wifi off mcast_router 3 mcast_fast_leave on mcast_flood on mcast_to_unicast off group_fwd_mask 0 neigh_suppress on neigh_suppress on backup_port eth0backup')
749
+
750
+ expect_command(host.ip(object_variant, 'set', {
751
+ dev: 'eth0bridge',
752
+ type: 'bridge_slave',
753
+ type_opts: {
754
+ nobackup_port: true
755
+ }
756
+ }), 'ip link set dev eth0bridge type bridge_slave nobackup_port')
757
+
758
+ expect_command(host.ip(object_variant, 'set', {
759
+ dev: 'eth0bond',
760
+ type: 'bond_slave',
761
+ type_opts: {
762
+ queue_id: 1
763
+ }
764
+ }), 'ip link set dev eth0bond type bond_slave queue_id 1')
765
+
766
+ expect_command(host.ip(object_variant, 'set', {
767
+ dev: 'eth1macvlan',
768
+ type: 'macvlan',
769
+ type_opts: {
770
+ mode: 'bridge',
771
+ flag: 'nopromisc',
772
+ mode_opts: 'add',
773
+ mac_address: '19:18:4F:92:5E:CD'
774
+ }
775
+ }), 'ip link set dev eth1macvlan type macvlan mode bridge flag nopromisc add 19:18:4F:92:5E:CD')
776
+
777
+ expect_command(host.ip(object_variant, 'set', {
778
+ dev: 'eth1macvlan',
779
+ type: 'macvlan',
780
+ type_opts: {
781
+ mode_opts: 'del',
782
+ mac_address: '19:18:4F:92:5E:CD'
783
+ }
784
+ }), 'ip link set dev eth1macvlan type macvlan del 19:18:4F:92:5E:CD')
785
+
786
+ expect_command(host.ip(object_variant, 'set', {
787
+ dev: 'eth1macvlan',
788
+ type: 'macvlan',
789
+ type_opts: {
790
+ mode_opts: 'set',
791
+ mac_address: '07:88:8C:11:C3:80'
792
+ }
793
+ }), 'ip link set dev eth1macvlan type macvlan set 07:88:8C:11:C3:80')
794
+
795
+ expect_command(host.ip(object_variant, 'set', {
796
+ dev: 'eth1macvlan',
797
+ type: 'macvtap',
798
+ type_opts: {
799
+ mode_opts: 'set',
800
+ mac_address: ['0D:42:6D:3E:22:B8', '7F:3D:FC:AF:A3:F3']
801
+ }
802
+ }), 'ip link set dev eth1macvlan type macvtap set 0D:42:6D:3E:22:B8 7F:3D:FC:AF:A3:F3')
803
+
804
+ expect_command(host.ip(object_variant, 'set', {
805
+ dev: 'eth1macvlan',
806
+ type: 'macvlan',
807
+ type_opts: {
808
+ mode_opts: 'flush'
809
+ }
810
+ }), 'ip link set dev eth1macvlan type macvlan flush')
811
+ end
812
+ end
813
+ end
814
+ end