def test_parse_factory_schedds(self): """ Verify factory config dom contains a list of schedds """ # Test valid entries valid_file = open('valid.xml', 'w') valid_file.write('<glidein schedd_name="[email protected],[email protected]"> \ <entries> \ <entry name="valid_entry" \ enabled="True" \ gatekeeper="node.fnal.gov/jobmanager-condor" \ gridtype="gt2" \ rsl="(queue=default)" \ schedd_name="*****@*****.**" \ verbosity="std" \ work_dir="OSG"> \ <attrs> \ </attrs> \ <infosys_refs> \ </infosys_refs> \ </entry> \ </entries> \ <condor_tarball arch="default" base_dir="/opt/glidecondor" os="default" \ tar_file="/var/www/html/glidefactory/stage/glidein_v2plus/condor.tgz" version="default"/> \ </glidein>') valid_file.close() config_dom = minidom.parse('valid.xml') schedds = parse_factory_schedds(config_dom) self.assertEqual(len(schedds), 2) self.assertEqual(schedds, ['*****@*****.**', '*****@*****.**']) os.remove('valid.xml') # Test missing schedd name missing_schedds_file = open('missing_schedds.xml', 'w') missing_schedds_file.write('<glidein> \ <entries> \ <entry name="valid_entry" \ enabled="True" \ gatekeeper="node.fnal.gov/jobmanager-condor" \ gridtype="gt2" \ schedd_name="*****@*****.**" \ verbosity="std" \ work_dir="."> \ <infosys_refs> \ <infosys_ref ref="GlueCEUniqueID=node.fnal.gov:2119/jobmanager-condor_default,Mds-Vo-name=TEST,Mds-Vo-name=local,o=grid" server="exp-bdii.cern.ch" type="BDII"/> \ </infosys_refs> \ </entry> \ </entries> \ <condor_tarball arch="default" base_dir="/opt/glidecondor" os="default" \ tar_file="/var/www/html/glidefactory/stage/glidein_v2plus/condor.tgz" version="default"/> \ </glidein>') missing_schedds_file.close() config_dom = minidom.parse('missing_schedds.xml') self.assertRaises(KeyError, parse_factory_schedds, config_dom) os.remove('missing_schedds.xml')
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