def delete_nps_directories(self,dirs): """ Delete the contents of directories with privilege separation NOT in effect.""" for type in dirs.keys(): if type in ["client logs", "client proxies",]: common.remove_dir_contents(dirs[type]) continue common.remove_dir_path(dirs[type])
def verify_directories_empty(self): dirs = {} if len(os.listdir(self.client_log_dir())) > 0: dirs["client_log_dir"] = self.client_log_dir() if len(os.listdir(self.client_proxy_dir())) > 0: dirs["client_proxy_dir"] = self.client_proxy_dir() if len(os.listdir(self.logs_dir())) > 0: dirs["logs_dir"] = self.logs_dir() for dir in ["monitor","stage"]: subdir = os.path.join(self.glidein.web_location(),dir) if os.path.isdir(subdir) and len(os.listdir(subdir)) > 0: dirs["web_location/%s" % dir] = subdir if len(os.listdir(self.install_location())) > 0: if len(os.listdir(self.install_location())) > self.nbr_of_nested_dirs(): dirs["install_location"] = self.install_location() if len(dirs) == 0: return # all directories are empty common.logit("""The following directories must be empty for the install to succeed: """) for option in dirs.keys(): common.logit(""" %(option)s: %(dir)s""" % \ { "option" : option, "dir" : dirs[option] }) common.ask_continue("... can we remove their contents") for option in dirs.keys(): common.remove_dir_contents(dirs[option]) # this re-validation is performed to resolve problem of nesting some dirs self.validate_needed_directories()
def create_factory_client_dirs(self,owner,perm): dirs = [self.factory.client_log_dir(),self.factory.client_proxy_dir(),] for dir in dirs: common.logit("... checking factory client directory: %s" % dir) if os.path.isdir(dir): if len(os.listdir(dir)) > 0: common.ask_continue("This directory must be empty. Can we delete the contents") common.remove_dir_contents(dir) common.make_directory(dir,owner,perm)
def verify_directories_empty(self): """ This method attempts to clean up all directories so a fresh install can be accomplished successfully. It is consoldiated in a single check so as to only ask once and not for each directory. It also (attempts) to insure that if directories are nested, it does not create a problem. Not an easy task. When privilege separation is in effect, the condor_root_switchboard must be used to clean out the client log and proxy files as the owners are different and permissions problems will occur. """ dirs = {} if len(os.listdir(self.client_log_dir())) > 0: dirs["client_log_dir"] = self.client_log_dir() if len(os.listdir(self.client_proxy_dir())) > 0: dirs["client_proxy_dir"] = self.client_proxy_dir() if len(os.listdir(self.logs_dir())) > 0: dirs["logs_dir"] = self.logs_dir() for dir in ["monitor","stage"]: subdir = os.path.join(self.glidein.web_location(),dir) if os.path.isdir(subdir) and len(os.listdir(subdir)) > 0: dirs["web_location/%s" % dir] = subdir if len(os.listdir(self.install_location())) > 0: if len(os.listdir(self.install_location())) > self.nbr_of_nested_dirs(): dirs["install_location"] = self.install_location() if len(dirs) == 0: return # all directories are empty common.logit("""The following directories must be empty for the install to succeed: """) for option in dirs.keys(): common.logit(""" %(option)s: %(dir)s""" % \ { "option" : option, "dir" : dirs[option] }) common.ask_continue("... can we remove their contents") for option in dirs.keys(): if self.wms.privilege_separation() == "y": if option in ["client_log_dir","client_proxy_dir",]: #-- Factory create requires these directories be empty #-- when privspep is in effect condor_sbin = "%s/sbin" % self.wms.condor_location() condor_bin = "%s/bin" % self.wms.condor_location() condorExe.set_path(condor_bin,condor_sbin) parent_dir = dirs[option] subdirs = os.listdir(parent_dir) for base_dir in subdirs: if os.path.isdir("%s/%s" % (parent_dir,base_dir)): condorPrivsep.rmtree(parent_dir,base_dir) else: common.remove_dir_contents(dirs[option]) else: common.remove_dir_contents(dirs[option]) # this re-validation is performed to resolve problem of nesting some dirs self.validate_needed_directories()
def __verify_directories_empty__(self): if self.install_type() == "rpm": return # For RPM install we don't want to clean anything dirs = {} if len(os.listdir(self.condor_location())) > 0: dirs["condor_location"] = self.condor_location() if len(dirs) == 0: return # all directories are empty common.logit("""The following directories must be empty for the install to succeed: """) for option in dirs.keys(): common.logit(""" %(option)s: %(dir)s""" % {"option": option, "dir": dirs[option]}) common.ask_continue("... can we remove their contents") for option in dirs.keys(): common.remove_dir_contents(dirs[option]) self.__validate_needed_directories__()
def verify_directories_empty(self): """ This method attempts to clean up all directories so a fresh install can be accomplished successfully. It is consoldiated in a single check so as to only ask once and not for each directory. """ if self.install_type == "rpm": return # For RPM install we don't want to clean anything instance_dir = "frontend_%(service)s-%(instance)s" % \ { "service" : self.service_name(), "instance" : self.glidein.instance_name(), } #-- directories to check --- dirs = {} dirs["logs........"] = os.path.join(self.logs_dir(),instance_dir) dirs["install....."] = os.path.join(self.install_location(),instance_dir) dirs["config......"] = self.config_dir() for subdir in ["monitor","stage"]: dirs["web %s " % subdir] = os.path.join(self.glidein.web_location(),subdir,instance_dir) #--- check them -- for type in dirs.keys(): if os.path.isdir(dirs[type]): if len(os.listdir(dirs[type])) == 0: os.rmdir(dirs[type]) del dirs[type] # remove from dict else: del dirs[type] # it does not exist, remove from dict #--- if all are empty, return if len(dirs) == 0: time.sleep(3) return # all directories are empty #--- See if we can remove them --- common.logit("""The following directories must be empty for the install to succeed: """) types = dirs.keys() types.sort() for type in types: common.logit(""" %(type)s: %(dir)s""" % \ { "type" : type, "dir" : dirs[type] }) common.ask_continue("... can we remove their contents") for type in dirs.keys(): common.remove_dir_contents(dirs[type]) os.rmdir(dirs[type]) time.sleep(3) return
def verify_directories_empty(self): if self.install_type == "rpm": return # For RPM install we don't want to clean anything dirs = {} if len(os.listdir(self.logs_dir())) > 0: dirs["logs_dir"] = self.logs_dir() for dir in ["monitor","stage"]: subdir = os.path.join(self.glidein.web_location(),dir) if os.path.isdir(subdir) and len(os.listdir(subdir)) > 0: dirs["web_location/%s" % dir] = subdir if len(os.listdir(self.install_location())) > 0: if len(os.listdir(self.install_location())) > self.nbr_of_nested_dirs(): dirs["install_location"] = self.install_location() if len(dirs) == 0: return # all directories are empty common.logit("""The following directories must be empty for the install to succeed: """) for option in dirs.keys(): common.logit(""" %(option)s: %(dir)s""" % \ { "option" : option, "dir" : dirs[option] }) common.ask_continue("... can we remove their contents") for option in dirs.keys(): common.remove_dir_contents(dirs[option]) self.validate_needed_directories()
def verify_directories_empty(self): """ This method attempts to clean up all directories so a fresh install can be accomplished successfully. It is consoldiated in a single check so as to only ask once and not for each directory. When privilege separation is in effect, the condor_root_switchboard must be used to clean out the client log and proxy files as the owners are different and permissions problems will occur. """ instance_dir = "glidein_%(instance)s" % \ { "instance" : self.glidein.instance_name(), } dirs = {} dirs["logs.........."] = os.path.join(self.logs_dir(),instance_dir) dirs["install......."] = os.path.join(self.install_location(),instance_dir) dirs["config........"] = self.config_dir() for frontend in self.wms.frontend_users().keys(): ## user = "******" + self.wms.frontend_users()[frontend] ## dirs["%s client logs..." % user] = os.path.join(self.client_log_dir(),user,instance_dir) ## dirs["%s client proxies" % user] = os.path.join(self.client_proxy_dir(),user,instance_dir) dirs["client logs"] = self.client_log_dir() dirs["client proxies"] = self.client_proxy_dir() for subdir in ["monitor","stage"]: dirs["web %s " % subdir] = os.path.join(self.glidein.web_location(),subdir,instance_dir) #--- check them -- for type in dirs.keys(): if os.path.isdir(dirs[type]): if len(os.listdir(dirs[type])) == 0: if self.wms.privilege_separation() == "y": if type in ["client logs", "client proxies",]: del dirs[type] # remove from dict else: # will have permission to delete it # os.rmdir(dirs[type]) del dirs[type] # remove from dict else: # will have permission to delete it #os.rmdir(dirs[type]) for rootdir, dirlist, filelist in os.walk(dirs[type],topdown=False): for filename in filelist: os.remove(os.path.join(rootdir, filename)) del dirs[type] # remove from dict else: # it does not exist, remove from dict del dirs[type] #--- if all are empty, return if len(dirs) == 0: os.system("sleep 3") return # all directories are empty #--- See if we can remove them --- common.logit("""The following directories must be empty for the install to succeed: """) types = dirs.keys() types.sort() for type in types: common.logit(""" %(type)s: %(dir)s""" % \ { "type" : type, "dir" : dirs[type] }) common.ask_continue("... can we remove their contents") for type in dirs.keys(): if self.wms.privilege_separation() == "y": if type in ["client logs", "client proxies",]: #-- Factory create requires these directories be empty #-- when privspep is in effect condor_sbin = "%s/sbin" % self.wms.condor_location() condor_bin = "%s/bin" % self.wms.condor_location() condorExe.set_path(condor_bin,condor_sbin) parent_dir = dirs[type] subdirs = os.listdir(parent_dir) for base_dir in subdirs: if os.path.isdir("%s/%s" % (parent_dir,base_dir)): try: condorPrivsep.rmtree(parent_dir,base_dir) except Exception,e: common.logerr("""Encountered a problem in executing condor_root_switchboard to remove this client's sub-directories: %(dir)s %(error)s Check your /etc/condor/privsep.conf file to verify. You may need to configure/install your WMS Collector to resolve or correct the ini file for the %(type)s attribute. Be careful now. """ % { "dir" : parent_dir, "type" : type, "error" : e, } ) common.logit("Files in %s deleted" % parent_dir) else: # not client logs or proxies common.remove_dir_contents(dirs[type]) os.rmdir(dirs[type]) else: #no privsep in effect common.remove_dir_contents(dirs[type]) os.rmdir(dirs[type])