Skip to content

Commit

Permalink
Merge branch 'release/0.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
storax committed Jul 17, 2015
2 parents 15c5806 + 2bdbc81 commit 18df480
Show file tree
Hide file tree
Showing 13 changed files with 295 additions and 36 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -30,6 +30,7 @@ pip-delete-this-directory.txt
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
Expand Down
35 changes: 35 additions & 0 deletions .travis.yml
@@ -0,0 +1,35 @@
language: python
python: 2.7
env:
global: LD_PRELOAD=/lib/x86_64-linux-gnu/libSegFault.so
matrix:
- TOXENV=check
- TOXENV=2.7,coveralls
- TOXENV=2.7-nocover
- TOXENV=3.3,coveralls
- TOXENV=3.3-nocover
- TOXENV=3.4,coveralls
- TOXENV=3.4-nocover
before_install:
- python --version
- virtualenv --version
- pip --version
- uname -a
- lsb_release -a
install:
- pip install tox
script:
- tox -v
notifications:
email:
on_success: never
on_failure: never
deploy:
provider: pypi
user: RayCrafter
distributions: sdist bdist_wheel
on:
tags: true
repo: RayCrafter/clusterlogger
password:
secure: xi1GnKW2t9hx9pX3PAMee0UsJ4QG182HmIeFfo0egunANS2M8qvk/c2n114YUGXi2CmhvzbVjhJDCdZmcsU/2a2rQ2ueDRXLQPSyCIj9van4FL00TVZLU4Vhvg4a/zLHBvh+Aq9mCgWVrHcdDsibcNVTLNSnuk7/CMlNn/NU/JxRJ2uVXe6DsDCDiNJblRVbRyJ33Gpq+Ngok5hxleN1kQ47WiQcKu1938w0+BzgNnUvquac6dPf0GSd1974Mgq6Yek5dyQPCsQYdZNDEcbcfm1G6Z9ufUkgqVa3mvmY61FvumHAkU3B/+XYRdezIMEL5UosfKBNYb4nyvkfbzp2xtxck/NsWVAZAS8mRvKf6lI1xowsTk8tJkQrScuRecKum/sDRdbkK3tSTkWhED+JHzPTwjuFd85qwrLFXcuhiYRl9A+M09xuYDQKbzeOQUFCADeTW+3FpwkWtyJI1xMl4TVvo8zeNy+FWM61x7gYQ0/iyQPKsg9DZkWHGinA/L8z0q6dZJjrTGz6bBLzD1QwQ+e0znS2CyKnassHl1Ys4vNCp9xxfTLaucesmZH/rRwy0cu/EkKjGOZgR20guOlTPk5B3mqGk5glu0fwAEZV42DHOFuJ6Kgce53MCLPkDMruwRdyYRSPjHzVJjD9p/nOMl74PbB7WtX+UGSRYtOBFHg=
4 changes: 3 additions & 1 deletion conf/.travis.yml
Expand Up @@ -31,4 +31,6 @@ deploy:
distributions: "sdist bdist_wheel"
on:
tags: true
repo: RayCrafter/clusterlogger
repo: RayCrafter/clusterlogger
password:
secure: xi1GnKW2t9hx9pX3PAMee0UsJ4QG182HmIeFfo0egunANS2M8qvk/c2n114YUGXi2CmhvzbVjhJDCdZmcsU/2a2rQ2ueDRXLQPSyCIj9van4FL00TVZLU4Vhvg4a/zLHBvh+Aq9mCgWVrHcdDsibcNVTLNSnuk7/CMlNn/NU/JxRJ2uVXe6DsDCDiNJblRVbRyJ33Gpq+Ngok5hxleN1kQ47WiQcKu1938w0+BzgNnUvquac6dPf0GSd1974Mgq6Yek5dyQPCsQYdZNDEcbcfm1G6Z9ufUkgqVa3mvmY61FvumHAkU3B/+XYRdezIMEL5UosfKBNYb4nyvkfbzp2xtxck/NsWVAZAS8mRvKf6lI1xowsTk8tJkQrScuRecKum/sDRdbkK3tSTkWhED+JHzPTwjuFd85qwrLFXcuhiYRl9A+M09xuYDQKbzeOQUFCADeTW+3FpwkWtyJI1xMl4TVvo8zeNy+FWM61x7gYQ0/iyQPKsg9DZkWHGinA/L8z0q6dZJjrTGz6bBLzD1QwQ+e0znS2CyKnassHl1Ys4vNCp9xxfTLaucesmZH/rRwy0cu/EkKjGOZgR20guOlTPk5B3mqGk5glu0fwAEZV42DHOFuJ6Kgce53MCLPkDMruwRdyYRSPjHzVJjD9p/nOMl74PbB7WtX+UGSRYtOBFHg=
4 changes: 0 additions & 4 deletions docs/source/devdoc/index.rst

This file was deleted.

2 changes: 0 additions & 2 deletions docs/source/index.rst
Expand Up @@ -16,8 +16,6 @@ Contents:

installation
usage
userdoc/index
devdoc/index
reference
contributing
authors
Expand Down
12 changes: 10 additions & 2 deletions docs/source/usage.rst
Expand Up @@ -2,6 +2,14 @@
Usage
========

To use ClusterLogger in a project::
Logfilters in this case provide contextual information about the cluster platform.

import clusterlogger
To use a filter on a logger::

import logging
import clusterlogger

logger = logging.getLogger(__name__)
logger.addFilter(clusterlogger.HazelHenFilter)

Now logs are sent with contextual information of the specific cluster platform.
2 changes: 0 additions & 2 deletions docs/source/userdoc/index.rst

This file was deleted.

1 change: 1 addition & 0 deletions setup.cfg
@@ -1,5 +1,6 @@
[flake8]
max-line-length = 140
ignore = F403

[bdist_wheel]
universal=1
Expand Down
7 changes: 6 additions & 1 deletion src/clusterlogger/__init__.py
@@ -1,4 +1,9 @@
from __future__ import absolute_import

from .logfilter import *

__all__ = [logfilter.__all__]

__author__ = 'David Zuber'
__email__ = 'zuber.david@gmx.de'
__version__ = '0.1.0'

49 changes: 49 additions & 0 deletions src/clusterlogger/logfilter.py
@@ -0,0 +1,49 @@
import logging
import os
import socket

__all__ = ['HazelHenFilter']


class HazelHenFilter(logging.Filter):
"""Filter for adding contextual information on ``Hazel Hen``
`Hazel Hen <http://www.hlrs.de/systems/platforms/cray-xc40-hazel-hen/>`_
is the Cray XC40 system at HLRS in Stuttgart.
This filter adds information about the currently running job.
"""
def __init__(self):
"""Initialize a new HazelHenFilter
:raises: None
"""
self.jobid = os.environ.get('PBS_JOBID', -1)
"""The job identifier assigned to the job by the batch system.
This is the same number you see when you do qstat.
-1 if logging when not running in a job.
"""
self.logname = os.environ.get('PBS_O_LOGNAME')
"""Value of the LOGNAME variable in the environment in which qsub was executed"""
self.jobname = os.environ.get('PBS_JOBNAME')
"""The job name supplied by the user"""
self.queue = os.environ.get('PBS_QUEUE')
"""The name of the queue from which the job is executed"""
self.fqdn = socket.getfqdn()
"""The fully qualified domain name."""

def filter(self, record):
"""Add contextual information to the log record
:param record: the log record
:type record: :class:`logging.LogRecord`
:returns: True, if log should get sent
:rtype: :class:`bool`
:raises: None
"""
record.jobid = self.jobid
record.submitter = self.logname
record.jobname = self.jobname
record.queue = self.queue
record.fqdn = self.fqdn
return True
20 changes: 0 additions & 20 deletions test/test_clusterlogger.py

This file was deleted.

49 changes: 49 additions & 0 deletions test/test_logfilter.py
@@ -0,0 +1,49 @@
"""
Tests for `logfilter` module.
"""
import os
import socket

import pytest

from clusterlogger import logfilter


class DummyRecord(object):
pass


@pytest.fixture(scope='module')
def hazelhen_environ(request):
envvars = {'PBS_JOBID': '28572',
'PBS_O_LOGNAME': 'hpcmscuser',
'PBS_JOBNAME': 'loggingtest',
'PBS_QUEUE': 'test'}
oldvars = {}
for k, v in envvars.items():
oldvars[k] = os.environ.get(k, '')
os.environ[k] = v

def restore():
os.environ.update(oldvars)
request.addfinalizer(restore)


@pytest.mark.parametrize('attr,envvar',
[('jobid', 'PBS_JOBID'),
('submitter', 'PBS_O_LOGNAME'),
('jobname', 'PBS_JOBNAME'),
('queue', 'PBS_QUEUE')])
def test_hazelhen_filter_envvar(hazelhen_environ, attr, envvar):
hhf = logfilter.HazelHenFilter()
record = DummyRecord()
hhf.filter(record)
assert getattr(record, attr) == os.environ[envvar],\
'Filter did not add envvar %s to the logrecord attribute %s.' % (envvar, attr)


def test_hazelhen_filter_fqdn(hazelhen_environ):
hhf = logfilter.HazelHenFilter()
record = DummyRecord()
hhf.filter(record)
assert record.fqdn == socket.getfqdn()
145 changes: 141 additions & 4 deletions tox.ini
@@ -1,13 +1,150 @@
; this is just a bootstrap tox configuration, run tox or ./bootstrap.py to have the full tox.ini

[tox]
toxworkdir = {toxinidir}/../.toxclusterlogger
envlist = configure
envlist =
clean,
check,
2.7,
2.7-nocover,
3.3,
3.3-nocover,
3.4,
3.4-nocover,
report,
docs

[testenv]
setenv =
PYTHONPATH={toxinidir}/tests
PYTHONUNBUFFERED=yes
deps =
pytest
pytest-capturelog
commands =
{posargs:py.test -vv}

[testenv:spell]
setenv =
SPELLCHECK = 1
commands =
sphinx-build -b spelling docs/source dist/docs
usedevelop = true
deps =
-r{toxinidir}/docs/requirements.txt
sphinxcontrib-spelling
pyenchant

[testenv:docs]
whitelist_externals =
rm
commands =
rm -rf dist/docs
sphinx-build -b linkcheck docs/source dist/docs
sphinx-build -b html docs/source dist/docs
usedevelop = true
deps =
-r{toxinidir}/docs/requirements.txt
-r{toxinidir}/requirements.txt

[testenv:configure]
deps =
jinja2
matrix
usedevelop = true
commands =
python bootstrap.py
python bootstrap.py

[testenv:check]
deps =
docutils
flake8
collective.checkdocs
usedevelop = true
commands =
python setup.py checkdocs
python setup.py check --restructuredtext --strict --metadata
flake8 src

[testenv:coveralls]
passenv = TRAVIS TRAVIS_JOB_ID TRAVIS_BRANCH
deps =
coveralls
usedevelop = true
commands =
coverage combine
coverage report
coveralls

[testenv:report]
commands =
coverage combine
coverage report
usedevelop = true
deps = coverage<3.999

[testenv:clean]
commands = coverage erase
usedevelop = true
deps = coverage<3.999

[testenv:2.7]
basepython = python2.7
setenv =
{[testenv]setenv}
WITH_COVERAGE=yes
usedevelop = true
commands =
{posargs:py.test --cov src -vv}
deps =
{[testenv]deps}
coverage<3.999
pytest-cov

[testenv:2.7-nocover]
basepython = python2.7
deps =
{[testenv]deps}
coverage<3.999
pytest-cov

[testenv:3.3]
basepython = python3.3
setenv =
{[testenv]setenv}
WITH_COVERAGE=yes
usedevelop = true
commands =
{posargs:py.test --cov src -vv}
deps =
{[testenv]deps}
coverage<3.999
pytest-cov

[testenv:3.3-nocover]
basepython = python3.3
deps =
{[testenv]deps}
coverage<3.999
pytest-cov

[testenv:3.4]
basepython = python3.4
setenv =
{[testenv]setenv}
WITH_COVERAGE=yes
usedevelop = true
commands =
{posargs:py.test --cov src -vv}
deps =
{[testenv]deps}
coverage<3.999
pytest-cov

[testenv:3.4-nocover]
basepython = python3.4
deps =
{[testenv]deps}
coverage<3.999
pytest-cov



0 comments on commit 18df480

Please sign in to comment.