[PATCH] [RFC] moving samba tool tests to dedicated directory

Jelmer Vernooij jelmer at samba.org
Mon Oct 17 13:56:46 MDT 2011


Hi Sean,

On Mon, Oct 17, 2011 at 03:20:45PM -0400, Sean Dague wrote:
> I'd like to move and extend samba-tool blackbox testing. The
> following rfc patch would duplicate the existing samba-tool time
> test as an example. The goal here would be making it easy to add in
> tests for all of the samba-tool commands to verify the tool in our
> environment.
> 
> This test can be run with:
> 
> make test TESTS=samba4.blackbox.samba_tool.time
> 
> the time test is really simple, so the power of this will be seen on
> things like user. But before going down that road too far I'd like
> to get early review on this.
Thanks for helping improve the unit tests for samba-tool.

Please add new tests under samba.tests, where the existing tests for netcmd
reside, rather than under samba.netcmd. Your tests also seem to duplicate some
of the infrastructure that is already present in the tests there (see samba.tests.netcmd),
including the functionality to easily run samba-tool subcommands.

Cheers,

Jelmer

> diff --git a/source4/scripting/python/samba/netcmd/tests/test_samba_tool_common.py b/source4/scripting/python/samba/netcmd/tests/test_samba_tool_common.py
> new file mode 100644
> index 0000000..ce5673a
> --- /dev/null
> +++ b/source4/scripting/python/samba/netcmd/tests/test_samba_tool_common.py
> @@ -0,0 +1,60 @@
> +# -*- coding: utf-8 -*-
> +#
> +# Unix SMB/CIFS implementation.
> +# Copyright (C) Sean Dague <sdague at 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 sys
> +import time
> +import os
> +import commands
> +
> +sys.path.insert(0, "bin/python")
> +import samba
> +samba.ensure_external_module("testtools", "testtools")
> +samba.ensure_external_module("subunit", "subunit/python")
> +import unittest
> +
> +class SambaToolTest(unittest.TestCase):
> +    """Base class for samba tool tests"""
> +
> +    def setUp(self):
> +        super(SambaToolTest, self).setUp()
> +
> +        exe = os.environ.get("EXEEXT", "")
> +        samba4bindir = os.environ.get("BINDIR", "")
> +
> +        self.status = 0
> +        self.output = ""
> +        self.lastcmd = ""
> +        self.args = {
> +            "conf" : os.environ.get("CONFIGURATION",""),
> +            "server" : sys.argv[1],
> +            "username" : sys.argv[2],
> +            "password" : sys.argv[3],
> +            "domain" : sys.argv[4],
> +            "sambatool" : "%s/samba-tool%s" % (samba4bindir, exe),
> +            "smbclient" : "%s/smbclient%s" % (samba4bindir, exe)
> +            }
> +
> +    def runcmd(self, cmd = ""):
> +        """wrapper to run command and keep last command, success, and output for future investigation"""
> +        self.lastcmd = cmd % self.args
> +        (self.status, self.output) = commands.getstatusoutput(self.lastcmd)
> +
> +    def assertCmdSuccess(self):
> +        """assert that the command returned 0 on completion"""
> +        self.assertEquals(self.status, 0, "Ensure '%s' ran successfully" % self.lastcmd)
> diff --git a/source4/scripting/python/samba/netcmd/tests/test_samba_tool_time.py b/source4/scripting/python/samba/netcmd/tests/test_samba_tool_time.py
> new file mode 100755
> index 0000000..af1adb6
> --- /dev/null
> +++ b/source4/scripting/python/samba/netcmd/tests/test_samba_tool_time.py
> @@ -0,0 +1,56 @@
> +#!/usr/bin/env python
> +# -*- coding: utf-8 -*-
> +#
> +# Unix SMB/CIFS implementation.
> +# Copyright (C) Sean Dague <sdague at 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 sys
> +import time
> +import os
> +
> +sys.path.insert(0, "bin/python")
> +sys.path.insert(1, "bin/python/samba/netcmd/tests")
> +import samba
> +samba.ensure_external_module("testtools", "testtools")
> +samba.ensure_external_module("subunit", "subunit/python")
> +import unittest
> +
> +from subunit.run import SubunitTestRunner
> +from test_samba_tool_common import SambaToolTest
> +
> +class SambaToolTime(SambaToolTest):
> +    """Test the samba-tool time command"""
> +
> +    def test_time(self):
> +        """tests running"""
> +        self.runcmd("%(smbclient)s -c 'ls' %(conf)s //%(server)s/tmp --machine-pass -k no")
> +        self.assertCmdSuccess()
> +
> +        self.runcmd("%(smbclient)s -c 'ls' %(conf)s //%(server)s/tmp --machine-pass -k yes")
> +        self.assertCmdSuccess()
> +
> +        self.runcmd("%(sambatool)s time %(server)s %(conf)s -W %(domain)s -U%(username)s%%%(password)s")
> +        self.assertCmdSuccess()
> +
> +# if run as a command
> +if __name__ == "__main__":
> +    runner = SubunitTestRunner()
> +    rc = 0
> +    if not runner.run(unittest.makeSuite(SambaToolTime)).wasSuccessful():
> +        rc = 1
> +    sys.exit(rc)
> +
> diff --git a/source4/selftest/tests.py b/source4/selftest/tests.py
> index 7dae7a2..db62174 100755
> --- a/source4/selftest/tests.py
> +++ b/source4/selftest/tests.py
> @@ -299,6 +299,8 @@ for f in sorted(os.listdir(os.path.join(samba4srcdir, "../pidl/tests"))):
>  planpythontestsuite("none", "samba.tests.blackbox.ndrdump")
>  planpythontestsuite("none", "samba.tests.source")
>  plantestsuite("samba4.blackbox.samba_tool(dc:local)", "dc:local", [os.path.join(samba4srcdir, "utils/tests/test_samba_tool.sh"),  '$SERVER', "$USERNAME", "$PASSWORD", "$DOMAIN"])
> +plantestsuite("samba4.blackbox.samba_tool.time(dc:local)", "dc:local", [os.path.join(samba4srcdir, "scripting/python/samba/netcmd/tests/test_samba_tool_time.py"),  '$SERVER', "$USERNAME", "$PASSWORD", "$DOMAIN"])
> +
>  plantestsuite("samba4.blackbox.pkinit(dc:local)", "dc:local", [os.path.join(bbdir, "test_pkinit.sh"), '$SERVER', '$USERNAME', '$PASSWORD', '$REALM', '$DOMAIN', '$PREFIX', "aes256-cts-hmac-sha1-96", configuration])
>  plantestsuite("samba4.blackbox.kinit(dc:local)", "dc:local", [os.path.join(bbdir, "test_kinit.sh"), '$SERVER', '$USERNAME', '$PASSWORD', '$REALM', '$DOMAIN', '$PREFIX', "aes256-cts-hmac-sha1-96", configuration])
>  plantestsuite("samba4.blackbox.kinit(fl2000dc:local)", "fl2000dc:local", [os.path.join(bbdir, "test_kinit.sh"), '$SERVER', '$USERNAME', '$PASSWORD', '$REALM', '$DOMAIN', '$PREFIX', "arcfour-hmac-md5", configuration])


-- 


More information about the samba-technical mailing list