def test_gip_conf(self): """ Make sure that the $GIP_LOCATION/etc/gip.conf file is read. """ old_gip_location = os.environ['GIP_LOCATION'] tmpdir = tempfile.mkdtemp() try: os.environ['GIP_LOCATION'] = tmpdir etc_dir = os.path.join(tmpdir, 'etc') try: os.mkdir(etc_dir) cp_orig = ConfigParser.ConfigParser() cp_orig.add_section("gip_test") cp_orig.set("gip_test", "gip_conf", "True") gip_conf = os.path.join(etc_dir, 'gip.conf') fp = open(gip_conf, 'w') try: cp_orig.write(fp) fp.close() cp = ConfigParser.ConfigParser() cp.read([gip_conf]) result = cp_getBoolean(cp, "gip_test", "gip_conf", False) self.failUnless(result, msg="Failed to load $GIP_LOCATION"\ "/etc/gip.conf") finally: os.unlink(gip_conf) finally: os.rmdir(etc_dir) finally: os.rmdir(tmpdir) os.environ['GIP_LOCATION'] = old_gip_location
def test_config_dir(self): # create temp dir old_gip_location = os.environ['GIP_LOCATION'] tmpdir = tempfile.mkdtemp() try: os.environ['GIP_LOCATION'] = tmpdir etc_dir = os.path.join(tmpdir, 'etc') config_dir = os.path.join(tmpdir, 'config.d') # create gip.conf os.mkdir(etc_dir) cp_gip = ConfigParser.ConfigParser() cp_gip.add_section("gip") cp_gip.set("gip", "osg_config", config_dir) gip_conf = os.path.join(etc_dir, 'gip.conf') fp = open(gip_conf, 'w') cp_gip.write(fp) fp.close() os.mkdir(config_dir) # create configs for i in range(0, 4): cp_config = ConfigParser.ConfigParser() cp_config.add_section("Condor") cp_config.set("Condor", "value_%i" % i, i) config_fp = os.path.join(config_dir, "config_%i.ini" % i) fp = open(config_fp, 'w') cp_config.write(fp) fp.close() # now test the configs try: cp = config() for i in range(0, 4): value = cp_get(cp, "condor", "value_%i" % i, -1) self.failUnless(int(value) == i, msg="Config failure, value returned: %s" % value) except Exception, e: tb = traceback.format_exception(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2]) self.fail("Configs failed: %s" % tb) finally: shutil.rmtree(tmpdir) os.environ['GIP_LOCATION'] = old_gip_location