Пример #1
0
 def test_format_entry_pair_output(self):
     """
     Test formatting
     """
     
     config_entry = {'name' : 'config_entry',
                      'gridtype' : 'gt2',
                      'gatekeeper' : 'node1.fnal.gov/jobmanager-condor',
                      'rsl' : '(queue=default)',
                      'wall_clocktime' : 24,
                      'ref_id' : 'GlueCEUniqueID=config_entry.fnal.gov:2119/jobmanager-condor_default',
                      'ce_status' : 'cestatus',
                      'glexec_bin' : 'NONE',
                      'work_dir' : 'OSG',
                      'source' : 'exp-bdii.cern.ch',
                      'source_type' : 'BDII'}
     infosys_entry = {'site_name' : 'infosys_entry',
                      'gridtype' : 'cream',
                      'gatekeeper' : 'node2.fnal.gov/jobmanager-condor',
                      'rsl' : '(queue=default)',
                      'wall_clocktime' : 24,
                      'ref_id' : 'GlueCEUniqueID=infosys_entry.fnal.gov:2119/jobmanager-condor_default',
                      'ce_status' : 'cestatus',
                      'glexec_bin' : 'NONE',
                      'work_dir' : 'OSG',
                      'source' : 'exp-bdii.cern.ch',
                      'source_type' : 'BDII'}
     entry_pairs = [[config_entry, infosys_entry]]
     output = format_entry_pair_output(entry_pairs)
     expected = "Config Ref Id : GlueCEUniqueID=config_entry.fnal.gov:2119/jobmanager-condor_default\n" \
                 "Config entry Name : config_entry\n" \
                 "Config gatekeeper : node1.fnal.gov/jobmanager-condor\n" \
                 "Config rsl : (queue=default)\n" \
                 "Config gridtype : gt2\n" \
                 "Infosys BDII Id : GlueCEUniqueID=infosys_entry.fnal.gov:2119/jobmanager-condor_default\n" \
                 "Infosys source url: exp-bdii.cern.ch\n" \
                 "Infosys site name : infosys_entry\n" \
                 "Infosys gatekeeper : node2.fnal.gov/jobmanager-condor\n" \
                 "Infosys rsl : (queue=default)\n" \
                 "Infosys gridtype : cream\n\n"
     self.assertEqual(output,expected)
Пример #2
0
def main(argv):
    """
    Takes input configuration file and information system and finds entries where the id partially matches one published in 
    the given information system.
    """ 
    
    # Set defaults for the arguments
    config_xml = ""
    skip_disabled = 'yes'
    
    try:
        opts, args = getopt.getopt(argv, "hx: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 == '-d':
                skip_disabled = arg
            else:
                print "Unrecognized input arguments. "
                print USAGE
                sys.exit(2)
            
    # Validate arg exists
    if config_xml == '':
        print "No configuration file was provided. "
        print USAGE
        sys.exit(2)
    else: 
        if not os.path.isfile(config_xml):
            print "Config file '%s' does not exist." % config_xml
            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 entries with partial id matches      
    partial_bdii, partial_ress, partial_tg = find_entries_with_partial_id_match(config_xml, skip_disabled)
    
    # Format output
    datestamp = datetime.datetime.now().strftime("%Y-%m-%d %M:%S")
    output = "\nThis file contains entries that have <infosys_ref> information that is similar to " \
                "what is published in the information system.\n"
    output += "Script run on : %s \n" % datestamp
    output += "Number of entries: %i\n\n" % (len(partial_bdii) + len(partial_ress) + len(partial_tg))

    if len(partial_bdii) == 0 and len(partial_ress) == 0 and len(partial_tg) == 0:
        output += "No entries were found with partial matching ids.\n"
    else:
        output += infosys_lib.format_entry_pair_output(partial_bdii)
        output += infosys_lib.format_entry_pair_output(partial_ress)
        output += infosys_lib.format_entry_pair_output(partial_tg)
    
    # Output results
    print output