-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cterasdk/core/messaging.py cterasdk/tests/ut/test_core_messaging.py cterasdk/docs/source/user_guides/Portal/GlobalAdmin.rst
- Loading branch information
1 parent
5276a5f
commit 5640b18
Showing
6 changed files
with
156 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,5 +19,6 @@ | |
'cloudfs', | ||
'zones', | ||
'files', | ||
'decorator' | ||
'decorator', | ||
'messaging' | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import logging | ||
|
||
from .base_command import BaseCommand | ||
from ..common import Object | ||
|
||
|
||
class Messaging(BaseCommand): | ||
""" | ||
Portal Messaging Service Management APIs | ||
""" | ||
|
||
def is_active(self): | ||
""" | ||
Check if messaging service is Active | ||
""" | ||
return self._portal.get('/microservices/messaging/globalStatus').status == 'Active' | ||
|
||
def get_status(self): | ||
""" | ||
Retrieve the global status of messaging service | ||
""" | ||
res = self._portal.get('/microservices/messaging/globalStatus') | ||
return res | ||
|
||
def get_servers_status(self): | ||
""" | ||
Retrieve the status of the messaging servers | ||
""" | ||
return {f'{srv.server.name}: "{srv.serverStatus.status}"' for srv in self._portal.get('/microservices/messaging').currentNodes} | ||
|
||
def add(self, servers): | ||
""" | ||
Add messaging servers to cluster | ||
:param list[str] servers: Server names (number of allowed servers: 1 or 3) | ||
""" | ||
nodes = [] | ||
messaging_obj = self._portal.get('/microservices/messaging') | ||
if messaging_obj.globalStatus.canAddServers: | ||
for node in messaging_obj.availableNodes: | ||
if node.server.name in servers and node.canAssignAsMessaging.allowed: | ||
param = Object() | ||
param._class = 'CurrentMessagingNode' # pylint: disable=protected-access | ||
param.server = node.server | ||
nodes.append(param) | ||
if len(nodes) in messaging_obj.globalStatus.validServerNumber: | ||
response = self._portal.put('microservices/messaging/currentNodes', nodes) | ||
logging.getLogger().info('Nodes added to cluster successfully') | ||
return response | ||
logging.getLogger().error('Wrong number of servers. expected:"1" or "3", %s', {'given': len(servers)}) | ||
else: | ||
logging.getLogger().error('Can not add new servers: %s', {messaging_obj.globalStatus.cantAddServersReason}) | ||
return None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
from unittest import mock | ||
|
||
from cterasdk.common import Object | ||
from cterasdk.core import messaging | ||
from tests.ut import base_core | ||
|
||
|
||
class TestCoreMessaging(base_core.BaseCoreTest): | ||
|
||
def setUp(self): | ||
super().setUp() | ||
self._servers = ["server1", "server2", "server3"] | ||
self._messaging = Object() | ||
|
||
self._messaging.globalStatus = Object() | ||
self._messaging.globalStatus._class = "GlobalMessagingStatus" # pylint: disable=protected-access | ||
self._messaging.globalStatus.status = "Active" | ||
self._messaging.globalStatus.canAddServers = True | ||
self._messaging.globalStatus.cantAddServersReason = "" | ||
self._messaging.globalStatus.validServerNumber = [1, 3] | ||
|
||
self._messaging.availableNodes = [] | ||
self._messaging.currentNodes = [] | ||
for server in self._servers: | ||
_node = Object() | ||
_node._class = "MessagingServerCandidate" # pylint: disable=protected-access | ||
_node.canAssignAsMessaging = Object() | ||
_node.canAssignAsMessaging.allowed = True | ||
_node.server = Object() | ||
_node.server.name = server | ||
self._messaging.availableNodes.append(_node) | ||
|
||
def test_status(self): | ||
self._init_global_admin(get_response=self._messaging.globalStatus) | ||
ret = messaging.Messaging(self._global_admin).get_status() | ||
self._global_admin.get.assert_called_once_with('/microservices/messaging/globalStatus') | ||
self.assertEqual(ret, self._messaging.globalStatus) | ||
|
||
def test_is_active(self): | ||
self._init_global_admin(get_response=self._messaging.globalStatus) | ||
messaging.Messaging(self._global_admin).is_active() | ||
self._global_admin.get.assert_called_once_with('/microservices/messaging/globalStatus') | ||
|
||
def test_add_server(self): | ||
self._init_global_admin(get_response=self._messaging) | ||
messaging.Messaging(self._global_admin).add(self._servers) | ||
self._global_admin.get.assert_called_once_with('/microservices/messaging') | ||
self._global_admin.put.assert_called_once_with('microservices/messaging/currentNodes', mock.ANY) | ||
expected_param = self._get_current_node_objects() | ||
actual_param = self._global_admin.put.call_args[0][1] | ||
self._assert_equal_objects(actual_param, expected_param) | ||
|
||
def _get_current_node_objects(self): | ||
nodes = [] | ||
for node in self._messaging.availableNodes: | ||
current_node_object = Object() | ||
current_node_object._class = "CurrentMessagingNode" # pylint: disable=protected-access | ||
current_node_object.server = node.server | ||
current_node_object.serverStatus = Object() | ||
current_node_object.serverStatus.status = "Running" | ||
current_node_object.serverStatus._class = "MessagingServerStatus" # pylint: disable=protected-access | ||
nodes.append(current_node_object) | ||
return nodes |