Skip to content

Commit 5712c30

Browse files
authored
Fix sort_key and sort_dir parameters for BlockStorage/v2/listSnapshots and Images/v2/listImages
1 parent 3c85b6f commit 5712c30

File tree

8 files changed

+207
-11
lines changed

8 files changed

+207
-11
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,24 @@
11
Snapshots
22
=========
3+
4+
List volumes
5+
------------
6+
7+
.. sample:: BlockStorage/v2/snapshots/list.php
8+
.. refdoc:: OpenStack/BlockStorage/v2/Service.html#method_listSnapshots
9+
10+
Each iteration will return a php:class:`Snapshot` instance <OpenStack/BlockStorage/v2/Models/Snapshot.html>.
11+
12+
.. include:: /common/generators.rst
13+
14+
List volumes sorted
15+
~~~~~~~~~~~~~~~~~~~
16+
17+
Possible values for sort_key are:
18+
* display_name
19+
20+
Possible values for sort_dir are:
21+
* asc
22+
* desc
23+
24+
.. sample:: BlockStorage/v2/snapshots/list_sorted.php

doc/services/images/v2/images.rst

+12
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,18 @@ List images
1717

1818
.. include:: /common/generators.rst
1919

20+
List images sorted
21+
-----------
22+
23+
Possible values for sort_key are:
24+
* name
25+
26+
Possible values for sort_dir are:
27+
* asc
28+
* desc
29+
30+
.. sample:: Images/v2/images/list_sorted.php
31+
2032
Show image details
2133
------------------
2234

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
require 'vendor/autoload.php';
4+
5+
$openstack = new OpenStack\OpenStack([
6+
'authUrl' => '{authUrl}',
7+
'region' => '{region}',
8+
'user' => ['id' => '{userId}', 'password' => '{password}'],
9+
'scope' => ['project' => ['id' => '{projectId}']]
10+
]);
11+
12+
$service = $openstack->blockStorageV2();
13+
14+
$snapshots = $service->listSnapshots(false, ['sortKey' => '{sortKey}', 'sortDir' => '{sortDir}']);
15+
16+
foreach ($snapshots as $snapshot) {
17+
/** @var $snapshot \OpenStack\BlockStorage\v2\Models\Snapshot */
18+
}

samples/Images/v2/images/list.php

+1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@
1313
->listImages();
1414

1515
foreach ($images as $image) {
16+
/** @var \OpenStack\Images\v2\Models\Image $image */
1617
}
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
require 'vendor/autoload.php';
4+
5+
$openstack = new OpenStack\OpenStack([
6+
'authUrl' => '{authUrl}',
7+
'region' => '{region}',
8+
'user' => ['id' => '{userId}', 'password' => '{password}'],
9+
'scope' => ['project' => ['id' => '{projectId}']]
10+
]);
11+
12+
$images = $openstack->imagesV2()->listImages(['sortKey' => '{sortKey}', 'sortDir' => '{sortDir}']);
13+
14+
foreach ($images as $image) {
15+
/** @var \OpenStack\Images\v2\Models\Image $image */
16+
}

src/Common/Api/AbstractParams.php

+2
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ public function sortDir(): array
8585
return [
8686
'type' => self::STRING_TYPE,
8787
'location' => self::QUERY,
88+
'sentAs' => 'sort_dir',
8889
'description' => 'Sorts by one or more sets of attribute and sort direction combinations.',
8990
'enum' => ['asc', 'desc'],
9091
];
@@ -95,6 +96,7 @@ public function sortKey(): array
9596
return [
9697
'type' => self::STRING_TYPE,
9798
'location' => self::QUERY,
99+
'sentAs' => 'sort_key',
98100
'description' => 'Sorts by one or more sets of attribute and sort direction combinations.',
99101
];
100102
}

tests/integration/BlockStorage/v2/CoreTest.php

+70-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace OpenStack\integration\BlockStorage\v2;
3+
namespace OpenStack\Integration\BlockStorage\v2;
44

55
use OpenStack\BlockStorage\v2\Models\Snapshot;
66
use OpenStack\BlockStorage\v2\Models\Volume;
@@ -34,22 +34,24 @@ public function runTests()
3434
$this->volumeTypes();
3535
$this->logger->info('-> Snapshots');
3636
$this->snapshots();
37+
$this->logger->info('-> Snapshot list');
38+
$this->snapshotList();
3739

3840
$this->outputTimeTaken();
3941
}
4042

4143
public function volumes()
4244
{
43-
$this->logStep('-> Volumes tests');
45+
$this->logStep('Creating volume type');
4446
$volumeType = $this->getService()->createVolumeType(['name' => $this->randomStr()]);
4547

4648
$replacements = [
4749
'{description}' => $this->randomStr(),
48-
"'{size}'" => 1,
49-
'{name}' => $this->randomStr(),
50-
'{volumeType}' => $volumeType->id,
51-
'{key1}' => $this->randomStr(),
52-
'{val1}' => $this->randomStr(),
50+
"'{size}'" => 1,
51+
'{name}' => $this->randomStr(),
52+
'{volumeType}' => $volumeType->id,
53+
'{key1}' => $this->randomStr(),
54+
'{val1}' => $this->randomStr(),
5355
];
5456

5557
$this->logStep('Creating volume');
@@ -70,7 +72,7 @@ public function volumes()
7072

7173
$replacements += [
7274
'{newName}' => $this->randomStr(),
73-
'{newDescription}' => $this->randomStr()
75+
'{newDescription}' => $this->randomStr(),
7476
];
7577

7678
$this->logStep('Updating volume');
@@ -82,6 +84,7 @@ public function volumes()
8284
/** @var \Generator $volumes */
8385
require_once $this->sampleFile($replacements, 'volumes/list.php');
8486

87+
$volume = $this->getService()->getVolume($volumeId);
8588
$volume->waitUntil('available');
8689

8790
$this->logStep('Deleting volume');
@@ -135,8 +138,8 @@ public function snapshots()
135138
$volume->waitUntil('available', 60);
136139

137140
$replacements = [
138-
'{volumeId}' => $volume->id,
139-
'{name}' => $this->randomStr(),
141+
'{volumeId}' => $volume->id,
142+
'{name}' => $this->randomStr(),
140143
'{description}' => $this->randomStr(),
141144
];
142145

@@ -183,11 +186,68 @@ public function snapshots()
183186

184187
$snapshot->waitUntil('available', 60);
185188

189+
$this->logStep('Listing snapshots');
190+
require_once $this->sampleFile($replacements, 'snapshots/list.php');
191+
186192
$this->logStep('Deleting snapshot');
187193
require_once $this->sampleFile($replacements, 'snapshots/delete.php');
188194
$snapshot->waitUntilDeleted();
189195

190196
$this->logStep('Deleting volume');
191197
$volume->delete();
192198
}
199+
200+
public function snapshotList()
201+
{
202+
$this->logStep('Creating volume');
203+
$volume = $this->getService()->createVolume(['name' => $this->randomStr(), 'size' => 1]);
204+
$volume->waitUntil('available', 60);
205+
206+
$names = ['b' . $this->randomStr(), 'a' . $this->randomStr(), 'd' . $this->randomStr(), 'c' . $this->randomStr()];
207+
$createdSnapshots = [];
208+
foreach ($names as $name) {
209+
$this->logStep('Creating snapshot ' . $name);
210+
$snapshot = $this->getService()->createSnapshot([
211+
'volumeId' => $volume->id,
212+
'name' => $name,
213+
]);
214+
215+
self::assertInstanceOf(Snapshot::class, $snapshot);
216+
217+
$createdSnapshots[] = $snapshot;
218+
$snapshot->waitUntil('available', 60);
219+
}
220+
221+
try {
222+
$replacements = [
223+
'{sortKey}' => 'display_name',
224+
'{sortDir}' => 'asc',
225+
];
226+
227+
$this->logStep('Listing snapshots');
228+
require_once $this->sampleFile($replacements, 'snapshots/list.php');
229+
230+
$this->logStep('Listing snapshots sorted asc');
231+
/** @var Snapshot $snapshot */
232+
require_once $this->sampleFile($replacements, 'snapshots/list_sorted.php');
233+
self::assertInstanceOf(Snapshot::class, $snapshot);
234+
self::assertEquals($names[2], $snapshot->name);
235+
236+
$this->logStep('Listing snapshots sorted desc');
237+
$replacements['{sortDir}'] = 'desc';
238+
/** @var Snapshot $snapshot */
239+
require_once $this->sampleFile($replacements, 'snapshots/list_sorted.php');
240+
self::assertInstanceOf(Snapshot::class, $snapshot);
241+
self::assertEquals($names[1], $snapshot->name);
242+
} finally {
243+
foreach ($createdSnapshots as $snapshot) {
244+
$this->logStep('Deleting snapshot ' . $snapshot->name);
245+
$snapshot->delete();
246+
$snapshot->waitUntilDeleted();
247+
}
248+
249+
$this->logStep('Deleting volume');
250+
$volume->delete();
251+
}
252+
}
193253
}

tests/integration/Images/v2/CoreTest.php

+66-1
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,39 @@
11
<?php
22

3-
namespace OpenStack\integration\Images\v2;
3+
namespace OpenStack\Integration\Images\v2;
44

5+
use OpenStack\BlockStorage\v2\Models\Snapshot;
56
use OpenStack\Images\v2\Models\Image;
67
use OpenStack\Images\v2\Models\Member;
78
use OpenStack\Integration\TestCase;
9+
use OpenStack\Integration\Utils;
810

911
class CoreTest extends TestCase
1012
{
13+
private $service;
14+
15+
private function getService(): \OpenStack\Images\v2\Service
16+
{
17+
if (null === $this->service) {
18+
$this->service = Utils::getOpenStack()->imagesV2();
19+
}
20+
21+
return $this->service;
22+
}
23+
1124
public function runTests()
1225
{
1326
$this->startTimer();
1427

28+
$this->logger->info('-> Images');
1529
$this->images();
30+
31+
$this->logger->info('-> Members');
1632
$this->members();
1733

34+
$this->logger->info('-> Image list');
35+
$this->imageList();
36+
1837
$this->outputTimeTaken();
1938
}
2039

@@ -97,4 +116,50 @@ public function members()
97116
/** @var Image $image */
98117
require_once $this->sampleFile($replacements, 'images/delete.php');
99118
}
119+
120+
public function imageList()
121+
{
122+
$this->logStep('Creating image');
123+
124+
$postfix = $this->randomStr();
125+
$names = ['b' . $postfix, 'a' . $postfix, 'd' . $postfix, 'c' . $postfix];
126+
$createdImages = [];
127+
foreach ($names as $name) {
128+
$this->logStep("Creating image $name");
129+
$image = $this->getService()->createImage([
130+
'name' => $name,
131+
]);
132+
133+
self::assertInstanceOf(Image::class, $image);
134+
$createdImages[] = $image;
135+
}
136+
137+
138+
$this->logStep('Listing images sorted asc');
139+
140+
$replacements = [
141+
'{sortKey}' => 'name',
142+
'{sortDir}' => 'asc',
143+
];
144+
145+
/** @var \OpenStack\Images\v2\Models\Image $image */
146+
require_once $this->sampleFile($replacements, 'images/list_sorted.php');
147+
self::assertInstanceOf(Image::class, $image);
148+
self::assertEquals($names[2], $image->name);
149+
150+
151+
$this->logStep('Listing images sorted desc');
152+
153+
$replacements['{sortDir}'] = 'desc';
154+
/** @var \OpenStack\Images\v2\Models\Image $image */
155+
require_once $this->sampleFile($replacements, 'images/list_sorted.php');
156+
self::assertInstanceOf(Image::class, $image);
157+
self::assertEquals($names[1], $image->name);
158+
159+
foreach ($createdImages as $image) {
160+
$this->logStep("Deleting image $image->name");
161+
$image->delete();
162+
}
163+
}
164+
100165
}

0 commit comments

Comments
 (0)