mirror of
https://github.com/andres-montanez/Magallanes
synced 2024-05-04 23:13:16 +02:00
[Nostromo] Tweak tasks and tests
This commit is contained in:
parent
8c49823e15
commit
3908c20d8e
|
@ -90,7 +90,7 @@ class RollbackCommand extends DeployCommand
|
|||
return $exception->getCode();
|
||||
}
|
||||
} else {
|
||||
throw new DeploymentException(sprintf('Release %s is not available on all hosts', $releaseToRollback), 72);
|
||||
throw new DeploymentException(sprintf('Release "%s" is not available on all hosts', $releaseToRollback), 72);
|
||||
}
|
||||
|
||||
$output->writeln('Finished <fg=blue>Magallanes</>');
|
||||
|
@ -106,11 +106,10 @@ class RollbackCommand extends DeployCommand
|
|||
*/
|
||||
protected function checkReleaseAvailability($releaseToRollback)
|
||||
{
|
||||
$releaseIdCandidate = false;
|
||||
$hosts = $this->runtime->getEnvironmentConfig('hosts');
|
||||
$hostPath = rtrim($this->runtime->getEnvironmentConfig('host_path'), '/');
|
||||
|
||||
$releaseAvailableInAllHosts = true;
|
||||
$releaseAvailableInHosts = 0;
|
||||
foreach ($hosts as $host) {
|
||||
$this->runtime->setWorkingHost($host);
|
||||
|
||||
|
@ -127,20 +126,14 @@ class RollbackCommand extends DeployCommand
|
|||
}
|
||||
|
||||
if (in_array($releaseToRollback, $releases)) {
|
||||
if ($releaseIdCandidate === false) {
|
||||
$releaseIdCandidate = $releaseToRollback;
|
||||
} else {
|
||||
if ($releaseIdCandidate != $releaseToRollback) {
|
||||
$releaseAvailableInAllHosts = false;
|
||||
}
|
||||
}
|
||||
$releaseAvailableInHosts++;
|
||||
}
|
||||
|
||||
$this->runtime->setWorkingHost(null);
|
||||
}
|
||||
|
||||
if ($releaseAvailableInAllHosts) {
|
||||
return $releaseIdCandidate;
|
||||
if ($releaseAvailableInHosts === count($hosts)) {
|
||||
return $releaseToRollback;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
namespace Mage\Task\BuiltIn\Deploy\TarGz;
|
||||
|
||||
use Mage\Runtime\Exception\DeploymentException;
|
||||
use Mage\Task\ErrorException;
|
||||
use Symfony\Component\Process\Process;
|
||||
use Mage\Task\AbstractTask;
|
||||
|
||||
|
@ -34,7 +34,7 @@ class CopyTask extends AbstractTask
|
|||
public function execute()
|
||||
{
|
||||
if (!$this->runtime->getEnvironmentConfig('releases', false)) {
|
||||
throw new DeploymentException('This task is only available with releases enabled', 40);
|
||||
throw new ErrorException('This task is only available with releases enabled', 40);
|
||||
}
|
||||
|
||||
$user = $this->runtime->getEnvironmentConfig('user', $this->runtime->getCurrentUser());
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
namespace Mage\Task\BuiltIn\Deploy\TarGz;
|
||||
|
||||
use Mage\Runtime\Exception\DeploymentException;
|
||||
use Mage\Task\ErrorException;
|
||||
use Symfony\Component\Process\Process;
|
||||
use Mage\Task\AbstractTask;
|
||||
|
||||
|
@ -34,7 +34,7 @@ class PrepareTask extends AbstractTask
|
|||
public function execute()
|
||||
{
|
||||
if (!$this->runtime->getEnvironmentConfig('releases', false)) {
|
||||
throw new DeploymentException('This task is only available with releases enabled', 40);
|
||||
throw new ErrorException('This task is only available with releases enabled', 40);
|
||||
}
|
||||
|
||||
$tarGzLocal = $this->runtime->getTempFile();
|
||||
|
|
|
@ -93,9 +93,11 @@ class DeployCommandMiscTasksTest extends TestCase
|
|||
$command = $application->find('deploy');
|
||||
$this->assertTrue($command instanceof DeployCommand);
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
|
||||
try {
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
|
||||
$this->assertTrue(false, 'Command did not failed');
|
||||
} catch (Exception $exception) {
|
||||
$this->assertTrue($exception instanceof RuntimeException);
|
||||
$this->assertEquals('Invalid task name "invalid/task"', $exception->getMessage());
|
||||
|
|
|
@ -68,4 +68,68 @@ class DeployCommandWithReleasesTest extends TestCase
|
|||
|
||||
$this->assertEquals(0, $tester->getStatusCode());
|
||||
}
|
||||
|
||||
public function testDeploymentWithoutReleasesTarPrepare()
|
||||
{
|
||||
$application = new MageApplicationMockup();
|
||||
$application->configure(__DIR__ . '/../../Resources/testhost-force-tar1.yml');
|
||||
|
||||
/** @var AbstractCommand $command */
|
||||
$command = $application->find('deploy');
|
||||
$this->assertTrue($command instanceof DeployCommand);
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
|
||||
|
||||
$this->assertContains('This task is only available with releases enabled', $tester->getDisplay());
|
||||
$this->assertNotEquals(0, $tester->getStatusCode());
|
||||
}
|
||||
|
||||
public function testDeploymentWithoutReleasesTarCopy()
|
||||
{
|
||||
$application = new MageApplicationMockup();
|
||||
$application->configure(__DIR__ . '/../../Resources/testhost-force-tar2.yml');
|
||||
|
||||
/** @var AbstractCommand $command */
|
||||
$command = $application->find('deploy');
|
||||
$this->assertTrue($command instanceof DeployCommand);
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
|
||||
|
||||
$this->assertContains('This task is only available with releases enabled', $tester->getDisplay());
|
||||
$this->assertNotEquals(0, $tester->getStatusCode());
|
||||
}
|
||||
|
||||
public function testDeploymentWithoutReleasesTarCleanup()
|
||||
{
|
||||
$application = new MageApplicationMockup();
|
||||
$application->configure(__DIR__ . '/../../Resources/testhost-force-tar3.yml');
|
||||
|
||||
/** @var AbstractCommand $command */
|
||||
$command = $application->find('deploy');
|
||||
$this->assertTrue($command instanceof DeployCommand);
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
|
||||
|
||||
$this->assertContains('This task is only available with releases enabled', $tester->getDisplay());
|
||||
$this->assertNotEquals(0, $tester->getStatusCode());
|
||||
}
|
||||
|
||||
public function testDeploymentFailCopyCommands()
|
||||
{
|
||||
$application = new MageApplicationMockup();
|
||||
$application->configure(__DIR__ . '/../../Resources/testhost-fail-copy-tar.yml');
|
||||
|
||||
/** @var AbstractCommand $command */
|
||||
$command = $application->find('deploy');
|
||||
$this->assertTrue($command instanceof DeployCommand);
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
|
||||
|
||||
$this->assertContains('Copying files with TarGZ ... FAIL', $tester->getDisplay());
|
||||
$this->assertNotEquals(0, $tester->getStatusCode());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -78,6 +78,7 @@ class ListCommandTest extends TestCase
|
|||
|
||||
try {
|
||||
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
|
||||
$this->assertTrue(false, 'Command did not failed');
|
||||
} catch (Exception $exception) {
|
||||
$this->assertTrue($exception instanceof DeploymentException);
|
||||
$this->assertEquals('Releases are not enabled', $exception->getMessage());
|
||||
|
@ -97,6 +98,7 @@ class ListCommandTest extends TestCase
|
|||
|
||||
try {
|
||||
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
|
||||
$this->assertTrue(false, 'Command did not failed');
|
||||
} catch (Exception $exception) {
|
||||
$this->assertTrue($exception instanceof RuntimeException);
|
||||
$this->assertEquals('Unable to retrieve current release from host "host1"', $exception->getMessage());
|
||||
|
@ -131,6 +133,7 @@ class ListCommandTest extends TestCase
|
|||
|
||||
try {
|
||||
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
|
||||
$this->assertTrue(false, 'Command did not failed');
|
||||
} catch (Exception $exception) {
|
||||
$this->assertTrue($exception instanceof RuntimeException);
|
||||
$this->assertEquals('Unable to retrieve releases from host "host3"', $exception->getMessage());
|
||||
|
|
|
@ -73,12 +73,34 @@ class RollbackCommandTest extends TestCase
|
|||
$command = $application->find('releases:rollback');
|
||||
$this->assertTrue($command instanceof RollbackCommand);
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
|
||||
try {
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute(['command' => $command->getName(), 'environment' => 'test', 'release' => '20170101015115']);
|
||||
$this->assertTrue(false, 'Command did not failed');
|
||||
} catch (Exception $exception) {
|
||||
$this->assertTrue($exception instanceof DeploymentException);
|
||||
$this->assertEquals('Releases are not enabled', $exception->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function testRollbackReleaseNotAvailable()
|
||||
{
|
||||
$application = new MageApplicationMockup();
|
||||
$application->configure(__DIR__ . '/../../../Resources/testhost-not-have-release.yml');
|
||||
|
||||
/** @var AbstractCommand $command */
|
||||
$command = $application->find('releases:rollback');
|
||||
$this->assertTrue($command instanceof RollbackCommand);
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
|
||||
try {
|
||||
$tester->execute(['command' => $command->getName(), 'environment' => 'test', 'release' => '20170101015115']);
|
||||
$this->assertTrue(false, 'Command did not failed');
|
||||
} catch (Exception $exception) {
|
||||
$this->assertTrue($exception instanceof DeploymentException);
|
||||
$this->assertEquals('Release "20170101015115" is not available on all hosts', $exception->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
14
src/Mage/Tests/Resources/testhost-fail-copy-tar.yml
Normal file
14
src/Mage/Tests/Resources/testhost-fail-copy-tar.yml
Normal file
|
@ -0,0 +1,14 @@
|
|||
magephp:
|
||||
log_dir: /tmp
|
||||
environments:
|
||||
test:
|
||||
user: tester
|
||||
branch: test
|
||||
releases: 4
|
||||
host_path: /var/www/test
|
||||
exclude:
|
||||
- ./var/cache/*
|
||||
- ./var/log/*
|
||||
- ./web/app_dev.php
|
||||
hosts:
|
||||
- host4
|
15
src/Mage/Tests/Resources/testhost-force-tar1.yml
Normal file
15
src/Mage/Tests/Resources/testhost-force-tar1.yml
Normal file
|
@ -0,0 +1,15 @@
|
|||
magephp:
|
||||
log_dir: /tmp
|
||||
environments:
|
||||
test:
|
||||
user: tester
|
||||
branch: test
|
||||
host_path: /var/www/test
|
||||
exclude:
|
||||
- ./var/cache/*
|
||||
- ./var/log/*
|
||||
- ./web/app_dev.php
|
||||
hosts:
|
||||
- host2
|
||||
pre-deploy:
|
||||
- deploy/targz/prepare
|
15
src/Mage/Tests/Resources/testhost-force-tar2.yml
Normal file
15
src/Mage/Tests/Resources/testhost-force-tar2.yml
Normal file
|
@ -0,0 +1,15 @@
|
|||
magephp:
|
||||
log_dir: /tmp
|
||||
environments:
|
||||
test:
|
||||
user: tester
|
||||
branch: test
|
||||
host_path: /var/www/test
|
||||
exclude:
|
||||
- ./var/cache/*
|
||||
- ./var/log/*
|
||||
- ./web/app_dev.php
|
||||
hosts:
|
||||
- host2
|
||||
on-deploy:
|
||||
- deploy/targz/copy
|
15
src/Mage/Tests/Resources/testhost-force-tar3.yml
Normal file
15
src/Mage/Tests/Resources/testhost-force-tar3.yml
Normal file
|
@ -0,0 +1,15 @@
|
|||
magephp:
|
||||
log_dir: /tmp
|
||||
environments:
|
||||
test:
|
||||
user: tester
|
||||
branch: test
|
||||
host_path: /var/www/test
|
||||
exclude:
|
||||
- ./var/cache/*
|
||||
- ./var/log/*
|
||||
- ./web/app_dev.php
|
||||
hosts:
|
||||
- host2
|
||||
post-deploy:
|
||||
- deploy/targz/cleanup
|
16
src/Mage/Tests/Resources/testhost-not-have-release.yml
Normal file
16
src/Mage/Tests/Resources/testhost-not-have-release.yml
Normal file
|
@ -0,0 +1,16 @@
|
|||
magephp:
|
||||
log_dir: /tmp
|
||||
environments:
|
||||
test:
|
||||
user: tester
|
||||
branch: test
|
||||
host_path: /var/www/test
|
||||
releases: 4
|
||||
exclude:
|
||||
- ./var/cache/*
|
||||
- ./var/log/*
|
||||
- ./web/app_dev.php
|
||||
hosts:
|
||||
- hostdemo1
|
||||
- hostdemo2
|
||||
- hostdemo3
|
|
@ -37,6 +37,14 @@ class ProcessMockup extends Process
|
|||
if ($this->commandline == 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@host3 sh -c \"ls -1 /var/www/test/releases\"') {
|
||||
$this->success = false;
|
||||
}
|
||||
|
||||
if ($this->commandline == 'scp -P 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no /tmp/mageXYZ tester@host4:/var/www/test/releases/1234567890/mageXYZ') {
|
||||
$this->success = false;
|
||||
}
|
||||
|
||||
if ($this->commandline == 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@hostdemo2 sh -c \"ls -1 /var/www/test/releases\"') {
|
||||
$this->success = false;
|
||||
}
|
||||
}
|
||||
|
||||
public function isSuccessful()
|
||||
|
@ -67,6 +75,14 @@ class ProcessMockup extends Process
|
|||
return implode(PHP_EOL, ['20170101015110', '20170101015111', '20170101015112', '20170101015113', '20170101015114', '20170101015115', '20170101015116', '20170101015117']);
|
||||
}
|
||||
|
||||
if ($this->commandline == 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@hostdemo1 sh -c \"ls -1 /var/www/test/releases\"') {
|
||||
return implode(PHP_EOL, ['20170101015110', '20170101015111', '20170101015112', '20170101015113', '20170101015114', '20170101015115', '20170101015116', '20170101015117']);
|
||||
}
|
||||
|
||||
if ($this->commandline == 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@hostdemo3 sh -c \"ls -1 /var/www/test/releases\"') {
|
||||
return implode(PHP_EOL, ['20170101015110', '20170101015111', '20170101015112', '20170101015113', '20170101015114', '20170101015116', '20170101015117']);
|
||||
}
|
||||
|
||||
if ($this->commandline == 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@host2 sh -c \"ls -1 /var/www/test/releases\"') {
|
||||
return '';
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue