-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Renamed platform_info to system_info for wider applicability
- Loading branch information
1 parent
c61fe30
commit 82b1663
Showing
5 changed files
with
108 additions
and
83 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,71 @@ | ||
"""SystemInfo adapter class for the ODIN server. | ||
This class implements a system information adapter for the ODIN server, exposing | ||
via an API adapter information about the system that the server is running on. | ||
Tim Nicholls, STFC Application Engineering | ||
""" | ||
import logging | ||
import platform | ||
|
||
from odin.adapters.adapter import ApiAdapter, ApiAdapterResponse, request_types, response_types | ||
|
||
|
||
class SystemInfoAdapter(ApiAdapter): | ||
"""Platform info adapter for the ODIN server. | ||
This adapter provides read-only (via HTTP GET requests) access to underlying system | ||
information. | ||
""" | ||
|
||
def __init__(self, **kwargs): | ||
"""Initialize the SystemInfoAdapter object. | ||
This constructor initializes the SystemInfoAdapter object, resolving static underlying | ||
information about the plaform on which the ODIN server is running. | ||
:param kwargs: keyword arguments specifying options | ||
""" | ||
super(SystemInfoAdapter, self).__init__(**kwargs) | ||
|
||
self.system_info = {} | ||
|
||
self.system_info['system'] = platform.system() | ||
self.system_info['release'] = platform.release() | ||
self.system_info['version'] = platform.version() | ||
|
||
self.system_info['type'] = self._resolve_platform_type() | ||
|
||
logging.debug("SystemInfoAdapter loaded with system_info", self.system_info) | ||
|
||
def _resolve_platform_type(self): | ||
"""Resolve platform type. | ||
This private method attempts to resolve the platform type (e.g. BeagleBoneBlack, Mac) | ||
from the platform information | ||
""" | ||
platform_type = 'Unknown' | ||
|
||
if platform.system() == 'Darwin': | ||
platform_type = 'mac' | ||
|
||
return platform_type | ||
|
||
def get(self, path, request): | ||
"""Handle an HTTP GET request. | ||
This method handles an HTTP GET request, returning a JSON response. | ||
:param path: URI path of request | ||
:param request: HTTP request object | ||
:return: an ApiAdapterResponse object containing the appropriate response | ||
""" | ||
response = {'system_info': self.system_info} | ||
|
||
content_type = 'application/json' | ||
status_code = 200 | ||
|
||
logging.debug(response) | ||
|
||
return ApiAdapterResponse(response, content_type=content_type, | ||
status_code=status_code) |
This file was deleted.
Oops, something went wrong.
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,33 @@ | ||
import sys | ||
import platform | ||
|
||
from nose.tools import * | ||
|
||
if sys.version_info[0] == 3: # pragma: no cover | ||
from unittest.mock import Mock | ||
else: # pragma: no cover | ||
from mock import Mock | ||
|
||
from odin.adapters.system_info import SystemInfoAdapter | ||
|
||
class TestSystemInfoAdapter(): | ||
|
||
@classmethod | ||
def setup_class(cls): | ||
cls.adapter = SystemInfoAdapter() | ||
cls.path = "/" | ||
cls.request = Mock() | ||
cls.request.headers = {'Accept': 'application/json', 'Content-Type': 'application/json'} | ||
cls.system_info = { | ||
'system': platform.system(), | ||
'version': platform.version(), | ||
'release': platform.release(), | ||
} | ||
|
||
def test_adapter_get(self): | ||
expected_response = {'system_info': self.system_info} | ||
response = self.adapter.get(self.path, self.request) | ||
assert_true('system_info' in response.data) | ||
for entry in self.system_info: | ||
assert_true(response.data['system_info'][entry], self.system_info[entry]) | ||
assert_equal(response.status_code, 200) |
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