Наследование: extends Altax\Foundation\ModuleFacade
Пример #1
0
 protected function setUp()
 {
     $this->container = new Container();
     ModuleFacade::clearResolvedInstances();
     ModuleFacade::setContainer($this->container);
     $module = new \Altax\Module\Server\ServerModule($this->container);
     $this->container->addModule(Server::getModuleName(), $module);
     $module = new \Altax\Module\Env\EnvModule($this->container);
     $this->container->addModule(Env::getModuleName(), $module);
     $this->originalHome = getenv('HOME');
 }
Пример #2
0
 public function testSet()
 {
     try {
         Server::node();
         $this->assertEquals(false, true);
     } catch (\RuntimeException $e) {
         $this->assertEquals(true, true);
     }
     Server::node("web1.exsample.com");
     Server::node("web2.exsample.com");
 }
Пример #3
0
 protected function setUp()
 {
     $this->container = new Container();
     $this->task = new DefinedTask();
     $this->task->setName("test_process_run");
     $this->input = new ArgvInput();
     $this->bufOutput = new BufferedOutput();
     $this->runtimeTask = new RuntimeTask(null, $this->task, $this->input, $this->bufOutput);
     ModuleFacade::clearResolvedInstances();
     ModuleFacade::setContainer($this->container);
     $module = new \Altax\Module\Server\ServerModule($this->container);
     $this->container->addModule(Server::getModuleName(), $module);
     $module = new \Altax\Module\Env\EnvModule($this->container);
     $this->container->addModule(Env::getModuleName(), $module);
     // Env::set('server.port', 2222);
     // Env::set("server.username", 'vagrant');
 }
Пример #4
0
 protected function setUp()
 {
     $this->container = new Container();
     ModuleFacade::clearResolvedInstances();
     ModuleFacade::setContainer($this->container);
     $this->container->addModule(\Altax\Module\Server\Facade\Server::getModuleName(), new \Altax\Module\Server\ServerModule($this->container));
     $this->container->addModule(\Altax\Module\Task\Facade\Task::getModuleName(), new \Altax\Module\Task\TaskModule($this->container));
     $this->container->addModule(\Altax\Module\Env\Facade\Env::getModuleName(), new \Altax\Module\Env\EnvModule($this->container));
     Server::node("127.0.0.1", "test");
     Server::node("localhost", "test");
     Server::node("nodeIsSameNameOfRole", "nodeIsSameNameOfRole");
     $this->task = new DefinedTask();
     $this->task->setName("test_process_run");
     $this->input = new ArgvInput();
     $this->bufOutput = new BufferedOutput();
     $this->runtimeTask = new RuntimeTask(null, $this->task, $this->input, $this->bufOutput);
 }
Пример #5
0
    public function testDefault()
    {
        $application = new Application($this->container);
        $application->setAutoExit(false);
        $application->add(new RolesCommand());
        $command = $application->find("roles");
        Server::node("web1.example.com", "web");
        Server::node("web2.example.com", "web");
        Server::node("db1.example.com", "db");
        $commandTester = new CommandTester($command);
        $commandTester->execute(array("command" => $command->getName()));
        $expected = <<<EOL
+------+------------------------------------+
| name | nodes                              |
+------+------------------------------------+
| web  | web1.example.com, web2.example.com |
| db   | db1.example.com                    |
+------+------------------------------------+

EOL;
        $this->assertEquals($expected, $commandTester->getDisplay(true));
    }
Пример #6
0
    public function testDetailOutput()
    {
        $application = new Application($this->container);
        $application->setAutoExit(false);
        $application->add(new NodesCommand());
        $command = $application->find("nodes");
        Server::node("web1.example.com");
        Server::node("web2.example.com");
        Server::node("web3.example.com");
        $commandTester = new CommandTester($command);
        $commandTester->execute(array("command" => $command->getName(), "--detail" => true));
        $expected = <<<EOL
+------------------+------+------+----------+-----+-------+
| name             | host | port | username | key | roles |
+------------------+------+------+----------+-----+-------+
| web1.example.com |      |      |          |     |       |
| web2.example.com |      |      |          |     |       |
| web3.example.com |      |      |          |     |       |
+------------------+------+------+----------+-----+-------+

EOL;
        $this->assertEquals($expected, $commandTester->getDisplay(true));
    }
Пример #7
0
 /**
  * Load nods from variable length argument lists same 'on' and 'for' method.
  * @return array Array of Altax\Module\Server\Resource\Node
  */
 protected function loadNodes(array $args)
 {
     $candidateNodeNames = array();
     $concreteNodes = array();
     if (Arr::isVector($args)) {
         foreach ($args as $arg) {
             if (is_string($arg)) {
                 $candidateNodeNames[] = array("type" => null, "name" => $arg);
             }
         }
     } else {
         foreach ($args as $key => $value) {
             if ($key == "nodes" || $key == "node") {
                 $nodes = array();
                 if (is_string($value)) {
                     $nodes[] = $value;
                 } elseif (is_array($value)) {
                     $nodes = $value;
                 }
                 foreach ($nodes as $node) {
                     $candidateNodeNames[] = array("type" => "node", "name" => $node);
                 }
             }
             if ($key == "roles" || $key == "role") {
                 $roles = array();
                 if (is_string($value)) {
                     $roles[] = $value;
                 } elseif (is_array($value)) {
                     $roles = $value;
                 }
                 foreach ($roles as $role) {
                     $candidateNodeNames[] = array("type" => "role", "name" => $role);
                 }
             }
         }
     }
     foreach ($candidateNodeNames as $candidateNodeName) {
         $node = null;
         $role = null;
         if ($candidateNodeName["type"] === null || $candidateNodeName["type"] == "node") {
             $node = Server::getNode($candidateNodeName["name"]);
         }
         if ($candidateNodeName["type"] === null || $candidateNodeName["type"] == "role") {
             $role = Server::getRole($candidateNodeName["name"]);
         }
         if ($node && $role) {
             throw new \RuntimeException("The key '" . $candidateNodeName["name"] . "' was found in both nodes and roles. So It couldn't identify to unique node.");
         }
         if (!$node && !$role && ($candidateNodeName["type"] === null || $candidateNodeName["type"] == "node")) {
             // Passed unregistered node name. Create node instance.
             $node = new Node();
             $node->setName($candidateNodeName["name"]);
         }
         if ($node) {
             $concreteNodes[$node->getName()] = $node;
         }
         if ($role) {
             foreach ($role as $nodeName) {
                 $concreteNodes[$nodeName] = Server::getNode($nodeName);
             }
         }
     }
     return $concreteNodes;
 }