Skip to content

Commit 29c946e

Browse files
authored
Merge pull request #27 from ByteInternet/add-fpm-status
add bin/get_fpm_status
2 parents ba41f05 + 99ef772 commit 29c946e

File tree

5 files changed

+112
-0
lines changed

5 files changed

+112
-0
lines changed

bin/get_fpm_status

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
command

hypernode_api_python/client.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
HYPERNODE_API_BLOCK_ATTACK_ENDPOINT = "/v2/app/{}/block_attack/"
2222
HYPERNODE_API_BLOCK_ATTACK_DESCRIPTION_ENDPOINT = "/v2/app/block_attack_descriptions/"
2323
HYPERNODE_API_BRANCHER_APP_ENDPOINT = "/v2/brancher/app/{}/"
24+
HYPERNODE_API_FPM_STATUS_APP_ENDPOINT = "/v2/nats/{}/hypernode.show-fpm-status"
2425
HYPERNODE_API_BRANCHER_ENDPOINT = "/v2/brancher/{}/"
2526
HYPERNODE_API_PRODUCT_APP_DETAIL_ENDPOINT = "/v2/product/app/{}/current/"
2627
HYPERNODE_API_PRODUCT_LIST_ENDPOINT = "/v2/product/"
@@ -840,6 +841,24 @@ def get_active_branchers(self, app_name):
840841
"GET", HYPERNODE_API_BRANCHER_APP_ENDPOINT.format(app_name)
841842
)
842843

844+
def get_fpm_status(self, app_name):
845+
"""
846+
Get the status of the FPM service for the specified app
847+
Example:
848+
> client.get_fpm_status("yourhypernodeappname").json()
849+
{
850+
"message": null,
851+
"data": "50570 IDLE 0.0s - phpfpm 127.0.0.1 GET magweb/status.php (python-requests/2.28.1)\n50571 IDLE 0.0s - phpfpm 127.0.0.1 GET magweb/status.php (python-requests/2.28.1)\n",
852+
"status": 200
853+
}
854+
855+
:param str app_name: The name of the Hypernode to get the FPM status for
856+
:return obj response: The request response object
857+
"""
858+
return self.requests(
859+
"POST", HYPERNODE_API_FPM_STATUS_APP_ENDPOINT.format(app_name)
860+
)
861+
843862
def create_brancher(self, app_name, data):
844863
"""
845864
Create a new branch (server replica) of your Hypernode.

hypernode_api_python/commands.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,3 +701,24 @@ def destroy_brancher(args=None):
701701
)
702702
)
703703
exit(EX_UNAVAILABLE)
704+
705+
706+
def get_fpm_status(args=None):
707+
parser = ArgumentParser(
708+
description="""
709+
Show the status of the PHP-FPM workers.
710+
711+
Example:
712+
$ ./bin/get_fpm_status
713+
{
714+
"message": null,
715+
"data": "50570 IDLE 0.0s - phpfpm 127.0.0.1 GET magweb/status.php (python-requests/2.28.1)\n50571 IDLE 0.0s - phpfpm 127.0.0.1 GET magweb/status.php (python-requests/2.28.1)\n",
716+
"status": 200
717+
}
718+
""",
719+
formatter_class=RawTextHelpFormatter,
720+
)
721+
parser.parse_args(args=args)
722+
client = get_client()
723+
app_name = get_app_name()
724+
print_response(client.get_fpm_status(app_name))

tests/client/test_get_fpm_status.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from unittest import TestCase
2+
from unittest.mock import Mock
3+
4+
from hypernode_api_python.client import (
5+
HypernodeAPIPython,
6+
HYPERNODE_API_FPM_STATUS_APP_ENDPOINT,
7+
)
8+
9+
10+
class TestGetFPMStatus(TestCase):
11+
def setUp(self):
12+
self.client = HypernodeAPIPython(token="my_token")
13+
self.mock_request = Mock()
14+
self.client.requests = self.mock_request
15+
self.app_name = "my_app"
16+
17+
def test_get_fpm_status_endpoint_is_correct(self):
18+
self.assertEqual(
19+
"/v2/nats/{}/hypernode.show-fpm-status",
20+
HYPERNODE_API_FPM_STATUS_APP_ENDPOINT,
21+
)
22+
23+
def test_calls_fpm_status_endpoint_properly(self):
24+
self.client.get_fpm_status(self.app_name)
25+
26+
self.mock_request.assert_called_once_with(
27+
"POST",
28+
f"/v2/nats/{self.app_name}/hypernode.show-fpm-status",
29+
)
30+
31+
def test_returns_fpm_status_data(self):
32+
response = Mock()
33+
response.status_code = 200
34+
self.mock_request.return_value = response
35+
36+
self.assertEqual(
37+
self.client.get_fpm_status(self.app_name),
38+
self.mock_request.return_value,
39+
)

tests/commands/test_get_fpm_status.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from hypernode_api_python.commands import get_fpm_status
2+
from tests.testcase import TestCase
3+
4+
5+
class TestGetFPMStatus(TestCase):
6+
def setUp(self):
7+
self.print_response = self.set_up_patch(
8+
"hypernode_api_python.commands.print_response"
9+
)
10+
self.get_client = self.set_up_patch("hypernode_api_python.commands.get_client")
11+
self.client = self.get_client.return_value
12+
self.get_app_name = self.set_up_patch(
13+
"hypernode_api_python.commands.get_app_name"
14+
)
15+
self.get_app_name.return_value = "myappname"
16+
17+
def test_get_fpm_status_gets_client(self):
18+
get_fpm_status([])
19+
20+
self.get_client.assert_called_once_with()
21+
22+
def test_get_fpm_status_gets_fpm_status(self):
23+
get_fpm_status([])
24+
25+
self.client.get_fpm_status.assert_called_once_with("myappname")
26+
27+
def test_get_fpm_status_prints_fpm_status(self):
28+
get_fpm_status([])
29+
30+
self.print_response.assert_called_once_with(
31+
self.client.get_fpm_status.return_value
32+
)

0 commit comments

Comments
 (0)