if (file_exists($filename)) { // tidy up unlink($filename); } } }); // ======================================================================== // // POSSIBLE ACTION(S) // // ------------------------------------------------------------------------ $story->addAction(function () { foreach (hostWithRole('upload_target') as $hostname) { fromHost($hostname)->downloadFile('testfile.txt', "/tmp/testfile-{$hostname}.txt"); } }); // ======================================================================== // // POST-TEST INSPECTION // // ------------------------------------------------------------------------ $story->addPostTestInspection(function () { // we should have a file for each host in the configuration foreach (hostWithRole('upload_target') as $hostname) { $filename = '/tmp/testfile-' . $hostname . '.txt'; if (!file_exists($filename)) { usingLog()->writeToLog("file not downloaded from host '{$hostname}'"); usingErrors()->throwException("file '{$filename}' not downloaded"); } } });
// // POSSIBLE ACTION(S) // // ------------------------------------------------------------------------ $story->addAction(function () { foreach (hostWithRole('upload_target') as $hostname) { usingHost($hostname)->uploadFile(__DIR__ . '/testfile.txt', "testfile.txt"); } }); // ======================================================================== // // POST-TEST INSPECTION // // ------------------------------------------------------------------------ $story->addPostTestInspection(function () { foreach (hostWithRole('upload_target') as $hostname) { $result = usingHost($hostname)->runCommand('ls testfile.txt'); $fileFound = false; $lines = explode("\n", $result->output); foreach ($lines as $line) { if ($line == "testfile.txt") { $fileFound = true; } } if (!$fileFound) { $msg = "file not found on host '{$hostname}'"; usingLog()->writeToLog($msg); usingErrors()->throwException($msg); } } });