});
// ========================================================================
//
// POSSIBLE ACTION(S)
//
// ------------------------------------------------------------------------
$story->addAction(function () {
    // make sure all the sessions are running first
    $checkpoint = getCheckpoint();
    foreach (hostWithRole('host_target') as $hostId) {
        foreach ($checkpoint->sessions as $session) {
            expectsHost($hostId)->screenIsRunning($session);
        }
    }
    foreach (hostWithRole('host_target') as $hostId) {
        usingHost($hostId)->stopAllScreens();
    }
});
// ========================================================================
//
// POST-TEST INSPECTION
//
// ------------------------------------------------------------------------
$story->addPostTestInspection(function () {
    $checkpoint = getCheckpoint();
    foreach (hostWithRole('host_target') as $hostId) {
        foreach ($checkpoint->sessions as $session) {
            expectsHost($hostId)->screenIsNotRunning($session);
        }
    }
});
    $checkpoint = getCheckpoint();
    // if we've left the session running, go and kill it off
    foreach (hostWithRole('host_target') as $hostId) {
        $details = fromHost($hostId)->getScreenSessionDetails($checkpoint->session);
        if ($details) {
            usingHost($hostId)->stopProcess($details->pid);
        }
    }
});
// ========================================================================
//
// POSSIBLE ACTION(S)
//
// ------------------------------------------------------------------------
$story->addAction(function () {
    $checkpoint = getCheckpoint();
    foreach (hostWithRole('host_target') as $hostId) {
        usingHost($hostId)->startInScreen($checkpoint->session, "top");
    }
});
// ========================================================================
//
// POST-TEST INSPECTION
//
// ------------------------------------------------------------------------
$story->addPostTestInspection(function () {
    $checkpoint = getCheckpoint();
    foreach (hostWithRole('host_target') as $hostId) {
        expectsHost($hostId)->screenIsRunning($checkpoint->session);
    }
});
//
// ------------------------------------------------------------------------
$story->addAction(function () {
    foreach (hostWithRole('upload_target') as $hostId) {
        // get the default user details for this test environment
        $hostUser = fromHost($hostId)->getStorySetting("user.username");
        $hostGroup = fromHost($hostId)->getStorySetting("user.group");
        // get the details for this file
        $details = fromHost($hostId)->getFileDetails('testfile.txt');
        // make sure we have the details that we expect
        assertsObject($details)->isNotNull();
        assertsObject($details)->hasAttribute("user");
        assertsString($details->user)->equals($hostUser);
        assertsObject($details)->hasAttribute("group");
        assertsString($details->group)->equals($hostGroup);
    }
});
// ========================================================================
//
// POST-TEST INSPECTION
//
// ------------------------------------------------------------------------
$story->addPostTestInspection(function () {
    foreach (hostWithRole('upload_target') as $hostId) {
        // get the default user details for this test environment
        $hostUser = fromHost($hostId)->getStorySetting("user.username");
        $hostGroup = fromHost($hostId)->getStorySetting("user.group");
        // check the details for this file
        expectsHost($hostId)->hasFileWithPermissions('testfile.txt', $hostUser, $hostGroup, 0644);
    }
});
// STORY DETAILS
//
// ------------------------------------------------------------------------
$story = newStoryFor('Storyplayer')->inGroup(['Modules', 'Host'])->called('Can check that an operating system package is installed');
$story->requiresStoryplayerVersion(2);
// ========================================================================
//
// TEST SETUP / TEARDOWN
//
// ------------------------------------------------------------------------
// ========================================================================
//
// POSSIBLE ACTION(S)
//
// ------------------------------------------------------------------------
$story->addAction(function () {
});
// ========================================================================
//
// POST-TEST INSPECTION
//
// ------------------------------------------------------------------------
$story->addPostTestInspection(function () {
    foreach (hostWithRole('host_target') as $hostId) {
        // do we have 'screen' installed?
        expectsHost($hostId)->packageIsInstalled('screen');
        // add in a negative test too, in case the other test is returning
        // false positives
        expectsHost($hostId)->packageIsNotInstalled('storyplayer');
    }
});
Example #5
0
 public function startInScreen($sessionName, $commandLine)
 {
     // what are we doing?
     $log = usingLog()->startAction("start screen session '{$sessionName}' ({$commandLine}) on host '{$this->args[0]}'");
     // do we already have this session running on the host?
     expectsHost($this->args[0])->screenIsNotRunning($sessionName);
     // build up our command to run
     $commandLine = 'screen -L -d -m -S "' . $sessionName . '" bash -c "' . $commandLine . '"';
     // run our command
     //
     // this creates a detached screen session called $sessionName
     $this->runCommand($commandLine);
     // find the PID of the screen session, for future use
     $sessionDetails = fromHost($this->args[0])->getScreenSessionDetails($sessionName);
     // did the process start, or has it already terminated?
     if (empty($sessionDetails->pid)) {
         $log->endAction("session failed to start, or command exited quickly");
         throw new E5xx_ActionFailed(__METHOD__, "failed to start session '{$sessionName}'");
     }
     // all done
     $log->endAction("session running as PID {$sessionDetails->pid}");
 }