def testMissingAttribute(self): """ Test the parsing when attributes are missing, should get exceptions """ config_file = get_test_config("siteattributes/siteattributes2.ini") configuration = ConfigParser.SafeConfigParser() configuration.read(config_file) settings = siteinformation.SiteInformation(logger=global_logger) try: settings.parse_configuration(configuration) except Exception as e: self.fail("Received exception while parsing configuration: %s" % e) mandatory_on_all = ['group'] # ^ TODO OSG 3.5: add "resource" to this list mandatory_on_ce = [ 'host_name', 'sponsor', 'contact', 'email', 'city', 'country', 'longitude', 'latitude' ] mandatory = list(mandatory_on_all) if ce_installed(): mandatory += mandatory_on_ce for option in mandatory: config_file = get_test_config("siteattributes/siteattributes1.ini") configuration = ConfigParser.SafeConfigParser() configuration.read(config_file) configuration.remove_option('Site Information', option) settings = siteinformation.SiteInformation(logger=global_logger) self.assertRaises(exceptions.SettingError, settings.parse_configuration, configuration)
def testBadHost(self): """ Test the check_attributes function when the squid proxy hostname is not valie """ if not ce_installed(): return True config_file = get_test_config("squid/squid_bad_host.ini") configuration = configparser.SafeConfigParser() configuration.read(config_file) settings = squid.SquidConfiguration(logger=global_logger) try: settings.parse_configuration(configuration) except Exception as e: self.fail("Received exception while parsing configuration: %s" % e) attributes = settings.get_attributes() self.assertFalse(settings.check_attributes(attributes), "Did not notice invalid host") config_file = get_test_config("squid/squid_bad_host2.ini") configuration = configparser.SafeConfigParser() configuration.read(config_file) settings = squid.SquidConfiguration(logger=global_logger) try: settings.parse_configuration(configuration) except Exception as e: self.fail("Received exception while parsing configuration") attributes = settings.get_attributes() self.assertFalse(settings.check_attributes(attributes), "Did not notice invalid host")
def testInvalidLongitude(self): """ Test the check_attributes with invalid longitude values """ config_file = get_test_config("siteattributes/" \ "invalid_longitude1.ini") configuration = configparser.SafeConfigParser() configuration.read(config_file) settings = siteinformation.SiteInformation(logger=global_logger) try: settings.parse_configuration(configuration) except Exception as e: self.fail("Received exception while parsing configuration: %s" % e) attributes = settings.get_attributes() self.assertFalse(settings.check_attributes(attributes), "Invalid latitude ignored") config_file = get_test_config("siteattributes/" \ "invalid_longitude2.ini") configuration = configparser.SafeConfigParser() configuration.read(config_file) settings = siteinformation.SiteInformation(logger=global_logger) try: settings.parse_configuration(configuration) except Exception as e: self.fail("Received exception while parsing configuration: %s" % e) attributes = settings.get_attributes() self.assertFalse(settings.check_attributes(attributes), "Invalid latitude ignored")
def testServiceList(self): """ Test to make sure right services get returned """ config_file = get_test_config("lsf/check_ok.ini") configuration = configparser.SafeConfigParser() configuration.read(config_file) settings = lsf.LSFConfiguration(logger=global_logger) try: settings.parse_configuration(configuration) except Exception as e: self.fail("Received exception while parsing configuration: %s" % e) services = settings.enabled_services() expected_services = {'condor-ce', 'globus-gridftp-server'} self.assertEqual(services, expected_services, "List of enabled services incorrect, " + "got %s but expected %s" % (services, expected_services)) config_file = get_test_config("lsf/lsf_disabled.ini") configuration = configparser.SafeConfigParser() configuration.read(config_file) settings = lsf.LSFConfiguration(logger=global_logger) try: settings.parse_configuration(configuration) except Exception as e: self.fail("Received exception while parsing configuration: %s" % e) services = settings.enabled_services() expected_services = set() self.assertEqual(services, expected_services, "List of enabled services incorrect, " + "got %s but expected %s" % (services, expected_services))
def test_get_option_location(self): """ Test the get option location method in configfile module """ config_directory = get_test_config('config-test1.d') location = get_test_config('config-test1.d/00-test.ini') opt_location = configfile.get_option_location( 'first_opt', 'Common', config_directory=config_directory) self.assertEqual( location, opt_location, "Didn't get the correct location for first_opt:" + "got %s expected %s" % (opt_location, location)) location = get_test_config('config-test1.d/10-test.ini') opt_location = configfile.get_option_location( 'second_opt', 'Common', config_directory=config_directory) self.assertEqual( location, opt_location, "Didn't get the correct location for second_opt:" + "got %s expected %s" % (opt_location, location)) location = None opt_location = configfile.get_option_location( 'missing_opt', 'Common', config_directory=config_directory) self.assertEqual( location, opt_location, "Didn't get the correct location for missing_opt:" + "got %s expected None" % (opt_location))
def testMissingAttribute(self): """ Test the parsing when attributes are missing, should get exceptions """ config_file = get_test_config("rsv/rsv2.ini") configuration = configparser.SafeConfigParser() configuration.read(config_file) settings = rsv.RsvConfiguration(logger=global_logger) settings.rsv_meta_dir = RSV_META_DIR settings.parse_configuration(configuration) mandatory = ['enable_nagios'] for option in mandatory: config_file = get_test_config("rsv/rsv1.ini") configuration = configparser.SafeConfigParser() configuration.read(config_file) configuration.remove_option('RSV', option) settings = rsv.RsvConfiguration(logger=global_logger) settings.rsv_meta_dir = RSV_META_DIR self.assertRaises(exceptions.SettingError, settings.parse_configuration, configuration)
def test_valid_file(self): """ Test functionality of valid_file function """ filename = get_test_config('utilities/newline.ini') _stderr = sys.stderr sys.stderr = file(os.devnull, 'wb') # need to do this instead of putting this in assert so that stderr can # be restored after call result = validation.valid_ini_file(filename) self.assertFalse(result, "Didn't detect newline in %s" % filename) # test whether we catch sections that has a space before the first setting filename = get_test_config('utilities/section_space.ini') self.assertFalse(result, "Didn't detect space in %s" % filename) sys.stderr = _stderr filename = get_test_config('utilities/valid_boolean.ini') self.assertTrue(validation.valid_ini_file(filename), "Got error on valid file %s" % filename) filename = get_test_config('utilities/valid_variable.ini') self.assertTrue(validation.valid_ini_file(filename), "Got error on valid file %s" % filename)
def test_get_file_list(self): """ Test the list of files that the module things it's reading and the order that the files are read in """ config_directory = get_test_config('config-test1.d') file_order = [get_test_config('config-test1.d/00-test.ini'), get_test_config('config-test1.d/10-test.ini'), get_test_config('config-test1.d/A-test.ini'), get_test_config('config-test1.d/atest.ini')] file_list = configfile.get_file_list(config_directory=config_directory) self.assertEqual(file_order, file_list, "Didn't get the files in the correct order: " + " %s\n instead of\n %s" % (file_list, file_order)) config_directory = get_test_config('config-test2.d') file_order = [get_test_config('config-test2.d/00-test.ini'), get_test_config('config-test2.d/10-test.ini'), get_test_config('config-test2.d/A-test.ini'), get_test_config('config-test2.d/atest.ini')] file_list = configfile.get_file_list(config_directory=config_directory) self.assertEqual(file_order, file_list, "Didn't get the files in the correct order: " + " %s\n instead of\n %s" % (file_list, file_order))
def test_get_option_location(self): """ Test the get option location method in configfile module """ config_directory = get_test_config('config-test1.d') location = get_test_config('config-test1.d/00-test.ini') opt_location = configfile.get_option_location('first_opt', 'Common', config_directory=config_directory) self.assertEqual(location, opt_location, "Didn't get the correct location for first_opt:" + "got %s expected %s" % (opt_location, location)) location = get_test_config('config-test1.d/10-test.ini') opt_location = configfile.get_option_location('second_opt', 'Common', config_directory=config_directory) self.assertEqual(location, opt_location, "Didn't get the correct location for second_opt:" + "got %s expected %s" % (opt_location, location)) location = None opt_location = configfile.get_option_location('missing_opt', 'Common', config_directory=config_directory) self.assertEqual(location, opt_location, "Didn't get the correct location for missing_opt:" + "got %s expected None" % (opt_location))
def test_get_file_list(self): """ Test the list of files that the module things it's reading and the order that the files are read in """ config_directory = get_test_config('config-test1.d') file_order = [ get_test_config('config-test1.d/00-test.ini'), get_test_config('config-test1.d/10-test.ini'), get_test_config('config-test1.d/A-test.ini'), get_test_config('config-test1.d/atest.ini') ] file_list = configfile.get_file_list(config_directory=config_directory) self.assertEqual( file_order, file_list, "Didn't get the files in the correct order: " + " %s\n instead of\n %s" % (file_list, file_order)) config_directory = get_test_config('config-test2.d') file_order = [ get_test_config('config-test2.d/00-test.ini'), get_test_config('config-test2.d/10-test.ini'), get_test_config('config-test2.d/A-test.ini'), get_test_config('config-test2.d/atest.ini') ] file_list = configfile.get_file_list(config_directory=config_directory) self.assertEqual( file_order, file_list, "Didn't get the files in the correct order: " + " %s\n instead of\n %s" % (file_list, file_order))
def testMissingCondorConfig(self): """ Test the check_attributes function to see if it catches missing condor config locations """ for filename in [ get_test_config("condor/missing_config1.ini"), get_test_config("condor/missing_config2.ini") ]: config_file = os.path.abspath(filename) configuration = configparser.SafeConfigParser() configuration.read(config_file) settings = condor.CondorConfiguration(logger=global_logger) try: settings.parse_configuration(configuration) except Exception as e: self.fail( "Received exception while parsing configuration: %s" % e) attributes = settings.get_attributes() self.assertFalse( settings.check_attributes(attributes), "Did not notice missing condor config location: " + attributes['OSG_CONDOR_CONFIG'])
def test_user_check_valid_user(self): config_parser = ConfigParser.SafeConfigParser() config_file = get_test_config("gip/valid_user.ini") config_parser.read(config_file) config_parser.set('Install Locations', 'user_vo_map', get_test_config(SAMPLE_VO_MAP_LOCATION)) gip_config = gip.GipConfiguration(logger=global_logger) self.assertTrue( gip_config._parse_configuration(config_parser) is None, "Flagged valid user as being missing")
def test_user_check_valid_user(self): config_parser = ConfigParser.SafeConfigParser() config_file = get_test_config("gip/valid_user.ini") config_parser.read(config_file) config_parser.set('Install Locations', 'user_vo_map', get_test_config(SAMPLE_VO_MAP_LOCATION)) gip_config = gip.GipConfiguration(logger=global_logger) self.assertTrue(gip_config._parse_configuration(config_parser) is None, "Flagged valid user as being missing")
def _test_lcmaps(self, pre_file, post_file, errstring, *update_lcmaps_text_args): lcmaps_pre = open(get_test_config(pre_file)).read().strip() expected_lcmaps_post = open(get_test_config(post_file)).read().strip() settings = misc.MiscConfiguration(logger=global_logger) lcmaps_post = settings._update_lcmaps_text(lcmaps_pre, *update_lcmaps_text_args) diff = diff_strings(expected_lcmaps_post, lcmaps_post) self.assertEqual(diff, '', "%s (diff: \n%s\n)" % (errstring, diff))
def test_allowed_vos(self): """ Make sure the allowed VOs is filtered properly. """ config_parser = ConfigParser.SafeConfigParser() config_file = get_test_config("gip/allowed_vos.ini") config_parser.read(config_file) config_parser.set('Install Locations', 'user_vo_map', get_test_config(SAMPLE_VO_MAP_LOCATION)) gip_config = gip.GipConfiguration(logger=global_logger) gip_config._parse_configuration(config_parser) gip_config._parse_configuration_ce(config_parser)
def test_allowed_vos(self): """ Make sure the allowed VOs is filtered properly. """ config_parser = ConfigParser.SafeConfigParser() config_file = get_test_config("gip/allowed_vos.ini") config_parser.read(config_file) config_parser.set('Install Locations', 'user_vo_map', get_test_config(SAMPLE_VO_MAP_LOCATION)) gip_config = gip.GipConfiguration(logger=global_logger) gip_config._parse_configuration(config_parser)
def test_user_check_invalid_user(self): """ Check to make sure gip class will distinguish between valid and invalid users """ config_parser = ConfigParser.SafeConfigParser() config_file = get_test_config("gip/invalid_user.ini") config_parser.read(config_file) config_parser.set('Install Locations', 'user_vo_map', get_test_config(SAMPLE_VO_MAP_LOCATION)) gip_config = gip.GipConfiguration(logger=global_logger) self.assertRaises(exceptions.SettingError, gip_config._parse_configuration, config_parser)
def test_ini_spaces(self): """ Test to make sure ini files with spaces work correctly """ config_dirs = [get_test_config('config-space1.d'), get_test_config('config-space2.d'), get_test_config('config-space3.d')] temp = sys.stderr sys.stderr = open(os.devnull, 'w') for directory in config_dirs: self.assertRaises(SystemExit, configfile.read_config_files, config_directory=directory) sys.stderr = temp
def testParsingMissingITBDefault(self): """ Make sure gratia picks up the itb defaults when the gratia section is missing """ # need to be on a CE to get CE defaults if not gratia.requirements_are_installed(): return config_file = get_test_config("gratia/itb_default2.ini") configuration = configparser.SafeConfigParser() configuration.read(config_file) settings = gratia.GratiaConfiguration(logger=global_logger) try: settings.parse_configuration(configuration) except Exception as e: self.fail("Received exception while parsing configuration: %s" % e) options = settings.options variables = { 'probes': 'jobmanager:gratia-osg-itb.opensciencegrid.org:80' } for var in variables: self.assertTrue(var in options, "Attribute %s missing" % var) self.assertEqual(options[var].value, variables[var], "Wrong value obtained for %s, got %s but " \ "expected %s" % (var, options[var].value, variables[var])) config_file = get_test_config("gratia/itb_default3.ini") configuration = configparser.SafeConfigParser() configuration.read(config_file) settings = gratia.GratiaConfiguration(logger=global_logger) try: settings.parse_configuration(configuration) except Exception as e: self.fail("Received exception while parsing configuration: %s" % e) options = settings.options variables = { 'probes': 'jobmanager:gratia-osg-itb.opensciencegrid.org:80' } for var in variables: self.assertTrue(var in options, "Attribute %s missing" % var) self.assertEqual(options[var].value, variables[var], "Wrong value obtained for %s, got %s but " \ "expected %s" % (var, options[var].value, variables[var]))
class TestNetwork(unittest.TestCase): """ Unit test class to test NetworkConfiguration class """ def testParsing(self): """ Test misc parsing """ config_file = get_test_config("network/check_blank.ini") configuration = ConfigParser.SafeConfigParser() configuration.read(config_file) settings = network.NetworkConfiguration(logger=global_logger) try: settings.parse_configuration(configuration) except Exception, e: self.fail("Received exception while parsing configuration: %s" % e) self.assertTrue(settings.check_attributes({}), "Flagged blank file as invalid") config_file = get_test_config("network/check_ok1.ini") configuration = ConfigParser.SafeConfigParser() configuration.read(config_file) settings = network.NetworkConfiguration(logger=global_logger) try: settings.parse_configuration(configuration) except Exception, e: self.fail("Received exception while parsing configuration: %s" % e)
def testParsing2(self): """ Test siteattributes parsing """ config_file = get_test_config("siteattributes/siteattributes2.ini") configuration = configparser.SafeConfigParser() configuration.read(config_file) settings = siteinformation.SiteInformation(logger=global_logger) try: settings.parse_configuration(configuration) except Exception as e: self.fail("Received exception while parsing configuration: %s" % e) attributes = settings.get_attributes() variables = {'OSG_GROUP': 'OSG', 'OSG_HOSTNAME': 'example.com', 'OSG_SITE_NAME': 'MY_SITE', 'OSG_SPONSOR': 'osg:50 usatlas:50', 'OSG_SITE_INFO': 'http://example/com/policy.html', 'OSG_CONTACT_NAME': 'Admin Name', 'OSG_CONTACT_EMAIL': '*****@*****.**', 'OSG_SITE_CITY': 'Chicago', 'OSG_SITE_COUNTRY': 'US', 'OSG_SITE_LONGITUDE': '-84.23', 'OSG_SITE_LATITUDE': '-23.32'} for var in variables: self.assertTrue(var in attributes, "Attribute %s missing" % var) self.assertEqual(attributes[var], variables[var], "Wrong value obtained for %s, got %s but " \ "expected %s" % (var, attributes[var], variables[var]))
def testOASISConfig(self): """ Test storage parsing when using OASIS configuration """ # StorageConfiguration is not enabled on non-ce installs if not utilities.ce_installed(): return config_file = get_test_config("storage/oasis.ini") configuration = configparser.SafeConfigParser() configuration.read(config_file) settings = storage.StorageConfiguration(logger=global_logger) try: settings.parse_configuration(configuration) except Exception as e: self.fail("Received exception while parsing configuration: %s" % e) attributes = settings.get_attributes() variables = { 'OSG_STORAGE_ELEMENT': 'False', 'OSG_DEFAULT_SE': 'test.domain.org', 'OSG_GRID': '/etc', 'OSG_APP': '/cvmfs/oasis.opensciencegrid.org', 'OSG_DATA': 'UNAVAILABLE', 'OSG_SITE_READ': '/var', 'OSG_SITE_WRITE': '/usr' } for var in variables: self.assertTrue(var in attributes, "Attribute %s missing" % var) self.assertEqual(attributes[var], variables[var], "Wrong value obtained for %s, got %s but " \ "expected %s" % (var, attributes[var], variables[var])) self.assertTrue(settings.check_attributes(attributes))
def test_local_settings(self): """ Test to see if the local settings parsing works. """ config_parser = ConfigParser.SafeConfigParser() config_parser.optionxform = str config_file = get_test_config("gip/local_settings.ini") config_parser.read(config_file) local_settings = localsettings.LocalSettings(logger= \ global_logger) local_settings.parse_configuration(config_parser) attributes = local_settings.get_attributes() self.assertTrue('default' not in attributes, msg="Attributes set that weren't in the test config file") self.assertTrue('Foo' in attributes and attributes['Foo'] == 'value1', msg="Incorrectly named key." \ " Desired name: Foo; only found %s." % (" ".join(attributes.keys()))) self.assertTrue(attributes['Foo'] == 'value1', msg="Incorrect value wanted value1, " \ "got %s" % attributes['Foo']) self.assertTrue('bar' in attributes and attributes['bar'] == 'value2', msg="Incorrectly named key." \ " Desired name: bar; only found %s." % (" ".join(attributes.keys()))) self.assertTrue('bar' in attributes and attributes['bar'] == 'value2', msg="Incorrect value wanted value2, " \ "got %s" % attributes['bar'])
def testParsing(self): """ Test configuration parsing """ config_file = get_test_config("sge/sge1.ini") configuration = configparser.SafeConfigParser() configuration.read(config_file) settings = sge.SGEConfiguration(logger=global_logger) try: settings.parse_configuration(configuration) except Exception as e: self.fail("Received exception while parsing configuration: %s" % e) attributes = settings.get_attributes() options = { 'OSG_JOB_MANAGER_HOME': './test_files', 'OSG_SGE_LOCATION': './test_files', 'OSG_SGE_ROOT': './test_files', 'OSG_SGE_CELL': 'sge', 'OSG_JOB_MANAGER': 'SGE' } for option in options: value = options[option] self.assertTrue(option in attributes, "Attribute %s missing" % option) err_msg = "Wrong value obtained for %s, " \ "got %s instead of %s" % (option, attributes[option], value) self.assertEqual(attributes[option], value, err_msg)
def testParsing(self): """ Test configuration parsing """ config_file = get_test_config("slurm/slurm1.ini") configuration = ConfigParser.SafeConfigParser() configuration.read(config_file) settings = slurm.SlurmConfiguration(logger=global_logger) try: settings.parse_configuration(configuration) except Exception as e: self.fail("Received exception while parsing configuration: %s" % e) attributes = settings.get_attributes() options = { 'OSG_JOB_MANAGER_HOME': '/opt/slurm', 'OSG_PBS_LOCATION': '/opt/slurm', 'OSG_JOB_MANAGER': 'SLURM' } for option in options: value = options[option] self.assertTrue(attributes.has_key(option), "Attribute %s missing" % option) err_msg = "Wrong value obtained for %s, " \ "got %s instead of %s" % (option, attributes[option], value) self.assertEqual(attributes[option], value, err_msg)
def testParsing(self): """ Test Gateway module parsing """ config_file = get_test_config("gateway/gateway_default.ini") configuration = ConfigParser.SafeConfigParser() configuration.read(config_file) settings = gateway.GatewayConfiguration(logger=global_logger) try: settings.parse_configuration(configuration) except Exception as e: self.fail("Received exception while parsing configuration: %s" % e) options = settings.options variables = { 'gram_gateway_enabled': False, 'htcondor_gateway_enabled': True } for var in variables: self.assertTrue(options.has_key(var), "Option %s missing" % var) self.assertEqual( options[var].value, variables[var], "Wrong value obtained for %s, got %s but " "expected %s" % (var, options[var].value, variables[var]))
def testParsing2(self): """ Test misc parsing with negative values """ config_file = get_test_config("misc/misc2.ini") configuration = ConfigParser.SafeConfigParser() configuration.read(config_file) settings = misc.MiscConfiguration(logger=global_logger) try: settings.parse_configuration(configuration) except Exception as e: self.fail("Received exception while parsing configuration: %s" % e) options = settings.options variables = { 'gums_host': 'my.gums.org', 'authorization_method': 'xacml' } for var in variables: self.assertTrue(options.has_key(var), "Option %s missing" % var) self.assertEqual(options[var].value, variables[var], "Wrong value obtained for %s, got %s but " \ "expected %s" % (var, options[var].value, variables[var]))
def testParsingIgnored(self): """ Test parsing when ignored """ config_file = get_test_config("squid/ignored.ini") configuration = configparser.SafeConfigParser() configuration.read(config_file) settings = squid.SquidConfiguration(logger=global_logger) try: settings.parse_configuration(configuration) except Exception as e: self.fail("Received exception while parsing configuration: %s" % e) attributes = settings.get_attributes() self.assertEqual(len(attributes), 1, "Ignored configuration should have 1 attribute") variables = {'OSG_SQUID_LOCATION': 'test.com:3128'} for var in variables: self.assertTrue(var in attributes, "Attribute %s missing" % var) self.assertEqual(attributes[var], variables[var], "Wrong value obtained for %s, got %s but " \ "expected %s" % (var, attributes[var], variables[var]))
def testParsing(self): """ Test condor parsing """ config_file = get_test_config("condor/condor1.ini") configuration = configparser.SafeConfigParser() configuration.read(config_file) settings = condor.CondorConfiguration(logger=global_logger) try: settings.parse_configuration(configuration) except Exception as e: self.fail("Received exception while parsing configuration: %s" % e) attributes = settings.get_attributes() options = { 'OSG_JOB_MANAGER_HOME': '/opt/condor', 'OSG_CONDOR_LOCATION': '/opt/condor', 'OSG_CONDOR_CONFIG': '/etc/condor/condor_config', 'OSG_JOB_MANAGER': 'Condor' } for option in options: value = options[option] self.assertTrue(option in attributes, "Attribute %s missing" % option) err_msg = "Wrong value obtained for %s, " \ "got %s instead of %s" % (option, attributes[option], value) self.assertEqual(attributes[option], value, err_msg)
def testParsing(self): """ Test install locations parsing """ config_file = get_test_config("localsettings/local_settings1.ini") configuration = configparser.SafeConfigParser() configuration.optionxform = str configuration.read(config_file) settings = localsettings.LocalSettings(logger=global_logger) try: settings.parse_configuration(configuration) except Exception as e: self.fail("Received exception while parsing configuration: %s" % e) attributes = settings.get_attributes() self.assertTrue('test1' in attributes, 'Attribute test1 missing') self.assertEqual(attributes['test1'], 'Value1', 'Wrong value obtained for test1') self.assertFalse('missing_key' in attributes, 'Non-existent key (missing_key) found') self.assertFalse('default_key' in attributes, 'Default key recognized as a local attribute')
def test_local_settings(self): """ Test to see if the local settings parsing works. """ config_parser = configparser.SafeConfigParser() config_parser.optionxform = str config_file = get_test_config("subcluster/local_settings.ini") config_parser.read(config_file) local_settings = localsettings.LocalSettings(logger= \ global_logger) local_settings.parse_configuration(config_parser) attributes = local_settings.get_attributes() self.assertTrue( 'default' not in attributes, msg="Attributes set that weren't in the test config file") self.assertTrue('Foo' in attributes and attributes['Foo'] == 'value1', msg="Incorrectly named key." \ " Desired name: Foo; only found %s." % (" ".join(attributes.keys()))) self.assertTrue(attributes['Foo'] == 'value1', msg="Incorrect value wanted value1, " \ "got %s" % attributes['Foo']) self.assertTrue('bar' in attributes and attributes['bar'] == 'value2', msg="Incorrectly named key." \ " Desired name: bar; only found %s." % (" ".join(attributes.keys()))) self.assertTrue('bar' in attributes and attributes['bar'] == 'value2', msg="Incorrect value wanted value2, " \ "got %s" % attributes['bar'])
def test_write_attribute_file(self): """ Check to make sure that write_attribute_file writes out files properly """ attribute_file = ("/tmp/temp_attributes.conf") attribute_standard = get_test_config( "test_files/attributes_output.conf") try: try: attributes = { 'Foo': 123, 'test_attr': 'abc-234#$', 'my-Attribute': 'test_attribute' } utilities.write_attribute_file(attribute_file, attributes) self.assertEqual( open(attribute_file).read(), open(attribute_standard).read(), 'Attribute files are not equal') except Exception as ex: self.fail('Got exception while testing write_attribute_file' \ "functionality:\n%s" % ex) finally: if os.path.exists(attribute_file): os.unlink(attribute_file)
def test_ini_spaces(self): """ Test to make sure ini files with spaces work correctly """ config_dirs = [ get_test_config('config-space1.d'), get_test_config('config-space2.d'), get_test_config('config-space3.d') ] temp = sys.stderr sys.stderr = open(os.devnull, 'w') for directory in config_dirs: self.assertRaises(SystemExit, configfile.read_config_files, config_directory=directory) sys.stderr = temp
def test_new_config(self): """ Make sure that we can correctly parse a correct new-style GIP config. """ config_parser = configparser.SafeConfigParser() config_file = get_test_config("subcluster/red-new-gip-config.ini") config_parser.read(config_file) self.assertTrue(subcluster.check_config(config_parser))
def test_valid_user_vo_file(self): """ Test functionality of valid_user_vo_file function """ test_file = get_test_config("./test_files/valid-user-vo-map.txt") self.assertTrue(validation.valid_user_vo_file(test_file, False), "Valid file flagged as invalid") test_file = get_test_config("./test_files/invalid-user-vo-map.txt") self.assertFalse(validation.valid_user_vo_file(test_file, False), "Invalid file flagged as valid") bad_lines = validation.valid_user_vo_file(test_file, True)[1] standard_lines = ["fdjkf394f023", "sam= 34f3"] self.assertEqual( bad_lines, standard_lines, "Wrong lines from the vo map obtained, " + "got:\n%s\n" % (bad_lines) + "expected:\n%s" % (standard_lines), )
def test_get_vos(self): """ Test get_vos function """ vo_file = get_test_config('test_files/sample-vos.txt') self.assertEqual(utilities.get_vos(vo_file), ['osg', 'LIGO', 'cdf'], "Correct vos not found")
def test_jobmanager_enabled(self): """ Test configurations to make sure that they are properly understood as being for a CE """ config_dirs = [get_test_config('config-ce-pbs.d'), get_test_config('config-ce-condor.d'), get_test_config('config-ce-lsf.d'), get_test_config('config-ce-sge.d')] for directory in config_dirs: config = configfile.read_config_files(config_directory=directory) self.assertTrue(configfile.jobmanager_enabled(config), "%s has an enabled jobmanager" % directory) config = configfile.read_config_files(config_directory=get_test_config('config-nonce.d')) self.assertFalse(configfile.jobmanager_enabled(config), "jobmanager_enabled returned true on a config without an enabled jobmanager")
def testServiceList(self): """ Test to make sure right services get returned """ config_file = get_test_config("misc/misc_xacml.ini") configuration = ConfigParser.SafeConfigParser() configuration.read(config_file) settings = misc.MiscConfiguration(logger=global_logger) try: settings.parse_configuration(configuration) except Exception as e: self.fail("Received exception while parsing configuration: %s" % e) services = settings.enabled_services() if utilities.rpm_installed('fetch-crl'): expected_services = set( ['fetch-crl-cron', 'fetch-crl-boot', 'gums-client-cron']) else: expected_services = set(['gums-client-cron']) self.assertEqual( services, expected_services, "List of enabled services incorrect, " + "got %s but expected %s" % (services, expected_services)) config_file = get_test_config("misc/misc_gridmap.ini") configuration = ConfigParser.SafeConfigParser() configuration.read(config_file) settings = misc.MiscConfiguration(logger=global_logger) try: settings.parse_configuration(configuration) except Exception as e: self.fail("Received exception while parsing configuration: %s" % e) services = settings.enabled_services() if utilities.rpm_installed('fetch-crl'): expected_services = set( ['fetch-crl-cron', 'fetch-crl-boot', 'edg-mkgridmap']) else: expected_services = set(['edg-mkgridmap']) self.assertEqual( services, expected_services, "List of enabled services incorrect, " + "got %s but expected %s" % (services, expected_services))
def test_doherty(self): """ Make sure that we can correctly parse a correct new-style GIP config. """ config_parser = ConfigParser.SafeConfigParser() config_file = get_test_config("gip/doherty.ini") config_parser.read(config_file) gip_config = gip.GipConfiguration(logger=global_logger) gip_config._parse_configuration(config_parser)
def test_no_name(self): """ Make sure a missing name causes an error """ config_parser = ConfigParser.SafeConfigParser() config_file = get_test_config("gip/sc_samples.ini") config_parser.read(config_file) gip_config = gip.GipConfiguration(logger=global_logger) self.assertRaises(exceptions.SettingError, gip_config.check_sc, config_parser, "Subcluster No Name")
def test_old_config(self): """ Make sure that we can correctly parse an old-style GIP config. """ config_parser = ConfigParser.SafeConfigParser() config_file = get_test_config("gip/red-old-gip-config.ini") config_parser.read(config_file) gip_config = gip.GipConfiguration(logger=global_logger) gip_config._parse_configuration(config_parser)
def test_resource_entry(self): """ Make sure a Resource Entry section is detected """ config_parser = ConfigParser.SafeConfigParser() config_file = get_test_config("gip/resourceentry.ini") config_parser.read(config_file) gip_config = gip.GipConfiguration(logger=global_logger) found_scs = gip_config.check_subclusters(config_parser) self.assertTrue(found_scs, msg="Resource Entry Valid not found.")
def test_valid_location(self): """ Check the valid_location functionality """ test_location = get_test_config("misc/misc1.ini") self.assertTrue(validation.valid_location(test_location), "%s not marked as a valid location" % test_location) test_location = "configs/invalid_foo.config" self.assertFalse(validation.valid_location(test_location), "%s marked as a valid location" % test_location)
def testMissingLSFProfile(self): """ Test the check_attributes function to see if it catches missing LSF profile """ config_file = get_test_config("lsf/missing_profile.ini") configuration = ConfigParser.SafeConfigParser() configuration.read(config_file) settings = lsf.LSFConfiguration(logger=global_logger) self.assertRaises(exceptions.SettingError, settings.parse_configuration, configuration)
def test_valid_file_location(self): """ Check the valid_file functionality """ test_file = get_test_config("utilities/valid_boolean.ini") message = "%s not marked as a valid file location" % test_file self.assertTrue(validation.valid_location(test_file), message) test_file = "configs/invalid_foo.config" message = "%s marked as a valid file location" % test_file self.assertFalse(validation.valid_location(test_file), message)
def load_settings_from_files(self, *cfgfiles): configuration = ConfigParser.SafeConfigParser() for cfgfile in cfgfiles: configuration.read(get_test_config(cfgfile)) settings = rsv.RsvConfiguration(logger=global_logger) settings.rsv_meta_dir = RSV_META_DIR try: settings.parse_configuration(configuration) except Exception, e: self.fail("Received exception while parsing configuration: %s" % e)
def test_valid_boolean(self): """ Test functionality of valid_boolean function """ config_file = get_test_config("utilities/valid_boolean.ini") config = ConfigParser.SafeConfigParser() config.read(config_file) self.assertFalse(validation.valid_boolean(config, "Test", "invalid_bool"), "invalid_bool flagged as valid") self.assertFalse(validation.valid_boolean(config, "Test", "invalid_bool2"), "invalid_bool2 flagged as valid") self.assertFalse(validation.valid_boolean(config, "Test", "missing"), "invalid_bool2 flagged as valid") self.assertTrue(validation.valid_boolean(config, "Test", "valid_bool"), "valid_bool flagged as invalid") self.assertTrue(validation.valid_boolean(config, "Test", "valid_bool2"), "valid_bool2 flagged as invalid")
def testInvalidBDII1(self): """ Test the check_attributes function to see if it catches invalid bdii servers """ config_file = get_test_config("infoservices/invalid_bdii1.ini") configuration = ConfigParser.SafeConfigParser() configuration.read(config_file) settings = infoservices.InfoServicesConfiguration(logger=global_logger) self.assertRaises(exceptions.SettingError, settings.parse_configuration, configuration=configuration)
def test_valid_executable(self): """ Test functionality of valid_executable function """ binary = "/bin/ls" text = get_test_config("test_files/subscriptions.xml") missing = "./test_files/foo" self.assertFalse(validation.valid_executable(missing), "Non-existent file is not a valid executable") self.assertFalse(validation.valid_executable(text), "Text file is not a valid executable") self.assertTrue(validation.valid_executable(binary), "/bin/ls should be a valid binary")
def testValidSettings2(self): """ Test the check_attributes function to see if it works on valid settings """ config_file = get_test_config("slurm/check_ok2.ini") configuration = ConfigParser.SafeConfigParser() configuration.read(config_file) settings = slurm.SlurmConfiguration(logger=global_logger) try: settings.parse_configuration(configuration) except Exception, e: self.fail("Received exception while parsing configuration: %s" % e)
def testMissingCondorConfig(self): """ Test the check_attributes function to see if it catches missing condor config locations """ for filename in [get_test_config("condor/missing_config1.ini"), get_test_config("condor/missing_config2.ini")]: config_file = os.path.abspath(filename) configuration = ConfigParser.SafeConfigParser() configuration.read(config_file) settings = condor.CondorConfiguration(logger=global_logger) try: settings.parse_configuration(configuration) except Exception, e: self.fail("Received exception while parsing configuration: %s" % e) attributes = settings.get_attributes() self.assertFalse(settings.check_attributes(attributes), "Did not notice missing condor config location: " + attributes['OSG_CONDOR_CONFIG'])
def test_valid_file(self): """ Test functionality of valid_file function """ filename = get_test_config("utilities/newline.ini") _stderr = sys.stderr sys.stderr = file(os.devnull, "wb") # need to do this instead of putting this in assert so that stderr can # be restored after call result = validation.valid_ini_file(filename) self.assertFalse(result, "Didn't detect newline in %s" % filename) # test whether we catch sections that has a space before the first setting filename = get_test_config("utilities/section_space.ini") self.assertFalse(result, "Didn't detect space in %s" % filename) sys.stderr = _stderr filename = get_test_config("utilities/valid_boolean.ini") self.assertTrue(validation.valid_ini_file(filename), "Got error on valid file %s" % filename) filename = get_test_config("utilities/valid_variable.ini") self.assertTrue(validation.valid_ini_file(filename), "Got error on valid file %s" % filename)
def testValidProductionDefaults(self): """ Test the production defaults and make sure that they are valid """ config_file = get_test_config("gratia/prod_default.ini") configuration = ConfigParser.SafeConfigParser() configuration.read(config_file) settings = gratia.GratiaConfiguration(logger=global_logger) try: settings.parse_configuration(configuration) except Exception, e: self.fail("Received exception while parsing configuration: %s" % e)
def testMissingAttribute(self): """ Test the parsing when attributes are missing, should get exceptions """ config_file = get_test_config("siteattributes/siteattributes2.ini") configuration = ConfigParser.SafeConfigParser() configuration.read(config_file) settings = siteattributes.SiteAttributes(logger=global_logger) try: settings.parse_configuration(configuration) except Exception, e: self.fail("Received exception while parsing configuration: %s" % e)
def testMissingPBSLocation(self): """ Test the check_attributes function to see if it catches missing pbs location """ config_file = get_test_config("slurm/missing_location.ini") configuration = ConfigParser.SafeConfigParser() configuration.read(config_file) settings = slurm.SlurmConfiguration(logger=global_logger) try: settings.parse_configuration(configuration) except Exception, e: self.fail("Received exception while parsing configuration: %s" % e)
def test_changeme1(self): """ Test should pass if SE CHANGEME section is disabled. """ did_fail = False try: config_parser = ConfigParser.SafeConfigParser() config_file = get_test_config("gip/changeme_section.ini") config_parser.read(config_file) gip_config = gip.GipConfiguration(logger=global_logger) gip_config._parse_configuration(config_parser) except exceptions.SettingError: did_fail = True self.assertFalse(did_fail, msg="Falsely detected an enabled CHANGEME section.")
def test_hepspec_valid(self): """ Make sure a valid HEPSPEC value is accepted. """ did_fail = False config_parser = ConfigParser.SafeConfigParser() config_file = get_test_config("gip/sc_samples.ini") config_parser.read(config_file) gip_config = gip.GipConfiguration(logger=global_logger) try: gip_config.check_sc(config_parser, "Subcluster Valid") except exceptions.SettingError: did_fail = True self.assertFalse(did_fail, msg="Valid HEPSPEC entry threw an exception.")