diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d41ced77..240ec73e8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/app/Console/Commands/Server/BulkPowerActionCommand.php b/app/Console/Commands/Server/BulkPowerActionCommand.php index 91e761e68..c6b5e435f 100644 --- a/app/Console/Commands/Server/BulkPowerActionCommand.php +++ b/app/Console/Commands/Server/BulkPowerActionCommand.php @@ -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, diff --git a/tests/Unit/Commands/Server/BulkPowerActionCommandTest.php b/tests/Unit/Commands/Server/BulkPowerActionCommandTest.php index a1c3bfaf2..d3661ca66 100644 --- a/tests/Unit/Commands/Server/BulkPowerActionCommandTest.php +++ b/tests/Unit/Commands/Server/BulkPowerActionCommandTest.php @@ -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',