def test_create_shift_delete(self): """Create a subnet, shift it to another site, then delete it.""" basedn = self.ldb.get_config_basedn() cidr = "10.11.12.0/24" subnets.create_subnet(self.ldb, basedn, cidr, self.sitename) subnets.set_subnet_site(self.ldb, basedn, cidr, self.sitename2) ret = self.ldb.search(base=basedn, scope=SCOPE_SUBTREE, expression='(&(objectclass=subnet)(cn=%s))' % cidr) sites = ret[0]['siteObject'] self.assertEqual(len(sites), 1) self.assertEqual( str(sites[0]), 'CN=testsite2,CN=Sites,%s' % self.ldb.get_config_basedn()) self.assertRaises(subnets.SubnetAlreadyExists, subnets.create_subnet, self.ldb, basedn, cidr, self.sitename) subnets.delete_subnet(self.ldb, basedn, cidr) ret = self.ldb.search(base=basedn, scope=SCOPE_SUBTREE, expression='(&(objectclass=subnet)(cn=%s))' % cidr) self.assertEqual(len(ret), 0, 'Failed to delete subnet %s' % cidr)
def test_create_shift_delete(self): """Create a subnet, shift it to another site, then delete it.""" basedn = self.ldb.get_config_basedn() cidr = "10.11.12.0/24" subnets.create_subnet(self.ldb, basedn, cidr, self.sitename) subnets.set_subnet_site(self.ldb, basedn, cidr, self.sitename2) ret = self.ldb.search(base=basedn, scope=SCOPE_SUBTREE, expression='(&(objectclass=subnet)(cn={0!s}))'.format(cidr)) sites = ret[0]['siteObject'] self.assertEqual(len(sites), 1) self.assertEqual(sites[0], 'CN=testsite2,CN=Sites,{0!s}'.format(self.ldb.get_config_basedn())) self.assertRaises(subnets.SubnetAlreadyExists, subnets.create_subnet, self.ldb, basedn, cidr, self.sitename) subnets.delete_subnet(self.ldb, basedn, cidr) ret = self.ldb.search(base=basedn, scope=SCOPE_SUBTREE, expression='(&(objectclass=subnet)(cn={0!s}))'.format(cidr)) self.assertEqual(len(ret), 0, 'Failed to delete subnet {0!s}'.format(cidr))
def run(self, subnetname, site_of_subnet, H=None, sambaopts=None, credopts=None, versionopts=None): lp = sambaopts.get_loadparm() creds = credopts.get_credentials(lp) samdb = SamDB(url=H, session_info=system_session(), credentials=creds, lp=lp) samdb.transaction_start() try: subnets.set_subnet_site(samdb, samdb.get_config_basedn(), subnetname, site_of_subnet) samdb.transaction_commit() except subnets.SubnetException as e: samdb.transaction_cancel() raise CommandError("Error assigning subnet %s to site %s: %s" % (subnetname, site_of_subnet, e)) print(("Subnet %s shifted to site %s" % (subnetname, site_of_subnet)), file=self.outf)
def run(self, subnetname, site_of_subnet, H=None, sambaopts=None, credopts=None, versionopts=None): lp = sambaopts.get_loadparm() creds = credopts.get_credentials(lp) samdb = SamDB(url=H, session_info=system_session(), credentials=creds, lp=lp) samdb.transaction_start() try: subnets.set_subnet_site(samdb, samdb.get_config_basedn(), subnetname, site_of_subnet) samdb.transaction_commit() except subnets.SubnetException, e: samdb.transaction_cancel() raise CommandError("Error assigning subnet %s to site %s: %s" % (subnetname, site_of_subnet, e))