tests: Add simple check whether netlogon server is running
authorTim Beale <timbeale@catalyst.net.nz>
Mon, 3 Jul 2017 21:31:54 +0000 (09:31 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Tue, 4 Jul 2017 04:57:20 +0000 (06:57 +0200)
Netlogon only needs to run in DC environment. This is a simple test to
check whether the netlogon service is running. This will allow us to
disable the netlogon service on setups that don't require it.

Signed-off-by: Tim Beale <timbeale@catalyst.net.nz>
Reviewed-by: Garming Sam <garming@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
python/samba/tests/netlogonsvc.py [new file with mode: 0644]
source4/selftest/tests.py

diff --git a/python/samba/tests/netlogonsvc.py b/python/samba/tests/netlogonsvc.py
new file mode 100644 (file)
index 0000000..87afa3e
--- /dev/null
@@ -0,0 +1,69 @@
+# Tests to check the netlogon service is only running when it's required
+#
+# Copyright (C) Catalyst IT Ltd. 2017
+#
+# 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/>.
+#
+from samba.tests import TestCase
+import os
+
+import samba
+from samba.credentials import Credentials
+from samba.dcerpc import netlogon
+from samba import NTSTATUSError, ntstatus
+import ctypes
+
+"""
+Tests whether the netlogon service is running
+"""
+
+class NetlogonServiceTests(TestCase):
+
+    def setUp(self):
+        super(NetlogonServiceTests, self).setUp()
+
+        self.server      = os.environ["SERVER"]
+        self.lp          = self.get_loadparm()
+        self.creds = Credentials()
+
+        # prefer the DC user/password in environments that have it
+        if "DC_USERNAME" in os.environ and "DC_PASSWORD" in os.environ:
+            self.creds.set_username(os.environ["DC_USERNAME"])
+            self.creds.set_password(os.environ["DC_PASSWORD"])
+        else:
+            self.creds.set_username(os.environ["USERNAME"])
+            self.creds.set_password(os.environ["PASSWORD"])
+
+        self.creds.guess(self.lp)
+
+    def tearDown(self):
+        super(NetlogonServiceTests, self).tearDown()
+
+    def test_have_netlogon_connection(self):
+        try:
+            c = self.get_netlogon_connection()
+            self.assertIsNotNone(c)
+        except NTSTATUSError as e:
+            # On non-DC test environments, netlogon should not be running on
+            # the server, so we expect the test to fail here
+            enum = ctypes.c_uint32(e[0]).value
+            if enum == ntstatus.NT_STATUS_OBJECT_NAME_NOT_FOUND:
+                self.fail("netlogon service is not running")
+            else:
+                raise
+
+    # Establish netlogon connection over NP
+    def get_netlogon_connection(self):
+        return netlogon.netlogon("ncacn_np:%s[seal]" % self.server, self.lp,
+                                 self.creds)
index 049009fe125fd1a89c4411de04ec6297da48b5a5..c74d0fef715d8bccef51f51bb39054626ed3334e 100755 (executable)
@@ -893,6 +893,11 @@ for env in [
                            extra_path=[os.path.join(srcdir(), "samba/python"), ]
                            )
 
+for env in [ "simpleserver", "fileserver", "nt4_dc", "ad_dc", "ad_dc_ntvfs", "ad_member"]:
+    planoldpythontestsuite(env, "netlogonsvc",
+                           extra_path=[os.path.join(srcdir(), 'python/samba/tests')],
+                           name="samba.tests.netlogonsvc.python(%s)" % env)
+
 # Demote the vampire DC, it must be the last test each DC, before the dbcheck
 for env in ['vampire_dc', 'promoted_dc', 'rodc']:
     plantestsuite("samba4.blackbox.samba_tool_demote(%s)" % env, env, [os.path.join(samba4srcdir, "utils/tests/test_demote.sh"), '$SERVER', '$SERVER_IP', '$USERNAME', '$PASSWORD', '$DOMAIN', '$DC_SERVER', '$PREFIX/%s' % env, smbclient4])