Skip to content

Commit e83d546

Browse files
committed
Server action tests: volume attachment, security group
1 parent 1c369ff commit e83d546

File tree

4 files changed

+123
-0
lines changed

4 files changed

+123
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
HTTP/1.1 200 OK
2+
Content-Type: application/json
3+
4+
{
5+
"security_groups": [
6+
{
7+
"description": "default",
8+
"id": 1,
9+
"name": "default",
10+
"rules": [],
11+
"tenant_id": "openstack"
12+
}
13+
]
14+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
HTTP/1.1 200 OK
2+
Content-Type: application/json
3+
4+
5+
{
6+
"volumeAttachment": {
7+
"device": "/dev/vdd",
8+
"id": "a26887c6-c47b-4654-abb5-dfadf7d3f803",
9+
"serverId": "serverId",
10+
"volumeId": "fooooobarrrr"
11+
}
12+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
HTTP/1.1 200 OK
2+
Content-Type: application/json
3+
4+
{
5+
"volumeAttachments": [
6+
{
7+
"device": "/dev/sdd",
8+
"id": "a26887c6-c47b-4654-abb5-dfadf7d3f803",
9+
"serverId": "4d8c3732-a248-40ed-bebc-539a6ffd25c0",
10+
"volumeId": "a26887c6-c47b-4654-abb5-dfadf7d3f803"
11+
},
12+
{
13+
"device": "/dev/sdc",
14+
"id": "a26887c6-c47b-4654-abb5-dfadf7d3f804",
15+
"serverId": "4d8c3732-a248-40ed-bebc-539a6ffd25c0",
16+
"volumeId": "a26887c6-c47b-4654-abb5-dfadf7d3f804"
17+
}
18+
]
19+
}

tests/unit/Compute/v2/Models/ServerTest.php

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@
33
namespace OpenStack\Test\Compute\v2\Models;
44

55
use GuzzleHttp\Psr7\Response;
6+
use OpenStack\BlockStorage\v2\Models\VolumeAttachment;
67
use OpenStack\Compute\v2\Api;
78
use OpenStack\Compute\v2\Models\Flavor;
89
use OpenStack\Compute\v2\Models\Server;
910
use OpenCloud\Test\TestCase;
11+
use OpenStack\Networking\v2\Extensions\SecurityGroups\Models\SecurityGroup;
1012
use Prophecy\Argument;
1113

1214
class ServerTest extends TestCase
1315
{
16+
/** @var Server */
1417
private $server;
1518

1619
public function setUp()
@@ -246,4 +249,79 @@ public function test_it_deletes_a_metadata_item()
246249

247250
$this->assertNull($this->server->deleteMetadataItem('fooKey'));
248251
}
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+
}
249327
}

0 commit comments

Comments
 (0)