Exemplo n.º 1
0
    def get_fsuuid(self, name_or_ip, _user = "", cached = True) :
        """
        returns UUID of a fileserver, which is used as key for server-entries
        in other tables. This does not silently update the Cache
        """
        self._logger.debug("get_fsuuid: called with %s" % name_or_ip)
        if cached :
        # local Cache first
            if name_or_ip in self.memory_cache["fsuuids"].keys() :
                return self.memory_cache["fsuuids"][name_or_ip]
            else :
                name_or_ip = self.get_dns_info(name_or_ip)["names"][0] 
                if name_or_ip in self.memory_cache["fsuuids"].keys() :
                    return self.memory_cache["fsuuids"][name_or_ip]
        # then DB
            if  self._config.DB_CACHE:
                from afs.util.DBManager import DBManager
                from afs.model.FileServer import FileServer
                self._logger.debug("looking up FSUUID in DB_Cache for serv=%s" \
                     % name_or_ip)
                dns_info = self.get_dns_info(name_or_ip)
                this_dbmanager = DBManager(self._config)
                fileserver = this_dbmanager.get_from_cache_by_list_element(\
                    FileServer, FileServer.servernames_js, \
                    dns_info["names"][0])
                if fileserver != None :
                    # store it in memory_cache 
                    self.memory_cache["fsuuids"][fileserver.servernames[0]] = \
                        fileserver.uuid 
                    self.memory_cache["fsuuids"][fileserver.ipaddrs[0]] = \
                        fileserver.uuid
                    return fileserver.uuid

        # not found in local cache and not in DB Cache, get it from live-system
            
        from afs.lla.VLDBLLA import VLDBLLA
        dns_info = self.get_dns_info(name_or_ip)
        uuid = ""
        _vl_lla = VLDBLLA()

        uuid = _vl_lla.get_fileserver_uuid(dns_info["names"][0], _user = _user, \
             _cfg = self._config)

        # store it in memory_cache 
        self.memory_cache["fsuuids"][name_or_ip] = uuid                  
        self.memory_cache["fsuuids"][dns_info["names"][0]] = uuid
        self._logger.debug("returning %s" % (uuid))
        return uuid
Exemplo n.º 2
0
    def get_hostname_by_fsuuid(self, uuid, _user = "", cached = True) :
        """
        returns hostname of a fileserver by uuid
        """
        self._logger.debug("called with %s, cached=%s" % (uuid, cached))
        if cached :
            # local Cache first
            for hostname in self.memory_cache["fsuuids"] :
                if not is_name(hostname) : 
                    continue
                if self.memory_cache["fsuuids"][hostname] == uuid :
                    self._logger.debug("returning from local cache: %s" % \
                        hostname)
                    return hostname
            # then DB 
            if self._config.DB_CACHE:
                from afs.util.DBManager import DBManager
                from afs.model.FileServer import FileServer
                this_dbmanager = DBManager(self._config)
                fileserver = this_dbmanager.get_from_cache(FileServer, \
                    uuid = uuid)
                self._logger.debug("looking up hostname in db_cache " + \
                   "for uuid=%s" % uuid)
                if fileserver != None :
                    self.memory_cache["fsuuids"][fileserver.servernames[0]] = \
                        fileserver.uuid
                    return fileserver.servernames[0]

        # not found in local cache and not in DB Cache, or cacheing disabled.
        # get it from live-system
        from afs.lla.VLDBLLA import VLDBLLA
        _vl_lla = VLDBLLA()
        name_or_ip = None
        for fileserver in _vl_lla.getFsServList(\
            _cfg = self._config, _user="" ) :
            if fileserver['uuid'] == uuid :
                name_or_ip = fileserver['name_or_ip']
        if name_or_ip == None :
            raise LookupUtilError("No Server with uuid=%s " + \
                "registered in live-system" % uuid)
        # store it in memory_cache 
        self._logger.debug("get_hostname_by_fsuuid: got " + \
            " name_or_ip = %s from live-system" % name_or_ip)
        name_or_ip = self.get_dns_info(name_or_ip)["names"][0]
        self.memory_cache["fsuuids"][name_or_ip] = uuid                  
        self._logger.debug("returning: %s" % name_or_ip)
        return name_or_ip
Exemplo n.º 3
0
        return    

    def test_get_archived_volumes_by_name(self) :
        archived_rw_objs = self.volMng.get_archived( historic_Volume,  name=self.VolName )
        self.assertEqual(len(archived_rw_objs), 1)
        archived_ro_objs = self.volMng.get_archived( historic_Volume,  name="%s.readonly" % self.VolName )
        self.assertEqual(len(archived_ro_objs), 2)
        return    

if __name__ == '__main__' :
    parse_commandline()
    sys.stderr.write("Vacuum history tables\n")
    sys.stderr.write("==============================\n")
    afs.CONFIG.DB_HISTORY_NUM_PER_DAY = 0
    afs.CONFIG.DB_HISTORY_NUM_DAYS = 0
    DBMng = DBManager()
    DBMng.vacuum_history(historic_Volume, 0)
    sys.stderr.write("Testing live methods to fill DB_CACHE\n")
    sys.stderr.write("==============================\n")
    suite = unittest.TestLoader().loadTestsFromTestCase(TestVolServiceMethods)
    unittest.TextTestRunner(verbosity=2).run(suite)
    sys.stderr.write("Testing methods accessing DB_CACHE\n")
    sys.stderr.write("================================\n")
    if afs.CONFIG.DB_CACHE :
        suite = unittest.TestLoader().loadTestsFromTestCase(TestVolServiceMethods_cached)
        unittest.TextTestRunner(verbosity=2).run(suite)
    else :
        sys.stderr.write("Skipped, because DB_CACHE is disabled.\n")

    sys.stderr.write("Testing live methods in async mode\n")
    sys.stderr.write("==================================\n")