Fix bulk power when spanning multiple nodes, closes #1526

This commit is contained in:
Dane Everitt 2019-08-03 14:04:31 -07:00
parent 81409947cf
commit e7e41d8ee8
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
3 changed files with 19 additions and 7 deletions

View file

@ -15,6 +15,7 @@ error encountered during creation or update.
* Two-factor tokens generated when a company name has a space in it will now properly be parsed on iOS authenticator devices.
* Fixed 500 error when trying to request subuser's from a server in the application API.
* Creating a node allocation via the API no longer requires an alias field be passed through in the request.
* Bulk power management for servers via the CLI no longer fails when servers span multiple nodes.
### Added
* Server listing view now displays the total used disk space for each server.

View file

@ -102,7 +102,10 @@ class BulkPowerActionCommand extends Command
$bar->clear();
try {
$this->powerRepository->setServer($server)->sendSignal($action);
$this->powerRepository
->setNode($server->node)
->setServer($server)
->sendSignal($action);
} catch (RequestException $exception) {
$this->output->error(trans('command/messages.server.power.action_failed', [
'name' => $server->name,

View file

@ -3,6 +3,8 @@
namespace Tests\Unit\Commands\Server;
use Mockery as m;
use Pterodactyl\Models\Node;
use GuzzleHttp\Psr7\Response;
use Pterodactyl\Models\Server;
use Illuminate\Validation\Factory;
use Tests\Unit\Commands\CommandTestCase;
@ -38,8 +40,13 @@ class BulkPowerActionCommandTest extends CommandTestCase
*/
public function testSendAction()
{
/** @var \Pterodactyl\Models\Server[] $servers */
$servers = factory(Server::class)->times(2)->make();
foreach ($servers as &$server) {
$server->setRelation('node', factory(Node::class)->make());
}
$this->repository->shouldReceive('getServersForPowerActionCount')
->once()
->with([], [])
@ -51,7 +58,7 @@ class BulkPowerActionCommandTest extends CommandTestCase
->andReturn($servers);
for ($i = 0; $i < count($servers); $i++) {
$this->powerRepository->shouldReceive('setServer->sendSignal')
$this->powerRepository->shouldReceive('setNode->setServer->sendSignal')
->once()
->with('kill')
->andReturnNull();
@ -70,6 +77,7 @@ class BulkPowerActionCommandTest extends CommandTestCase
public function testSendWithFilters()
{
$server = factory(Server::class)->make();
$server->setRelation('node', $node = factory(Node::class)->make());
$this->repository->shouldReceive('getServersForPowerActionCount')
->once()
@ -81,10 +89,9 @@ class BulkPowerActionCommandTest extends CommandTestCase
->with([1, 2], [3, 4])
->andReturn([$server]);
$this->powerRepository->shouldReceive('setServer->sendSignal')
->once()
->with('kill')
->andReturnNull();
$this->powerRepository->expects('setNode')->with($node)->andReturnSelf();
$this->powerRepository->expects('setServer')->with($server)->andReturnSelf();
$this->powerRepository->expects('sendSignal')->with('kill')->andReturn(new Response);
$display = $this->runCommand($this->getCommand(), [
'action' => 'kill',
@ -103,6 +110,7 @@ class BulkPowerActionCommandTest extends CommandTestCase
public function testSendWithEmptyOptions()
{
$server = factory(Server::class)->make();
$server->setRelation('node', factory(Node::class)->make());
$this->repository->shouldReceive('getServersForPowerActionCount')
->once()
@ -110,7 +118,7 @@ class BulkPowerActionCommandTest extends CommandTestCase
->andReturn(1);
$this->repository->shouldReceive('getServersForPowerAction')->once()->with([], [])->andReturn([$server]);
$this->powerRepository->shouldReceive('setServer->sendSignal')->once()->with('kill')->andReturnNull();
$this->powerRepository->shouldReceive('setNode->setServer->sendSignal')->once()->with('kill')->andReturnNull();
$display = $this->runCommand($this->getCommand(), [
'action' => 'kill',