Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

various updates and cleanup #290

Merged
merged 1 commit into from
Apr 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions synse_server/cache.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
"""Synse Server caches and cache utilities."""

import asyncio

import aiocache
import grpc

import synse_grpc.utils

from synse_server import config, plugin
from synse_server.i18n import _
from synse_server.log import logger


transaction_cache = aiocache.SimpleMemoryCache(
ttl=config.options.get('cache.transaction.ttl', None)
)
Expand Down Expand Up @@ -72,8 +71,7 @@ async def add_transaction(transaction_id, context, plugin_name):
# transaction info by converting it to dict (commands/write.py)

logger.debug(
_('Caching transaction {} from plugin {} ({})').format(
transaction_id, plugin_name, context)
_('caching transaction'), plugin=plugin_name, id=transaction_id, context=context,
)
return await transaction_cache.set(
transaction_id,
Expand Down Expand Up @@ -198,7 +196,6 @@ async def get_plugin(device_id):
return plugin.manager.get(device.plugin)



# import aiocache
# import grpc
#
Expand Down
1 change: 0 additions & 1 deletion synse_server/commands/plugins.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Command handler for the `plugins` route."""

import grpc

import synse_grpc.utils

from synse_server import plugin, utils
Expand Down
9 changes: 5 additions & 4 deletions synse_server/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from sanic.handlers import ErrorHandler

from synse_server.i18n import _
from synse_server.response import json
from synse_server.utils import rfc3339now

Expand Down Expand Up @@ -68,7 +69,7 @@ class InvalidUsage(SynseError):
"""

http_code = 400
description = 'invalid user input'
description = _('invalid user input')


class NotFound(SynseError):
Expand All @@ -80,7 +81,7 @@ class NotFound(SynseError):
"""

http_code = 404
description = 'resource not found'
description = _('resource not found')


class UnsupportedAction(SynseError):
Expand All @@ -92,7 +93,7 @@ class UnsupportedAction(SynseError):
"""

http_code = 405
description = 'device action not supported'
description = _('device action not supported')


class ServerError(SynseError):
Expand All @@ -104,4 +105,4 @@ class ServerError(SynseError):
"""

http_code = 500
description = 'error processing the request'
description = _('error processing the request')
4 changes: 0 additions & 4 deletions synse_server/i18n.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
import gettext
import os

# TODO (etd): see if there is a better way of defining this.. perhaps
# in the Synse obj in server.py?
# could also look at how other projects handle this

_here = os.path.dirname(os.path.realpath(__file__))

# Here, we are not setting the translation to fall back onto anything.
Expand Down
5 changes: 1 addition & 4 deletions synse_server/plugin.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
"""Management and access logic for configured plugin backends."""

import os
import stat

from synse_grpc import client, utils

from synse_server import config, const, errors
from synse_server import config, errors
from synse_server.discovery import kubernetes
from synse_server.i18n import _
from synse_server.log import logger
Expand Down
2 changes: 1 addition & 1 deletion synse_server/routes/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from sanic import Blueprint
from sanic.response import stream

from synse_server import commands, errors, validate, __api_version__
from synse_server import __api_version__, commands, errors, validate
from synse_server.i18n import _
from synse_server.log import logger
from synse_server.response import json
Expand Down
2 changes: 1 addition & 1 deletion synse_server/scheme/version.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Response scheme for the `version` endpoint."""

from synse_server.scheme.base_response import SynseResponse
from synse_server import __api_version__, __version__
from synse_server.scheme.base_response import SynseResponse


class VersionResponse(SynseResponse):
Expand Down
8 changes: 5 additions & 3 deletions synse_server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import synse_server
from synse_server import app, config
from synse_server.i18n import _
from synse_server.log import logger, setup_logger


Expand Down Expand Up @@ -48,8 +49,9 @@ class Synse:

{synse_server.__description__}

version: {synse_server.__version__}
author: {synse_server.__author__}
version: {synse_server.__version__}
api: {synse_server.__api_version__}
url: {synse_server.__url__}
license: {synse_server.__license__}

Expand All @@ -76,7 +78,7 @@ def _setup(self):
the backing Sanic application. Additionally, it lets us set up
logging early on.
"""
logger.debug('Setting up Synse Server')
logger.debug(_('setting up synse server'))

# Make sure that the filesystem layout needed by Synse Server
# is present. If not, create the required directories.
Expand All @@ -91,7 +93,7 @@ def _setup(self):

def run(self):
"""Run Synse Server."""
logger.debug('Running Synse Server...')
logger.info(_('running synse server'))

# If we are configured to log the header, write it to stdout instead
# of using the logger, since the structured logger will not format
Expand Down
2 changes: 2 additions & 0 deletions synse_server/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def rfc3339now():
return now.isoformat('T') + 'Z'


# fixme: remove--unused
def composite(rack, board, device):
"""Create a composite string out of a rack, board, and device.

Expand All @@ -32,6 +33,7 @@ def composite(rack, board, device):
return '-'.join([rack, board, device])


# fixme: remove--unused
def type_from_kind(kind):
"""Get the device type from the device kind.

Expand Down
3 changes: 1 addition & 2 deletions tests/integration/routes/aliases/test_boot_target_route.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Test the 'synse_server.routes.aliases' module's boot target route."""

from synse_server import errors
from synse_server import __api_version__
from synse_server import __api_version__, errors
from tests import utils

invalid_boot_target_route_url = '/synse/{}/boot_target/invalid-rack/invalid-board/invalid-device'\
Expand Down
3 changes: 1 addition & 2 deletions tests/integration/routes/aliases/test_fan_route.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Test the 'synse_server.routes.aliases' module's fan route."""

from synse_server import errors
from synse_server import __api_version__
from synse_server import __api_version__, errors
from tests import utils

invalid_fan_route_url = '/synse/{}/fan/invalid-rack/invalid-board/invalid-device'\
Expand Down
3 changes: 1 addition & 2 deletions tests/integration/routes/aliases/test_led_route.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Test the 'synse_server.routes.aliases' module's led route."""

from synse_server import errors
from synse_server import __api_version__
from synse_server import __api_version__, errors
from tests import utils

invalid_led_route_url = '/synse/{}/led/invalid-rack/invalid-board/invalid-device'\
Expand Down
3 changes: 1 addition & 2 deletions tests/integration/routes/aliases/test_lock_route.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Test the 'synse_server.routes.aliases' module's lock route."""

from synse_server import errors
from synse_server import __api_version__
from synse_server import __api_version__, errors
from tests import utils

invalid_lock_route_url = '/synse/{}/lock/invalid-rack/invalid-board/invalid-device'\
Expand Down
3 changes: 1 addition & 2 deletions tests/integration/routes/aliases/test_power_route.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Test the 'synse_server.routes.aliases' module's power route."""

from synse_server import errors
from synse_server import __api_version__
from synse_server import __api_version__, errors
from tests import utils

invalid_power_route_url = '/synse/{}/power/invalid-rack/invalid-board/invalid-device'\
Expand Down
2 changes: 0 additions & 2 deletions tests/integration/routes/core/test_config_route.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""Test the 'synse_server.routes.core' module's config route."""

import ujson

from synse_server import __api_version__

config_url = '/synse/{}/config'.format(__api_version__)
Expand Down
3 changes: 1 addition & 2 deletions tests/integration/routes/core/test_info_route.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Test the 'synse_server.routes.core' module's info route."""

from synse_server import errors
from synse_server import __api_version__
from synse_server import __api_version__, errors
from tests import utils

info_url = '/synse/{}/info'.format(__api_version__)
Expand Down
3 changes: 1 addition & 2 deletions tests/integration/routes/core/test_read_route.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Test the 'synse_server.routes.core' module's read route."""

from synse_server import errors
from synse_server import __api_version__
from synse_server import __api_version__, errors
from tests import utils

invalid_read_url = '/synse/{}/read/invalid-rack/invalid-board/invalid-device'\
Expand Down
3 changes: 1 addition & 2 deletions tests/integration/routes/core/test_scan_route.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

import ujson

from synse_server import errors
from synse_server import __api_version__
from synse_server import __api_version__, errors
from tests import utils

scan_url = '/synse/{}/scan'.format(__api_version__)
Expand Down
3 changes: 1 addition & 2 deletions tests/integration/routes/core/test_transaction_route.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Test the 'synse_server.routes.core' module's transaction route."""

from synse_server import errors
from synse_server import __api_version__
from synse_server import __api_version__, errors
from tests import utils

invalid_transaction_url = '/synse/{}/transaction/invalid-id'.format(__api_version__)
Expand Down
3 changes: 1 addition & 2 deletions tests/integration/routes/core/test_write_route.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

import ujson

from synse_server import errors
from synse_server import __api_version__
from synse_server import __api_version__, errors
from tests import utils

invalid_write_url = '/synse/{}/write/invalid-rack/invalid-board/invalid-device'\
Expand Down