Beispiel #1
0
 def tearDown(self):
     super(ACLResolverTestCase, self).tearDown()
     for dn in self.__remove_objects:
         try:
             obj = ObjectProxy(dn)
             obj.remove()
         except ProxyException:
             pass
Beispiel #2
0
    def sync_type(self, object_type, foreman_type=None):
        """ sync foreman objects, request data from foreman API and apply those values to the object """
        index = PluginRegistry.getInstance("ObjectIndex")
        backend_attributes = self.factory.getObjectBackendProperties(object_type)

        if "Foreman" not in backend_attributes:
            self.log.warning("no foreman backend attributes found for '%s' object" % object_type)
            return

        if foreman_type is None:
            foreman_type = backend_attributes["Foreman"]["type"]

        new_data = self.client.get(foreman_type)
        found_ids = []
        ForemanBackend.modifier = "foreman"

        uuid_attribute = backend_attributes["Foreman"]["_uuidSourceAttribute"] \
            if '_uuidSourceAttribute' in backend_attributes["Foreman"] else backend_attributes["Foreman"]["_uuidAttribute"]

        for data in new_data["results"]:
            found_ids.append(str(data[uuid_attribute]))
            self.log.debug(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
            self.log.debug(">>> START syncing foreman object of type '%s' with id '%s'" % (object_type, data[uuid_attribute]))
            foreman_object = self.get_object(object_type, data[uuid_attribute], data=data)
            if foreman_type == "discovered_hosts":
                # add status to data
                if not foreman_object.is_extended_by("ForemanHost"):
                    foreman_object.extend("ForemanHost")
                foreman_object.status = "discovered"
                self.update_type(object_type, foreman_object, data, uuid_attribute)
            else:
                self.update_type(object_type, foreman_object, data, uuid_attribute)
            self.log.debug("<<< DONE syncing foreman object of type '%s' with id '%s'" % (object_type, data[uuid_attribute]))
            self.log.debug("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")

        types = self.factory.getObjectTypes()[object_type]
        base_type = object_type if types["base"] is True else types["extends"][0]

        # delete not existing ones
        query = {'_type': base_type}
        if base_type != object_type:
            query["extension"] = object_type

        if len(found_ids):
            query[backend_attributes["Foreman"]["_uuidAttribute"]] = {'not_in_': found_ids}
        if foreman_type == "discovered_hosts":
            query["status"] = "discovered"

        res = index.search(query, {'dn': 1})

        for entry in res:
            foreman_object = ObjectProxy(entry['dn'])
            self.log.debug("removing %s '%s'" % (base_type, foreman_object.dn))
            foreman_object.remove()

        ForemanBackend.modifier = None
Beispiel #3
0
    def create_test_data():
        """
        Insert new data just for testing purposes
        """
        index = PluginRegistry.getInstance("ObjectIndex")
        res = index.search({"dn": "dc=test,dc=example,dc=net"}, {"dn": 1})
        if len(res) > 0:
            new_domain = ObjectProxy("dc=test,dc=example,dc=net")
            new_domain.remove(True)

        new_domain = ObjectProxy("dc=example,dc=net", "DomainComponent")
        new_domain.dc = "test"
        new_domain.description = "Domain for testing purposes"
        new_domain.commit()
        return "dc=test,dc=example,dc=net"
Beispiel #4
0
    def create_test_data():
        """
        Insert new data just for testing purposes
        """
        index = PluginRegistry.getInstance("ObjectIndex")
        res = index.search({"dn": "dc=test,dc=example,dc=net"}, {"dn": 1})
        if len(res) > 0:
            new_domain = ObjectProxy("dc=test,dc=example,dc=net")
            new_domain.remove(True)
            new_domain.commit()

        new_domain = ObjectProxy("dc=example,dc=net", "DomainComponent")
        new_domain.dc = "test"
        new_domain.description = "Domain for testing purposes"
        new_domain.commit()
        return "dc=test,dc=example,dc=net"
Beispiel #5
0
    def test_add_host(self, m_get, m_del, m_put, m_post):
        self._create_test_data()

        m_get.return_value = MockResponse(
            {
                "status": 0,
                "status_label": "Build"
            }, 200)

        logging.getLogger("gosa.backend.objects.index").setLevel(logging.DEBUG)
        key = self.foreman.add_host("testhost", base=self._test_dn)

        device = ObjectProxy("cn=testhost,ou=devices,%s" % self._test_dn)
        assert device.dn == "cn=testhost,ou=devices,%s" % self._test_dn
        assert device.cn == "testhost"
        assert device.userPassword[0][0:6] == "{SSHA}"

        m_del.return_value = MockResponse('{}', 200)

        device.remove()
Beispiel #6
0
    def tearDown(self):
        backend = ObjectBackendRegistry.getBackend("Foreman")
        backend.client.foreman_host = None
        # logging.getLogger("gosa.backend.plugins.foreman").setLevel(logging.INFO)
        # logging.getLogger("gosa.backend.objects").setLevel(logging.INFO)

        # remove them all
        with mock.patch(
                "gosa.backend.objects.backend.back_foreman.requests.delete"
        ) as m_del:
            m_del.return_value = MockResponse({}, 200)

            for dn in self.dns_to_delete:
                try:
                    self.log.info("deleting dn: %s" % dn)
                    obj = ObjectProxy(dn)
                    obj.remove()
                except Exception as e:
                    self.log.error("%s" % e)
                    pass

        super(ForemanSyncTestCase, self).tearDown()
Beispiel #7
0
 def remove_test_data(dn):
     if dn is not None:
         new_domain = ObjectProxy(dn)
         new_domain.remove(True)
Beispiel #8
0
 def remove_test_data(dn):
     if dn is not None:
         new_domain = ObjectProxy(dn)
         new_domain.remove(True)
         new_domain.commit()