@@ -218,7 +218,7 @@ func (s *LiveTests) TestSecurityGroupsV2(c *gc.C) {
218
218
c .Errorf ("expected to find added security group %s" , newSecGrp )
219
219
}
220
220
// Change the created SecurityGroup's name
221
- updatedSecGroup , err := s .neutron .UpdateSecurityGroupV2 (newSecGrp .Id , "NameChanged" , "" )
221
+ updatedSecGroup , err := s .neutron .UpdateSecurityGroupV2 (newSecGrp .Id , "NameChanged" , "" , [] string {} )
222
222
c .Assert (err , gc .IsNil )
223
223
// Verify the name change
224
224
foundSecGrps , err := s .neutron .SecurityGroupByNameV2 (updatedSecGroup .Name )
@@ -238,6 +238,96 @@ func (s *LiveTests) TestSecurityGroupsV2(c *gc.C) {
238
238
c .Assert (err , gc .Not (gc .IsNil ))
239
239
}
240
240
241
+ func (s * LiveTests ) TestUpdateSecurityGroupsWithTagsV2 (c * gc.C ) {
242
+ newSecGrp , err := s .neutron .CreateSecurityGroupV2 ("SecurityGroupTest" , "Testing create security group" , []string {})
243
+ c .Assert (err , gc .IsNil )
244
+ c .Assert (newSecGrp , gc .Not (gc .IsNil ))
245
+ c .Assert (newSecGrp .Tags , gc .HasLen , 0 )
246
+ defer s .deleteSecurityGroup (newSecGrp .Id , c )
247
+ query := neutron.ListSecurityGroupsV2Query {}
248
+ secGrps , err := s .neutron .ListSecurityGroupsV2 (query )
249
+ c .Assert (err , gc .IsNil )
250
+ c .Assert (secGrps , gc .Not (gc .HasLen ), 0 )
251
+ var found bool
252
+ for _ , secGrp := range secGrps {
253
+ c .Check (secGrp .Id , gc .Not (gc .Equals ), "" )
254
+ c .Check (secGrp .Name , gc .Not (gc .Equals ), "" )
255
+ c .Check (secGrp .Description , gc .Not (gc .Equals ), "" )
256
+ c .Check (secGrp .TenantId , gc .Not (gc .Equals ), "" )
257
+ // Is this the SecurityGroup we just created?
258
+ if secGrp .Id == newSecGrp .Id {
259
+ found = true
260
+ }
261
+ }
262
+ if ! found {
263
+ c .Errorf ("expected to find added security group %s" , newSecGrp )
264
+ }
265
+ // Change the created SecurityGroup's name
266
+ updatedSecGroup , err := s .neutron .UpdateSecurityGroupV2 (newSecGrp .Id , "NameChanged" , "" , []string {"new-tag-here" })
267
+ c .Assert (err , gc .IsNil )
268
+ // Verify the name change
269
+ foundSecGrps , err := s .neutron .SecurityGroupByNameV2 (updatedSecGroup .Name )
270
+ c .Assert (err , gc .IsNil )
271
+ c .Assert (foundSecGrps , gc .Not (gc .HasLen ), 0 )
272
+ c .Assert (updatedSecGroup .Tags , gc .HasLen , 1 )
273
+ c .Assert (updatedSecGroup .Tags [0 ], gc .Equals , "new-tag-here" )
274
+ found = false
275
+ for _ , secGrp := range foundSecGrps {
276
+ if secGrp .Id == updatedSecGroup .Id {
277
+ found = true
278
+ break
279
+ }
280
+ }
281
+ if ! found {
282
+ c .Errorf ("expected to find added security group %s, when requested by name" , updatedSecGroup .Name )
283
+ }
284
+ _ , err = s .neutron .SecurityGroupByNameV2 (newSecGrp .Name )
285
+ c .Assert (err , gc .Not (gc .IsNil ))
286
+ }
287
+
288
+ func (s * LiveTests ) TestUpdateSecurityGroupsWithTagsV2Rollback (c * gc.C ) {
289
+ newSecGrp , err := s .neutron .CreateSecurityGroupV2 ("SecurityGroupTest" , "Testing create security group" , []string {"awesome-group" })
290
+ c .Assert (err , gc .IsNil )
291
+ c .Assert (newSecGrp , gc .Not (gc .IsNil ))
292
+ c .Assert (newSecGrp .Tags , gc .HasLen , 1 )
293
+ defer s .deleteSecurityGroup (newSecGrp .Id , c )
294
+ query := neutron.ListSecurityGroupsV2Query {
295
+ Tags : []string {"awesome-group" },
296
+ }
297
+ secGrps , err := s .neutron .ListSecurityGroupsV2 (query )
298
+ c .Assert (err , gc .IsNil )
299
+ c .Assert (secGrps , gc .Not (gc .HasLen ), 0 )
300
+ var found bool
301
+ for _ , secGrp := range secGrps {
302
+ c .Check (secGrp .Id , gc .Not (gc .Equals ), "" )
303
+ c .Check (secGrp .Name , gc .Not (gc .Equals ), "" )
304
+ c .Check (secGrp .Description , gc .Not (gc .Equals ), "" )
305
+ c .Check (secGrp .TenantId , gc .Not (gc .Equals ), "" )
306
+ // Is this the SecurityGroup we just created?
307
+ if secGrp .Id == newSecGrp .Id {
308
+ found = true
309
+ }
310
+ }
311
+ if ! found {
312
+ c .Errorf ("expected to find added security group %s" , newSecGrp )
313
+ }
314
+ // The given tag forces it to rollback
315
+ updatedSecGroup , err := s .neutron .UpdateSecurityGroupV2 (newSecGrp .Id , "NameChanged" , "" , []string {"unit-test-rollback" })
316
+ c .Assert (updatedSecGroup , gc .IsNil )
317
+ c .Assert (err , gc .NotNil )
318
+ c .Assert (strings .Contains (err .Error (), "updating tags failed, rolled back security group" ), gc .Equals , true )
319
+ // Verify that the name is still the same
320
+ foundSecGrps , err := s .neutron .SecurityGroupByNameV2 (newSecGrp .Name )
321
+ c .Assert (foundSecGrps , gc .HasLen , 1 )
322
+ c .Assert (err , gc .IsNil )
323
+ c .Assert (foundSecGrps , gc .NotNil )
324
+ c .Assert (foundSecGrps [0 ].Name , gc .Equals , "SecurityGroupTest" )
325
+ c .Assert (foundSecGrps [0 ].Tags , gc .HasLen , 1 )
326
+
327
+ nonExistingGroups , _ := s .neutron .SecurityGroupByNameV2 ("NameChanged" )
328
+ c .Assert (nonExistingGroups , gc .HasLen , 0 )
329
+ }
330
+
241
331
func (s * LiveTests ) TestSecurityGroupsV2WithTags (c * gc.C ) {
242
332
newSecGrp , err := s .neutron .CreateSecurityGroupV2 ("SecurityGroupTest" , "Testing create security group" , []string {"awesome-group" })
243
333
c .Assert (err , gc .IsNil )
0 commit comments