@@ -368,3 +368,139 @@ func (s *ControllerAddressesSuite) TestWatchAPIHostPortsForAgents(c *gc.C) {
368
368
statetesting .AssertStop (c , w )
369
369
wc .AssertClosed ()
370
370
}
371
+
372
+ type CAASAddressesSuite struct {
373
+ statetesting.StateSuite
374
+ }
375
+
376
+ var _ = gc .Suite (& CAASAddressesSuite {})
377
+
378
+ func (s * CAASAddressesSuite ) SetUpTest (c * gc.C ) {
379
+ s .StateSuite .SetUpTest (c )
380
+ state .SetModelTypeToCAAS (c , s .State , s .Model )
381
+ }
382
+
383
+ func (s * CAASAddressesSuite ) TestAPIHostPortsCloudLocalOnly (c * gc.C ) {
384
+ machineAddr := network.MachineAddress {
385
+ Value : "10.10.10.10" ,
386
+ Type : network .IPv4Address ,
387
+ Scope : network .ScopeCloudLocal ,
388
+ }
389
+
390
+ _ , err := s .State .SaveCloudService (state.SaveCloudServiceArgs {
391
+ Id : s .Model .ControllerUUID (),
392
+ ProviderId : "whatever" ,
393
+ Addresses : network.SpaceAddresses {{MachineAddress : machineAddr }},
394
+ })
395
+ c .Assert (err , jc .ErrorIsNil )
396
+
397
+ exp := []network.SpaceHostPorts {{{
398
+ SpaceAddress : network.SpaceAddress {MachineAddress : machineAddr },
399
+ NetPort : 17777 ,
400
+ }}}
401
+
402
+ addrs , err := s .State .APIHostPortsForAgents ()
403
+ c .Assert (err , jc .ErrorIsNil )
404
+ c .Assert (addrs , gc .DeepEquals , exp )
405
+
406
+ addrs , err = s .State .APIHostPortsForClients ()
407
+ c .Assert (err , jc .ErrorIsNil )
408
+ c .Assert (addrs , gc .DeepEquals , exp )
409
+ }
410
+
411
+ func (s * CAASAddressesSuite ) TestAPIHostPortsPublicOnly (c * gc.C ) {
412
+ machineAddr := network.MachineAddress {
413
+ Value : "10.10.10.10" ,
414
+ Type : network .IPv4Address ,
415
+ Scope : network .ScopePublic ,
416
+ }
417
+
418
+ _ , err := s .State .SaveCloudService (state.SaveCloudServiceArgs {
419
+ Id : s .Model .ControllerUUID (),
420
+ ProviderId : "whatever" ,
421
+ Addresses : network.SpaceAddresses {{MachineAddress : machineAddr }},
422
+ })
423
+ c .Assert (err , jc .ErrorIsNil )
424
+
425
+ exp := []network.SpaceHostPorts {{{
426
+ SpaceAddress : network.SpaceAddress {MachineAddress : machineAddr },
427
+ NetPort : 17777 ,
428
+ }}}
429
+
430
+ addrs , err := s .State .APIHostPortsForAgents ()
431
+ c .Assert (err , jc .ErrorIsNil )
432
+ c .Assert (addrs , gc .DeepEquals , exp )
433
+
434
+ addrs , err = s .State .APIHostPortsForClients ()
435
+ c .Assert (err , jc .ErrorIsNil )
436
+ c .Assert (addrs , gc .DeepEquals , exp )
437
+ }
438
+
439
+ func (s * CAASAddressesSuite ) TestAPIHostPortsMultiple (c * gc.C ) {
440
+ machineAddr1 := network.MachineAddress {
441
+ Value : "10.10.10.1" ,
442
+ Type : network .IPv4Address ,
443
+ Scope : network .ScopePublic ,
444
+ }
445
+ machineAddr2 := network.MachineAddress {
446
+ Value : "10.10.10.2" ,
447
+ Type : network .IPv4Address ,
448
+ Scope : network .ScopePublic ,
449
+ }
450
+ machineAddr3 := network.MachineAddress {
451
+ Value : "100.10.10.1" ,
452
+ Type : network .IPv4Address ,
453
+ Scope : network .ScopeCloudLocal ,
454
+ }
455
+ machineAddr4 := network.MachineAddress {
456
+ Value : "100.10.10.2" ,
457
+ Type : network .IPv4Address ,
458
+ Scope : network .ScopeCloudLocal ,
459
+ }
460
+
461
+ _ , err := s .State .SaveCloudService (state.SaveCloudServiceArgs {
462
+ Id : s .Model .ControllerUUID (),
463
+ ProviderId : "whatever" ,
464
+ Addresses : network.SpaceAddresses {
465
+ {MachineAddress : machineAddr1 },
466
+ {MachineAddress : machineAddr2 },
467
+ {MachineAddress : machineAddr3 },
468
+ {MachineAddress : machineAddr4 },
469
+ },
470
+ })
471
+ c .Assert (err , jc .ErrorIsNil )
472
+
473
+ addrs , err := s .State .APIHostPortsForAgents ()
474
+ c .Assert (err , jc .ErrorIsNil )
475
+
476
+ // Local-cloud addresses must come first.
477
+ c .Assert (addrs [0 ][:2 ], jc .SameContents , network.SpaceHostPorts {
478
+ {
479
+ SpaceAddress : network.SpaceAddress {MachineAddress : machineAddr3 },
480
+ NetPort : 17777 ,
481
+ },
482
+ {
483
+ SpaceAddress : network.SpaceAddress {MachineAddress : machineAddr4 },
484
+ NetPort : 17777 ,
485
+ },
486
+ })
487
+
488
+ exp := network.SpaceHostPorts {
489
+ {
490
+ SpaceAddress : network.SpaceAddress {MachineAddress : machineAddr1 },
491
+ NetPort : 17777 ,
492
+ },
493
+ {
494
+ SpaceAddress : network.SpaceAddress {MachineAddress : machineAddr2 },
495
+ NetPort : 17777 ,
496
+ },
497
+ }
498
+
499
+ // Public ones should also follow.
500
+ c .Assert (addrs [0 ][2 :], jc .SameContents , exp )
501
+
502
+ // Only the public ones should be returned.
503
+ addrs , err = s .State .APIHostPortsForClients ()
504
+ c .Assert (err , jc .ErrorIsNil )
505
+ c .Assert (addrs , gc .DeepEquals , []network.SpaceHostPorts {exp })
506
+ }
0 commit comments