저자: Stuart Herbert (stuart.herbert@datasift.com)
상속: implements DataSift\Storyplayer\CommandLib\CommandClient
예제 #1
0
 /**
  * get an SSH client to contact this host
  *
  * @param  \DataSift\Storyplayer\PlayerLib\StoryTeller $st
  *         our ubiquitous state object
  * @param  \DataSift\Storyplayer\HostLib\HostDetails $hostDetails
  *         details about the host that you want a client for
  * @return \DataSift\Storyplayer\CommandLib\SshClient
  *         the SSH client for you to use
  */
 public function getClient($st, $hostDetails)
 {
     // shorthand
     $hostId = $hostDetails->hostId;
     // do we already have a client?
     if (isset($this->sshClients[$hostId])) {
         // yes - reuse it
         return $this->sshClients[$hostId];
     }
     // if we get here, we need to make a new client
     $sshClient = new SshClient($st, $hostDetails->sshOptions, $hostDetails->scpOptions);
     $sshClient->setIpAddress($hostDetails->ipAddress);
     $sshClient->setSshUsername($hostDetails->sshUsername);
     if (isset($hostDetails->sshKey)) {
         $sshClient->setSshKey($hostDetails->sshKey);
     }
     // all done
     $this->sshClients[$hostId] = $sshClient;
     return $sshClient;
 }
예제 #2
0
 /**
  * @covers DataSift\Storyplayer\CommandLib\SshClient::runCommand
  * @covers DataSift\Storyplayer\CommandLib\E4xx_NeedIpAddress::__construct
  */
 public function testMustProvideIpAddressToRunCommands()
 {
     // ----------------------------------------------------------------
     // setup your test
     // our mocked $st
     $st = Mockery::mock("DataSift\\Storyplayer\\PlayerLib\\StoryTeller");
     // our fake Output for logging purposes
     $output = Mockery::mock("DataSift\\Storyplayer\\Output");
     $output->shouldReceive('logPhaseActivity');
     // our fake injectables container
     $injectables = new Injectables();
     $injectables->dataFormatter = new DataFormatter();
     $injectables->dataFormatter->setIsVerbose(true);
     $injectables->output = $output;
     // our mocked $st needs to do things too
     //
     // we have to put this down here, because we need to pass $st into
     // our mocked CommandRunner
     $st->shouldReceive('startAction')->once()->andReturn(new Action_LogItem($injectables, 1));
     // our test subject
     $obj = new SshClient($st);
     $obj->setSshUsername('fred');
     // ----------------------------------------------------------------
     // perform the change
     $caughtException = false;
     try {
         $result = $obj->runCommand('ls /tmp');
     } catch (E4xx_NeedIpAddress $e) {
         $caughtException = true;
     }
     // ----------------------------------------------------------------
     // test the results
     $this->assertTrue($caughtException);
     // all done
     Mockery::close();
 }