Skip to content

Commit

Permalink
tests/samba_dnsupdate: Add a trivial test of automatic site coverage
Browse files Browse the repository at this point in the history
Signed-off-by: Garming Sam <[email protected]>
Reviewed-by: Douglas Bagnall <[email protected]>
  • Loading branch information
GSam authored and douglasbagnall committed Mar 21, 2018
1 parent b71f897 commit 79b640f
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
54 changes: 54 additions & 0 deletions python/samba/tests/blackbox/samba_dnsupdate.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
#

import samba.tests
from StringIO import StringIO
from samba.netcmd.main import cmd_sambatool
from samba.credentials import Credentials
from samba.auth import system_session
from samba.samdb import SamDB
import ldb

class SambaDnsUpdateTests(samba.tests.BlackboxTestCase):
"""Blackbox test case for samba_dnsupdate."""
Expand Down Expand Up @@ -57,3 +63,51 @@ def test_samba_dnsupate_set_ip(self):
self.assertTrue(" DNS deletes needed" in rpc_out, rpc_out)
out = self.check_output("samba_dnsupdate --verbose")
self.assertTrue("No DNS updates needed" in out, out + rpc_out)

def test_add_new_uncovered_site(self):
name = 'sites'
cmd = cmd_sambatool.subcommands[name]
cmd.outf = StringIO()
cmd.errf = StringIO()

site_name = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

# Clear out any existing site
cmd._run("samba-tool %s" % name, 'remove', site_name)

result = cmd._run("samba-tool %s" % name, 'create', site_name)
if result is not None:
self.fail("Error creating new site")

self.lp = samba.tests.env_loadparm()
self.creds = Credentials()
self.creds.guess(self.lp)
self.session = system_session()

self.samdb = SamDB(session_info=self.session,
credentials=self.creds,
lp=self.lp)

m = ldb.Message()
m.dn = ldb.Dn(self.samdb, 'CN=DEFAULTIPSITELINK,CN=IP,'
'CN=Inter-Site Transports,CN=Sites,{}'.format(
self.samdb.get_config_basedn()))
m['siteList'] = ldb.MessageElement("CN={},CN=Sites,{}".format(
site_name,
self.samdb.get_config_basedn()),
ldb.FLAG_MOD_ADD, "siteList")

out = self.check_output("samba_dnsupdate --verbose")
self.assertTrue("No DNS updates needed" in out, out)

self.samdb.modify(m)

out = self.check_output("samba_dnsupdate --verbose --use-samba-tool"
" --rpc-server-ip={}".format(self.server_ip))

self.assertFalse("No DNS updates needed" in out, out)
self.assertTrue(site_name.lower() in out, out)

result = cmd._run("samba-tool %s" % name, 'remove', site_name)
if result is not None:
self.fail("Error deleting site")
1 change: 1 addition & 0 deletions selftest/knownfail.d/autosite_coverage
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
^samba.tests.blackbox.samba_dnsupdate.samba.tests.blackbox.samba_dnsupdate.SambaDnsUpdateTests.test_add_new_uncovered_site

0 comments on commit 79b640f

Please sign in to comment.