def factory(app, db, config, cluster): """This method returns the appropriate UserImporter object depending on what is specified in configuration. In case of configuration error, HPCStatsConfigurationException is raised. """ implem = config.get(cluster.name, 'users') if implem == 'ldap': return UserImporterLdap(app, db, config, cluster) if implem == 'ldap+slurm': return UserImporterLdapSlurm(app, db, config, cluster) else: raise HPCStatsConfigurationException( \ "UserImporter %s is not implemented" \ % (implem))
def setUp(self): self.filename = 'fake' self.cluster = Cluster('testcluster') self.cluster.cluster_id = 0 HPCStatsConf.__bases__ = (MockConfigParser, object) self.conf = HPCStatsConf(self.filename, self.cluster) self.conf.conf = CONFIG.copy() self.db = HPCStatsDB(self.conf) self.db.bind() self.app = MockApp(self.db, self.conf, self.cluster) self.importer = UserImporterLdapSlurm(self.app, self.db, self.conf, self.cluster) # Disable strict_user_membership to avoid exception when user found # in Slurm and not in LDAP then. self.importer.strict_user_membership = False init_reqs()