1 # Blackbox tests for "samba_dnsupdate" command
2 # Copyright (C) Kamen Mazdrashki <kamenim@samba.org> 2011
3 # Copyright (C) Andrew Bartlett <abartlet@samba.org> 2015
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/>.
20 from StringIO import StringIO
21 from samba.netcmd.main import cmd_sambatool
22 from samba.credentials import Credentials
23 from samba.auth import system_session
24 from samba.samdb import SamDB
29 class SambaDnsUpdateTests(samba.tests.BlackboxTestCase):
30 """Blackbox test case for samba_dnsupdate."""
33 self.server_ip = samba.tests.env_get_var_value("DNS_SERVER_IP")
34 super(SambaDnsUpdateTests, self).setUp()
36 out = self.check_output("samba_dnsupdate --verbose")
37 self.assertTrue("Looking for DNS entry" in out, out)
38 except samba.tests.BlackboxProcessError:
41 def test_samba_dnsupate_no_change(self):
43 out = self.check_output("samba_dnsupdate --verbose")
44 except samba.tests.BlackboxProcessError as e:
45 self.fail("Error calling samba_dnsupdate: %s" % e)
46 self.assertTrue("No DNS updates needed" in out, out)
48 def test_samba_dnsupate_set_ip(self):
50 out = self.check_output("samba_dnsupdate --verbose --current-ip=10.0.0.1")
51 self.assertTrue(" DNS updates and" in out, out)
52 self.assertTrue(" DNS deletes needed" in out, out)
53 except samba.tests.BlackboxProcessError:
57 out = self.check_output("samba_dnsupdate --verbose --use-nsupdate --current-ip=10.0.0.1")
58 except samba.tests.BlackboxProcessError as e:
59 self.fail("Error calling samba_dnsupdate: %s" % e)
61 self.assertTrue("No DNS updates needed" in out, out)
63 rpc_out = self.check_output("samba_dnsupdate --verbose --use-samba-tool --rpc-server-ip=%s" % self.server_ip)
64 except samba.tests.BlackboxProcessError as e:
65 self.fail("Error calling samba_dnsupdate: %s" % e)
67 self.assertTrue(" DNS updates and" in rpc_out, rpc_out)
68 self.assertTrue(" DNS deletes needed" in rpc_out, rpc_out)
69 out = self.check_output("samba_dnsupdate --verbose")
70 self.assertTrue("No DNS updates needed" in out, out + rpc_out)
72 def test_add_new_uncovered_site(self):
74 cmd = cmd_sambatool.subcommands[name]
78 site_name = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
80 # Clear out any existing site
81 cmd._run("samba-tool %s" % name, 'remove', site_name)
83 result = cmd._run("samba-tool %s" % name, 'create', site_name)
84 if result is not None:
85 self.fail("Error creating new site")
87 self.lp = samba.tests.env_loadparm()
88 self.creds = Credentials()
89 self.creds.guess(self.lp)
90 self.session = system_session()
91 uc_fn = self.lp.private_path('dns_update_cache')
92 tmp_uc = uc_fn + '_tmp'
93 shutil.copyfile(uc_fn, tmp_uc)
95 self.samdb = SamDB(session_info=self.session,
96 credentials=self.creds,
100 m.dn = ldb.Dn(self.samdb, 'CN=DEFAULTIPSITELINK,CN=IP,'
101 'CN=Inter-Site Transports,CN=Sites,{}'.format(
102 self.samdb.get_config_basedn()))
103 m['siteList'] = ldb.MessageElement("CN={},CN=Sites,{}".format(
105 self.samdb.get_config_basedn()),
106 ldb.FLAG_MOD_ADD, "siteList")
108 dns_c = "samba_dnsupdate --verbose --use-file={}".format(tmp_uc)
109 out = self.check_output(dns_c)
110 self.assertFalse(site_name.lower() in out, out)
114 shutil.copyfile(uc_fn, tmp_uc)
115 out = self.check_output(dns_c)
117 self.assertFalse("No DNS updates needed" in out, out)
118 self.assertTrue(site_name.lower() in out, out)
120 result = cmd._run("samba-tool %s" % name, 'remove', site_name)
121 if result is not None:
122 self.fail("Error deleting site")