mirror of
https://github.com/samba-team/samba.git
synced 2025-01-22 22:04:08 +03:00
tests/kcc_util: Add unit tests for automatic site coverage
Signed-off-by: Garming Sam <garming@catalyst.net.nz> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
This commit is contained in:
parent
ecf503ce76
commit
b71f897b4f
@ -21,6 +21,10 @@
|
||||
import samba
|
||||
import samba.tests
|
||||
from samba.kcc.kcc_utils import *
|
||||
from samba.credentials import Credentials
|
||||
from samba.auth import system_session
|
||||
from samba.samdb import SamDB
|
||||
from samba.tests import delete_force
|
||||
|
||||
|
||||
class ScheduleTests(samba.tests.TestCase):
|
||||
@ -35,3 +39,351 @@ class ScheduleTests(samba.tests.TestCase):
|
||||
# OK, this is pathetic, but the rest of it looks really hard, with the
|
||||
# classes all intertwingled with each other and the samdb. That is to say:
|
||||
# XXX later.
|
||||
|
||||
class SiteCoverageTests(samba.tests.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.prefix = "kcc_"
|
||||
self.lp = samba.tests.env_loadparm()
|
||||
|
||||
self.sites = {}
|
||||
self.site_links = {}
|
||||
|
||||
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)
|
||||
|
||||
def tearDown(self):
|
||||
self.samdb.transaction_start()
|
||||
|
||||
for site in self.sites:
|
||||
delete_force(self.samdb, site, controls=['tree_delete:1'])
|
||||
|
||||
for site_link in self.site_links:
|
||||
delete_force(self.samdb, site_link)
|
||||
|
||||
self.samdb.transaction_commit()
|
||||
|
||||
def _add_server(self, name, site):
|
||||
dn = "CN={},CN=Servers,{}".format(name, site)
|
||||
self.samdb.add({
|
||||
"dn": dn,
|
||||
"objectClass": "server",
|
||||
"serverReference": self.samdb.domain_dn()
|
||||
})
|
||||
return dn
|
||||
|
||||
def _add_site(self, name):
|
||||
dn = "CN={},CN=Sites,{}".format(
|
||||
name, self.samdb.get_config_basedn()
|
||||
)
|
||||
self.samdb.add({
|
||||
"dn": dn,
|
||||
"objectClass": "site"
|
||||
})
|
||||
self.samdb.add({
|
||||
"dn": "CN=Servers," + dn,
|
||||
"objectClass": ["serversContainer"]
|
||||
})
|
||||
|
||||
self.sites[dn] = name
|
||||
return dn, name.lower()
|
||||
|
||||
def _add_site_link(self, name, links=[], cost=100):
|
||||
dn = "CN={},CN=IP,CN=Inter-Site Transports,CN=Sites,{}".format(
|
||||
name, self.samdb.get_config_basedn()
|
||||
)
|
||||
self.samdb.add({
|
||||
"dn": dn,
|
||||
"objectClass": "siteLink",
|
||||
"cost": str(cost),
|
||||
"siteList": links
|
||||
})
|
||||
self.site_links[dn] = name
|
||||
return dn
|
||||
|
||||
def test_single_site_link_same_dc_count(self):
|
||||
self.samdb.transaction_start()
|
||||
site1, name1 = self._add_site(self.prefix + "ABCD")
|
||||
site2, name2 = self._add_site(self.prefix + "BCDE")
|
||||
|
||||
uncovered_dn, uncovered = self._add_site(self.prefix + "uncovered")
|
||||
|
||||
self._add_server(self.prefix + "ABCD" + '1', site1)
|
||||
self._add_server(self.prefix + "BCDE" + '1', site2)
|
||||
|
||||
self._add_site_link(self.prefix + "link",
|
||||
[site1, site2, uncovered_dn])
|
||||
self.samdb.transaction_commit()
|
||||
|
||||
to_cover = uncovered_sites_to_cover(self.samdb, name1)
|
||||
to_cover.sort()
|
||||
|
||||
self.assertEqual([uncovered], to_cover)
|
||||
|
||||
to_cover = uncovered_sites_to_cover(self.samdb, name2)
|
||||
to_cover.sort()
|
||||
|
||||
self.assertEqual([], to_cover)
|
||||
|
||||
def test_single_site_link_different_dc_count(self):
|
||||
self.samdb.transaction_start()
|
||||
site1, name1 = self._add_site(self.prefix + "ABCD")
|
||||
site2, name2 = self._add_site(self.prefix + "BCDE")
|
||||
|
||||
uncovered_dn, uncovered = self._add_site(self.prefix + "uncovered")
|
||||
|
||||
self._add_server(self.prefix + "ABCD" + '1', site1)
|
||||
self._add_server(self.prefix + "ABCD" + '2', site1)
|
||||
self._add_server(self.prefix + "BCDE" + '1', site2)
|
||||
self._add_server(self.prefix + "BCDE" + '2', site2)
|
||||
self._add_server(self.prefix + "BCDE" + '3', site2)
|
||||
|
||||
self._add_site_link(self.prefix + "link",
|
||||
[site1, site2, uncovered_dn])
|
||||
self.samdb.transaction_commit()
|
||||
|
||||
to_cover = uncovered_sites_to_cover(self.samdb, name1)
|
||||
to_cover.sort()
|
||||
|
||||
self.assertEqual([], to_cover)
|
||||
|
||||
to_cover = uncovered_sites_to_cover(self.samdb, name2)
|
||||
to_cover.sort()
|
||||
|
||||
self.assertEqual([uncovered], to_cover)
|
||||
|
||||
def test_two_site_links_same_cost(self):
|
||||
self.samdb.transaction_start()
|
||||
site1, name1 = self._add_site(self.prefix + "ABCD")
|
||||
site2, name2 = self._add_site(self.prefix + "BCDE")
|
||||
|
||||
uncovered_dn, uncovered = self._add_site(self.prefix + "uncovered")
|
||||
|
||||
self._add_server(self.prefix + "ABCD" + '1', site1)
|
||||
self._add_server(self.prefix + "ABCD" + '2', site1)
|
||||
self._add_server(self.prefix + "BCDE" + '1', site2)
|
||||
self._add_server(self.prefix + "BCDE" + '2', site2)
|
||||
self._add_server(self.prefix + "BCDE" + '3', site2)
|
||||
|
||||
self._add_site_link(self.prefix + "link1",
|
||||
[site1, uncovered_dn])
|
||||
self._add_site_link(self.prefix + "link2",
|
||||
[site2, uncovered_dn])
|
||||
self.samdb.transaction_commit()
|
||||
|
||||
to_cover = uncovered_sites_to_cover(self.samdb, name1)
|
||||
to_cover.sort()
|
||||
|
||||
self.assertEqual([uncovered], to_cover)
|
||||
|
||||
to_cover = uncovered_sites_to_cover(self.samdb, name2)
|
||||
to_cover.sort()
|
||||
|
||||
self.assertEqual([uncovered], to_cover)
|
||||
|
||||
def test_two_site_links_different_costs(self):
|
||||
self.samdb.transaction_start()
|
||||
site1, name1 = self._add_site(self.prefix + "ABCD")
|
||||
site2, name2 = self._add_site(self.prefix + "BCDE")
|
||||
|
||||
uncovered_dn, uncovered = self._add_site(self.prefix + "uncovered")
|
||||
|
||||
self._add_server(self.prefix + "ABCD" + '1', site1)
|
||||
self._add_server(self.prefix + "BCDE" + '1', site2)
|
||||
self._add_server(self.prefix + "BCDE" + '2', site2)
|
||||
|
||||
self._add_site_link(self.prefix + "link1",
|
||||
[site1, uncovered_dn],
|
||||
cost=50)
|
||||
self._add_site_link(self.prefix + "link2",
|
||||
[site2, uncovered_dn],
|
||||
cost=75)
|
||||
self.samdb.transaction_commit()
|
||||
|
||||
to_cover = uncovered_sites_to_cover(self.samdb, name1)
|
||||
to_cover.sort()
|
||||
|
||||
self.assertEqual([uncovered], to_cover)
|
||||
|
||||
to_cover = uncovered_sites_to_cover(self.samdb, name2)
|
||||
to_cover.sort()
|
||||
|
||||
self.assertEqual([], to_cover)
|
||||
|
||||
def test_three_site_links_different_costs(self):
|
||||
self.samdb.transaction_start()
|
||||
site1, name1 = self._add_site(self.prefix + "ABCD")
|
||||
site2, name2 = self._add_site(self.prefix + "BCDE")
|
||||
site3, name3 = self._add_site(self.prefix + "CDEF")
|
||||
|
||||
uncovered_dn, uncovered = self._add_site(self.prefix + "uncovered")
|
||||
|
||||
self._add_server(self.prefix + "ABCD" + '1', site1)
|
||||
self._add_server(self.prefix + "BCDE" + '1', site2)
|
||||
self._add_server(self.prefix + "CDEF" + '1', site3)
|
||||
self._add_server(self.prefix + "CDEF" + '2', site3)
|
||||
|
||||
self._add_site_link(self.prefix + "link1",
|
||||
[site1, uncovered_dn],
|
||||
cost=50)
|
||||
self._add_site_link(self.prefix + "link2",
|
||||
[site2, uncovered_dn],
|
||||
cost=75)
|
||||
self._add_site_link(self.prefix + "link3",
|
||||
[site3, uncovered_dn],
|
||||
cost=60)
|
||||
self.samdb.transaction_commit()
|
||||
|
||||
to_cover = uncovered_sites_to_cover(self.samdb, name1)
|
||||
to_cover.sort()
|
||||
|
||||
self.assertEqual([uncovered], to_cover)
|
||||
|
||||
to_cover = uncovered_sites_to_cover(self.samdb, name2)
|
||||
to_cover.sort()
|
||||
|
||||
self.assertEqual([], to_cover)
|
||||
|
||||
to_cover = uncovered_sites_to_cover(self.samdb, name3)
|
||||
to_cover.sort()
|
||||
|
||||
self.assertEqual([], to_cover)
|
||||
|
||||
def test_three_site_links_different_costs(self):
|
||||
self.samdb.transaction_start()
|
||||
site1, name1 = self._add_site(self.prefix + "ABCD")
|
||||
site2, name2 = self._add_site(self.prefix + "BCDE")
|
||||
site3, name3 = self._add_site(self.prefix + "CDEF")
|
||||
|
||||
uncovered_dn, uncovered = self._add_site(self.prefix + "uncovered")
|
||||
|
||||
self._add_server(self.prefix + "ABCD" + '1', site1)
|
||||
self._add_server(self.prefix + "BCDE" + '1', site2)
|
||||
self._add_server(self.prefix + "CDEF" + '1', site3)
|
||||
self._add_server(self.prefix + "CDEF" + '2', site3)
|
||||
|
||||
self._add_site_link(self.prefix + "link1",
|
||||
[site1, uncovered_dn],
|
||||
cost=50)
|
||||
self._add_site_link(self.prefix + "link2",
|
||||
[site2, uncovered_dn],
|
||||
cost=75)
|
||||
self._add_site_link(self.prefix + "link3",
|
||||
[site3, uncovered_dn],
|
||||
cost=50)
|
||||
self.samdb.transaction_commit()
|
||||
|
||||
to_cover = uncovered_sites_to_cover(self.samdb, name1)
|
||||
to_cover.sort()
|
||||
|
||||
self.assertEqual([uncovered], to_cover)
|
||||
|
||||
to_cover = uncovered_sites_to_cover(self.samdb, name2)
|
||||
to_cover.sort()
|
||||
|
||||
self.assertEqual([], to_cover)
|
||||
|
||||
to_cover = uncovered_sites_to_cover(self.samdb, name3)
|
||||
to_cover.sort()
|
||||
|
||||
self.assertEqual([uncovered], to_cover)
|
||||
|
||||
def test_complex_setup_with_multiple_uncovered_sites(self):
|
||||
self.samdb.transaction_start()
|
||||
site1, name1 = self._add_site(self.prefix + "ABCD")
|
||||
site2, name2 = self._add_site(self.prefix + "BCDE")
|
||||
site3, name3 = self._add_site(self.prefix + "CDEF")
|
||||
|
||||
site4, name4 = self._add_site(self.prefix + "1234")
|
||||
site5, name5 = self._add_site(self.prefix + "2345")
|
||||
site6, name6 = self._add_site(self.prefix + "3456")
|
||||
|
||||
uncovered_dn1, uncovered1 = self._add_site(self.prefix + "uncovered1")
|
||||
uncovered_dn2, uncovered2 = self._add_site(self.prefix + "uncovered2")
|
||||
uncovered_dn3, uncovered3 = self._add_site(self.prefix + "uncovered3")
|
||||
|
||||
# Site Link Cluster 1 - Server List
|
||||
self._add_server(self.prefix + "ABCD" + '1', site1)
|
||||
|
||||
self._add_server(self.prefix + "BCDE" + '1', site2)
|
||||
self._add_server(self.prefix + "BCDE" + '2', site2)
|
||||
|
||||
self._add_server(self.prefix + "CDEF" + '1', site3)
|
||||
self._add_server(self.prefix + "CDEF" + '2', site3)
|
||||
self._add_server(self.prefix + "CDEF" + '3', site3)
|
||||
|
||||
# Site Link Cluster 2 - Server List
|
||||
self._add_server(self.prefix + "1234" + '1', site4)
|
||||
self._add_server(self.prefix + "1234" + '2', site4)
|
||||
|
||||
self._add_server(self.prefix + "2345" + '1', site5)
|
||||
self._add_server(self.prefix + "2345" + '2', site5)
|
||||
|
||||
self._add_server(self.prefix + "3456" + '1', site6)
|
||||
|
||||
# Join to Uncovered1 (preference to site link cluster 1)
|
||||
self._add_site_link(self.prefix + "link1A",
|
||||
[site1, site2, site3, uncovered_dn1],
|
||||
cost=49)
|
||||
self._add_site_link(self.prefix + "link2A",
|
||||
[site4, site5, site6, uncovered_dn1],
|
||||
cost=50)
|
||||
|
||||
# Join to Uncovered2 (no preferene on site links)
|
||||
self._add_site_link(self.prefix + "link1B",
|
||||
[site1, site2, site3, uncovered_dn2],
|
||||
cost=50)
|
||||
self._add_site_link(self.prefix + "link2B",
|
||||
[site4, site5, site6, uncovered_dn2],
|
||||
cost=50)
|
||||
|
||||
# Join to Uncovered3 (preference to site link cluster 2)
|
||||
self._add_site_link(self.prefix + "link1C",
|
||||
[site1, site2, site3, uncovered_dn3],
|
||||
cost=50)
|
||||
self._add_site_link(self.prefix + "link2C",
|
||||
[site4, site5, site6, uncovered_dn3],
|
||||
cost=49)
|
||||
|
||||
self.samdb.transaction_commit()
|
||||
|
||||
to_cover = uncovered_sites_to_cover(self.samdb, name1)
|
||||
to_cover.sort()
|
||||
|
||||
self.assertEqual([], to_cover)
|
||||
|
||||
to_cover = uncovered_sites_to_cover(self.samdb, name2)
|
||||
to_cover.sort()
|
||||
|
||||
self.assertEqual([], to_cover)
|
||||
|
||||
to_cover = uncovered_sites_to_cover(self.samdb, name3)
|
||||
to_cover.sort()
|
||||
|
||||
self.assertEqual([uncovered1, uncovered2], to_cover)
|
||||
|
||||
to_cover = uncovered_sites_to_cover(self.samdb, name4)
|
||||
to_cover.sort()
|
||||
|
||||
self.assertEqual([uncovered2, uncovered3], to_cover)
|
||||
|
||||
to_cover = uncovered_sites_to_cover(self.samdb, name5)
|
||||
to_cover.sort()
|
||||
|
||||
self.assertEqual([], to_cover)
|
||||
|
||||
to_cover = uncovered_sites_to_cover(self.samdb, name6)
|
||||
to_cover.sort()
|
||||
|
||||
self.assertEqual([], to_cover)
|
||||
|
||||
for to_check in [uncovered1, uncovered2, uncovered3]:
|
||||
to_cover = uncovered_sites_to_cover(self.samdb, to_check)
|
||||
to_cover.sort()
|
||||
|
||||
self.assertEqual([], to_cover)
|
||||
|
@ -147,7 +147,6 @@ planpythontestsuite("none", "samba.tests.ntacls")
|
||||
planpythontestsuite("none", "samba.tests.policy")
|
||||
planpythontestsuite("none", "samba.tests.kcc.graph")
|
||||
planpythontestsuite("none", "samba.tests.kcc.graph_utils")
|
||||
planpythontestsuite("none", "samba.tests.kcc.kcc_utils")
|
||||
planpythontestsuite("none", "samba.tests.kcc.ldif_import_export")
|
||||
planpythontestsuite("none", "samba.tests.graph")
|
||||
plantestsuite("wafsamba.duplicate_symbols", "none", [os.path.join(srcdir(), "buildtools/wafsamba/test_duplicate_symbol.sh")])
|
||||
|
@ -999,6 +999,8 @@ for env in [
|
||||
)
|
||||
planpythontestsuite(env, "samba.tests.samba_tool.visualize_drs")
|
||||
|
||||
planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.kcc.kcc_utils")
|
||||
|
||||
for env in [ "simpleserver", "fileserver", "nt4_dc", "ad_dc", "ad_dc_ntvfs", "ad_member"]:
|
||||
planoldpythontestsuite(env, "netlogonsvc",
|
||||
extra_path=[os.path.join(srcdir(), 'python/samba/tests')],
|
||||
|
Loading…
x
Reference in New Issue
Block a user