示例#1
0
def main(argv):
    """
    Takes input configuration file and information system and finds new entries in the given information system. 
    """ 
    
    # Set defaults for the arguments
    config_xml = source = source_type = vo_name = ""
    skip_disabled = 'yes'
    
    try:
        opts, args = getopt.getopt(argv, "hx:s:t:v:d:", ["help"])
    except getopt.GetoptError:
        print "Unrecognized or incomplete input arguments."
        print USAGE
        sys.exit(2)
    for opt, arg in opts:
        if opt in ("-h", "--help"):
            print USAGE
            sys.exit()
        else:
            if opt == '-x':
                config_xml = arg
            elif opt == '-s': 
                source = arg
            elif opt == '-t':
                source_type = arg
            elif opt == '-v':
                vo_name = arg  #TODO do we want to accept a list of VOs?
            elif opt == '-d':
                skip_disabled = arg
            else:
                print "Unrecognized input arguments."
                print USAGE
                sys.exit(2)
               
    # Validate args
    err_msg = ""
    if config_xml == "":
        err_msg += "No configuration file was provided.\n"
    else: 
        if not os.path.isfile(config_xml):
            err_msg += "Config file '%s' does not exist.\n" % config_xml
    if source == '' or source_type == '':
        err_msg += "Source and source type must be defined.\n" 
    if err_msg:
        print err_msg
        print USAGE
        sys.exit(2)

    if skip_disabled.lower() != 'yes' and skip_disabled.lower() != 'no':
        print "Skip disabled argument must be 'yes' or 'no'."
        print USAGE
        sys.exit(2)  
    if skip_disabled == 'yes':
        skip_disabled = True
    else:
        skip_disabled = False
        
    # Find new entries       
    new_entries = find_new_entries_in_infosys(config_xml, source, source_type, skip_disabled, vo_name)
           
    # Format output
    datestamp = datetime.datetime.now().strftime("%Y-%m-%d %M:%S")
    output = "\nThis file contains all new entries published in the information system that are not identifiable in " \
                 "the config file.  They are formatted to be pasted directly into the config file.\n"
    output += "Script run on : %s \n" % datestamp
    output += "Number of new entries : %i\n\n" % len(new_entries)
        
    # Create formatted xml output
    if len(new_entries) > 0:
        
        # Get list of schedd
        try:
            # Find all config entries not disabled
            config_dom = minidom.parse(config_xml)
            schedds = infosys_lib.parse_factory_schedds(config_dom)
        except: 
            print "Error parsing the config file '%s' for the schedds, exiting the tool." % config_xml
            sys.exit(2)    
            
        for entry in new_entries:
            # Pick a random schedd to assign to this entry TODO - need to be able to assign to a specific schedd?
            random.shuffle(schedds)
            output += infosys_lib.generate_entry_xml(entry, schedds[0])  
    else:
        output = "No new entries were found.\n"  

    # Output results
    print output
示例#2
0
 def test_generate_entry_xml(self):
     """
     Verify correct formatted xml string is generated.
     """
     
     # Test full xml correctly created
     entry = {'site_name' : 'has_rsl',
                      'gridtype' : 'cream',
                      'gatekeeper' : 'node2.fnal.gov/jobmanager-condor',
                      'rsl' : '(queue=default)',
                      'wall_clocktime' : 24,
                      'ref_id' : 'GlueCEUniqueID=has_rsl.fnal.gov:2119/jobmanager-condor_default,Mds-Vo-name=TEST,Mds-Vo-name=local,o=grid',
                      'ce_status' : 'cestatus',
                      'glexec_bin' : 'NONE',
                      'work_dir' : 'OSG',
                      'source' : 'exp-bdii.cern.ch',
                      'source_type' : 'BDII'}
     schedd_name = '*****@*****.**'
     expected = '\
   <entry name="has_rsl" enabled="True" gatekeeper="node2.fnal.gov/jobmanager-condor" gridtype="cream" rsl="(queue=default)" verbosity="std" work_dir="OSG" schedd_name="*****@*****.**">\n\
      <config>\n\
         <max_jobs held="100" idle="400" running="10000"/>\n\
         <release max_per_cycle="20" sleep="0.2"/>\n\
         <remove max_per_cycle="5" sleep="0.2"/>\n\
         <submit cluster_size="10" max_per_cycle="100" sleep="0.2"/>\n\
      </config>\n\
      <downtimes/>\n\
      <attrs>\n\
         <attr name="CONDOR_OS" const="True" glidein_publish="False" job_publish="False" parameter="True" publish="False" type="string" value="default"/>\n\
         <attr name="GLEXEC_BIN" const="True" glidein_publish="False" job_publish="False" parameter="True" publish="True" type="string" value="NONE"/>\n\
         <attr name="GLIDEIN_Max_Walltime" const="True" glidein_publish="False" job_publish="False" parameter="True" publish="False" type="int" value="1440"/>\n\
         <attr name="USE_CCB" const="True" glidein_publish="True" job_publish="False" parameter="True" publish="True" type="string" value="True"/>\n\
      </attrs>\n\
      <files>\n\
      </files>\n\
      <infosys_refs>\n\
         <infosys_ref ref="GlueCEUniqueID=has_rsl.fnal.gov:2119/jobmanager-condor_default,Mds-Vo-name=TEST,Mds-Vo-name=local,o=grid" server="exp-bdii.cern.ch" type="BDII"/>\n\
      </infosys_refs>\n\
      <monitorgroups>\n\
      </monitorgroups>\n\
   </entry>\n'
     entry_xml = generate_entry_xml(entry, schedd_name)
     self.assertEqual(entry_xml, expected)
     
     # Test that correct xml is created with rsl
     has_rsl_entry = {'site_name' : 'has_rsl',
                      'gridtype' : 'cream',
                      'gatekeeper' : 'node2.fnal.gov/jobmanager-condor',
                      'rsl' : '(queue=default)',
                      'wall_clocktime' : 100,
                      'ref_id' : 'GlueCEUniqueID=has_rsl.fnal.gov:2119/jobmanager-condor_default,Mds-Vo-name=TEST,Mds-Vo-name=local,o=grid',
                      'ce_status' : 'cestatus',
                      'glexec_bin' : 'NONE',
                      'work_dir' : 'OSG',
                      'source' : 'exp-bdii.cern.ch',
                      'source_type' : 'BDII'}
     has_rsl_xml_expected = '<entry name="has_rsl" enabled="True" gatekeeper="node2.fnal.gov/jobmanager-condor" gridtype="cream" rsl="(queue=default)" verbosity="std" work_dir="OSG" schedd_name="*****@*****.**">'
     has_rsl_xml = generate_entry_xml(has_rsl_entry, schedd_name)
     self.assertTrue(has_rsl_xml_expected in has_rsl_xml)
     
     # Test that correct xml is created without rsl
     without_rsl_entry = {'site_name' : 'without_rsl',
                      'gridtype' : 'cream',
                      'gatekeeper' : 'node2.fnal.gov/jobmanager-condor',
                      'rsl' : '',
                      'wall_clocktime' : 100,
                      'ref_id' : 'GlueCEUniqueID=without_rsl.fnal.gov:2119/jobmanager-condor_default,Mds-Vo-name=TEST,Mds-Vo-name=local,o=grid',
                      'ce_status' : 'cestatus',
                      'glexec_bin' : 'NONE',
                      'work_dir' : 'OSG',
                      'source' : 'exp-bdii.cern.ch',
                      'source_type' : 'BDII'}
     without_rsl_xml_expected = '<entry name="without_rsl" enabled="True" gatekeeper="node2.fnal.gov/jobmanager-condor" gridtype="cream" verbosity="std" work_dir="OSG" schedd_name="*****@*****.**">'
     without_rsl_xml = generate_entry_xml(without_rsl_entry, schedd_name)
     self.assertTrue(without_rsl_xml_expected in without_rsl_xml)