Skip to content
This repository has been archived by the owner on Nov 21, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' into fix/devicedetailstags
Browse files Browse the repository at this point in the history
  • Loading branch information
cicharka authored Apr 19, 2024
2 parents 0c9affc + 21b7fb5 commit 19fdfde
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 6 deletions.
2 changes: 1 addition & 1 deletion catalystwan/api/monitoring_status_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import logging
from typing import TYPE_CHECKING, List

from catalystwan.endpoints.monitoring_status import MonitoringStatus, Status, UpdateStatus
from catalystwan.endpoints.monitoring.status import MonitoringStatus, Status, UpdateStatus
from catalystwan.typed_list import DataSequence

logger = logging.getLogger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion catalystwan/api/templates/payloads/tenant/tenant_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from pydantic import BaseModel, ConfigDict

from catalystwan.api.templates.feature_template import FeatureTemplate
from catalystwan.endpoints.monitoring_device_details import Tier as TierInfo
from catalystwan.endpoints.monitoring.device_details import Tier as TierInfo
from catalystwan.models.tenant import Tenant as TenantInfo

if TYPE_CHECKING:
Expand Down
6 changes: 4 additions & 2 deletions catalystwan/endpoints/endpoints_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@
from catalystwan.endpoints.configuration_group import ConfigurationGroup
from catalystwan.endpoints.configuration_settings import ConfigurationSettings
from catalystwan.endpoints.misc import MiscellaneousEndpoints
from catalystwan.endpoints.monitoring_device_details import MonitoringDeviceDetails
from catalystwan.endpoints.monitoring_status import MonitoringStatus
from catalystwan.endpoints.monitoring.device_details import MonitoringDeviceDetails
from catalystwan.endpoints.monitoring.server_info import ServerInfo
from catalystwan.endpoints.monitoring.status import MonitoringStatus
from catalystwan.endpoints.real_time_monitoring.reboot_history import RealTimeMonitoringRebootHistory
from catalystwan.endpoints.sdavc_cloud_connector import SDAVCCloudConnector
from catalystwan.endpoints.tenant_backup_restore import TenantBackupRestore
Expand Down Expand Up @@ -198,6 +199,7 @@ def __init__(self, session: ManagerSession):
self.configuration_software_actions = ConfigurationSoftwareActions(session)
self.configuration_disaster_recovery = ConfigurationDisasterRecovery(session)
self.monitoring_device_details = MonitoringDeviceDetails(session)
self.monitoring_server_info = ServerInfo(session)
self.monitoring_status = MonitoringStatus(session)
self.sdavc_cloud_connector = SDAVCCloudConnector(session)
self.tenant_backup_restore = TenantBackupRestore(session)
Expand Down
12 changes: 12 additions & 0 deletions catalystwan/endpoints/monitoring/server_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright 2024 Cisco Systems, Inc. and its affiliates

# mypy: disable-error-code="empty-body"

from catalystwan.endpoints import APIEndpoints, get
from catalystwan.models.monitoring.server_info import ServerInfoResponse


class ServerInfo(APIEndpoints):
@get("/server/info")
def get_server_info(self) -> ServerInfoResponse:
...
12 changes: 12 additions & 0 deletions catalystwan/models/monitoring/server_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright 2024 Cisco Systems, Inc. and its affiliates

from pydantic import BaseModel, Field


class ServerInfoResponse(BaseModel):
"""The response may contain an incorrect spelling "Achitecture"."""

architecture: str = Field(..., alias="Achitecture")
available_processors: int = Field(
..., serialization_alias="Available processors", validation_alias="Available processors"
)
2 changes: 1 addition & 1 deletion catalystwan/tests/test_devices_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from catalystwan.api.basic_api import DevicesAPI, DeviceStateAPI
from catalystwan.dataclasses import BfdSessionData, Connection, Device, WanInterface
from catalystwan.endpoints.endpoints_container import APIEndpointContainter
from catalystwan.endpoints.monitoring_device_details import DeviceData
from catalystwan.endpoints.monitoring.device_details import DeviceData
from catalystwan.endpoints.real_time_monitoring.reboot_history import RebootEntry
from catalystwan.exceptions import CatalystwanException
from catalystwan.response import ManagerResponse
Expand Down
49 changes: 49 additions & 0 deletions catalystwan/tests/test_monitoring_server_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Copyright 2022 Cisco Systems, Inc. and its affiliates

import unittest
from unittest.mock import MagicMock, patch

from catalystwan.endpoints.monitoring.server_info import ServerInfo
from catalystwan.models.monitoring.server_info import ServerInfoResponse


class TestServerInfo(unittest.TestCase):
def setUp(self) -> None:
self.mock_server_info_data = {
"Achitecture": "x86_64",
"Available processors": 4,
} # Note the spelling error

@patch("catalystwan.session.ManagerSession")
def test_get_server_info(self, mock_session):
# Arrange
# Create a MagicMock for the response that has a dataobj method
mock_response = MagicMock()
# Set up the mock response's dataobj method to return a ServerInfoResponse
mock_response.dataobj.return_value = ServerInfoResponse(**self.mock_server_info_data)

# Mock the request method of the ManagerSession to return the mock response
mock_session_instance = mock_session.return_value
mock_session_instance.request.return_value = mock_response

server_info_api = ServerInfo(mock_session_instance)

# Act
response = server_info_api.get_server_info()

# Assert
self.assertIsInstance(response, ServerInfoResponse)
self.assertEqual(response.architecture, self.mock_server_info_data["Achitecture"])
self.assertEqual(
response.available_processors,
self.mock_server_info_data["Available processors"],
)
self.assertEqual(response.architecture, "x86_64")
self.assertEqual(response.available_processors, 4)

# Ensure the request method was called
mock_session_instance.request.assert_called_once()


if __name__ == "__main__":
unittest.main()
2 changes: 1 addition & 1 deletion catalystwan/tests/test_monitoring_status_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from unittest.mock import MagicMock, patch

from catalystwan.api.monitoring_status_api import MonitoringStatusAPI
from catalystwan.endpoints.monitoring_status import (
from catalystwan.endpoints.monitoring.status import (
DisabledDeviceListResponse,
EnabledIndexDeviceListResponse,
Status,
Expand Down

0 comments on commit 19fdfde

Please sign in to comment.