Ido Barkan has uploaded a new change for review.
Change subject: net: backport cmdutils.systemd_run
......................................................................
net: backport cmdutils.systemd_run
This is a minimal backport of cmdutils to 3.5. cmdutils is only a
partial version of what was already included in the master branch. This
was done to avoid meeting many dependencies just in order to fix a bug
in the stable branch.
Change-Id: I7686e80c0880dcc28fa735d1dd3ab658136889f9
Signed-off-by: Federico Simoncelli <fsimonce(a)redhat.com>
---
M configure.ac
M debian/vdsm-python.install
M lib/vdsm/Makefile.am
A lib/vdsm/cmdutils.py
M lib/vdsm/constants.py.in
M tests/Makefile.am
A tests/cmdutilsTests.py
M vdsm.spec.in
M vdsm/sudoers.vdsm.in
9 files changed, 87 insertions(+), 1 deletion(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/52/43852/1
diff --git a/configure.ac b/configure.ac
index 7d3472c..46c857b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -264,6 +264,7 @@
AC_PATH_PROG([SU_PATH], [su], [/bin/su])
AC_PATH_PROG([SYSCTL_PATH], [sysctl], [/sbin/sysctl])
AC_PATH_PROG([SYSTEMCTL_PATH], [systemctl], [/bin/systemctl])
+AC_PATH_PROG([SYSTEMD_RUN_PATH], [systemd-run], [/usr/bin/systemd-run])
AC_PATH_PROG([TAR_PATH], [tar], [/bin/tar])
AC_PATH_PROG([TC_PATH], [tc], [/sbin/tc])
AC_PATH_PROG([TEE_PATH], [tee], [/usr/bin/tee])
diff --git a/debian/vdsm-python.install b/debian/vdsm-python.install
index 5f142a7..142dfce 100644
--- a/debian/vdsm-python.install
+++ b/debian/vdsm-python.install
@@ -2,6 +2,7 @@
./usr/bin/vdsm-tool
./usr/lib/python2.7/dist-packages/vdsm/SecureXMLRPCServer.py
./usr/lib/python2.7/dist-packages/vdsm/__init__.py
+./usr/lib/python2.7/dist-packages/vdsm/cmdutils.py
./usr/lib/python2.7/dist-packages/vdsm/compat.py
./usr/lib/python2.7/dist-packages/vdsm/config.py
./usr/lib/python2.7/dist-packages/vdsm/constants.py
diff --git a/lib/vdsm/Makefile.am b/lib/vdsm/Makefile.am
index aaf26bf..a0f5c72 100644
--- a/lib/vdsm/Makefile.am
+++ b/lib/vdsm/Makefile.am
@@ -23,6 +23,7 @@
dist_vdsmpylib_PYTHON = \
__init__.py \
+ cmdutils.py \
compat.py \
define.py \
exception.py \
diff --git a/lib/vdsm/cmdutils.py b/lib/vdsm/cmdutils.py
new file mode 100644
index 0000000..5d1c96e
--- /dev/null
+++ b/lib/vdsm/cmdutils.py
@@ -0,0 +1,32 @@
+#
+# 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
+#
+from . import constants
+
+
+def systemd_run(cmd, scope=False, unit=None, slice=None):
+ command = [constants.EXT_SYSTEMD_RUN]
+ if scope:
+ command.append('--scope')
+ if unit:
+ command.append('--unit=%s' % unit)
+ if slice:
+ command.append('--slice=%s' % slice)
+ command.extend(cmd)
+ return command
diff --git a/lib/vdsm/constants.py.in b/lib/vdsm/constants.py.in
index 4539d26..e75796a 100644
--- a/lib/vdsm/constants.py.in
+++ b/lib/vdsm/constants.py.in
@@ -168,3 +168,4 @@
EXT_CURL_IMG_WRAP = '@LIBEXECDIR@/curl-img-wrap'
EXT_FC_SCAN = '@LIBEXECDIR@/fc-scan'
+EXT_SYSTEMD_RUN = '@SYSTEMD_RUN_PATH@'
diff --git a/tests/Makefile.am b/tests/Makefile.am
index ec9ab0b..bd15c19 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -29,6 +29,7 @@
cPopenTests.py \
capsTests.py \
clientifTests.py \
+ cmdutilsTests.py \
configNetworkTests.py \
fileVolumeTests.py \
fileUtilTests.py \
diff --git a/tests/cmdutilsTests.py b/tests/cmdutilsTests.py
new file mode 100644
index 0000000..a8c928b
--- /dev/null
+++ b/tests/cmdutilsTests.py
@@ -0,0 +1,47 @@
+#
+# Copyright 2015 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
+#
+
+from vdsm import cmdutils
+from vdsm import constants
+
+from testlib import VdsmTestCase
+
+
+class SystemdRunTests(VdsmTestCase):
+
+ def test_defaults(self):
+ cmd = cmdutils.systemd_run(['a', 'b'])
+ res = [constants.EXT_SYSTEMD_RUN, 'a', 'b']
+ self.assertEqual(cmd, res)
+
+ def test_scope(self):
+ cmd = cmdutils.systemd_run(['a', 'b'], scope=True)
+ res = [constants.EXT_SYSTEMD_RUN, '--scope', 'a', 'b']
+ self.assertEqual(cmd, res)
+
+ def test_unit(self):
+ cmd = cmdutils.systemd_run(['a', 'b'], unit='unit')
+ res = [constants.EXT_SYSTEMD_RUN, '--unit=unit', 'a',
'b']
+ self.assertEqual(cmd, res)
+
+ def test_slice(self):
+ cmd = cmdutils.systemd_run(['a', 'b'], slice='slice')
+ res = [constants.EXT_SYSTEMD_RUN, '--slice=slice', 'a',
'b']
+ self.assertEqual(cmd, res)
diff --git a/vdsm.spec.in b/vdsm.spec.in
index 8a54ed8..4f06070 100644
--- a/vdsm.spec.in
+++ b/vdsm.spec.in
@@ -1251,6 +1251,7 @@
%dir %{python_sitelib}/%{vdsm_name}
%dir %{python_sitelib}/%{vdsm_name}/tool
%{python_sitelib}/%{vdsm_name}/__init__.py*
+%{python_sitelib}/%{vdsm_name}/cmdutils.py*
%{python_sitelib}/%{vdsm_name}/compat.py*
%{python_sitelib}/%{vdsm_name}/config.py*
%{python_sitelib}/%{vdsm_name}/constants.py*
diff --git a/vdsm/sudoers.vdsm.in b/vdsm/sudoers.vdsm.in
index dff5539..121e2bf 100644
--- a/vdsm/sudoers.vdsm.in
+++ b/vdsm/sudoers.vdsm.in
@@ -32,7 +32,8 @@
@MULTIPATH_PATH@, \
@SETSID_PATH@ @IONICE_PATH@ -c ? -n ? @SU_PATH@ vdsm -s /bin/sh -c
/usr/libexec/vdsm/spmprotect.sh*, \
@SERVICE_PATH@ vdsmd *, \
- @REBOOT_PATH@ -f
+ @REBOOT_PATH@ -f, \
+ @SYSTEMD_RUN_PATH@
vdsm ALL=(ALL) NOPASSWD: VDSM_LIFECYCLE, VDSM_STORAGE
Defaults:vdsm !requiretty
--
To view, visit
https://gerrit.ovirt.org/43852
To unsubscribe, visit
https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I7686e80c0880dcc28fa735d1dd3ab658136889f9
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: ovirt-3.5
Gerrit-Owner: Ido Barkan <ibarkan(a)redhat.com>