def _test_backup_restore_into_site(self): """Does a backup and restores into a non-default site""" # create a new non-default site sitename = "Test-Site-For-Backups" sites.create_site(self.ldb, self.ldb.get_config_basedn(), sitename) self.addCleanup(sites.delete_site, self.ldb, self.ldb.get_config_basedn(), sitename) # restore the backup DC into the site we just created backup_file = self.create_backup() self.restore_backup(backup_file, ["--site=" + sitename]) lp = self.check_restored_smbconf() restored_ldb = self.check_restored_database(lp) # check the restored DC was added to the site we created, i.e. there's # an entry matching the new DC sitting underneath the site DN site_dn = "CN={0},CN=Sites,{1}".format( sitename, restored_ldb.get_config_basedn()) match_server = "(&(objectClass=server)(cn={0}))".format( self.new_server) res = restored_ldb.search(site_dn, scope=ldb.SCOPE_SUBTREE, expression=match_server) self.assertTrue(len(res) == 1, "Failed to find new DC under site")
def setUp(self): super(SitesSubnetCmdTestCase, self).setUp() self.sitename = "testsite" self.sitename2 = "testsite2" self.samdb.transaction_start() sites.create_site(self.samdb, self.config_dn, self.sitename) sites.create_site(self.samdb, self.config_dn, self.sitename2) self.samdb.transaction_commit()
def setUp(self): super(SimpleSubnetTests, self).setUp() self.basedn = self.ldb.get_config_basedn() self.sitename = "testsite" self.sitename2 = "testsite2" self.ldb.transaction_start() sites.create_site(self.ldb, self.basedn, self.sitename) sites.create_site(self.ldb, self.basedn, self.sitename2) self.ldb.transaction_commit()
def test_create_and_delete(self): """test creation and deletion of 1 site""" sites.create_site(self.ldb, self.ldb.get_config_basedn(), "testsamba") self.assertRaises(sites.SiteAlreadyExistsException, sites.create_site, self.ldb, self.ldb.get_config_basedn(), "testsamba") sites.delete_site(self.ldb, self.ldb.get_config_basedn(), "testsamba") self.assertRaises(sites.SiteNotFoundException, sites.delete_site, self.ldb, self.ldb.get_config_basedn(), "testsamba")
def run(self, sitename, H=None, sambaopts=None, credopts=None, versionopts=None): lp = sambaopts.get_loadparm() creds = credopts.get_credentials(lp, fallback_machine=True) samdb = SamDB(url=H, session_info=system_session(), credentials=creds, lp=lp) samdb.transaction_start() try: sites.create_site(samdb, samdb.get_config_basedn(), sitename) samdb.transaction_commit() except sites.SiteAlreadyExistsException, e: samdb.transaction_cancel() raise CommandError("Error while creating site %s, error: %s" % (sitename, str(e)))
def create_default_site(self, samdb, logger): '''Creates the default site, if it doesn't already exist''' sitename = DEFAULTSITE search_expr = "(&(cn={0})(objectclass=site))".format(sitename) res = samdb.search(samdb.get_config_basedn(), scope=ldb.SCOPE_SUBTREE, expression=search_expr) if len(res) == 0: logger.info("Creating default site '{0}'".format(sitename)) sites.create_site(samdb, samdb.get_config_basedn(), sitename) return sitename
def run(self, sitename, H=None, sambaopts=None, credopts=None, versionopts=None): lp = sambaopts.get_loadparm() creds = credopts.get_credentials(lp, fallback_machine=True) samdb = SamDB(url=H, session_info=system_session(), credentials=creds, lp=lp) samdb.transaction_start() try: sites.create_site(samdb, samdb.get_config_basedn(), sitename) samdb.transaction_commit() except sites.SiteAlreadyExistsException as e: samdb.transaction_cancel() raise CommandError("Error while creating site %s, error: %s" % (sitename, str(e))) self.outf.write("Site %s created !\n" % sitename)
def test_create(self): """test creation of 1 site""" self.ldb_admin.transaction_start() ok = sites.create_site(self.ldb_admin, self.ldb_admin.get_config_basedn(), "testsamba") self.ldb_admin.transaction_commit() self.assertRaises(sites.SiteAlreadyExistsException, sites.create_site, self.ldb_admin, self.ldb_admin.get_config_basedn(), "testsamba")
def run(self, sitename, sambaopts=None, credopts=None, versionopts=None): lp = sambaopts.get_loadparm() creds = credopts.get_credentials(lp, fallback_machine=True) url = lp.private_path("sam.ldb") if not os.path.exists(url): raise CommandError("secret database not found at %s " % url) samdb = SamDB(url=url, session_info=system_session(), credentials=creds, lp=lp) samdb.transaction_start() try: ok = sites.create_site(samdb, samdb.get_config_basedn(), sitename) samdb.transaction_commit() except sites.SiteAlreadyExistsException, e: samdb.transaction_cancel() raise CommandError("Error while creating site %s, error: %s" % (sitename, str(e)))