def checkOsgConfigured(cp): """ Make sure that the OSG has been configured when this is run. Checks for the presence of the file - In the config object, gip.osg_attribtues, if the attribute exists; else, - $VDT_LOCATION/monitoring/osg-attributes.conf @param cp: Site config object @return: True @raise ValueError: If the specified file does not exist. """ etcDir = vdtDir(os.path.expandvars("$VDT_LOCATION/monitoring/"), '/etc/osg/') # Check to see if the osg-user-vo-map.txt exists and that its size is > 0 defaultLoc = vdtDir(os.path.join(etcDir, "osg-user-vo-map.txt"), "/var/lib/osg/user-vo-map") osg_user_vo_map = cp_get(cp, "vo", "user_vo_map", defaultLoc) if not os.path.exists(osg_user_vo_map): raise ValueError("%s does not exist; we may be " "running in an unconfigured OSG install!" % osg_user_vo_map) fd = open(osg_user_vo_map, "r") has_uncommented_lines = False; for line in fd.readlines(): if len(line) > 3 and line[0] != "#": has_uncommented_lines = True break if not has_uncommented_lines: raise ValueError("%s has no uncommented lines; we may be " "running in an unconfigured OSG install!" % osg_user_vo_map) return True
def publish_gums(cp, template): hostname = cp_get(cp, "ce", 'name', gethostname()) siteID = cp_get(cp, "site", "unique_name", gethostname()) gumsConfig = vdtDir(os.path.expandvars('$VDT_LOCATION/gums/config/gums-client.properties'), '/etc/gums/gums-client.properties') gumsConfigFile = open(gumsConfig, 'r') gums_re = re.compile('gums.authz\s*=\s*(https://(.*):.*?/(.*))') lines = gumsConfigFile.readlines() for line in lines: m = gums_re.match(line) if m: (gums_uri, gums_host) = m.groups()[0:2] os.putenv('X509_USER_CERT', '/etc/grid-security/http/httpcert.pem') os.putenv('X509_USER_KEY' , '/etc/grid-security/http/httpkey.pem') mapping_subject_dn = '/GIP-GUMS-Probe-Identity' mapping_subject_name = '`grid-cert-info -subject` ' gums_command = vdtDir(os.path.expandvars('$VDT_LOCATION/gums/scripts/gums-service'), '/usr/bin/gums-service') gums_command += ' mapUser -s ' + mapping_subject_name + mapping_subject_dn (gums_output, pin) = popen2.popen4(gums_command) gums_id_re = re.compile('.*\[userName: (.*)\].*') status = "Warning" statusInfo = "Test mapping failed: if GUMS was not down, check logs" +\ " at " + gums_host + ':' + '$VDT_LOCATION/tomcat/v55/logs' lines = gums_output.readlines() for line in lines: m = gums_id_re.match(line) if m: uidMapping = m.groups([0]) status = "OK" statusInfo = "Test mapping successful: user id = %s" % uidMapping break info = {'serviceID': gums_uri, 'serviceType': 'GUMS', 'serviceName': 'Authorization', 'version': 'UNDEFINED', 'endpoint': gums_uri, 'semantics': 'UNDEFINED', 'owner': '', 'url': gums_uri, 'uri': gums_uri, 'status': status, 'statusInfo': statusInfo, 'wsdl': 'Not Applicable', 'startTime': 'Not Applicable', 'siteID': siteID, 'acbr': '__GIP_DELETEME' } printTemplate(template, info)
def main(cp=None, return_entries=False): """ Main method for the osg-info-wrapper script. This script safely runs the plugin and provider modules, caching where necessary, and combines it with the static data. It then outputs the final GLUE information for this site. """ log.debug("Starting up the osg-info-wrapper.") if cp == None: cp = config() temp_dir = os.path.expandvars(cp_get(cp, "gip", "temp_dir", \ gipDir("$GIP_LOCATION/var/tmp", '/var/cache/gip'))) plugin_dir = os.path.expandvars(cp_get(cp, "gip", "plugin_dir", \ gipDir("$GIP_LOCATION/plugins", '/usr/libexec/gip/plugins'))) provider_dir = os.path.expandvars(cp_get(cp, "gip", "provider_dir", \ gipDir("$GIP_LOCATION/providers", '/usr/libexec/gip/providers'))) static_dir = os.path.expandvars(cp_get(cp, "gip", "static_dir", \ gipDir("$GIP_LOCATION/var/ldif", '/etc/gip/ldif.d'))) # Make sure that our directories exist. create_if_not_exist(temp_dir, plugin_dir, provider_dir, static_dir) # Load up our add, alter, and delete attributes add_attributes = os.path.expandvars(cp_get(cp, "gip", \ "add_attributes", vdtDir("$VDT_LOCATION/gip/etc/add-attributes.conf", '/etc/gip/add-attributes.conf'))) alter_attributes = os.path.expandvars(cp_get(cp, "gip", \ "alter_attributes", vdtDir("$VDT_LOCATION/gip/etc/alter-attributes.conf", '/etc/gip/alter-attributes.conf'))) remove_attributes = os.path.expandvars(cp_get(cp, "gip", \ "remove_attributes", vdtDir("$VDT_LOCATION/gip/etc/remove-attributes.conf", '/etc/gip/remove-attributes.conf'))) # Flush the cache if appropriate do_flush_cache = cp_getBoolean(cp, "gip", "flush_cache", False) if do_flush_cache: log.info("Flushing cache upon request.") flush_cache(temp_dir) # Load up our parameters freshness = cp_getInt(cp, "gip", "freshness", 300) cache_ttl = cp_getInt(cp, "gip", "cache_ttl", 600) response = cp_getInt(cp, "gip", "response", 240) timeout = cp_getInt(cp, "gip", "timeout", 240) try: os.setpgrp() except OSError, oe: # If launched from a batch system (condor), we might not have perms if oe.errno != 1: raise
def main(cp = None, return_entries=False): """ Main method for the osg-info-wrapper script. This script safely runs the plugin and provider modules, caching where necessary, and combines it with the static data. It then outputs the final GLUE information for this site. """ log.debug("Starting up the osg-info-wrapper.") if cp == None: cp = config() temp_dir = os.path.expandvars(cp_get(cp, "gip", "temp_dir", \ gipDir("$GIP_LOCATION/var/tmp", '/var/cache/gip'))) plugin_dir = os.path.expandvars(cp_get(cp, "gip", "plugin_dir", \ gipDir("$GIP_LOCATION/plugins", '/usr/libexec/gip/plugins'))) provider_dir = os.path.expandvars(cp_get(cp, "gip", "provider_dir", \ gipDir("$GIP_LOCATION/providers", '/usr/libexec/gip/providers'))) static_dir = os.path.expandvars(cp_get(cp, "gip", "static_dir", \ gipDir("$GIP_LOCATION/var/ldif", '/etc/gip/ldif.d'))) # Make sure that our directories exist. create_if_not_exist(temp_dir, plugin_dir, provider_dir, static_dir) # Load up our add, alter, and delete attributes add_attributes = os.path.expandvars(cp_get(cp, "gip", \ "add_attributes", vdtDir("$VDT_LOCATION/gip/etc/add-attributes.conf", '/etc/gip/add-attributes.conf'))) alter_attributes = os.path.expandvars(cp_get(cp, "gip", \ "alter_attributes", vdtDir("$VDT_LOCATION/gip/etc/alter-attributes.conf", '/etc/gip/alter-attributes.conf'))) remove_attributes = os.path.expandvars(cp_get(cp, "gip", \ "remove_attributes", vdtDir("$VDT_LOCATION/gip/etc/remove-attributes.conf", '/etc/gip/remove-attributes.conf'))) # Flush the cache if appropriate do_flush_cache = cp_getBoolean(cp, "gip", "flush_cache", False) if do_flush_cache: log.info("Flushing cache upon request.") flush_cache(temp_dir) # Load up our parameters freshness = cp_getInt(cp, "gip", "freshness", 300) cache_ttl = cp_getInt(cp, "gip", "cache_ttl", 600) response = cp_getInt(cp, "gip", "response", 240) timeout = cp_getInt(cp, "gip", "timeout", 240) try: os.setpgrp() except OSError, oe: # If launched from a batch system (condor), we might not have perms if oe.errno != 1: raise
def getHTCondorCEVersion(cp): """ Returns the running version of the HTCondor CE Copied from getOSGVersion() in gip_cluster.py """ log = logging.getLogger() htcondorce_ver_backup = cp_get(cp, "ce", "htcondorce_version", "1.8") htcondorce_version_script = cp_get(cp, "gip", "htcondorce_version_script", "") htcondorce_ver = '' if len(htcondorce_version_script) == 0: htcondorce_version_script = vdtDir('$VDT_LOCATION/condor_ce_config_val', '/usr/bin/condor_ce_config_val') htcondorce_version_script = os.path.expandvars(htcondorce_version_script) if not os.path.exists(htcondorce_version_script): htcondorce_version_script = os.path.expandvars("$VDT_LOCATION/osg/bin/" \ "osg-version") if os.path.exists(htcondorce_version_script): try: htcondorce_version_script += " HTCondorCEVersion" htcondorce_ver = runCommand(htcondorce_version_script).read().strip() htcondorce_ver = htcondorce_ver.replace('"','') except Exception, e: log.exception(e)
def getUniqueHash(cp): # EGI uses unix 'cksum' command; we'll use zlib's crc instead. loc = cp_get(cp, 'gip', 'osg_config', vdtDir(os.path.expandvars('$VDT_LOCATION/monitoring/config.ini'), '/etc/osg/config.ini')) loc = os.path.expandvars(loc) try: hash = zlib.crc32(loc) except: log.error('Could not find config.ini for checksum') hash = '0008675309' return hash
def getUniqueHash(cp): # EGI uses unix 'cksum' command; we'll use zlib's crc instead. loc = cp_get( cp, 'gip', 'osg_config', vdtDir(os.path.expandvars('$VDT_LOCATION/monitoring/config.ini'), '/etc/osg/config.ini')) loc = os.path.expandvars(loc) try: hash = zlib.crc32(loc) except: log.error('Could not find config.ini for checksum') hash = '0008675309' return hash
def checkOsgConfigured(cp): """ Make sure that the OSG has been configured when this is run. Checks for the presence of the file - In the config object, gip.osg_attribtues, if the attribute exists; else, - $VDT_LOCATION/monitoring/osg-attributes.conf @param cp: Site config object @return: True @raise ValueError: If the specified file does not exist. """ etcDir = vdtDir(os.path.expandvars("$VDT_LOCATION/monitoring/"), '/etc/osg/') # Check to see if the osg-user-vo-map.txt exists and that its size is > 0 defaultLoc = vdtDir(os.path.join(etcDir, "osg-user-vo-map.txt"), "/var/lib/osg/user-vo-map") osg_user_vo_map = cp_get(cp, "vo", "user_vo_map", defaultLoc) if not os.path.exists(osg_user_vo_map): raise ValueError("%s does not exist; we may be " "running in an unconfigured OSG install!" % osg_user_vo_map) fd = open(osg_user_vo_map, "r") has_uncommented_lines = False for line in fd.readlines(): if len(line) > 3 and line[0] != "#": has_uncommented_lines = True break if not has_uncommented_lines: raise ValueError("%s has no uncommented lines; we may be " "running in an unconfigured OSG install!" % osg_user_vo_map) return True
def configOsg(cp): """ Given the config object from the GIP, overwrite data coming from the OSG configuration file. """ # If override, then gip.conf overrides the config.ini settings try: override = cp.getboolean("gip", "override") except: override = False try: check_osg = cp.getboolean("gip", "check_osg") except: check_osg = True if check_osg and 'GIP_TESTING' not in os.environ: checkOsgConfigured(cp) # Load config.ini values cp2 = ConfigParser.ConfigParser() ini_dir = vdtDir(os.path.expandvars("$VDT_LOCATION/monitoring/config.ini"), '/etc/osg/config.d') loc = cp_get(cp, "gip", "osg_config", ini_dir) log.info("Using OSG config.ini %s." % loc) # if a directory is specified, then either we are an RPM install or a directory was # specified in gip.conf if os.path.isdir(loc): # get a list of the ini files in the directory file_list = get_file_list(loc) else: # must be a file file_list = [ loc, ] cp2.read(file_list) try: configSEs(cp2, cp) except SystemExit, KeyboardInterrupt: raise
def configOsg(cp): """ Given the config object from the GIP, overwrite data coming from the OSG configuration file. """ # If override, then gip.conf overrides the config.ini settings try: override = cp.getboolean("gip", "override") except: override = False try: check_osg = cp.getboolean("gip", "check_osg") except: check_osg = True if check_osg and 'GIP_TESTING' not in os.environ: checkOsgConfigured(cp) # Load config.ini values cp2 = ConfigParser.ConfigParser() ini_dir = vdtDir(os.path.expandvars("$VDT_LOCATION/monitoring/config.ini"), '/etc/osg/config.d') loc = cp_get(cp, "gip", "osg_config", ini_dir) log.info("Using OSG config.ini %s." % loc) # if a directory is specified, then either we are an RPM install or a directory was # specified in gip.conf if os.path.isdir(loc): # get a list of the ini files in the directory file_list = get_file_list(loc) else: # must be a file file_list = [loc,] cp2.read(file_list) try: configSEs(cp2, cp) except SystemExit, KeyboardInterrupt: raise
def getOSGVersion(cp): """ Returns the running version of the OSG """ osg_ver_backup = cp_get(cp, "ce", "osg_version", "OSG 1.2.0") osg_version_script = cp_get(cp, "gip", "osg_version_script", "") osg_ver = '' if len(osg_version_script) == 0: osg_version_script = vdtDir('$VDT_LOCATION/osg-version', '/usr/bin/osg-version') osg_version_script = os.path.expandvars(osg_version_script) if not os.path.exists(osg_version_script): osg_version_script = os.path.expandvars("$VDT_LOCATION/osg/bin/" \ "osg-version") if os.path.exists(osg_version_script): try: osg_ver = runCommand(osg_version_script).read().strip() except Exception, e: log.exception(e)
except Exception, e: #log.exception(e) print >> sys.stderr, str(e) try: config_info(cp2, cp) except SystemExit, KeyboardInterrupt: raise except Exception, e: print >> sys.stderr, str(e) # Set the site status: try: state_info_file = '$VDT_LOCATION/MIS-CI/etc/grid-site-state-info' state_info_file = os.path.expandvars(state_info_file) state_info_file = vdtDir(state_info_file, '/etc/osg/grid-site-state-info') if os.path.exists(state_info_file): results = int(os.popen("/bin/sh -c 'source %s; echo " \ "$grid_site_state_bit'" % state_info_file) .read().strip()) != 0 else: results = None if not results: if not cp.has_section('condor'): cp.add_section('condor') cp.set('condor', 'Closed') except: pass # get all the items in the [GIP] section of the config.ini try: