Skip to content

Commit

Permalink
tests/demote: replace demote test bash script to python
Browse files Browse the repository at this point in the history
Convert bash script to python and add demote and dns remove test on top.

Signed-off-by: Joe Guo <[email protected]>
Reviewed-by: Douglas Bagnall <[email protected]>
Reviewed-by: Garming Sam <[email protected]>

Autobuild-User(master): Douglas Bagnall <[email protected]>
Autobuild-Date(master): Thu Jun  7 04:21:17 CEST 2018 on sn-devel-144
  • Loading branch information
catalyst-joe-guo authored and douglasbagnall committed Jun 7, 2018
1 parent 00494a6 commit 0fb122a
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 40 deletions.
106 changes: 106 additions & 0 deletions python/samba/tests/samba_tool/demote.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# Unix SMB/CIFS implementation.
# Copyright (C) Andrew Bartlett <[email protected]> 2018
# Written by Joe Guo <[email protected]>
#
# 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 DemoteCmdTestCase(SambaToolCmdTest):
"""Test for samba-tool domain demote subcommand"""

def setUp(self):
super(DemoteCmdTestCase, self).setUp()
self.creds_string = "-U{}%{}".format(
os.environ["DC_USERNAME"], os.environ["DC_PASSWORD"])

self.dc_server = os.environ['DC_SERVER']
self.dburl = "ldap://%s" % os.environ["DC_SERVER"]
self.samdb = self.getSamDB("-H", self.dburl, self.creds_string)

def test_demote_and_remove_dns(self):
"""
Test domain demote command will also remove dns references
"""

server = os.environ['SERVER'] # the server to demote
zone = os.environ['REALM'].lower()

# make sure zone exist
result, out, err = self.runsubcmd(
"dns", "zoneinfo", server, zone, self.creds_string)
self.assertCmdSuccess(result, out, err)

# add a A record for the server to demote
result, out, err = self.runsubcmd(
"dns", "add", self.dc_server, zone,
server, "A", "192.168.0.193", self.creds_string)
self.assertCmdSuccess(result, out, err)

# make sure above A record exist
result, out, err = self.runsubcmd(
"dns", "query", self.dc_server, zone,
server, 'A', self.creds_string)
self.assertCmdSuccess(result, out, err)

# the above A record points to this host
dnshostname = '{}.{}'.format(server, zone)

# add a SRV record points to above host
srv_record = "{} 65530 65530 65530".format(dnshostname)
self.runsubcmd(
"dns", "add", self.dc_server, zone, 'testrecord', "SRV",
srv_record, self.creds_string)

# make sure above SRV record exist
result, out, err = self.runsubcmd(
"dns", "query", self.dc_server, zone,
"testrecord", 'SRV', self.creds_string)
self.assertCmdSuccess(result, out, err)

for type_ in ['CNAME', 'NS', 'PTR']:
# create record
self.runsubcmd(
"dns", "add", self.dc_server, zone,
'testrecord', type_, dnshostname,
self.creds_string)
self.assertCmdSuccess(result, out, err)

# check exist
result, out, err = self.runsubcmd(
"dns", "query", self.dc_server, zone,
"testrecord", 'SRV', self.creds_string)
self.assertCmdSuccess(result, out, err)

# now demote
result, out, err = self.runsubcmd(
"domain", "demote",
"--server", self.dc_server,
"--configfile", os.environ["CONFIGFILE"],
"--workgroup", os.environ["DOMAIN"],
self.creds_string)
self.assertCmdSuccess(result, out, err)

result, out, err = self.runsubcmd(
"dns", "query", self.dc_server, zone,
server, 'ALL', self.creds_string)
self.assertCmdFail(result)

result, out, err = self.runsubcmd(
"dns", "query", self.dc_server, zone,
"testrecord", 'ALL', self.creds_string)
self.assertCmdFail(result)
10 changes: 8 additions & 2 deletions source4/selftest/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1053,8 +1053,14 @@ def planoldpythontestsuite(env, module, name=None, extra_path=[], environ={}, ex

# 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])

planoldpythontestsuite(env, "samba.tests.samba_tool.demote",
name="samba.tests.samba_tool.demote",
environ={
'CONFIGFILE': '$PREFIX/%s/etc/smb.conf' % env
},
extra_args=['-U"$USERNAME%$PASSWORD"'],
extra_path=[os.path.join(srcdir(), "samba/python")]
)
# TODO: Verifying the databases really should be a part of the
# environment teardown.
# check the databases are all OK. PLEASE LEAVE THIS AS THE LAST TEST
Expand Down
38 changes: 0 additions & 38 deletions source4/utils/tests/test_demote.sh

This file was deleted.

0 comments on commit 0fb122a

Please sign in to comment.