|
3 | 3 | namespace OpenStack\Test\Compute\v2\Models;
|
4 | 4 |
|
5 | 5 | use GuzzleHttp\Psr7\Response;
|
| 6 | +use OpenStack\BlockStorage\v2\Models\VolumeAttachment; |
6 | 7 | use OpenStack\Compute\v2\Api;
|
7 | 8 | use OpenStack\Compute\v2\Models\Flavor;
|
8 | 9 | use OpenStack\Compute\v2\Models\Server;
|
9 | 10 | use OpenCloud\Test\TestCase;
|
| 11 | +use OpenStack\Networking\v2\Extensions\SecurityGroups\Models\SecurityGroup; |
10 | 12 | use Prophecy\Argument;
|
11 | 13 |
|
12 | 14 | class ServerTest extends TestCase
|
13 | 15 | {
|
| 16 | + /** @var Server */ |
14 | 17 | private $server;
|
15 | 18 |
|
16 | 19 | public function setUp()
|
@@ -246,4 +249,79 @@ public function test_it_deletes_a_metadata_item()
|
246 | 249 |
|
247 | 250 | $this->assertNull($this->server->deleteMetadataItem('fooKey'));
|
248 | 251 | }
|
| 252 | + |
| 253 | + public function test_it_lists_security_groups() |
| 254 | + { |
| 255 | + $this->setupMock('GET', 'servers/serverId/os-security-groups', null, [], 'server-security-groups-get'); |
| 256 | + |
| 257 | + $securityGroups = iterator_to_array($this->server->listSecurityGroups()); |
| 258 | + |
| 259 | + $this->assertInstanceOf(SecurityGroup::class, $securityGroups[0]); |
| 260 | + } |
| 261 | + |
| 262 | + public function test_it_lists_volume_attachments() |
| 263 | + { |
| 264 | + $this->setupMock('GET', 'servers/serverId/os-volume_attachments', null, [], 'server-volume-attachments-get'); |
| 265 | + |
| 266 | + $volumeAttachments = iterator_to_array($this->server->listVolumeAttachments()); |
| 267 | + |
| 268 | + $this->assertInstanceOf(VolumeAttachment::class, $volumeAttachments[0]); |
| 269 | + } |
| 270 | + |
| 271 | + public function test_it_remove_security_group() |
| 272 | + { |
| 273 | + $opt = [ |
| 274 | + 'name' => 'secgroup_to_remove' |
| 275 | + ]; |
| 276 | + |
| 277 | + $expectedJson = [ |
| 278 | + 'removeSecurityGroup' => $opt |
| 279 | + ]; |
| 280 | + |
| 281 | + $this->setupMock('POST', 'servers/serverId/action', $expectedJson, [], new Response(202)); |
| 282 | + |
| 283 | + $this->server->removeSecurityGroup($opt); |
| 284 | + } |
| 285 | + |
| 286 | + public function test_it_add_security_group() |
| 287 | + { |
| 288 | + $opt = [ |
| 289 | + 'name' => 'secgroup_to_add' |
| 290 | + ]; |
| 291 | + |
| 292 | + $expectedJson = [ |
| 293 | + 'addSecurityGroup' => $opt |
| 294 | + ]; |
| 295 | + |
| 296 | + $this->setupMock('POST', 'servers/serverId/action', $expectedJson, [], new Response(202)); |
| 297 | + |
| 298 | + $this->server->addSecurityGroup($opt); |
| 299 | + } |
| 300 | + |
| 301 | + public function test_it_attaches_volume() |
| 302 | + { |
| 303 | + $volumeId = 'fooooobarrrr'; |
| 304 | + |
| 305 | + $expectedJson = [ |
| 306 | + 'volumeAttachment' => ['volumeId' => $volumeId] |
| 307 | + ]; |
| 308 | + |
| 309 | + $this->setupMock('POST', 'servers/serverId/os-volume_attachments', $expectedJson, [], 'server-volume-attach-post'); |
| 310 | + |
| 311 | + $volumeAttachment = $this->server->attachVolume($volumeId); |
| 312 | + $this->assertInstanceOf(VolumeAttachment::class, $volumeAttachment); |
| 313 | + $this->assertEquals('serverId', $volumeAttachment->serverId); |
| 314 | + $this->assertEquals('a26887c6-c47b-4654-abb5-dfadf7d3f803', $volumeAttachment->id); |
| 315 | + $this->assertEquals($volumeId, $volumeAttachment->volumeId); |
| 316 | + $this->assertEquals('/dev/vdd', $volumeAttachment->device); |
| 317 | + } |
| 318 | + |
| 319 | + public function test_it_detaches_volume() |
| 320 | + { |
| 321 | + $attachmentId = 'a-dummy-attachment-id'; |
| 322 | + |
| 323 | + $this->setupMock('DELETE', 'servers/serverId/os-volume_attachments/' . $attachmentId, null, [], new Response(202)); |
| 324 | + |
| 325 | + $this->server->detachVolume($attachmentId); |
| 326 | + } |
249 | 327 | }
|
0 commit comments