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 io
import StringIO
21 from samba
.common
import get_string
22 from samba
.netcmd
.main
import samba_tool
23 from samba
.credentials
import Credentials
24 from samba
.auth
import system_session
25 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")
37 out
= self
.check_output("samba_dnsupdate --verbose")
38 self
.assertTrue(b
"Looking for DNS entry" in out
, out
)
39 except samba
.tests
.BlackboxProcessError
:
42 def test_samba_dnsupdate_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(b
"No DNS updates needed" in out
, out
)
49 def test_samba_dnsupdate_set_ip(self
):
51 out
= self
.check_output("samba_dnsupdate --verbose --current-ip=10.0.0.1")
52 self
.assertTrue(b
" DNS updates and" in out
, out
)
53 self
.assertTrue(b
" 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(b
"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(b
" DNS updates and" in rpc_out
, rpc_out
)
69 self
.assertTrue(b
" DNS deletes needed" in rpc_out
, rpc_out
)
70 out
= self
.check_output("samba_dnsupdate --verbose")
71 self
.assertTrue(b
"No DNS updates needed" in out
, out
+ rpc_out
)
73 def test_add_new_uncovered_site(self
):
74 site_name
= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
76 # Clear out any existing site
77 result
= samba_tool('sites', 'remove', site_name
,
81 result
= samba_tool('sites', '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,{0}'.format(
103 self
.samdb
.get_config_basedn()))
104 m
['siteList'] = ldb
.MessageElement("CN={0},CN=Sites,{1}".format(
106 self
.samdb
.get_config_basedn()),
107 ldb
.FLAG_MOD_ADD
, "siteList")
109 dns_c
= "samba_dnsupdate --verbose --use-file={0}".format(tmp_uc
)
110 out
= get_string(self
.check_output(dns_c
))
111 self
.assertNotIn(site_name
.lower(), out
)
115 shutil
.copyfile(uc_fn
, tmp_uc
)
116 out
= get_string(self
.check_output(dns_c
))
118 self
.assertNotIn("No DNS updates needed", out
)
119 self
.assertIn(site_name
.lower(), out
)
121 result
= samba_tool('sites', 'remove', site_name
,
124 if result
is not None:
125 self
.fail("Error deleting site")