diff options
-rw-r--r-- | source4/scripting/python/samba/netcmd/main.py | 2 | ||||
-rw-r--r-- | source4/scripting/python/samba/netcmd/processes.py | 78 | ||||
-rw-r--r-- | source4/scripting/python/samba/tests/samba_tool/processes.py | 35 | ||||
-rwxr-xr-x | source4/selftest/tests.py | 1 |
4 files changed, 116 insertions, 0 deletions
diff --git a/source4/scripting/python/samba/netcmd/main.py b/source4/scripting/python/samba/netcmd/main.py index af3abfd0d3..5f78823588 100644 --- a/source4/scripting/python/samba/netcmd/main.py +++ b/source4/scripting/python/samba/netcmd/main.py @@ -38,6 +38,7 @@ from samba.netcmd.testparm import cmd_testparm from samba.netcmd.time import cmd_time from samba.netcmd.user import cmd_user from samba.netcmd.vampire import cmd_vampire +from samba.netcmd.processes import cmd_processes class cmd_sambatool(SuperCommand): @@ -66,3 +67,4 @@ class cmd_sambatool(SuperCommand): subcommands["time"] = cmd_time() subcommands["user"] = cmd_user() subcommands["vampire"] = cmd_vampire() + subcommands["processes"] = cmd_processes() diff --git a/source4/scripting/python/samba/netcmd/processes.py b/source4/scripting/python/samba/netcmd/processes.py new file mode 100644 index 0000000000..751ab94c21 --- /dev/null +++ b/source4/scripting/python/samba/netcmd/processes.py @@ -0,0 +1,78 @@ +# Unix SMB/CIFS implementation. +# List processes (to aid debugging on systems without setproctitle) +# Copyright (C) 2010-2011 Jelmer Vernooij <jelmer@samba.org> +# +# 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 3 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, see <http://www.gnu.org/licenses/>. +# +# Testbed for loadparm.c/params.c +# +# This module simply loads a specified configuration file and +# if successful, dumps it's contents to stdout. Note that the +# operation is performed with DEBUGLEVEL at 3. +# +# Useful for a quick 'syntax check' of a configuration file. +# + +import os +import sys + +import samba +import samba.getopt as options +from samba.netcmd import Command, CommandError, Option +from samba.messaging import Messaging + +class cmd_processes(Command): + """List processes (to aid debugging on systems without setproctitle).""" + + synopsis = "%prog [options]" + + takes_optiongroups = { + "sambaopts": options.SambaOptions, + "versionopts": options.VersionOptions + } + + takes_options = [ + Option("--name", type=str, + help="Return only processes associated with one particular name"), + Option("--pid", type=int, + help="Return only names assoicated with one particular PID"), + ] + + takes_args = [] + + def run(self, sambaopts, versionopts, section_name=None, + name=None, pid=None): + + lp = sambaopts.get_loadparm() + logger = self.get_logger("processes") + + msg_ctx = Messaging() + + if name is not None: + ids = msg_ctx.irpc_servers_byname(name) + for server_id in ids: + print "%d\n" % server_id.pid + elif pid is not None: + names = msg_ctx.irpc_all_servers() + for name in names: + for server_id in name.ids: + if server_id.pid == int(pid): + print "%s\n" % name.name + else: + names = msg_ctx.irpc_all_servers() + for name in names: + print "%s: " % name.name + for server_id in name.ids: + print "%d " % server_id.pid + print "\n" diff --git a/source4/scripting/python/samba/tests/samba_tool/processes.py b/source4/scripting/python/samba/tests/samba_tool/processes.py new file mode 100644 index 0000000000..91a5266b54 --- /dev/null +++ b/source4/scripting/python/samba/tests/samba_tool/processes.py @@ -0,0 +1,35 @@ +# Unix SMB/CIFS implementation. +# Copyright (C) Andrew Bartlett 2012 +# +# based on time.py: +# Copyright (C) Sean Dague <sdague@linux.vnet.ibm.com> 2011 +# +# 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 3 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, see <http://www.gnu.org/licenses/>. +# + +import os +from samba.tests.samba_tool.base import SambaToolCmdTest + +class ProcessCmdTestCase(SambaToolCmdTest): + """Tests for samba-tool process subcommands""" + + def test_name(self): + """Run processes command""" + (result, out, err) = self.runcmd("processes", "--name", "samba") + self.assertCmdSuccess(result, "Ensuring processes ran successfully") + + def test_all(self): + """Run processes command""" + (result, out, err) = self.runcmd("processes") + self.assertCmdSuccess(result, "Ensuring processes ran successfully") diff --git a/source4/selftest/tests.py b/source4/selftest/tests.py index ea0907139a..ca5bdd39c1 100755 --- a/source4/selftest/tests.py +++ b/source4/selftest/tests.py @@ -405,6 +405,7 @@ planpythontestsuite("dc:local", "samba.tests.dcerpc.bare") planpythontestsuite("dc:local", "samba.tests.dcerpc.unix") planpythontestsuite("dc:local", "samba.tests.dcerpc.srvsvc") planpythontestsuite("dc:local", "samba.tests.samba_tool.timecmd") +planpythontestsuite("dc:local", "samba.tests.samba_tool.processes") planpythontestsuite("dc:local", "samba.tests.samba_tool.user") planpythontestsuite("dc:local", "samba.tests.samba_tool.group") planpythontestsuite("plugin_s4_dc:local", "samba.tests.samba_tool.ntacl") |