@@ -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 = [
0 commit comments