fuel-qa/fuelweb_test/helpers/log_server.py
Alexandr Kostrikov e317c2d6d2 doc: Added an initial Sphinx documentation
I have added a auto-generated documentation. It is done with
Sphinx library. Sphinx uses reStructuredText as its markup language
and docstrings as a source for automated documentation.

According to https://www.python.org/dev/peps/pep-0257/
I used a """ for quotes in docstrings and made
"""Docstring."""-looking one-liners and correct indentation
for multiple-liners.
Based on https://github.com/kennethreitz/requests
I moved Makefile, requirements.txt and conf.py to /doc folder.
Also I decided to make fuel-qa documentation
similar to https://docs.python.org/2/tutorial/index.html
with single table of contents.
I have added empty __init__.py files to be able to produce
documentation.
I have added sys_test.log to .gitigonre because it has
been generated at the documentation build.

To make it faster and non-conflicting I added some banal
class descriptions in order to get them in auto-generated documentation.
I decided not to fight with warnings and poor docstring descriptions
I added to make documentation less conflicting and for a faster review.
Docstring improvements and detailed code description are left for later.
For the same reasons I decied not to add docstrings to all methods.
At a places where I made poor docstrings I have added a
TODO documentation.

Change-Id: I7701a9a3429abbf62b13ec5a31972298c0be5201
Related-Bug: #1321682
2015-05-07 17:42:38 +03:00

82 lines
2.2 KiB
Python

# Copyright 2013 Mirantis, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import select
import socket
import threading
from fuelweb_test import logwrap
class LogServer(threading.Thread):
"""LogServer.""" # TODO documentation
@logwrap
def __init__(self, address="localhost", port=5514):
super(LogServer, self).__init__()
self.socket = socket.socket(
socket.AF_INET, socket.SOCK_DGRAM
)
self.socket.bind((str(address), port))
self.rlist = [self.socket]
self._stop = threading.Event()
self._handler = self.handler
self._status = False
def handler(self, messages):
pass
def set_status(self, status):
self._status = status
def get_status(self):
return self._status
def set_handler(self, handler):
self._handler = handler
@logwrap
def stop(self):
self.socket.close()
self._stop.set()
def started(self):
return not self._stop.is_set()
def rude_join(self, timeout=None):
self._stop.set()
super(LogServer, self).join(timeout)
def join(self, timeout=None):
self.rude_join(timeout)
@logwrap
def run(self):
while self.started():
r, w, e = select.select(self.rlist, [], [], 1)
if self.socket in r:
message, addr = self.socket.recvfrom(2048)
self._handler(message)
class TriggeredLogServer(LogServer):
"""TriggeredLogServer.""" # TODO documentation
def __init__(self, address="localhost", port=5514):
super(TriggeredLogServer, self).__init__(address, port)
self.set_handler(self.handler)
def handler(self, message):
self.set_status(True)