Ejemplo n.º 1
0
 public function startHornetDrone($clientName, $clientParams)
 {
     // what are we doing?
     $log = usingLog()->startAction("start hornet-drone '{$clientName}' with params '(" . implode(', ', $clientParams) . ")");
     // build the command to run
     $appSettings = fromStoryplayer()->getAppSettings('hornet');
     $command = $appSettings->path . '/hornet-drone ' . implode(' ', $clientParams);
     // run the command in a screen session
     usingShell()->startInScreen($clientName, $command);
     // all done
     $log->endAction();
 }
//
// PRE-TEST INSPECTION
//
// ------------------------------------------------------------------------
// ========================================================================
//
// POSSIBLE ACTION(S)
//
// ------------------------------------------------------------------------
$story->addAction(function () {
    // get the checkpoint, to store data in
    $checkpoint = getCheckpoint();
    // load our test page
    usingBrowser()->gotoPage("http://news.bbc.co.uk");
    // get the title of the test page
    $checkpoint->title = fromBrowser()->getTitle();
});
// ========================================================================
//
// POST-TEST INSPECTION
//
// ------------------------------------------------------------------------
$story->addPostTestInspection(function () {
    // get the checkpoint
    $checkpoint = getCheckpoint();
    // what title are we expecting?
    $expectedTitle = fromStoryplayer()->getStorySetting("modules.http.remotePage.title");
    // do we have the title we expected?
    assertsObject($checkpoint)->hasAttribute('title');
    assertsString($checkpoint->title)->equals($expectedTitle);
});
Ejemplo n.º 3
0
 /**
  * @return string
  */
 public function determineBridgedInterface()
 {
     // what are we doing?
     $log = usingLog()->startAction("determine bridged network interface for Vagrant VM");
     try {
         // 1. try to load Vagrant settings from storyplayer.json
         // e.g.: "moduleSettings":{"vagrant":{"bridgedIface":"eth0"}}
         $vagrantSettings = fromStoryplayer()->getModuleSetting('vagrant');
         if (!empty($vagrantSettings->bridgedIface)) {
             $log->endAction('Returning configured ' . $vagrantSettings->bridgedIface . ' interface');
             return $vagrantSettings->bridgedIface;
         }
     } catch (E5xx_ActionFailed $e) {
         // ignore errors as this setting may not exist
     }
     // 2. check if VirtualBox (VBoxManage) is installed
     $command = 'which VBoxManage';
     $commandRunner = new CommandRunner();
     $result = $commandRunner->runSilently($command);
     if ($result->returnCode !== 0) {
         // VBoxManage is not installed, we are probably using another provider
         // like OpenStack that do not require this setting
         $log->endAction('VBoxManage is not installed: returning default eth0 interface');
         return 'eth0';
     }
     // 3. VBoxManage can actually tell us what we need to know
     $command = 'VBoxManage list bridgedifs';
     $commandRunner = new CommandRunner();
     $result = $commandRunner->runSilently($command);
     if ($result->returnCode != 0) {
         $log->endAction('unable to get list of bridgable network interfaces from VBoxManage :(');
         throw new E5xx_ActionFailed(__METHOD__);
     }
     // now we just need to make sense of it all
     $lines = explode("\n", $result->output);
     $iface = null;
     foreach ($lines as $line) {
         $matches = [];
         if (preg_match("|Name:[\\s]+(.*)|", $line, $matches)) {
             $iface = $matches[1];
         } else {
             if ($iface !== null && preg_match("|IPAddress:[\\s]+(.*)|", $line, $matches)) {
                 // our network interface contains an IPAddress - it is likely
                 // to be one that works
                 if ($matches[1] != '0.0.0.0') {
                     $log->endAction($iface);
                     return $iface;
                 }
             }
         }
     }
     // if we get here, then we haven't found a network interface to use
     $log->endAction("no bridgeable network interface found :(");
     throw new E5xx_ActionFailed(__METHOD__);
 }