Skip to content

Commit e7e41d8

Browse files
committed
Fix bulk power when spanning multiple nodes, closes pterodactyl#1526
1 parent 8140994 commit e7e41d8

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ error encountered during creation or update.
1515
* Two-factor tokens generated when a company name has a space in it will now properly be parsed on iOS authenticator devices.
1616
* Fixed 500 error when trying to request subuser's from a server in the application API.
1717
* Creating a node allocation via the API no longer requires an alias field be passed through in the request.
18+
* Bulk power management for servers via the CLI no longer fails when servers span multiple nodes.
1819

1920
### Added
2021
* Server listing view now displays the total used disk space for each server.

app/Console/Commands/Server/BulkPowerActionCommand.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,10 @@ public function handle()
102102
$bar->clear();
103103

104104
try {
105-
$this->powerRepository->setServer($server)->sendSignal($action);
105+
$this->powerRepository
106+
->setNode($server->node)
107+
->setServer($server)
108+
->sendSignal($action);
106109
} catch (RequestException $exception) {
107110
$this->output->error(trans('command/messages.server.power.action_failed', [
108111
'name' => $server->name,

tests/Unit/Commands/Server/BulkPowerActionCommandTest.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
namespace Tests\Unit\Commands\Server;
44

55
use Mockery as m;
6+
use Pterodactyl\Models\Node;
7+
use GuzzleHttp\Psr7\Response;
68
use Pterodactyl\Models\Server;
79
use Illuminate\Validation\Factory;
810
use Tests\Unit\Commands\CommandTestCase;
@@ -38,8 +40,13 @@ public function setUp()
3840
*/
3941
public function testSendAction()
4042
{
43+
/** @var \Pterodactyl\Models\Server[] $servers */
4144
$servers = factory(Server::class)->times(2)->make();
4245

46+
foreach ($servers as &$server) {
47+
$server->setRelation('node', factory(Node::class)->make());
48+
}
49+
4350
$this->repository->shouldReceive('getServersForPowerActionCount')
4451
->once()
4552
->with([], [])
@@ -51,7 +58,7 @@ public function testSendAction()
5158
->andReturn($servers);
5259

5360
for ($i = 0; $i < count($servers); $i++) {
54-
$this->powerRepository->shouldReceive('setServer->sendSignal')
61+
$this->powerRepository->shouldReceive('setNode->setServer->sendSignal')
5562
->once()
5663
->with('kill')
5764
->andReturnNull();
@@ -70,6 +77,7 @@ public function testSendAction()
7077
public function testSendWithFilters()
7178
{
7279
$server = factory(Server::class)->make();
80+
$server->setRelation('node', $node = factory(Node::class)->make());
7381

7482
$this->repository->shouldReceive('getServersForPowerActionCount')
7583
->once()
@@ -81,10 +89,9 @@ public function testSendWithFilters()
8189
->with([1, 2], [3, 4])
8290
->andReturn([$server]);
8391

84-
$this->powerRepository->shouldReceive('setServer->sendSignal')
85-
->once()
86-
->with('kill')
87-
->andReturnNull();
92+
$this->powerRepository->expects('setNode')->with($node)->andReturnSelf();
93+
$this->powerRepository->expects('setServer')->with($server)->andReturnSelf();
94+
$this->powerRepository->expects('sendSignal')->with('kill')->andReturn(new Response);
8895

8996
$display = $this->runCommand($this->getCommand(), [
9097
'action' => 'kill',
@@ -103,14 +110,15 @@ public function testSendWithFilters()
103110
public function testSendWithEmptyOptions()
104111
{
105112
$server = factory(Server::class)->make();
113+
$server->setRelation('node', factory(Node::class)->make());
106114

107115
$this->repository->shouldReceive('getServersForPowerActionCount')
108116
->once()
109117
->with([], [])
110118
->andReturn(1);
111119

112120
$this->repository->shouldReceive('getServersForPowerAction')->once()->with([], [])->andReturn([$server]);
113-
$this->powerRepository->shouldReceive('setServer->sendSignal')->once()->with('kill')->andReturnNull();
121+
$this->powerRepository->shouldReceive('setNode->setServer->sendSignal')->once()->with('kill')->andReturnNull();
114122

115123
$display = $this->runCommand($this->getCommand(), [
116124
'action' => 'kill',

0 commit comments

Comments
 (0)