12
12
use OpenStack \Compute \v2 \Models \Server ;
13
13
use OpenStack \Integration \TestCase ;
14
14
use OpenStack \Integration \Utils ;
15
+ use OpenStack \Networking \v2 \Extensions \SecurityGroups \Models \SecurityGroup ;
15
16
use OpenStack \Networking \v2 \Models \Network ;
16
17
use OpenStack \Networking \v2 \Models \Subnet ;
17
18
use OpenStack \Networking \v2 \Service as NetworkService ;
18
19
use OpenStack \BlockStorage \v2 \Service as BlockStorageService ;
20
+ use OpenStack \Networking \v2 \Extensions \SecurityGroups \Service as SecurityGroupService ;
19
21
20
22
class CoreTest extends TestCase
21
23
{
@@ -24,6 +26,8 @@ class CoreTest extends TestCase
24
26
const SUBNET = 'phptest_subnet ' ;
25
27
const VOLUME = 'phptest_volume ' ;
26
28
29
+ const SECGROUP = 'phptest_secgroup ' ;
30
+
27
31
const IMAGE = 'cirros ' ;
28
32
29
33
/** @var NetworkService */
@@ -32,6 +36,9 @@ class CoreTest extends TestCase
32
36
/** @var BlockStorageService */
33
37
private $ blockStorageService ;
34
38
39
+ /** @var SecurityGroupService */
40
+ private $ secgroupService ;
41
+
35
42
/** @var Network */
36
43
private $ network ;
37
44
@@ -41,6 +48,9 @@ class CoreTest extends TestCase
41
48
/** @var Volume */
42
49
private $ volume ;
43
50
51
+ /** @var SecurityGroup */
52
+ private $ secgroup ;
53
+
44
54
// Core test
45
55
private $ service ;
46
56
private $ serverId ;
@@ -68,6 +78,12 @@ private function getNetworkService()
68
78
return $ this ->networkService ;
69
79
}
70
80
81
+ private function getSecurityGroupService (): SecurityGroupService
82
+ {
83
+ $ this ->secgroupService = $ this ->secgroupService ?? Utils::getOpenStack ()->networkingV2ExtSecGroups ();
84
+ return $ this ->secgroupService ;
85
+ }
86
+
71
87
private function getBlockStorageService ()
72
88
{
73
89
if (!$ this ->blockStorageService ) {
@@ -100,7 +116,7 @@ protected function setUp()
100
116
]
101
117
);
102
118
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 ]);
104
120
105
121
$ this ->subnet = $ this ->getNetworkService ()->createSubnet (
106
122
[
@@ -111,7 +127,7 @@ protected function setUp()
111
127
]
112
128
);
113
129
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 ]);
115
131
116
132
$ this ->volume = $ this ->getBlockStorageService ()->createVolume (
117
133
[
@@ -121,7 +137,11 @@ protected function setUp()
121
137
]
122
138
);
123
139
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 ]);
125
145
}
126
146
127
147
public function runTests ()
@@ -193,12 +213,14 @@ public function runTests()
193
213
// Interface attachments
194
214
$ this ->createInterfaceAttachment ();
195
215
} finally {
216
+ $ this ->logger ->info ('Tearing down ' );
196
217
// Teardown
197
218
$ this ->deleteServer ();
198
219
$ this ->deleteFlavor ();
199
220
$ this ->subnet ->delete ();
200
221
$ this ->network ->delete ();
201
222
$ this ->volume ->delete ();
223
+ $ this ->secgroup ->delete ();
202
224
}
203
225
204
226
$ this ->outputTimeTaken ();
@@ -341,6 +363,7 @@ private function resizeServer()
341
363
342
364
private function confirmServerResize ()
343
365
{
366
+ $ this ->logger ->info ('Waiting for status VERIFY_RESIZE ' );
344
367
$ replacements = ['{serverId} ' => $ this ->serverId ];
345
368
346
369
/** @var $server \OpenStack\Compute\v2\Models\Server */
@@ -623,8 +646,8 @@ private function getLimits()
623
646
private function addSecurityGroupToServer ()
624
647
{
625
648
$ replacements = [
626
- '{serverId} ' => $ this ->serverId ,
627
- '{secGroupName} ' => ' default '
649
+ '{serverId} ' => $ this ->serverId ,
650
+ '{secGroupName} ' => self :: SECGROUP ,
628
651
];
629
652
630
653
require_once $ this ->sampleFile ($ replacements , 'servers/add_security_group.php ' );
@@ -650,8 +673,8 @@ private function listServerSecurityGroups()
650
673
private function removeServerSecurityGroup ()
651
674
{
652
675
$ replacements = [
653
- '{serverId} ' => $ this ->serverId ,
654
- '{secGroupName} ' => ' default '
676
+ '{serverId} ' => $ this ->serverId ,
677
+ '{secGroupName} ' => self :: SECGROUP ,
655
678
];
656
679
657
680
require_once $ this ->sampleFile ($ replacements , 'servers/remove_security_group.php ' );
0 commit comments