Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add bin/get_fpm_status #27

Merged
merged 1 commit into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bin/get_fpm_status
19 changes: 19 additions & 0 deletions hypernode_api_python/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
HYPERNODE_API_BLOCK_ATTACK_ENDPOINT = "/v2/app/{}/block_attack/"
HYPERNODE_API_BLOCK_ATTACK_DESCRIPTION_ENDPOINT = "/v2/app/block_attack_descriptions/"
HYPERNODE_API_BRANCHER_APP_ENDPOINT = "/v2/brancher/app/{}/"
HYPERNODE_API_FPM_STATUS_APP_ENDPOINT = "/v2/nats/{}/hypernode.show-fpm-status"
HYPERNODE_API_BRANCHER_ENDPOINT = "/v2/brancher/{}/"
HYPERNODE_API_PRODUCT_APP_DETAIL_ENDPOINT = "/v2/product/app/{}/current/"
HYPERNODE_API_PRODUCT_LIST_ENDPOINT = "/v2/product/"
Expand Down Expand Up @@ -840,6 +841,24 @@ def get_active_branchers(self, app_name):
"GET", HYPERNODE_API_BRANCHER_APP_ENDPOINT.format(app_name)
)

def get_fpm_status(self, app_name):
"""
Get the status of the FPM service for the specified app
Example:
> client.get_fpm_status("yourhypernodeappname").json()
{
"message": null,
"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",
"status": 200
}

:param str app_name: The name of the Hypernode to get the FPM status for
:return obj response: The request response object
"""
return self.requests(
"POST", HYPERNODE_API_FPM_STATUS_APP_ENDPOINT.format(app_name)
)

def create_brancher(self, app_name, data):
"""
Create a new branch (server replica) of your Hypernode.
Expand Down
21 changes: 21 additions & 0 deletions hypernode_api_python/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -701,3 +701,24 @@ def destroy_brancher(args=None):
)
)
exit(EX_UNAVAILABLE)


def get_fpm_status(args=None):
parser = ArgumentParser(
description="""
Show the status of the PHP-FPM workers.

Example:
$ ./bin/get_fpm_status
{
"message": null,
"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",
"status": 200
}
""",
formatter_class=RawTextHelpFormatter,
)
parser.parse_args(args=args)
client = get_client()
app_name = get_app_name()
print_response(client.get_fpm_status(app_name))
39 changes: 39 additions & 0 deletions tests/client/test_get_fpm_status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from unittest import TestCase
from unittest.mock import Mock

from hypernode_api_python.client import (
HypernodeAPIPython,
HYPERNODE_API_FPM_STATUS_APP_ENDPOINT,
)


class TestGetFPMStatus(TestCase):
def setUp(self):
self.client = HypernodeAPIPython(token="my_token")
self.mock_request = Mock()
self.client.requests = self.mock_request
self.app_name = "my_app"

def test_get_fpm_status_endpoint_is_correct(self):
self.assertEqual(
"/v2/nats/{}/hypernode.show-fpm-status",
HYPERNODE_API_FPM_STATUS_APP_ENDPOINT,
)

def test_calls_fpm_status_endpoint_properly(self):
self.client.get_fpm_status(self.app_name)

self.mock_request.assert_called_once_with(
"POST",
f"/v2/nats/{self.app_name}/hypernode.show-fpm-status",
)

def test_returns_fpm_status_data(self):
response = Mock()
response.status_code = 200
self.mock_request.return_value = response

self.assertEqual(
self.client.get_fpm_status(self.app_name),
self.mock_request.return_value,
)
32 changes: 32 additions & 0 deletions tests/commands/test_get_fpm_status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from hypernode_api_python.commands import get_fpm_status
from tests.testcase import TestCase


class TestGetFPMStatus(TestCase):
def setUp(self):
self.print_response = self.set_up_patch(
"hypernode_api_python.commands.print_response"
)
self.get_client = self.set_up_patch("hypernode_api_python.commands.get_client")
self.client = self.get_client.return_value
self.get_app_name = self.set_up_patch(
"hypernode_api_python.commands.get_app_name"
)
self.get_app_name.return_value = "myappname"

def test_get_fpm_status_gets_client(self):
get_fpm_status([])

self.get_client.assert_called_once_with()

def test_get_fpm_status_gets_fpm_status(self):
get_fpm_status([])

self.client.get_fpm_status.assert_called_once_with("myappname")

def test_get_fpm_status_prints_fpm_status(self):
get_fpm_status([])

self.print_response.assert_called_once_with(
self.client.get_fpm_status.return_value
)
Loading