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

Avoid OSError [Errno 29] Illegal seek on Python 3.6 #250

Closed
wants to merge 70 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
20e78e5
In hostgroup definition, support multi members
netmarkjp Oct 31, 2016
b5e27a9
Merge branch 'fix-ci'
netmarkjp Oct 31, 2016
b757402
Merge remote-tracking branch 'upstream/master'
netmarkjp Sep 12, 2017
d05a413
enable `+` in hostname
netmarkjp Sep 12, 2017
395fe02
revert broken changes, and add use_regexp_matching support
netmarkjp Oct 27, 2017
90bb88f
enable `+` in hostname
netmarkjp Sep 12, 2017
b69f0a4
revert broken changes, and add use_regexp_matching support
netmarkjp Oct 27, 2017
5aa7d42
Merge branch 'hostname-enable-plus' of github.com:netmarkjp/pynag int…
netmarkjp Oct 27, 2017
6f8b05a
Merge pull request #1 from netmarkjp/hostname-enable-plus
netmarkjp Oct 27, 2017
b959f26
just only run 2to3
netmarkjp Nov 16, 2017
8e50eb0
add 3.6 and pretty fix
netmarkjp Nov 16, 2017
a0b44d4
avoid syntax error in unittest2
netmarkjp Nov 16, 2017
fd53562
unittest2 => nose
netmarkjp Nov 16, 2017
ac79803
unittest2 still needed
netmarkjp Nov 16, 2017
1371376
old nose does not have `--cover-erase` option
netmarkjp Nov 16, 2017
da4361e
re-convert with modernize
netmarkjp Nov 16, 2017
079b1f3
fix No module named 'StringIO' in 3.6.3
netmarkjp Nov 16, 2017
d2a5cfc
fix ValueError: level must be >= 0
netmarkjp Nov 16, 2017
e937148
trying to fix TypeError: '_FailedTest' object is not iterable''
netmarkjp Nov 16, 2017
2f77689
trying to fix TypeError: endswith first arg must be bytes or a tuple …
netmarkjp Nov 16, 2017
8c280a3
still trying to fix TypeError
netmarkjp Nov 16, 2017
cf6b1f5
same
netmarkjp Nov 16, 2017
7104c5b
fix handle StringIO
netmarkjp Nov 17, 2017
c638ebd
trying to fix StringIO handling
netmarkjp Nov 17, 2017
af8af64
fix import order aboud StringIO
netmarkjp Nov 17, 2017
918aa5e
fix startswith, endswith, str +
netmarkjp Nov 17, 2017
082c3e1
change str[0] to startswith
netmarkjp Nov 17, 2017
69f6bad
fix ValueError: zero length field name in format
netmarkjp Nov 17, 2017
4f38605
fix TypeError: cannot use a string pattern on a bytes-like object
netmarkjp Nov 17, 2017
371ee36
fix TypeError: a bytes-like object is required, not 'str'
netmarkjp Nov 17, 2017
9dfc857
convert bytes to str at head of function.
netmarkjp Nov 17, 2017
537c441
- fix typo
netmarkjp Nov 17, 2017
c9547cc
silly bug fixed
netmarkjp Nov 17, 2017
a8d8539
when os.write(), specify bytes
netmarkjp Nov 17, 2017
64bba12
fix bytes to str
netmarkjp Nov 17, 2017
df8a516
string.letters is removed
netmarkjp Nov 17, 2017
3427199
fix RuntimeError: dictionary changed size during iteration
netmarkjp Nov 17, 2017
1fbfb95
pretty bugfix
netmarkjp Nov 17, 2017
5c2da9e
shebang /usr/bin/python => /usr/bin/env python
netmarkjp Nov 18, 2017
57070dd
for local testing
netmarkjp Nov 18, 2017
a7e9be9
fix bytes/str
netmarkjp Nov 18, 2017
08057fe
six dependency move to setup.py
netmarkjp Nov 18, 2017
e2c8402
follow changes
netmarkjp Nov 18, 2017
45681d5
fix bytes/str problems
netmarkjp Nov 18, 2017
0da2af9
fix syntax in doctest
netmarkjp Nov 20, 2017
693a042
apply python-modernize to scripts/pynag
netmarkjp Nov 20, 2017
9b08118
fix doctest syntax
netmarkjp Nov 20, 2017
f77e982
fix doctest syntax
netmarkjp Nov 20, 2017
75771e5
fix str/unicode handling in doctest
netmarkjp Nov 20, 2017
b2214cd
fix doctest detail difference
netmarkjp Nov 21, 2017
3e944d4
fix binary/string problem(too much encoding by hand)
netmarkjp Nov 21, 2017
17fba7c
socket.send() arg is str on PY2, bytes on PY3
netmarkjp Nov 21, 2017
9f509b0
__cmp__ is no longer used. use __eq__
netmarkjp Nov 21, 2017
a326eaf
`__hash__` required to jsonise
netmarkjp Nov 21, 2017
975b079
run_command should return str
netmarkjp Nov 21, 2017
caac005
sort order over class type did not care...
netmarkjp Nov 21, 2017
c0ab644
external command results(stdout, stderr) may expect str
netmarkjp Nov 21, 2017
baabcfb
kwargs cannot keep order
netmarkjp Nov 22, 2017
1f3f4bb
specified attributes must decoded
netmarkjp Nov 22, 2017
c825608
Merge pull request #2 from netmarkjp/python2to3
netmarkjp Nov 22, 2017
88b1c78
fix broken dependency while setup
netmarkjp Nov 22, 2017
7cd39fe
Merge pull request #3 from netmarkjp/python2to3
netmarkjp Nov 22, 2017
d3cb31c
fix build rpm, and add dependency python-six
netmarkjp Nov 24, 2017
cf61911
Merge pull request #4 from netmarkjp/python2to3
netmarkjp Dec 6, 2017
c0aeab1
- catch UnicodeDecodeError when decode bytes
netmarkjp Dec 6, 2017
25cbbe2
fix UserWarning: Unknown distribution option: 'install_requires'
netmarkjp Dec 6, 2017
d588560
Merge pull request #5 from netmarkjp/fix-UnicodeDecodeError
netmarkjp Dec 6, 2017
23b8590
when get_current_status, enable to use parsed status
netmarkjp Dec 6, 2017
8ab9342
Merge pull request #6 from netmarkjp/use-parsed-status
netmarkjp Dec 6, 2017
1d2e01d
avoid `OSError [Errno 29] Illegal seek` on Python 3.6
netmarkjp Jan 15, 2018
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ dist
.idea
.coverage
man/.doctrees
.python-version
rpm-build/
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ language: python
python:
- "2.6"
- "2.7"
- "3.6"
before_install:
- sudo apt-get update -qq
install:
- sudo apt-get install nagios3 check-mk-livestatus
- pip install unittest2==0.5.1
- sudo apt-get -y install nagios3 check-mk-livestatus
- pip install unittest2==1.1.0
- pip install coveralls
- pip install mock
- python setup.py build
- python setup.py install
- sudo chmod 777 /etc/nagios3/nagios.cfg
Expand Down
44 changes: 44 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Local Testing Image
#
# Usage:
# docker build -t pynag .
#
# docker run --rm -d --name pynag_py27 -v $(pwd):/mnt pynag
# docker exec -it pynag_py27 sudo -u travis -i /mnt/docker_run.sh 2.7.14
#
# docker run --rm -d --name pynag_py36 -v $(pwd):/mnt pynag
# docker exec -it pynag_py36 sudo -u travis -i /mnt/docker_run.sh 3.6.3
FROM ubuntu:trusty
MAINTAINER Toshiaki Baba<toshiaki@netmark.jp>

# basic setup
RUN cp /usr/share/zoneinfo/Asia/Tokyo /etc/localtime
RUN localedef -i ja_JP -c -f UTF-8 -A /usr/share/locale/locale.alias ja_JP.UTF-8
ENV LC_ALL ja_JP.UTF-8

# pyenv
RUN apt-get -y update && apt-get -y install \
curl git build-essential openssl libssl-dev libbz2-dev libreadline-dev libsqlite3-dev \
rsync \
nagios3 check-mk-livestatus \
&& rm -rf /var/lib/apt/lists/*
RUN useradd -m travis && echo "travis ALL=(ALL) NOPASSWD: ALL " | tee /etc/sudoers.d/travis && chmod 400 /etc/sudoers.d/travis
RUN sudo -u travis -i bash -c 'curl -L https://raw.githubusercontent.com/pyenv/pyenv-installer/master/bin/pyenv-installer | bash'
RUN echo 'export PATH="/home/travis/.pyenv/bin:$PATH"' | tee -a /home/travis/.bash_profile
RUN echo 'eval "$(pyenv init -)"' | tee -a /home/travis/.bash_profile
RUN echo 'eval "$(pyenv virtualenv-init -)"' | tee -a /home/travis/.bash_profile
RUN chown travis /home/travis/.bash_profile
RUN sudo -u travis -i /home/travis/.pyenv/bin/pyenv install 2.6.9
RUN sudo -u travis -i /home/travis/.pyenv/bin/pyenv install 2.7.14
RUN sudo -u travis -i /home/travis/.pyenv/bin/pyenv install 3.6.3

# pynag, nagios
RUN install -d -o travis -g travis /opt/pynag
RUN chmod 777 /etc/nagios3/nagios.cfg
RUN chmod a+rx '/var/cache/nagios3/'
RUN echo "broker_module=/usr/lib/check_mk/livestatus.o /var/lib/nagios3/rw/livestatus" >> /etc/nagios3/nagios.cfg

RUN sudo -u travis -i git config --global user.email "travis@example.com"
RUN sudo -u travis -i git config --global user.name "Travis Local Image"

ENTRYPOINT ["/sbin/init"]
50 changes: 50 additions & 0 deletions docker_run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/bash
# Usage:
# docker build -t pynag .
# docker run -v $(pwd):/mnt pynag

set -ex

PYTHON_VERSION=$1

PYTHON_VERSIONS="
2.6.9
2.7.14
3.6.3"

if [[ "${PYTHON_VERSION}x" == "x" ]]; then
echo "Usage: $0 <python_version>"
echo "<python_version> is one of $(echo ${PYTHON_VERSIONS} | xargs echo)"
echo "ex: $0 3.6.3"
exit 1
fi
echo "TARGET VERSION=${PYTHON_VERSION:?}"

PYENV_BASE="/home/travis/.pyenv/versions/${PYTHON_VERSION:?}"

rsync -a --exclude=".git" --exclude="*.pyc" --exclude=".python-version" --exclude="__pycache__" /mnt/ /opt/pynag/

sudo service nagios3 start

cd /opt/pynag/

export PATH=${PYENV_BASE:?}/bin:/usr/sbin:$PATH
source ~/.bash_profile
pyenv global ${PYTHON_VERSION:?}

pip install unittest2==1.1.0
pip install coveralls
pip install mock
python setup.py build
python setup.py install

cat <<EOT


======================================
pynag unittest
======================================

EOT

coverage run --source=pynag tests/test.py
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# serve to show the default.


from __future__ import absolute_import
import sys, os

sys.path.insert(0,os.path.abspath('.'))
Expand Down
8 changes: 5 additions & 3 deletions examples/Model/edit_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@
#
# Example script on how to modify a single Nagios service

from __future__ import absolute_import
from __future__ import print_function
from pynag import Model
import sys

# Parse commandline arguments
if len(sys.argv) != 5:
print '''
print('''
Usage:
%s <host_name> <service_description> <field_name> <new_value>

Example:
%s localhost Ping check_command 'check_ping'
''' % (sys.argv[0], sys.argv[0])
''' % (sys.argv[0], sys.argv[0]))
sys.exit(1)

host_name = sys.argv[1]
Expand All @@ -26,7 +28,7 @@
search_results = Model.Service.objects.filter(host_name=host_name, service_description=service_description)

if len(search_results) == 0:
print "no service found for host_name=%s and service_description=%s" % ( host_name, service_description )
print("no service found for host_name=%s and service_description=%s" % ( host_name, service_description ))

my_service = search_results[0]
my_service.set_attribute(field_name,new_value)
Expand Down
4 changes: 3 additions & 1 deletion examples/Model/list_all_hostgroups.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/python

from __future__ import absolute_import
from __future__ import print_function
import sys
sys.path.insert(1, '/opt/pynag')
from pynag import Model
Expand All @@ -11,5 +13,5 @@
hostgroups = Model.Hostgroup.objects.all

for hostgroup in hostgroups:
print hostgroup['hostgroup_name']
print(hostgroup['hostgroup_name'])

6 changes: 4 additions & 2 deletions examples/Model/list_all_services.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/python

from __future__ import absolute_import
from __future__ import print_function
import sys
sys.path.insert(1, '/opt/pynag')
from pynag import Model
Expand All @@ -10,6 +12,6 @@

services = Model.Service.objects.all

print "%-30s %-30s" % ("Hostname", "Service_description")
print("%-30s %-30s" % ("Hostname", "Service_description"))
for service in services:
print "%-30s %-30s" % ( service['host_name'], service['service_description'] )
print("%-30s %-30s" % ( service['host_name'], service['service_description'] ))
6 changes: 4 additions & 2 deletions examples/Model/list_services_for_one_host.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/python

from __future__ import absolute_import
from __future__ import print_function
import sys
sys.path.insert(1, '/opt/pynag')
from pynag import Model
Expand All @@ -14,6 +16,6 @@

services = Model.Service.objects.filter(host_name='localhost')

print "%-30s %-30s" % ("Hostname", "Service_description")
print("%-30s %-30s" % ("Hostname", "Service_description"))
for service in services:
print "%-30s %-30s" % ( service['host_name'], service['service_description'] )
print("%-30s %-30s" % ( service['host_name'], service['service_description'] ))
1 change: 1 addition & 0 deletions examples/Model/parse-configmain.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# This script parses the configmain.html file from the Nagios project and tries
# to extract information regarding options.

from __future__ import absolute_import
import re
from pprint import pprint

Expand Down
4 changes: 3 additions & 1 deletion examples/Model/remove_empty_configfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# This script looks for files in your configuration that have no objects in them.
#
#
from __future__ import absolute_import
from __future__ import print_function
import os
import pynag.Model

Expand All @@ -17,5 +19,5 @@
for k,v, in pynag.Model.config.maincfg_values:
if k == 'cfg-file' and v == i:
continue
print "Empty config file: %s" % i
print("Empty config file: %s" % i)
# os.remove(i)
8 changes: 5 additions & 3 deletions examples/Model/restructure_config_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@



from __future__ import absolute_import
from __future__ import print_function
import pynag.Model
from pynag.Model import ObjectDefinition
import os
Expand All @@ -30,11 +32,11 @@
# all_objects = ObjectDefinition.objects.filter(filename__contains='/etc/nagios/all_the_services.cfg')

for i in all_objects:
print "Saving", i.object_type, i.get_description(), "...",
print("Saving", i.object_type, i.get_description(), "...", end=' ')
# Set a new filename for our object, None means
# That pynag decides where it goes
new_filename = i.get_suggested_filename()
print new_filename
print(new_filename)
continue
# Alternative:
# if i.object.type == 'host' and i.host_name is not None:
Expand All @@ -46,5 +48,5 @@
with open(new_filename, 'a') as f:
data = "\n" + str(i)
f.write(data)
print new_filename
print(new_filename)

20 changes: 11 additions & 9 deletions examples/Model/working_with_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
# }
#

from __future__ import absolute_import
from __future__ import print_function
import pynag.Model

# First create a test object
Expand All @@ -18,30 +20,30 @@
my_service['service_description'] = 'Test Service'
my_service['contact_groups'] = '+admins,webmasters,hostmasters'

print "*** Created a demo servicecheck that looks like this:"
print my_service
print("*** Created a demo servicecheck that looks like this:")
print(my_service)



print "\n--- Removing with attribute_removefield()"
print("\n--- Removing with attribute_removefield()")
my_service.attribute_removefield('contact_groups', 'hostmasters')
print "my_service.contact_groups = ", my_service.contact_groups
print("my_service.contact_groups = ", my_service.contact_groups)



print "\n--- Add a new contact_group with attribute_appendfield()"
print("\n--- Add a new contact_group with attribute_appendfield()")
my_service.attribute_appendfield('contact_groups', "mycontactgroup")
print "my_service.contact_groups = ", my_service.contact_groups
print("my_service.contact_groups = ", my_service.contact_groups)

print "\n-- Replacing a contact_group midfield with attribute_replacefield()"
print("\n-- Replacing a contact_group midfield with attribute_replacefield()")
my_service.attribute_replacefield('contact_groups', "webmasters", "hostmaster")
print "my_service.contact_groups = ", my_service.contact_groups
print("my_service.contact_groups = ", my_service.contact_groups)


# A more advanced example. Find all services that inherit from "generic-service" and
# Replace it with "my-specific-service":

print "\n--- More advanced example, editing multiple objects at once..."
print("\n--- More advanced example, editing multiple objects at once...")
my_services = pynag.Model.Service.objects.filter(use__hasfield='generic-service')

for service in my_services:
Expand Down
12 changes: 7 additions & 5 deletions examples/Parsers/find_orphans.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/usr/bin/python
from __future__ import absolute_import
from __future__ import print_function
import sys

## This is for the custom nagios module
Expand All @@ -16,18 +18,18 @@


orphan_hosts = []
print "The following hosts do not have parent items:"
print("The following hosts do not have parent items:")

for host in nc['all_host']:
use_attr = ''
for attribute in ['host_name', 'name', 'alias']:
if host.has_key(attribute):
if attribute in host:
use_attr = attribute

if not host.has_key('parents') or not host['parents']:
if 'parents' not in host or not host['parents']:
if host[use_attr] not in top_level_items:
orphan_hosts.append(host)
print "%-12s %-32s (%s)" % (use_attr, host[use_attr], host['meta']['filename'])
print("%-12s %-32s (%s)" % (use_attr, host[use_attr], host['meta']['filename']))

if not len(orphan_hosts):
print "No ophaned hosts found"
print("No ophaned hosts found")
4 changes: 3 additions & 1 deletion examples/Parsers/get_command.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/usr/bin/python
from __future__ import absolute_import
from __future__ import print_function
import sys

if len(sys.argv) != 2:
Expand All @@ -22,4 +24,4 @@
sys.stderr.write("Item not found: %s\n" % item)
sys.exit(2)

print nc.print_conf(item)
print(nc.print_conf(item))
4 changes: 3 additions & 1 deletion examples/Parsers/get_contact.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/usr/bin/python
from __future__ import absolute_import
from __future__ import print_function
import sys

if len(sys.argv) != 2:
Expand All @@ -22,4 +24,4 @@
sys.stderr.write("Item not found: %s\n" % item)
sys.exit(2)

print nc.print_conf(item)
print(nc.print_conf(item))
4 changes: 3 additions & 1 deletion examples/Parsers/get_contactgroup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/usr/bin/python
from __future__ import absolute_import
from __future__ import print_function
import sys

if len(sys.argv) != 2:
Expand All @@ -22,4 +24,4 @@
sys.stderr.write("Item not found: %s\n" % item)
sys.exit(2)

print nc.print_conf(item)
print(nc.print_conf(item))
4 changes: 3 additions & 1 deletion examples/Parsers/get_host.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/usr/bin/python
from __future__ import absolute_import
from __future__ import print_function
import sys

if len(sys.argv) != 2:
Expand All @@ -23,4 +25,4 @@
sys.stderr.write("Host not found: %s\n" % host)
sys.exit(2)

print nc.print_conf(host)
print(nc.print_conf(host))
Loading