summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorDavid Mulder <dmulder@suse.com>2021-11-23 08:59:01 -0700
committerAndrew Bartlett <abartlet@samba.org>2021-12-06 22:08:31 +0000
commit528e5efc17ddc3393c04b7add9c51303d5ff9336 (patch)
tree6013e0abd39deec766a9515fd7b73fb459bd38e3 /python
parent5e31e8f15bf0dea1de4f09d270f6bed1a71fb875 (diff)
downloadsamba-528e5efc17ddc3393c04b7add9c51303d5ff9336.tar.gz
samba-tool: Test DNS record creation on member join
Signed-off-by: David Mulder <dmulder@suse.com> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Diffstat (limited to 'python')
-rw-r--r--python/samba/tests/samba_tool/join_member.py71
1 files changed, 71 insertions, 0 deletions
diff --git a/python/samba/tests/samba_tool/join_member.py b/python/samba/tests/samba_tool/join_member.py
new file mode 100644
index 00000000000..c2ab02ff542
--- /dev/null
+++ b/python/samba/tests/samba_tool/join_member.py
@@ -0,0 +1,71 @@
+# Unix SMB/CIFS implementation.
+# Copyright (C) David Mulder <dmulder@samba.org> 2021
+#
+# 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
+import re
+from samba.tests.samba_tool.base import SambaToolCmdTest
+from samba.param import LoadParm
+from samba.netcmd.common import netcmd_dnsname
+
+class JoinMemberCmdTestCase(SambaToolCmdTest):
+ """Test for samba-tool domain join subcommand"""
+
+ def test_join_member(self):
+ """Run a domain member join, and check that dns is updated"""
+ smb_conf = os.environ["SERVERCONFFILE"]
+ zone = os.environ["REALM"].lower()
+ lp = LoadParm()
+ lp.load(smb_conf)
+ dnsname = netcmd_dnsname(lp)
+ # Fetch the existing dns A records
+ (result, out, err) = self.runsubcmd("dns", "query",
+ os.environ["DC_SERVER"],
+ zone, dnsname, 'A',
+ "-s", smb_conf,
+ "-U%s%%%s" % (os.environ["DC_USERNAME"],
+ os.environ["DC_PASSWORD"]))
+ self.assertCmdSuccess(result, out, err, 'Failed to find the record')
+
+ existing_records = re.findall('A:\s+(\d+\.\d+\.\d+\.\d+)\s', out)
+
+ # Remove the existing records
+ for record in existing_records:
+ (result, out, err) = self.runsubcmd("dns", "delete",
+ os.environ["DC_SERVER"],
+ zone, dnsname, 'A', record,
+ "-s", smb_conf,
+ "-U%s%%%s" % (os.environ["DC_USERNAME"],
+ os.environ["DC_PASSWORD"]))
+ self.assertCmdSuccess(result, out, err, 'Failed to remove record')
+
+ # Perform the s3 member join (net ads join)
+ (result, out, err) = self.runsubcmd("domain", "join",
+ os.environ["REALM"], "member",
+ "-s", smb_conf,
+ "-U%s%%%s" % (os.environ["DC_USERNAME"],
+ os.environ["DC_PASSWORD"]))
+ self.assertCmdSuccess(result, out, err, 'Failed to join member')
+
+ # Ensure the dns A record was created
+ (result, out, err) = self.runsubcmd("dns", "query",
+ os.environ["DC_SERVER"],
+ zone, dnsname, 'A',
+ "-s", smb_conf,
+ "-U%s%%%s" % (os.environ["DC_USERNAME"],
+ os.environ["DC_PASSWORD"]))
+ self.assertCmdSuccess(result, out, err,
+ 'Failed to find dns host records for %s' % dnsname)