Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resume suspend server #394

Merged
merged 7 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/workflows/integration_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ jobs:
name: Deploy OpenStack ${{ matrix.name }} and run integration tests with php ${{matrix.php_version}}
steps:
- uses: actions/checkout@v2

- name: get cache directory
id: composer-cache
run: |
echo "::set-output name=dir::$(composer config cache-files-dir)"

- uses: actions/cache@v3
with:
path: |
Expand All @@ -54,13 +56,16 @@ jobs:
key: ${{ runner.os }}-composer-${{ matrix.php_version }}-${{ hashFiles('**.composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-${{ matrix.php_version }}-

- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php_version }}
extensions: curl
tools: composer:v2
coverage: none

- run: composer install --prefer-dist --no-interaction --no-progress

- name: Restore devstack cache
uses: actions/cache@v3
with:
Expand All @@ -69,6 +74,7 @@ jobs:
!/opt/stack/data
~/devstack/
key: ${{ runner.os }}-openstack-${{ matrix.openstack_version }}-${{ github.workflow }}

- name: Deploy devstack
uses: EmilienM/devstack-action@v0.11
with:
Expand All @@ -81,6 +87,7 @@ jobs:
[filter:versioned_writes]
allow_object_versioning = true
enabled_services: 's-account,s-container,s-object,s-proxy,s-bak'

- name: Set env variables
run: |
{
Expand All @@ -96,9 +103,23 @@ jobs:
echo OS_FLAVOR=1
echo OS_DOMAIN_ID=default
} >> "$GITHUB_ENV"

- name: Check if Block Storage API v2 must be tested
if: matrix.block_storage_v2 == true
run: echo "OS_BLOCK_STORAGE_V2=1" >> "$GITHUB_ENV"

- name: Execute Integration tests via PhpUnit
run: vendor/bin/phpunit --configuration ./phpunit.sample.xml.dist

- name: Collect logs
if: ${{ failure() }}
run: |
set -x
journalctl >failure-logs

- name: Save logs
if: ${{ failure() }}
uses: actions/upload-artifact@v3
with:
name: failure-logs
path: failure-logs
11 changes: 11 additions & 0 deletions doc/services/compute/v2/servers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -280,3 +280,14 @@ You can also refine by network label:
$ipAddresses = $server->listAddresses([
'networkLabel' => '{networkLabel}',
]);

Suspend
-------

.. sample:: Compute/v2/images/suspend.php

Resume
------

.. sample:: Compute/v2/images/resume.php

17 changes: 17 additions & 0 deletions samples/Compute/v2/servers/resume.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

require 'vendor/autoload.php';

$openstack = new OpenStack\OpenStack([
'authUrl' => '{authUrl}',
'region' => '{region}',
'user' => [
'id' => '{userId}',
'password' => '{password}',
],
]);

$service = $openstack->computeV2();
$server = $service->getServer(['id' => '{serverId}']);

$server->resume();
17 changes: 17 additions & 0 deletions samples/Compute/v2/servers/suspend.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

require 'vendor/autoload.php';

$openstack = new OpenStack\OpenStack([
'authUrl' => '{authUrl}',
'region' => '{region}',
'user' => [
'id' => '{userId}',
'password' => '{password}',
],
]);

$service = $openstack->computeV2();
$server = $service->getServer(['id' => '{serverId}']);

$server->suspend();
24 changes: 24 additions & 0 deletions src/Compute/v2/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,30 @@ public function stopServer(): array
];
}

public function resumeServer(): array
{
return [
'method' => 'POST',
'path' => 'servers/{id}/action',
'params' => [
'id' => $this->params->urlId('server'),
'resume' => $this->params->nullAction(),
],
];
}

public function suspendServer(): array
{
return [
'method' => 'POST',
'path' => 'servers/{id}/action',
'params' => [
'id' => $this->params->urlId('server'),
'suspend' => $this->params->nullAction(),
],
];
}

public function rebuildServer(): array
{
return [
Expand Down
22 changes: 22 additions & 0 deletions src/Compute/v2/Models/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,28 @@ public function stop()
]);
}

/**
* Resumes server.
*/
public function resume(): void
{
$this->execute($this->api->resumeServer(), [
'id' => $this->id,
'resume' => null,
]);
}

/**
* Suspends server.
*/
public function suspend(): void
{
$this->execute($this->api->suspendServer(), [
'id' => $this->id,
'suspend' => null,
]);
}

/**
* Rebuilds the server.
*
Expand Down
32 changes: 31 additions & 1 deletion tests/sample/Compute/v2/ServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ public function testGetVncConsole(Server $createdServer)
{
/** @var array $console */
require_once $this->sampleFile('servers/get_server_vnc_console.php', [
'{serverId}' => $createdServer->id
'{serverId}' => $createdServer->id,
]);

$this->assertIsArray($console);
Expand All @@ -331,6 +331,9 @@ public function testGetVncConsole(Server $createdServer)
*/
public function testGetConsoleOutput(Server $createdServer)
{
// wait for the server to be ready
sleep(5);

/** @var string $consoleOutput */
require_once $this->sampleFile('servers/get_server_console_output.php', ['{serverId}' => $createdServer->id]);

Expand Down Expand Up @@ -361,4 +364,31 @@ public function testDelete(Server $createdServer)
$this->expectException(BadResponseError::class);
$createdServer->retrieve();
}

public function testSuspend()
{
$server = $this->createServer();

require_once $this->sampleFile('servers/suspend.php', ['{serverId}' => $server->id]);

$server->waitUntil('SUSPENDED');
$this->assertEquals('SUSPENDED', $server->status);

return $server;
}

/**
* @depends testSuspend
*/
public function testResume(Server $server)
{
$this->assertEquals('SUSPENDED', $server->status);

require_once $this->sampleFile('servers/resume.php', ['{serverId}' => $server->id]);

$server->waitUntil('ACTIVE', 300);
$this->assertEquals('ACTIVE', $server->status);

$this->deleteServer($server);
}
}
5 changes: 5 additions & 0 deletions tests/sample/Compute/v2/VolumeAttachmentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ public function testAttach(): VolumeAttachment
{
$server = $this->createServer();

// let's wait for the server to be completely up
// https://bugs.launchpad.net/nova/+bug/1998148
// https://bugs.launchpad.net/nova/+bug/1960346
sleep(10);

$volume = $this->getCachedService(Service::class)->createVolume(
[
'name' => $this->randomStr(),
Expand Down
18 changes: 18 additions & 0 deletions tests/unit/Compute/v2/Models/ServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,24 @@ public function test_it_stops()
self::assertNull($this->server->stop());
}

public function test_it_resumes()
{
$expectedJson = ['resume' => null];

$this->setupMock('POST', 'servers/serverId/action', $expectedJson, [], new Response(202));

$this->assertNull($this->server->resume());
}

public function test_it_suspends()
{
$expectedJson = ['suspend' => null];

$this->setupMock('POST', 'servers/serverId/action', $expectedJson, [], new Response(202));

$this->assertNull($this->server->suspend());
}

public function test_it_resizes()
{
$expectedJson = ['resize' => ['flavorRef' => 'flavorId']];
Expand Down
Loading