Skip to content

Commit

Permalink
Renamed platform_info to system_info for wider applicability
Browse files Browse the repository at this point in the history
  • Loading branch information
timcnicholls committed Jul 26, 2016
1 parent c61fe30 commit 82b1663
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 83 deletions.
57 changes: 0 additions & 57 deletions server/odin/adapters/platform_info.py

This file was deleted.

71 changes: 71 additions & 0 deletions server/odin/adapters/system_info.py
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)
25 changes: 0 additions & 25 deletions server/odin/testing/adapters/test_platform_info.py

This file was deleted.

33 changes: 33 additions & 0 deletions server/odin/testing/adapters/test_system_info.py
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)
5 changes: 4 additions & 1 deletion server/odin/testing/config/test.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ debug_mode = 1
http_port = 8888
http_addr = 0.0.0.0
static_path = ./static
adapters = dummy
adapters = dummy, system_info

[tornado]
logging = debug
Expand All @@ -12,3 +12,6 @@ logging = debug
module = odin.adapters.dummy.DummyAdapter
background_task_enable = 1
background_task_interval = 1.0

[adapter.system_info]
module = odin.adapters.system_info.SystemInfoAdapter

0 comments on commit 82b1663

Please sign in to comment.