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
30 class SambaDnsUpdateTests(samba.tests.BlackboxTestCase):
31 """Blackbox test case for samba_dnsupdate."""
34 self.server_ip = samba.tests.env_get_var_value("DNS_SERVER_IP")
35 super(SambaDnsUpdateTests, self).setUp()
37 out = self.check_output("samba_dnsupdate --verbose")
38 self.assertTrue("Looking for DNS entry" in out, out)
39 except samba.tests.BlackboxProcessError:
42 def test_samba_dnsupate_no_change(self):
44 out = self.check_output("samba_dnsupdate --verbose")
45 except samba.tests.BlackboxProcessError as e:
46 self.fail("Error calling samba_dnsupdate: %s" % e)
47 self.assertTrue("No DNS updates needed" in out, out)
49 def test_samba_dnsupate_set_ip(self):
51 out = self.check_output("samba_dnsupdate --verbose --current-ip=10.0.0.1")
52 self.assertTrue(" DNS updates and" in out, out)
53 self.assertTrue(" DNS deletes needed" in out, out)
54 except samba.tests.BlackboxProcessError:
58 out = self.check_output("samba_dnsupdate --verbose --use-nsupdate --current-ip=10.0.0.1")
59 except samba.tests.BlackboxProcessError as e:
60 self.fail("Error calling samba_dnsupdate: %s" % e)
62 self.assertTrue("No DNS updates needed" in out, out)
64 rpc_out = self.check_output("samba_dnsupdate --verbose --use-samba-tool --rpc-server-ip=%s" % self.server_ip)
65 except samba.tests.BlackboxProcessError as e:
66 self.fail("Error calling samba_dnsupdate: %s" % e)
68 self.assertTrue(" DNS updates and" in rpc_out, rpc_out)
69 self.assertTrue(" DNS deletes needed" in rpc_out, rpc_out)
70 out = self.check_output("samba_dnsupdate --verbose")
71 self.assertTrue("No DNS updates needed" in out, out + rpc_out)
73 def test_add_new_uncovered_site(self):
75 cmd = cmd_sambatool.subcommands[name]
79 site_name = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
81 # Clear out any existing site
82 cmd._run("samba-tool %s" % name, 'remove', site_name)
84 result = cmd._run("samba-tool %s" % name, 'create', site_name)
85 if result is not None:
86 self.fail("Error creating new site")
88 self.lp = samba.tests.env_loadparm()
89 self.creds = Credentials()
90 self.creds.guess(self.lp)
91 self.session = system_session()
92 uc_fn = self.lp.private_path('dns_update_cache')
93 tmp_uc = uc_fn + '_tmp'
94 shutil.copyfile(uc_fn, tmp_uc)
96 self.samdb = SamDB(session_info=self.session,
97 credentials=self.creds,
101 m.dn = ldb.Dn(self.samdb, 'CN=DEFAULTIPSITELINK,CN=IP,'
102 'CN=Inter-Site Transports,CN=Sites,{}'.format(
103 self.samdb.get_config_basedn()))
104 m['siteList'] = ldb.MessageElement("CN={},CN=Sites,{}".format(
106 self.samdb.get_config_basedn()),
107 ldb.FLAG_MOD_ADD, "siteList")
109 dns_c = "samba_dnsupdate --verbose --use-file={}".format(tmp_uc)
110 out = self.check_output(dns_c)
111 self.assertFalse(site_name.lower() in out, out)
115 shutil.copyfile(uc_fn, tmp_uc)
116 out = self.check_output(dns_c)
118 self.assertFalse("No DNS updates needed" in out, out)
119 self.assertTrue(site_name.lower() in out, out)
121 result = cmd._run("samba-tool %s" % name, 'remove', site_name)
122 if result is not None:
123 self.fail("Error deleting site")