1212use OpenStack \Compute \v2 \Models \Server ;
1313use OpenStack \Integration \TestCase ;
1414use OpenStack \Integration \Utils ;
15+ use OpenStack \Networking \v2 \Extensions \SecurityGroups \Models \SecurityGroup ;
1516use OpenStack \Networking \v2 \Models \Network ;
1617use OpenStack \Networking \v2 \Models \Subnet ;
1718use OpenStack \Networking \v2 \Service as NetworkService ;
1819use OpenStack \BlockStorage \v2 \Service as BlockStorageService ;
20+ use OpenStack \Networking \v2 \Extensions \SecurityGroups \Service as SecurityGroupService ;
1921
2022class CoreTest extends TestCase
2123{
@@ -24,6 +26,8 @@ class CoreTest extends TestCase
2426 const SUBNET = 'phptest_subnet ' ;
2527 const VOLUME = 'phptest_volume ' ;
2628
29+ const SECGROUP = 'phptest_secgroup ' ;
30+
2731 const IMAGE = 'cirros ' ;
2832
2933 /** @var NetworkService */
@@ -32,6 +36,9 @@ class CoreTest extends TestCase
3236 /** @var BlockStorageService */
3337 private $ blockStorageService ;
3438
39+ /** @var SecurityGroupService */
40+ private $ secgroupService ;
41+
3542 /** @var Network */
3643 private $ network ;
3744
@@ -41,6 +48,9 @@ class CoreTest extends TestCase
4148 /** @var Volume */
4249 private $ volume ;
4350
51+ /** @var SecurityGroup */
52+ private $ secgroup ;
53+
4454 // Core test
4555 private $ service ;
4656 private $ serverId ;
@@ -68,6 +78,12 @@ private function getNetworkService()
6878 return $ this ->networkService ;
6979 }
7080
81+ private function getSecurityGroupService (): SecurityGroupService
82+ {
83+ $ this ->secgroupService = $ this ->secgroupService ?? Utils::getOpenStack ()->networkingV2ExtSecGroups ();
84+ return $ this ->secgroupService ;
85+ }
86+
7187 private function getBlockStorageService ()
7288 {
7389 if (!$ this ->blockStorageService ) {
@@ -100,7 +116,7 @@ protected function setUp()
100116 ]
101117 );
102118
103- $ this ->logStep ('Created network {name} with id {id} ' , ['name ' => $ this ->network ->name , 'id ' => $ this ->network ->id ]);
119+ $ this ->logStep ('Created network {name} with {id} ' , ['name ' => $ this ->network ->name , 'id ' => $ this ->network ->id ]);
104120
105121 $ this ->subnet = $ this ->getNetworkService ()->createSubnet (
106122 [
@@ -111,7 +127,7 @@ protected function setUp()
111127 ]
112128 );
113129
114- $ this ->logStep ('Created subnet {name} with id {id} ' , ['name ' => $ this ->subnet ->name , 'id ' => $ this ->subnet ->id ]);
130+ $ this ->logStep ('Created subnet {name} with {id} ' , ['name ' => $ this ->subnet ->name , 'id ' => $ this ->subnet ->id ]);
115131
116132 $ this ->volume = $ this ->getBlockStorageService ()->createVolume (
117133 [
@@ -121,7 +137,11 @@ protected function setUp()
121137 ]
122138 );
123139
124- $ this ->logStep ('Created volume {name} with id {id} ' , ['name ' => $ this ->volume ->name , 'id ' => $ this ->volume ->id ]);
140+ $ this ->logStep ('Created volume {name} with {id} ' , ['name ' => $ this ->volume ->name , 'id ' => $ this ->volume ->id ]);
141+
142+ $ this ->getSecurityGroupService ()->createSecurityGroup (['name ' => self ::SECGROUP ]);
143+
144+ $ this ->logStep ('Created security group {secgroup} ' , ['secgroup ' => self ::SECGROUP ]);
125145 }
126146
127147 public function runTests ()
@@ -193,12 +213,14 @@ public function runTests()
193213 // Interface attachments
194214 $ this ->createInterfaceAttachment ();
195215 } finally {
216+ $ this ->logger ->info ('Tearing down ' );
196217 // Teardown
197218 $ this ->deleteServer ();
198219 $ this ->deleteFlavor ();
199220 $ this ->subnet ->delete ();
200221 $ this ->network ->delete ();
201222 $ this ->volume ->delete ();
223+ $ this ->secgroup ->delete ();
202224 }
203225
204226 $ this ->outputTimeTaken ();
@@ -341,6 +363,7 @@ private function resizeServer()
341363
342364 private function confirmServerResize ()
343365 {
366+ $ this ->logger ->info ('Waiting for status VERIFY_RESIZE ' );
344367 $ replacements = ['{serverId} ' => $ this ->serverId ];
345368
346369 /** @var $server \OpenStack\Compute\v2\Models\Server */
@@ -623,8 +646,8 @@ private function getLimits()
623646 private function addSecurityGroupToServer ()
624647 {
625648 $ replacements = [
626- '{serverId} ' => $ this ->serverId ,
627- '{secGroupName} ' => ' default '
649+ '{serverId} ' => $ this ->serverId ,
650+ '{secGroupName} ' => self :: SECGROUP ,
628651 ];
629652
630653 require_once $ this ->sampleFile ($ replacements , 'servers/add_security_group.php ' );
@@ -650,8 +673,8 @@ private function listServerSecurityGroups()
650673 private function removeServerSecurityGroup ()
651674 {
652675 $ replacements = [
653- '{serverId} ' => $ this ->serverId ,
654- '{secGroupName} ' => ' default '
676+ '{serverId} ' => $ this ->serverId ,
677+ '{secGroupName} ' => self :: SECGROUP ,
655678 ];
656679
657680 require_once $ this ->sampleFile ($ replacements , 'servers/remove_security_group.php ' );
0 commit comments