def _ensure_valid_user_vo_file(self): using_gums = self.authorization_method == 'xacml' if not (validation.valid_user_vo_file(USER_VO_MAP_LOCATION) and utilities.get_vos(USER_VO_MAP_LOCATION)): self.log("Trying to create user-vo-map file", level=logging.INFO) result = False if using_gums: sys.stdout.write( "Querying GUMS server. This may take some time\n") sys.stdout.flush() result = utilities.run_script(['/usr/bin/gums-host-cron']) if not result: # gums-host-cron failed, let's try the json interface try: sys.stdout.write( "Querying GUMS server via JSON interface. This may take some time\n" ) sys.stdout.flush() user_vo_file_text = gums_supported_vos.gums_json_user_vo_map_file( self.gums_host) open(USER_VO_MAP_LOCATION, "w").write(user_vo_file_text) return True except exceptions.Error as e: self.log( "Could not query GUMS server via JSON interface: %s" % e, level=logging.WARNING) else: sys.stdout.write( "Running edg-mkgridmap, this process may take some time to query vo servers\n" ) sys.stdout.flush() result = utilities.run_script(['/usr/sbin/edg-mkgridmap']) temp, invalid_lines = validation.valid_user_vo_file( USER_VO_MAP_LOCATION, True) result = result and temp if not result: if not invalid_lines: self.log( "Empty %s generated, please check the GUMS configuration (if using GUMS), " "the edg-mkgridmap configuration (if not using GUMS), and/or log messages for the above" % USER_VO_MAP_LOCATION, level=logging.WARNING) else: self.log("Invalid lines in user-vo-map file:", level=logging.WARNING) self.log("\n".join(invalid_lines), level=logging.WARNING) self.log("Error creating user-vo-map file", level=logging.WARNING) return False else: return True
def ensure_valid_user_vo_file(using_gums, logger=utilities.NullLogger): if not validation.valid_user_vo_file(USER_VO_MAP_LOCATION): logger.info("Trying to create user-vo-map file") result = create_user_vo_file(using_gums) temp, invalid_lines = validation.valid_user_vo_file(USER_VO_MAP_LOCATION, True) result = result and temp if not result: logger.error("Can't generate user-vo-map, manual intervention is needed") if not invalid_lines: logger.error("gums-host-cron or edg-mkgridmap generated an empty " + USER_VO_MAP_LOCATION + " file, please check the " "appropriate configuration and or log messages") raise exceptions.ConfigureError('Error when generating user-vo-map file') logger.error("Invalid lines in user-vo-map file:") logger.error("\n".join(invalid_lines)) raise exceptions.ConfigureError("Error when invoking gums-host-cron or edg-mkgridmap")
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_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 create_user_vo_file(using_gums=False): """ Check and create a mapfile if needed """ map_file = '/var/lib/osg/user-vo-map' try: if validation.valid_user_vo_file(map_file): return True if using_gums: gums_script = '/usr/bin/gums-host-cron' else: gums_script = '/usr/sbin/edg-mkgridmap' sys.stdout.write("Running %s, this process may take some time " % gums_script + "to query vo and gums servers\n") sys.stdout.flush() if not utilities.run_script([gums_script]): return False except IOError: return False return True