11<?php
22
3- namespace OpenStack \integration \BlockStorage \v2 ;
3+ namespace OpenStack \Integration \BlockStorage \v2 ;
44
55use OpenStack \BlockStorage \v2 \Models \Snapshot ;
66use 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}
0 commit comments