@@ -47,21 +47,18 @@ func Test_GetOrCreatePort(t *testing.T) {
47
47
portSecurityGroupID := "f51d1206-fc5a-4f7a-a5c0-2e03e44e4dc0"
48
48
49
49
// Other arbitrary variables passed in to the tests
50
- instanceSecurityGroups := []string {"instance-secgroup" }
51
- securityGroupUUIDs := []string {portSecurityGroupID }
52
50
portSecurityGroupFilters := []infrav1.SecurityGroupFilter {{ID : portSecurityGroupID , Name : "port-secgroup" }}
53
51
valueSpecs := map [string ]string {"key" : "value" }
54
52
55
53
pointerToTrue := pointerTo (true )
56
54
pointerToFalse := pointerTo (false )
57
55
58
56
tests := []struct {
59
- name string
60
- portName string
61
- port infrav1.PortOpts
62
- instanceSecurityGroups []string
63
- tags []string
64
- expect func (m * mock.MockNetworkClientMockRecorder )
57
+ name string
58
+ portName string
59
+ port infrav1.PortOpts
60
+ tags []string
61
+ expect func (m * mock.MockNetworkClientMockRecorder )
65
62
// Note the 'wanted' port isn't so important, since it will be whatever we tell ListPort or CreatePort to return.
66
63
// Mostly in this test suite, we're checking that ListPort/CreatePort is called with the expected port opts.
67
64
want * ports.Port
@@ -75,7 +72,6 @@ func Test_GetOrCreatePort(t *testing.T) {
75
72
ID : netID ,
76
73
},
77
74
},
78
- nil ,
79
75
[]string {},
80
76
func (m * mock.MockNetworkClientMockRecorder ) {
81
77
m .
@@ -99,7 +95,6 @@ func Test_GetOrCreatePort(t *testing.T) {
99
95
ID : netID ,
100
96
},
101
97
},
102
- nil ,
103
98
[]string {},
104
99
func (m * mock.MockNetworkClientMockRecorder ) {
105
100
m .
@@ -123,14 +118,13 @@ func Test_GetOrCreatePort(t *testing.T) {
123
118
true ,
124
119
},
125
120
{
126
- "creates port with defaults (description and secgroups ) if not specified in portOpts" ,
121
+ "creates port with defaults (description) if not specified in portOpts" ,
127
122
"foo-port-1" ,
128
123
infrav1.PortOpts {
129
124
Network : & infrav1.NetworkFilter {
130
125
ID : netID ,
131
126
},
132
127
},
133
- instanceSecurityGroups ,
134
128
[]string {},
135
129
func (m * mock.MockNetworkClientMockRecorder ) {
136
130
// No ports found
@@ -144,7 +138,6 @@ func Test_GetOrCreatePort(t *testing.T) {
144
138
CreateOptsBuilder : ports.CreateOpts {
145
139
Name : "foo-port-1" ,
146
140
Description : "Created by cluster-api-provider-openstack cluster test-cluster" ,
147
- SecurityGroups : & instanceSecurityGroups ,
148
141
NetworkID : netID ,
149
142
AllowedAddressPairs : []ports.AddressPair {},
150
143
},
@@ -170,7 +163,6 @@ func Test_GetOrCreatePort(t *testing.T) {
170
163
},
171
164
IPAddress : "192.168.0.50" ,
172
165
}, {IPAddress : "192.168.1.50" }},
173
- SecurityGroupFilters : portSecurityGroupFilters ,
174
166
AllowedAddressPairs : []infrav1.AddressPair {{
175
167
IPAddress : "10.10.10.10" ,
176
168
MACAddress : "f1:f1:f1:f1:f1:f1" ,
@@ -185,7 +177,6 @@ func Test_GetOrCreatePort(t *testing.T) {
185
177
Tags : []string {"my-port-tag" },
186
178
},
187
179
nil ,
188
- nil ,
189
180
func (m * mock.MockNetworkClientMockRecorder ) {
190
181
portCreateOpts := ports.CreateOpts {
191
182
NetworkID : netID ,
@@ -201,7 +192,6 @@ func Test_GetOrCreatePort(t *testing.T) {
201
192
IPAddress : "192.168.1.50" ,
202
193
},
203
194
},
204
- SecurityGroups : & securityGroupUUIDs ,
205
195
AllowedAddressPairs : []ports.AddressPair {{
206
196
IPAddress : "10.10.10.10" ,
207
197
MACAddress : "f1:f1:f1:f1:f1:f1" ,
@@ -267,7 +257,6 @@ func Test_GetOrCreatePort(t *testing.T) {
267
257
}},
268
258
},
269
259
nil ,
270
- nil ,
271
260
func (m * mock.MockNetworkClientMockRecorder ) {
272
261
m .
273
262
ListPort (ports.ListOpts {
@@ -295,37 +284,24 @@ func Test_GetOrCreatePort(t *testing.T) {
295
284
true ,
296
285
},
297
286
{
298
- "overrides default (instance) security groups if port security groups are specified" ,
287
+ "fails to create port with specified portOpts if security group filters are specified" ,
299
288
"foo-port-1" ,
300
289
infrav1.PortOpts {
301
290
Network : & infrav1.NetworkFilter {
302
291
ID : netID ,
303
292
},
304
293
SecurityGroupFilters : portSecurityGroupFilters ,
305
294
},
306
- instanceSecurityGroups ,
307
295
[]string {},
308
296
func (m * mock.MockNetworkClientMockRecorder ) {
309
- // No ports found
310
297
m .
311
298
ListPort (ports.ListOpts {
312
299
Name : "foo-port-1" ,
313
300
NetworkID : netID ,
314
301
}).Return ([]ports.Port {}, nil )
315
- m .
316
- CreatePort (portsbinding.CreateOptsExt {
317
- CreateOptsBuilder : ports.CreateOpts {
318
- Name : "foo-port-1" ,
319
- Description : "Created by cluster-api-provider-openstack cluster test-cluster" ,
320
- SecurityGroups : & securityGroupUUIDs ,
321
- NetworkID : netID ,
322
- AllowedAddressPairs : []ports.AddressPair {},
323
- },
324
- },
325
- ).Return (& ports.Port {ID : portID1 }, nil )
326
302
},
327
- & ports. Port { ID : portID1 } ,
328
- false ,
303
+ nil ,
304
+ true ,
329
305
},
330
306
{
331
307
"creates port with instance tags when port tags aren't specified" ,
@@ -335,7 +311,6 @@ func Test_GetOrCreatePort(t *testing.T) {
335
311
ID : netID ,
336
312
},
337
313
},
338
- nil ,
339
314
[]string {"my-instance-tag" },
340
315
func (m * mock.MockNetworkClientMockRecorder ) {
341
316
// No ports found
@@ -366,7 +341,6 @@ func Test_GetOrCreatePort(t *testing.T) {
366
341
},
367
342
Tags : []string {"my-port-tag" },
368
343
},
369
- nil ,
370
344
[]string {"my-instance-tag" },
371
345
func (m * mock.MockNetworkClientMockRecorder ) {
372
346
// No ports found
@@ -399,7 +373,6 @@ func Test_GetOrCreatePort(t *testing.T) {
399
373
},
400
374
Trunk : pointerToTrue ,
401
375
},
402
- nil ,
403
376
[]string {"my-tag" },
404
377
func (m * mock.MockNetworkClientMockRecorder ) {
405
378
// No ports found
@@ -451,7 +424,6 @@ func Test_GetOrCreatePort(t *testing.T) {
451
424
},
452
425
},
453
426
nil ,
454
- nil ,
455
427
func (m * mock.MockNetworkClientMockRecorder ) {
456
428
// No ports found
457
429
m .
@@ -482,7 +454,6 @@ func Test_GetOrCreatePort(t *testing.T) {
482
454
},
483
455
PropagateUplinkStatus : pointerToTrue ,
484
456
},
485
- instanceSecurityGroups ,
486
457
[]string {},
487
458
func (m * mock.MockNetworkClientMockRecorder ) {
488
459
// No ports found
@@ -496,7 +467,6 @@ func Test_GetOrCreatePort(t *testing.T) {
496
467
CreateOptsBuilder : ports.CreateOpts {
497
468
Name : "foo-port-1" ,
498
469
Description : "Created by cluster-api-provider-openstack cluster test-cluster" ,
499
- SecurityGroups : & instanceSecurityGroups ,
500
470
NetworkID : netID ,
501
471
AllowedAddressPairs : []ports.AddressPair {},
502
472
PropagateUplinkStatus : pointerToTrue ,
@@ -523,7 +493,6 @@ func Test_GetOrCreatePort(t *testing.T) {
523
493
"test-cluster" ,
524
494
tt .portName ,
525
495
& tt .port ,
526
- tt .instanceSecurityGroups ,
527
496
tt .tags ,
528
497
)
529
498
if tt .wantErr {
0 commit comments