Skip to content
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
25 changes: 13 additions & 12 deletions tabpy-server/server_tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ def test_config_file_present(self, mock_os, mock_path_exists,

mock_os.getenv.assert_has_calls(getenv_calls, any_order=True)
self.assertEqual(app.settings['port'], 1234)
self.assertEqual(app.settings['server_version'], open(
'VERSION').read().strip())
self.assertEqual(app.settings['server_version'],
open('VERSION').read().strip())
self.assertEqual(app.settings['upload_dir'], 'foo')
self.assertEqual(app.settings['state_file_path'], 'bar')
self.assertEqual(app.settings['transfer_protocol'], 'http')
Expand Down Expand Up @@ -171,12 +171,12 @@ def test_https_cert_and_key_file_not_found(self, mock_path):
"TABPY_KEY_FILE = bar")
self.fp.close()

mock_path.isfile.side_effect =\
lambda x: self.mock_isfile(x, {self.fp.name})
mock_path.isfile.side_effect = lambda x: self.mock_isfile(
x, {self.fp.name})

assert_raises_runtime_error(
'Error using HTTPS: The parameter(s) TABPY_CERTIFICATE_FILE '
'and TABPY_KEY_FILE must point to an existing file.',
'Error using HTTPS: The parameter(s) TABPY_CERTIFICATE_FILE and '
'TABPY_KEY_FILE must point to an existing file.',
TabPyApp, {self.fp.name})

@patch('tabpy_server.app.app.os.path')
Expand Down Expand Up @@ -207,8 +207,9 @@ def test_https_key_file_not_found(self, mock_path):
x, {self.fp.name, 'foo'})

assert_raises_runtime_error(
'Error using HTTPS: The parameter(s) TABPY_KEY_FILE must '
'point to an existing file.', TabPyApp, {self.fp.name})
'Error using HTTPS: The parameter(s) TABPY_KEY_FILE '
'must point to an existing file.',
TabPyApp, {self.fp.name})

@patch('tabpy_server.app.app.os.path.isfile', return_value=True)
@patch('tabpy_server.app.util.validate_cert')
Expand All @@ -235,14 +236,14 @@ def __init__(self, *args, **kwargs):

def test_expired_cert(self):
path = os.path.join(self.resources_path, 'expired.crt')
message = 'Error using HTTPS: The certificate provided expired '\
'on 2018-08-18 19:47:18.'
message = ('Error using HTTPS: The certificate provided expired '
'on 2018-08-18 19:47:18.')
assert_raises_runtime_error(message, validate_cert, {path})

def test_future_cert(self):
path = os.path.join(self.resources_path, 'future.crt')
message = 'Error using HTTPS: The certificate provided is not '\
'valid until 3001-01-01 00:00:00.'
message = ('Error using HTTPS: The certificate provided is not valid '
'until 3001-01-01 00:00:00.')
assert_raises_runtime_error(message, validate_cert, {path})

def test_valid_cert(self):
Expand Down
3 changes: 2 additions & 1 deletion tabpy-server/tabpy_server/app/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ def validate_cert(cert_file_path):
not_before), RuntimeError)
if now > not_after:
log_and_raise(https_error +
'The certificate provided expired on {}.'.format(not_after), RuntimeError)
f'The certificate provided expired on {not_after}.',
RuntimeError)


def parse_pwd_file(pwd_file_name):
Expand Down
19 changes: 12 additions & 7 deletions tabpy-server/tabpy_server/common/endpoint_file_mgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

logger = logging.getLogger(__name__)

_name_checker = _compile('^[a-zA-Z0-9-_\ ]+$')
_name_checker = _compile(r'^[a-zA-Z0-9-_\ ]+$')


def _check_endpoint_name(name):
Expand All @@ -28,8 +28,10 @@ def _check_endpoint_name(name):
log_and_raise("Endpoint name cannot be empty", ValueError)

if not _name_checker.match(name):
log_and_raise('Endpoint name can only contain: a-z, A-Z, 0-9,'
' underscore, hyphens and spaces.', ValueError)
log_and_raise(
'Endpoint name can only contain: a-z, A-Z, 0-9,'
' underscore, hyphens and spaces.',
ValueError)


def grab_files(directory):
Expand All @@ -48,12 +50,13 @@ def grab_files(directory):
elif os.path.isfile(full_path):
yield full_path


def get_local_endpoint_file_path(name, version, query_path):
_check_endpoint_name(name)
return os.path.join(query_path, name, str(version))


def cleanup_endpoint_files(name, query_path, retain_versions = None):
def cleanup_endpoint_files(name, query_path, retain_versions=None):
'''
Cleanup the disk space a certain endpiont uses.

Expand All @@ -63,8 +66,9 @@ def cleanup_endpoint_files(name, query_path, retain_versions = None):
The endpoint name

retain_version : int, optional
If given, then all files for this endpoint are removed except the folder
for the given version, otherwise, all files for that endpoint are removed.
If given, then all files for this endpoint are removed except the
folder for the given version, otherwise, all files for that endpoint
are removed.
'''
_check_endpoint_name(name)
local_dir = os.path.join(query_path, name)
Expand All @@ -84,5 +88,6 @@ def cleanup_endpoint_files(name, query_path, retain_versions = None):

for file_or_dir in os.listdir(local_dir):
candidate_dir = os.path.join(local_dir, file_or_dir)
if os.path.isdir(candidate_dir) and candidate_dir not in retain_folders:
if os.path.isdir(candidate_dir) and (
candidate_dir not in retain_folders):
shutil.rmtree(candidate_dir)
52 changes: 40 additions & 12 deletions tabpy-server/tabpy_server/common/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from abc import ABCMeta
from collections import namedtuple


class Msg(object):
"""
An abstract base class for all messages used for communicating between
Expand Down Expand Up @@ -36,98 +37,125 @@ def from_json(str):
return eval(type_str)(**d)


class LoadSuccessful(namedtuple(
'LoadSuccessful', ['uri', 'path', 'version', 'is_update', 'endpoint_type']), Msg):
class LoadSuccessful(namedtuple('LoadSuccessful', [
'uri', 'path', 'version', 'is_update', 'endpoint_type']), Msg):
__slots__ = ()

class LoadFailed(namedtuple('LoadFailed', ['uri', 'version', 'error_msg']), Msg):

class LoadFailed(namedtuple('LoadFailed', [
'uri', 'version', 'error_msg']), Msg):
__slots__ = ()

class LoadInProgress(namedtuple(
'LoadInProgress', ['uri', 'path', 'version', 'is_update', 'endpoint_type']), Msg):

class LoadInProgress(namedtuple('LoadInProgress', [
'uri', 'path', 'version', 'is_update', 'endpoint_type']), Msg):
__slots__ = ()


class Query(namedtuple('Query', ['uri', 'params']), Msg):
__slots__ = ()


class QuerySuccessful(namedtuple(
'QuerySuccessful', ['uri', 'version', 'response']), Msg):
__slots__ = ()

class LoadObject(namedtuple(
'LoadObject', ['uri', 'url', 'version', 'is_update', 'endpoint_type']), Msg):

class LoadObject(namedtuple('LoadObject', [
'uri', 'url', 'version', 'is_update', 'endpoint_type']), Msg):
__slots__ = ()


class DeleteObjects(namedtuple('DeleteObjects', ['uris']), Msg):
__slots__ = ()


# Used for testing to flush out objects
class FlushObjects(namedtuple('FlushObjects', []), Msg):
__slots__ = ()


class ObjectsDeleted(namedtuple('ObjectsDeleted', ['uris']), Msg):
__slots__ = ()


class ObjectsFlushed(namedtuple(
'ObjectsFlushed', ['n_before', 'n_after']), Msg):
__slots__ = ()


class CountObjects(namedtuple('CountObjects', []), Msg):
__slots__ = ()


class ObjectCount(namedtuple('ObjectCount', ['count']), Msg):
__slots__ = ()


class ListObjects(namedtuple('ListObjects', []), Msg):
__slots__ = ()


class ObjectList(namedtuple('ObjectList', ['objects']), Msg):
__slots__ = ()


class UnknownURI(namedtuple('UnknownURI', ['uri']), Msg):
__slots__ = ()


class UnknownMessage(namedtuple('UnknownMessage', ['msg']), Msg):
__slots__ = ()

class DownloadSkipped(namedtuple('DownloadSkipped', ['uri', 'version', 'msg','host']),
Msg):

class DownloadSkipped(namedtuple('DownloadSkipped', [
'uri', 'version', 'msg', 'host']), Msg):
__slots__ = ()


class QueryFailed(namedtuple('QueryFailed', ['uri', 'error']), Msg):
__slots__ = ()


class QueryError(namedtuple('QueryError', ['uri', 'error']), Msg):
__slots__ = ()


class CheckHealth(namedtuple('CheckHealth', []), Msg):
__slots__ = ()


class Healthy(namedtuple('Healthy', []), Msg):
__slots__ = ()


class Unhealthy(namedtuple('Unhealthy', []), Msg):
__slots__ = ()


class Ping(namedtuple('Ping', ['id']), Msg):
__slots__ = ()


class Pong(namedtuple('Pong', ['id']), Msg):
__slots__ = ()


class Listening(namedtuple('Listening', []), Msg):
__slots__ = ()


class EngineFailure(namedtuple('EngineFailure', ['error']), Msg):
__slots__ = ()


class FlushLogs(namedtuple('FlushLogs', []), Msg):
__slots__ = ()


class LogsFlushed(namedtuple('LogsFlushed', []), Msg):
__slots__ = ()

class ServiceError(namedtuple(
'ServiceError', ['error']), Msg):
__slots__ = ()

class ServiceError(namedtuple('ServiceError', ['error']), Msg):
__slots__ = ()
5 changes: 4 additions & 1 deletion tabpy-server/tabpy_server/common/util.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import traceback


def format_exception(e, context):
err_msg = "%s : " % e.__class__.__name__
err_msg += "%s" % str(e)
return err_msg

def format_exception_DEBUG(e, context,detail=0):

def format_exception_DEBUG(e, context, detail=0):
trace = traceback.format_exc()
err_msg = "Traceback\n %s\n" % trace
err_msg += "Error type : %s\n" % e.__class__.__name__
Expand Down
Loading