예제 #1
0
 def test_project_termination(self):
     """Terminated projects should remove its attributes."""
     entity_trait = EntityTrait(self._db)
     self.setup_project('del_me')
     eid = self._ou.entity_id
     self._ou.terminate()
     self.assertEqual(eid, self._ou.entity_id)
     # The OU object itself must remain, and its project ID and project name
     # No accounts:
     self.assertEqual(0, len(self._ac.list_accounts_by_type(
         ou_id=eid,
         filter_expired=False)))
     # No affiliated persons:
     self.assertEqual(0, len(self._pe.list_affiliations(
         ou_id=eid,
         include_deleted=True)))
     # Checking for different types of traits.
     # Are there any traits that should be left?
     # No groups:
     # list_traits returns an iterator instead of a list
     groups = tuple(self._gr.list_traits(
         code=self._co.trait_project_group, target_id=eid))
     self.assertEqual(0, len(groups))
     # No hosts:
     hosts = tuple(entity_trait.list_traits(
         target_id=eid, code=self._co.trait_project_host))
     self.assertEqual(0, len(hosts))
     # No subnets:
     subnets = tuple(entity_trait.list_traits(
         target_id=eid,
         code=(self._co.trait_project_subnet6,
               self._co.trait_project_subnet)))
     self.assertEqual(0, len(subnets))
def get_student_disks(db):
    """ Get disks tagged as student disks. """
    et = EntityTrait(db)
    co = Factory.get('Constants')(db)
    return set(
        t['entity_id']
        for t in et.list_traits(code=co.trait_student_disk))
def get_student_disks(db):
    """ Get disks tagged as student disks. """
    et = EntityTrait(db)
    co = Factory.get('Constants')(db)
    return set(
        t['entity_id']
        for t in et.list_traits(code=co.trait_student_disk))
예제 #4
0
 def test_project_termination(self):
     """Terminated projects should remove its attributes."""
     entity_trait = EntityTrait(self._db)
     self.setup_project('del_me')
     eid = self._ou.entity_id
     self._ou.terminate()
     self.assertEqual(eid, self._ou.entity_id)
     # The OU object itself must remain, and its project ID and project name
     # No accounts:
     self.assertEqual(
         0,
         len(self._ac.list_accounts_by_type(ou_id=eid,
                                            filter_expired=False)))
     # No affiliated persons:
     self.assertEqual(
         0, len(self._pe.list_affiliations(ou_id=eid,
                                           include_deleted=True)))
     # Checking for different types of traits.
     # Are there any traits that should be left?
     # No groups:
     # list_traits returns an iterator instead of a list
     groups = tuple(
         self._gr.list_traits(code=self._co.trait_project_group,
                              target_id=eid))
     self.assertEqual(0, len(groups))
     # No hosts:
     hosts = tuple(
         entity_trait.list_traits(target_id=eid,
                                  code=self._co.trait_project_host))
     self.assertEqual(0, len(hosts))
     # No subnets:
     subnets = tuple(
         entity_trait.list_traits(target_id=eid,
                                  code=(self._co.trait_project_subnet6,
                                        self._co.trait_project_subnet)))
     self.assertEqual(0, len(subnets))
예제 #5
0
    def terminate(self):
        """Remove all of a project, except its project ID and name (acronym).

        The project's entities are deleted by this method, so use with care!

        For the OU object, it does almost the same as L{delete} except from
        deleting the entity itself.
        """
        self.write_db()
        ent = EntityTrait(self._db)
        ac = Factory.get('Account')(self._db)
        pu = Factory.get('PosixUser')(self._db)
        # Delete PosixUsers
        for row in ac.list_accounts_by_type(ou_id=self.entity_id,
                                            filter_expired=False):
            try:
                pu.clear()
                pu.find(row['account_id'])
                pu.delete_posixuser()
            except Errors.NotFoundError:
                # not a PosixUser
                continue
        # Remove all project's groups
        gr = Factory.get('Group')(self._db)
        for row in gr.list_traits(code=self.const.trait_project_group,
                                  target_id=self.entity_id):
            gr.clear()
            gr.find(row['entity_id'])
            gr.delete()
        # Delete all users
        for row in ac.list_accounts_by_type(ou_id=self.entity_id):
            ac.clear()
            ac.find(row['account_id'])
            ac.delete()
        # Remove every trace of person affiliations to the project:
        pe = Factory.get('Person')(self._db)
        for row in pe.list_affiliations(ou_id=self.entity_id,
                                        include_deleted=True):
            pe.clear()
            pe.find(row['person_id'])
            pe.nuke_affiliation(ou_id=row['ou_id'],
                                affiliation=row['affiliation'],
                                source=row['source_system'],
                                status=row['status'])
            pe.write_db()
        # Remove all project's DnsOwners (hosts):
        dnsowner = dns.DnsOwner.DnsOwner(self._db)
        policy = PolicyComponent(self._db)
        update_helper = dns.IntegrityHelper.Updater(self._db)
        for row in ent.list_traits(code=self.const.trait_project_host,
                                   target_id=self.entity_id):
            # TODO: Could we instead update the Subnet classes to use
            # Factory.get('Entity'), and make use of EntityTrait there to
            # handle this?
            owner_id = row['entity_id']
            ent.clear()
            ent.find(owner_id)
            ent.delete_trait(row['code'])
            ent.write_db()
            # Remove the links to policies if hostpolicy is used
            for prow in policy.search_hostpolicies(dns_owner_id=owner_id):
                policy.clear()
                policy.find(prow['policy_id'])
                policy.remove_from_host(owner_id)
            # delete the DNS owner
            update_helper.full_remove_dns_owner(owner_id)
        # Delete all subnets
        subnet = dns.Subnet.Subnet(self._db)
        subnet6 = dns.IPv6Subnet.IPv6Subnet(self._db)
        for row in ent.list_traits(code=(self.const.trait_project_subnet6,
                                         self.const.trait_project_subnet),
                                   target_id=self.entity_id):
            ent.clear()
            ent.find(row['entity_id'])
            ent.delete_trait(row['code'])
            ent.write_db()
            if row['code'] == self.const.trait_project_subnet:
                subnet.clear()
                subnet.find(row['entity_id'])
                subnet.delete()
            if row['code'] == self.const.trait_project_subnet6:
                subnet6.clear()
                subnet6.find(row['entity_id'])
                subnet6.delete()
        # Remove all data from the OU except for:
        # The project ID and project name
        for tr in tuple(self.get_traits()):
            self.delete_trait(tr)
        for row in self.get_spread():
            self.delete_spread(row['spread'])
        for row in self.get_contact_info():
            self.delete_contact_info(row['source_system'],
                                     row['contact_type'])
        for row in self.get_entity_address():
            self.delete_entity_address(row['source_system'],
                                       row['address_type'])
        for row in self.search_name_with_language(entity_id=self.entity_id):
            # The project name must not be removed, to avoid reuse
            if row['name_variant'] == self.const.ou_name_acronym:
                continue
            self.delete_name_with_language(row['name_variant'])
        self.write_db()
예제 #6
0
    def terminate(self):
        """Remove all of a project, except its project ID and name (acronym).

        The project's entities are deleted by this method, so use with care!

        For the OU object, it does almost the same as L{delete} except from
        deleting the entity itself.
        """
        self.write_db()
        ent = EntityTrait(self._db)
        ac = Factory.get('Account')(self._db)
        pu = Factory.get('PosixUser')(self._db)
        # Delete PosixUsers
        for row in ac.list_accounts_by_type(ou_id=self.entity_id,
                                            filter_expired=False):
            try:
                pu.clear()
                pu.find(row['account_id'])
                pu.delete_posixuser()
            except Errors.NotFoundError:
                # not a PosixUser
                continue
        # Remove all project's groups
        gr = Factory.get('Group')(self._db)
        for row in gr.list_traits(code=self.const.trait_project_group,
                                  target_id=self.entity_id):
            gr.clear()
            gr.find(row['entity_id'])
            gr.delete()
        # Delete all users
        for row in ac.list_accounts_by_type(ou_id=self.entity_id):
            ac.clear()
            ac.find(row['account_id'])
            ac.delete()
        # Remove every trace of person affiliations to the project:
        pe = Factory.get('Person')(self._db)
        for row in pe.list_affiliations(ou_id=self.entity_id,
                                        include_deleted=True):
            pe.clear()
            pe.find(row['person_id'])
            pe.nuke_affiliation(ou_id=row['ou_id'],
                                affiliation=row['affiliation'],
                                source=row['source_system'],
                                status=row['status'])
            pe.write_db()
        # Remove all project's DnsOwners (hosts):
        dnsowner = DnsOwner.DnsOwner(self._db)
        policy = PolicyComponent(self._db)
        update_helper = IntegrityHelper.Updater(self._db)
        for row in ent.list_traits(code=self.const.trait_project_host,
                                   target_id=self.entity_id):
            # TODO: Could we instead update the Subnet classes to use
            # Factory.get('Entity'), and make use of EntityTrait there to
            # handle this?
            owner_id = row['entity_id']
            ent.clear()
            ent.find(owner_id)
            ent.delete_trait(row['code'])
            ent.write_db()
            # Remove the links to policies if hostpolicy is used
            for prow in policy.search_hostpolicies(dns_owner_id=owner_id):
                policy.clear()
                policy.find(prow['policy_id'])
                policy.remove_from_host(owner_id)
            # delete the DNS owner
            update_helper.full_remove_dns_owner(owner_id)
        # Delete all subnets
        subnet = Subnet.Subnet(self._db)
        subnet6 = IPv6Subnet.IPv6Subnet(self._db)
        for row in ent.list_traits(code=(self.const.trait_project_subnet6,
                                         self.const.trait_project_subnet),
                                   target_id=self.entity_id):
            ent.clear()
            ent.find(row['entity_id'])
            ent.delete_trait(row['code'])
            ent.write_db()
            if row['code'] == self.const.trait_project_subnet:
                subnet.clear()
                subnet.find(row['entity_id'])
                subnet.delete()
            if row['code'] == self.const.trait_project_subnet6:
                subnet6.clear()
                subnet6.find(row['entity_id'])
                subnet6.delete()
        # Remove all data from the OU except for:
        # The project ID and project name
        for tr in tuple(self.get_traits()):
            self.delete_trait(tr)
        for row in self.get_spread():
            self.delete_spread(row['spread'])
        for row in self.get_contact_info():
            self.delete_contact_info(row['source_system'],
                                     row['contact_type'])
        for row in self.get_entity_address():
            self.delete_entity_address(row['source_system'],
                                       row['address_type'])
        for row in self.search_name_with_language(entity_id=self.entity_id):
            # The project name must not be removed, to avoid reuse
            if row['name_variant'] == self.const.ou_name_acronym:
                continue
            self.delete_name_with_language(row['name_variant'])
        self.write_db()