s3: torture: adjust SMB1 cli_splice() test sizes
[Samba.git] / python / samba / tests / samba_tool / demote.py
blob0726d2b15afb216dbd8a7895e73089263b8104f3
1 # Unix SMB/CIFS implementation.
2 # Copyright (C) Andrew Bartlett <abartlet@samba.org> 2018
3 # Written by Joe Guo <joeg@catalyst.net.nz>
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 import os
20 from samba.tests.samba_tool.base import SambaToolCmdTest
23 class DemoteCmdTestCase(SambaToolCmdTest):
24 """Test for samba-tool domain demote subcommand"""
26 def setUp(self):
27 super(DemoteCmdTestCase, self).setUp()
28 self.creds_string = "-U{}%{}".format(
29 os.environ["DC_USERNAME"], os.environ["DC_PASSWORD"])
31 self.dc_server = os.environ['DC_SERVER']
32 self.dburl = "ldap://%s" % os.environ["DC_SERVER"]
33 self.samdb = self.getSamDB("-H", self.dburl, self.creds_string)
35 def test_demote_and_remove_dns(self):
36 """
37 Test domain demote command will also remove dns references
38 """
40 server = os.environ['SERVER'] # the server to demote
41 zone = os.environ['REALM'].lower()
43 # make sure zone exist
44 result, out, err = self.runsubcmd(
45 "dns", "zoneinfo", server, zone, self.creds_string)
46 self.assertCmdSuccess(result, out, err)
48 # add a A record for the server to demote
49 result, out, err = self.runsubcmd(
50 "dns", "add", self.dc_server, zone,
51 server, "A", "192.168.0.193", self.creds_string)
52 self.assertCmdSuccess(result, out, err)
54 # make sure above A record exist
55 result, out, err = self.runsubcmd(
56 "dns", "query", self.dc_server, zone,
57 server, 'A', self.creds_string)
58 self.assertCmdSuccess(result, out, err)
60 # the above A record points to this host
61 dnshostname = '{}.{}'.format(server, zone)
63 # add a SRV record points to above host
64 srv_record = "{} 65530 65530 65530".format(dnshostname)
65 self.runsubcmd(
66 "dns", "add", self.dc_server, zone, 'testrecord', "SRV",
67 srv_record, self.creds_string)
69 # make sure above SRV record exist
70 result, out, err = self.runsubcmd(
71 "dns", "query", self.dc_server, zone,
72 "testrecord", 'SRV', self.creds_string)
73 self.assertCmdSuccess(result, out, err)
75 for type_ in ['CNAME', 'NS', 'PTR']:
76 # create record
77 self.runsubcmd(
78 "dns", "add", self.dc_server, zone,
79 'testrecord', type_, dnshostname,
80 self.creds_string)
81 self.assertCmdSuccess(result, out, err)
83 # check exist
84 result, out, err = self.runsubcmd(
85 "dns", "query", self.dc_server, zone,
86 "testrecord", 'SRV', self.creds_string)
87 self.assertCmdSuccess(result, out, err)
89 # now demote
90 result, out, err = self.runsubcmd(
91 "domain", "demote",
92 "--server", self.dc_server,
93 "--configfile", os.environ["CONFIGFILE"],
94 "--workgroup", os.environ["DOMAIN"],
95 self.creds_string)
96 self.assertCmdSuccess(result, out, err)
98 result, out, err = self.runsubcmd(
99 "dns", "query", self.dc_server, zone,
100 server, 'ALL', self.creds_string)
101 self.assertCmdFail(result)
103 result, out, err = self.runsubcmd(
104 "dns", "query", self.dc_server, zone,
105 "testrecord", 'ALL', self.creds_string)
106 self.assertCmdFail(result)