Dima Kuznetsov has uploaded a new change for review. Change subject: Add filecontrol module ......................................................................
Add filecontrol module Added module with fcntl convenience functions Change-Id: I4f455711d81e84db600647a2d5d80a5e7cadd5e2 Signed-off-by: Dima Kuznetsov <dkuzn...@redhat.com> --- M configure.ac A doc/infra/filecontrol.rst M doc/infra/index.rst M lib/vdsm/infra/Makefile.am A lib/vdsm/infra/filecontrol/Makefile.am A lib/vdsm/infra/filecontrol/__init__.py A lib/vdsm/infra/filecontrol/tests.py M vdsm.spec.in 8 files changed, 98 insertions(+), 1 deletion(-) git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/18/35918/1 diff --git a/configure.ac b/configure.ac index 71901ac..f9848ab 100644 --- a/configure.ac +++ b/configure.ac @@ -344,6 +344,7 @@ lib/vdsm/tool/configurators/Makefile lib/yajsonrpc/Makefile lib/vdsm/infra/Makefile + lib/vdsm/infra/filecontrol/Makefile lib/vdsm/infra/zombiereaper/Makefile tests/Makefile tests/functional/Makefile diff --git a/doc/infra/filecontrol.rst b/doc/infra/filecontrol.rst new file mode 100644 index 0000000..58b4850 --- /dev/null +++ b/doc/infra/filecontrol.rst @@ -0,0 +1,5 @@ +File Control +============= + +.. automodule:: vdsm.infra.filecontrol + :members: diff --git a/doc/infra/index.rst b/doc/infra/index.rst index fa010c9..bb825f8 100644 --- a/doc/infra/index.rst +++ b/doc/infra/index.rst @@ -4,4 +4,5 @@ Contents: .. toctree:: + filecontrol zombiereaper diff --git a/lib/vdsm/infra/Makefile.am b/lib/vdsm/infra/Makefile.am index dd9d642..b1c28be 100644 --- a/lib/vdsm/infra/Makefile.am +++ b/lib/vdsm/infra/Makefile.am @@ -19,7 +19,10 @@ # include $(top_srcdir)/build-aux/Makefile.subs -SUBDIRS = zombiereaper +SUBDIRS = \ + filecontrol \ + zombiereaper \ + $(NULL) dist_vdsminfra_PYTHON = \ __init__.py \ diff --git a/lib/vdsm/infra/filecontrol/Makefile.am b/lib/vdsm/infra/filecontrol/Makefile.am new file mode 100644 index 0000000..4d33b22 --- /dev/null +++ b/lib/vdsm/infra/filecontrol/Makefile.am @@ -0,0 +1,34 @@ +# +# Copyright 2014 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# +# Refer to the README and COPYING files for full details of the license +# + +include $(top_srcdir)/build-aux/Makefile.subs + +filecontroldir = $(vdsminfradir)/filecontrol + +dist_filecontrol_PYTHON = \ + __init__.py \ + $(NULL) + +dist_noinst_PYTHON = \ + tests.py \ + $(NULL) + +check-local: + nosetests tests.py diff --git a/lib/vdsm/infra/filecontrol/__init__.py b/lib/vdsm/infra/filecontrol/__init__.py new file mode 100644 index 0000000..c15b008 --- /dev/null +++ b/lib/vdsm/infra/filecontrol/__init__.py @@ -0,0 +1,36 @@ +# +# Copyright 2014 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# +# Refer to the README and COPYING files for full details of the license +# +import fcntl +import os + + +def _add_flags(fd, flags): + old_flags = fcntl.fcntl(fd, fcntl.F_GETFL) + return fcntl.fcntl(fd, fcntl.F_SETFL, old_flags | flags) + + +def set_non_blocking(fd): + """Set O_NONBLOCK flag on file descriptor""" + return _add_flags(fd, os.O_NONBLOCK) + + +def set_close_on_exec(fd): + """Set O_CLOEXEC flag on file descriptor""" + return _add_flags(fd, os.O_CLOEXEC) diff --git a/lib/vdsm/infra/filecontrol/tests.py b/lib/vdsm/infra/filecontrol/tests.py new file mode 100644 index 0000000..ad3ce01 --- /dev/null +++ b/lib/vdsm/infra/filecontrol/tests.py @@ -0,0 +1,16 @@ +import os + +import nose.tools as nt + +from .. import filecontrol + + +def test_non_blocking(): + r, w = os.pipe() + try: + nt.assert_equals(0, filecontrol.set_non_blocking(r)) + with nt.assert_raises(OSError): + os.read(r, 1) + finally: + os.close(r) + os.close(w) diff --git a/vdsm.spec.in b/vdsm.spec.in index 7388aae..de6ec9b 100644 --- a/vdsm.spec.in +++ b/vdsm.spec.in @@ -1552,6 +1552,7 @@ %{python_sitelib}/yajsonrpc/stompReactor.py* %files infra +%{python_sitelib}/%{vdsm_name}/infra/filecontrol/__init__.py* %{python_sitelib}/%{vdsm_name}/infra/zombiereaper/__init__.py* %{python_sitelib}/%{vdsm_name}/infra/__init__.py* -- To view, visit http://gerrit.ovirt.org/35918 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I4f455711d81e84db600647a2d5d80a5e7cadd5e2 Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Dima Kuznetsov <dkuzn...@redhat.com> _______________________________________________ vdsm-patches mailing list vdsm-patches@lists.fedorahosted.org https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches