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. * 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. * 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. * 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 ### Added
* Server listing view now displays the total used disk space for each server. * 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(); $bar->clear();
try { try {
$this->powerRepository->setServer($server)->sendSignal($action); $this->powerRepository
->setNode($server->node)
->setServer($server)
->sendSignal($action);
} catch (RequestException $exception) { } catch (RequestException $exception) {
$this->output->error(trans('command/messages.server.power.action_failed', [ $this->output->error(trans('command/messages.server.power.action_failed', [
'name' => $server->name, 'name' => $server->name,

View file

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