From 87a592ce6003fbf0e0b9176d84bca80f57a09412 Mon Sep 17 00:00:00 2001 From: Maxime Fabre Date: Mon, 23 Mar 2015 20:02:33 +0100 Subject: [PATCH] Fix multiservers deployments issue --- CHANGELOG.md | 13 +++ .../Connections/ConnectionsHandler.php | 4 - .../Connections/ConnectionsHandlerTest.php | 83 +++++++++++++++++++ 3 files changed, 96 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cacb6af0e..c0b519533 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,18 @@ Rocketeer follows the [Semantic Versioning 2.0](http://semver.org/spec/v2.0.0.html) spec. +## [2.1.3] - 2015-03-23 + +### Fixed +- Fixed an issue with multiservers deployments + +## [2.1.2] - 2015-03-10 + +### Fixed +- Fixed an issue prevent using a custom command clas +- Fixed commands run in folders not working with LocalConnection +- Fixed port and key not being passed to rsync + ## [2.1.2] - 2015-03-10 ### Fixed @@ -370,6 +382,7 @@ Rocketeer follows the [Semantic Versioning 2.0](http://semver.org/spec/v2.0.0.ht - Added config file - Added `deploy:setup` and `deploy:deploy` commands +[2.1.3]: https://github.com/rocketeers/rocketeer/compare/2.1.2...2.1.3 [2.1.2]: https://github.com/rocketeers/rocketeer/compare/2.1.1...2.1.2 [2.1.1]: https://github.com/rocketeers/rocketeer/compare/2.1.0...2.1.1 [2.1.0]: https://github.com/rocketeers/rocketeer/compare/2.0.6...2.1.0 diff --git a/src/Rocketeer/Services/Connections/ConnectionsHandler.php b/src/Rocketeer/Services/Connections/ConnectionsHandler.php index bb5fbb824..9a6cc2eb3 100644 --- a/src/Rocketeer/Services/Connections/ConnectionsHandler.php +++ b/src/Rocketeer/Services/Connections/ConnectionsHandler.php @@ -70,10 +70,6 @@ class ConnectionsHandler */ public function getHandle($connection = null, $server = null, $stage = null) { - if ($this->handle) { - return $this->handle; - } - // Get identifiers $connection = $connection ?: $this->getConnection(); $server = $server ?: $this->getServer(); diff --git a/tests/Services/Connections/ConnectionsHandlerTest.php b/tests/Services/Connections/ConnectionsHandlerTest.php index 86a964916..d6717efd1 100644 --- a/tests/Services/Connections/ConnectionsHandlerTest.php +++ b/tests/Services/Connections/ConnectionsHandlerTest.php @@ -15,6 +15,15 @@ class ConnectionsHandlerTest extends RocketeerTestCase { + public function setUp() + { + parent::setUp(); + + $this->username = 'Anahkiasen'; + $this->password = 'foobar'; + $this->host = 'some.host'; + } + //////////////////////////////////////////////////////////////////// //////////////////////////////// TESTS ///////////////////////////// //////////////////////////////////////////////////////////////////// @@ -220,10 +229,84 @@ public function testAlwaysReturnsArrayIfNoCredentialsFound() $this->assertEquals([], $this->connections->getServerCredentials()); } + public function testCanHaveMultipleServerConnections() + { + $this->swapConfig(array( + 'rocketeer::connections' => array( + 'production-multiserver' => array( + 'servers' => $this->mockRuntimeMultiserverConnection() + ), + ), + )); + $this->mockCommand(array( + 'on' => 'production-multiserver' + )); + $this->credentials->getServerCredentials(); + + $credentials = $this->connections->getServerCredentials('production-multiserver', 0); + $this->assertEquals(array( + 'host' => "10.1.1.1", + 'username' => $this->username, + 'password' => '', + 'keyphrase' => '', + 'key' => '', + 'agent' => true, + 'agent-forward' => true, + 'db_role' => false + ), $credentials); + // also check handle generation as handles are used for connection cache keying in RemoteHandler + $this->assertEquals("production-multiserver/0", $this->connections->getHandle("production-multiserver", 0)); + + $credentials = $this->connections->getServerCredentials('production-multiserver', 1); + $this->assertEquals(array( + 'host' => "10.1.1.2", + 'username' => $this->username, + 'password' => '', + 'keyphrase' => '', + 'key' => '', + 'agent' => true, + 'agent-forward' => true, + 'db_role' => false + ), $credentials); + $this->assertEquals("production-multiserver/1", $this->connections->getHandle("production-multiserver", 1)); + + $credentials = $this->connections->getServerCredentials('production-multiserver', 2); + $this->assertEquals(array( + 'host' => "10.1.1.3", + 'username' => $this->username, + 'password' => '', + 'keyphrase' => '', + 'key' => '', + 'agent' => true, + 'agent-forward' => true, + 'db_role' => false + ), $credentials); + $this->assertEquals("production-multiserver/2", $this->connections->getHandle("production-multiserver", 2)); + } + //////////////////////////////////////////////////////////////////// //////////////////////////////// HELPERS /////////////////////////// //////////////////////////////////////////////////////////////////// + /** + * Mock a set of runtime injected credentials + */ + protected function mockRuntimeMultiserverConnection() + { + return array_map( + function ($ip) { + return [ + 'host' => $ip, + 'username' => $this->username, + 'agent' => true, + 'agent-forward' => true, + 'db_role' => false + ]; + }, + ['10.1.1.1', '10.1.1.2', '10.1.1.3'] + ); + } + /** * Make the config return specific SCM config. *