Skip to content

Commit

Permalink
Merge pull request #245 from Limmen/dev
Browse files Browse the repository at this point in the history
Test startPostgreSQL GRPC
  • Loading branch information
Limmen authored Aug 21, 2023
2 parents 4ed850e + cfb62ca commit 8785257
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def getNodeStatus(self, request: csle_cluster.cluster_manager.cluster_manager_pb
dockerEngineRunning=docker_engine_running
)

def startPosgtreSQL(self, request: csle_cluster.cluster_manager.cluster_manager_pb2.StartPostgreSQLMsg,
def startPostgreSQL(self, request: csle_cluster.cluster_manager.cluster_manager_pb2.StartPostgreSQLMsg,
context: grpc.ServicerContext) \
-> csle_cluster.cluster_manager.cluster_manager_pb2.ServiceStatusDTO:
"""
Expand All @@ -87,6 +87,7 @@ def startPosgtreSQL(self, request: csle_cluster.cluster_manager.cluster_manager_
"""
logging.info(f"Starting postgresql with command: {constants.COMMANDS.POSTGRESQL_START}")
operation_status, stdout, stderr = ManagementSystemController.start_postgresql(logger=logging.getLogger())

logging.info(f"Started postgresql, stdout:{stdout}, stderr: {stderr}")
return csle_cluster.cluster_manager.cluster_manager_pb2.ServiceStatusDTO(running=True)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import pytest
import pytest_mock
from csle_cluster.cluster_manager.cluster_manager import ClusterManagerServicer
from csle_cluster.cluster_manager.cluster_manager_pb2 import ServiceStatusDTO
from csle_common.dao.emulation_config.config import Config
import csle_cluster.cluster_manager.query_cluster_manager
from csle_cluster.cluster_manager.cluster_manager_pb2 import NodeStatusDTO
Expand Down Expand Up @@ -45,7 +46,7 @@ def grpc_stub_cls(self, grpc_channel):
def test_getNodeStatus(self, grpc_stub, mocker: pytest_mock.MockFixture, example_config: Config) -> None:
"""
Tests the getNodeStatus grpc
:param grpc_stub: the stub for the GRPC server to make the request to
:param mocker: the mocker object to mock functions with external dependencies
:return: None
Expand Down Expand Up @@ -123,3 +124,24 @@ def test_getNodeStatus(self, grpc_stub, mocker: pytest_mock.MockFixture, example
assert not response.nodeExporterRunning
assert not response.postgreSQLRunning
assert not response.dockerEngineRunning

def test_startPosgtreSQL(self, grpc_stub, mocker: pytest_mock.MockFixture, example_config: Config) -> None:
"""
Tests the startPosgtreSQL grpc
:param grpc_stub: the stub for the GRPC server to make the request to
:param mocker: the mocker object to mock functions with external dependencies
:return: None
"""
mocker.patch('csle_common.controllers.management_system_controller.'
'ManagementSystemController.start_postgresql', return_value=(False, None, None))
mocker.patch('csle_common.controllers.management_system_controller.'
'ManagementSystemController.is_postgresql_running', return_value=True)
response: ServiceStatusDTO = csle_cluster.cluster_manager.query_cluster_manager.start_postgresql(stub=grpc_stub)
assert response.running
mocker.patch('csle_common.controllers.management_system_controller.'
'ManagementSystemController.start_postgresql', return_value=(True, "PIPE", "PIPE"))
mocker.patch('csle_common.controllers.management_system_controller.'
'ManagementSystemController.is_postgresql_running', return_value=False)
response = csle_cluster.cluster_manager.query_cluster_manager.start_postgresql(stub=grpc_stub)
assert response.running

0 comments on commit 8785257

Please sign in to comment.