Skip to content

Commit 5e89b13

Browse files
committed
Integration tests: start/stop server
1 parent bc4fbf8 commit 5e89b13

File tree

4 files changed

+83
-5
lines changed

4 files changed

+83
-5
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
require 'vendor/autoload.php';
4+
5+
$openstack = new OpenStack\OpenStack([
6+
'authUrl' => '{authUrl}',
7+
'region' => '{region}',
8+
'user' => [
9+
'id' => '{userId}',
10+
'password' => '{password}'
11+
],
12+
'scope' => ['project' => ['id' => '{projectId}']]
13+
]);
14+
15+
$compute = $openstack->computeV2(['region' => '{region}']);
16+
17+
$server = $compute->getServer([
18+
'id' => '{serverId}',
19+
]);
20+
21+
$server->start();
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
require 'vendor/autoload.php';
4+
5+
$openstack = new OpenStack\OpenStack([
6+
'authUrl' => '{authUrl}',
7+
'region' => '{region}',
8+
'user' => [
9+
'id' => '{userId}',
10+
'password' => '{password}'
11+
],
12+
'scope' => ['project' => ['id' => '{projectId}']]
13+
]);
14+
15+
$compute = $openstack->computeV2(['region' => '{region}']);
16+
17+
$server = $compute->getServer([
18+
'id' => '{serverId}',
19+
]);
20+
21+
$server->stop();

tests/integration/Compute/v2/CoreTest.php

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ class CoreTest extends TestCase
2323
const SUBNET = 'phptest_subnet';
2424
const VOLUME = 'phptest_volume';
2525

26+
const IMAGE = 'cirros';
27+
2628
/** @var NetworkService */
2729
private $networkService;
2830

@@ -79,11 +81,13 @@ private function searchImages($name)
7981
foreach ($this->getService()->listImages() as $image) {
8082
if (strpos($image->name, $name) !== false) {
8183
$this->imageId = $image->id;
82-
return;
84+
break;
8385
}
8486
}
8587

86-
$this->logger->emergency('No image found');
88+
if (!$this->imageId) {
89+
throw new \RuntimeException(sprintf('Unable to find image "%s". Make sure this image is available for integration test.', $name));
90+
}
8791
}
8892

8993
protected function setUp()
@@ -126,7 +130,7 @@ public function runTests()
126130
// Manually trigger setUp
127131
$this->setUp();
128132

129-
$this->searchImages('cirros');
133+
$this->searchImages(self::IMAGE);
130134

131135
// Servers
132136
$this->createServer();
@@ -138,6 +142,8 @@ public function runTests()
138142

139143
// Server actions
140144
//$this->changeServerPassword();
145+
$this->stopServer();
146+
$this->startServer();
141147
$this->resizeServer();
142148
$this->confirmServerResize();
143149
$this->rebuildServer();
@@ -188,10 +194,16 @@ public function runTests()
188194

189195
private function createServer()
190196
{
197+
$flavorId = getenv('OS_FLAVOR');
198+
199+
if (!$flavorId) {
200+
throw new \RuntimeException('OS_FLAVOR env var must be set');
201+
}
202+
191203
$replacements = [
192204
'{serverName}' => $this->randomStr(),
193205
'{imageId}' => $this->imageId,
194-
'{flavorId}' => 1,
206+
'{flavorId}' => $flavorId,
195207
'{networkId}' => $this->network->id
196208
];
197209

@@ -355,6 +367,30 @@ private function rebootServer()
355367
$this->logStep('Rebooted server {serverId}', $replacements);
356368
}
357369

370+
private function stopServer()
371+
{
372+
$replacements = ['{serverId}' => $this->serverId];
373+
374+
/** @var $server \OpenStack\Compute\v2\Models\Server */
375+
require_once $this->sampleFile($replacements, 'servers/stop_server.php');
376+
377+
$server->waitUntil('SHUTOFF', false);
378+
379+
$this->logStep('Stopped server {serverId}', $replacements);
380+
}
381+
382+
private function startServer()
383+
{
384+
$replacements = ['{serverId}' => $this->serverId];
385+
386+
/** @var $server \OpenStack\Compute\v2\Models\Server */
387+
require_once $this->sampleFile($replacements, 'servers/start_server.php');
388+
389+
$server->waitUntilActive(false);
390+
391+
$this->logStep('Started server {serverId}', $replacements);
392+
}
393+
358394
private function createFlavor()
359395
{
360396
$replacements = [

tests/integration/TestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
abstract class TestCase extends \PHPUnit_Framework_TestCase implements TestInterface
99
{
10-
private $logger;
10+
protected $logger;
1111
private $startPoint;
1212
private $lastPoint;
1313
private $sampleManager;

0 commit comments

Comments
 (0)