-
Notifications
You must be signed in to change notification settings - Fork 157
Expand file tree
/
Copy pathServerGroupTest.php
More file actions
145 lines (119 loc) · 4.45 KB
/
ServerGroupTest.php
File metadata and controls
145 lines (119 loc) · 4.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<?php
namespace OpenStack\Sample\Compute\v2;
use OpenStack\Common\Error\BadResponseError;
use OpenStack\Compute\v2\Models\Server;
use OpenStack\Compute\v2\Models\ServerGroup;
use RuntimeException;
class ServerGroupTest extends TestCase
{
private function assertPolicy(ServerGroup $serverGroup, string $expected): void
{
$this->assertContains($expected, $serverGroup->policies);
$this->assertEquals($expected, $serverGroup->policy);
}
public function testCreateWithMicroversion264()
{
$name = $this->randomStr();
/** @var ServerGroup $serverGroup */
require_once $this->sampleFile('server_groups/create_2_64.php', ['{serverGroupName}' => $name]);
try {
$this->assertInstanceOf(ServerGroup::class, $serverGroup);
$this->assertEquals($name, $serverGroup->name);
$this->assertPolicy($serverGroup, 'anti-affinity');
$this->assertEquals(1, $serverGroup->rules['max_server_per_host']);
} finally {
$serverGroup->delete();
}
$this->expectException(BadResponseError::class);
$serverGroup->retrieve();
}
public function testCreate(): ServerGroup
{
$name = $this->randomStr();
/** @var ServerGroup $serverGroup */
require_once $this->sampleFile('server_groups/create.php', ['{serverGroupName}' => $name]);
$this->assertInstanceOf(ServerGroup::class, $serverGroup);
$this->assertEquals($name, $serverGroup->name);
$this->assertPolicy($serverGroup, 'affinity');
return $serverGroup;
}
/**
* @depends testCreate
*/
public function testCreateServerInGroup(ServerGroup $createdServerGroup)
{
$flavorId = getenv('OS_FLAVOR');
if (!$flavorId) {
throw new RuntimeException('OS_FLAVOR env var must be set');
}
$network = $this->getNetworkService()->createNetwork(['name' => $this->randomStr()]);
$this->getNetworkService()->createSubnet(
[
'name' => $this->randomStr(),
'networkId' => $network->id,
'ipVersion' => 4,
'cidr' => '10.20.30.0/24',
]
);
/** @var Server $server */
require_once $this->sampleFile(
'server_groups/create_server.php',
[
'{serverName}' => $this->randomStr(),
'{imageId}' => $this->searchImageId(),
'{flavorId}' => $flavorId,
'{networkId}' => $network->id,
'{serverGroupId}' => $createdServerGroup->id,
]
);
$this->assertInstanceOf(Server::class, $server);
$server->waitUntilActive(300);
$createdServerGroup->retrieve();
$this->assertContains($server->id, $createdServerGroup->members);
$this->deleteServer($server);
}
/**
* @depends testCreate
*/
public function testList(ServerGroup $createdServerGroup)
{
$found = false;
require_once $this->sampleFile(
'server_groups/list.php',
[
'/** @var \OpenStack\Compute\v2\Models\ServerGroup $serverGroup */' => <<<'PHP'
/** @var \OpenStack\Compute\v2\Models\ServerGroup $serverGroup */
if ($serverGroup->id === $createdServerGroup->id) {
$found = true;
}
PHP
,
]
);
$this->assertTrue($found);
}
/**
* @depends testCreate
*/
public function testRead(ServerGroup $createdServerGroup)
{
/** @var ServerGroup $serverGroup */
require_once $this->sampleFile('server_groups/read.php', ['{serverGroupId}' => $createdServerGroup->id]);
$this->assertInstanceOf(ServerGroup::class, $serverGroup);
$this->assertEquals($createdServerGroup->id, $serverGroup->id);
$this->assertEquals($createdServerGroup->name, $serverGroup->name);
$this->assertPolicy($serverGroup, 'affinity');
}
/**
* @depends testCreate
*/
public function testDelete(ServerGroup $createdServerGroup)
{
require_once $this->sampleFile('server_groups/delete.php', ['{serverGroupId}' => $createdServerGroup->id]);
foreach ($this->getService()->listServerGroups() as $serverGroup) {
$this->assertNotEquals($createdServerGroup->id, $serverGroup->id);
}
$this->expectException(BadResponseError::class);
$createdServerGroup->retrieve();
}
}