Ejemplo n.º 1
0
    def _write_lcmaps_file(self):
        old_lcmaps_contents = utilities.read_file(LCMAPS_DB_LOCATION,
                                                  default='')
        if old_lcmaps_contents and 'THIS FILE WAS WRITTEN BY OSG-CONFIGURE' not in old_lcmaps_contents:
            backup_path = LCMAPS_DB_LOCATION + '.pre-configure'
            self.log("Backing up %s to %s" % (LCMAPS_DB_LOCATION, backup_path),
                     level=logging.WARNING)
            if not utilities.atomic_write(backup_path, old_lcmaps_contents):
                msg = "Unable to back up old lcmaps.db to %s" % backup_path
                self.log(msg, level=logging.ERROR)
                raise exceptions.ConfigureError(msg)

        self.log("Writing " + LCMAPS_DB_LOCATION, level=logging.INFO)
        if self.authorization_method == 'xacml':
            lcmaps_template_fn = 'lcmaps.db.gums'
        elif self.authorization_method == 'gridmap' or self.authorization_method == 'local-gridmap':
            lcmaps_template_fn = 'lcmaps.db.gridmap'
        elif self.authorization_method == 'vomsmap':
            if self.all_fqans:
                lcmaps_template_fn = 'lcmaps.db.vomsmap.allfqans'
            else:
                lcmaps_template_fn = 'lcmaps.db.vomsmap'
        else:
            assert False

        lcmaps_template_path = os.path.join(LCMAPS_DB_TEMPLATES_LOCATION,
                                            lcmaps_template_fn)

        if not validation.valid_file(lcmaps_template_path):
            msg = "lcmaps.db template file not found at %s; ensure lcmaps-db-templates >= 1.6.6-1.8" \
                  " is installed or set edit_lcmaps_db=False" % lcmaps_template_path
            self.log(msg, level=logging.ERROR)
            raise exceptions.ConfigureError(msg)

        old_lcmaps_contents = utilities.read_file(LCMAPS_DB_LOCATION,
                                                  default='')
        if old_lcmaps_contents and 'THIS FILE WAS WRITTEN BY OSG-CONFIGURE' not in old_lcmaps_contents:
            backup_path = LCMAPS_DB_LOCATION + '.pre-configure'
            self.log("Backing up %s to %s" % (LCMAPS_DB_LOCATION, backup_path),
                     level=logging.WARNING)
            try:
                shutil.copy2(LCMAPS_DB_LOCATION, backup_path)
            except EnvironmentError as err:
                msg = "Unable to back up old lcmaps.db: " + str(err)
                self.log(msg, level=logging.ERROR)
                raise exceptions.ConfigureError(msg)

        lcmaps_contents = utilities.read_file(lcmaps_template_path)
        lcmaps_contents = (
            "# THIS FILE WAS WRITTEN BY OSG-CONFIGURE AND WILL BE OVERWRITTEN ON FUTURE RUNS\n"
            "# Set edit_lcmaps_db = False in the [%s] section of your OSG configuration to\n"
            "# keep your changes.\n" % self.config_section +
            lcmaps_contents.replace('@GUMSHOST@',
                                    str(self.options['gums_host'].value)))
        if not utilities.atomic_write(LCMAPS_DB_LOCATION, lcmaps_contents):
            msg = "Error while writing to " + LCMAPS_DB_LOCATION
            self.log(msg, level=logging.ERROR)
            raise exceptions.ConfigureError(msg)
Ejemplo n.º 2
0
    def setup_htcondor_ce_config(self):
        """
        Populate the config file that tells htcondor-ce where the condor
        pool is and where the spool directory is.

        Returns True if successful, False otherwise
        """
        if not utilities.rpm_installed('htcondor-ce'):
            self.log("Unable to configure htcondor-ce for Condor: htcondor-ce not installed", level=logging.ERROR)
            return False

        def get_condor_ce_config_val(variable):
            return utilities.get_condor_config_val(variable, executable='condor_ce_config_val', quiet_undefined=True)

        # Get values for the settings we want to update. We can get the
        # values from condor_config_val; in the case of JOB_ROUTER_SCHEDD2_NAME,
        # we have FULL_HOSTNAME as a fallback in case SCHEDD_NAME is missing.
        # We also get the current / default value from condor_ce_config_val;
        # only update the setting in case the value from
        # condor_config_val is different from the value from condor_ce_config_val.
        condor_ce_config = {}
        for condor_ce_config_key, condor_config_keys in [
            ('JOB_ROUTER_SCHEDD2_NAME', ['SCHEDD_NAME', 'FULL_HOSTNAME']),
            ('JOB_ROUTER_SCHEDD2_POOL', ['COLLECTOR_HOST']),
            ('JOB_ROUTER_SCHEDD2_SPOOL', ['SPOOL'])]:

            condor_config_value = None
            for condor_config_value in (utilities.get_condor_config_val(k, quiet_undefined=True) for k in
                                        condor_config_keys):
                if condor_config_value:
                    break

            condor_ce_config_value = get_condor_ce_config_val(condor_ce_config_key)
            if not (condor_config_value or condor_ce_config_value):
                self.log("Unable to determine value for %s from %s and default not set; check your Condor config" %
                         (condor_ce_config_key, ' or '.join(condor_config_keys)), level=logging.ERROR)
                return False
            elif not condor_config_value:
                continue  # can't set anything for this

            # Special case for JOB_ROUTER_SCHEDD2_POOL: append port if necessary (SOFTWARE-1744)
            if condor_ce_config_key == 'JOB_ROUTER_SCHEDD2_POOL':
                condor_collector_port = (utilities.get_condor_config_val('COLLECTOR_PORT', quiet_undefined=True)
                                         or '9618')
                condor_config_value = self._add_port_if_necessary(condor_config_value, condor_collector_port)

            if not condor_ce_config_value or condor_ce_config_value != condor_config_value:
                condor_ce_config[condor_ce_config_key] = condor_config_value

        if condor_ce_config:
            buf = utilities.read_file(JobManagerConfiguration.HTCONDOR_CE_CONFIG_FILE,
                                      default="# This file is managed by osg-configure\n")
            for key, value in condor_ce_config.items():
                buf = utilities.add_or_replace_setting(buf, key, value, quote_value=False)

            if not utilities.atomic_write(JobManagerConfiguration.HTCONDOR_CE_CONFIG_FILE, buf):
                return False

        return True
 def write_blah_disable_wn_proxy_renewal_to_blah_config(self):
     if os.path.exists(self.BLAH_CONFIG):
         contents = utilities.read_file(self.BLAH_CONFIG)
         for option, value in [("blah_disable_wn_proxy_renewal", "yes"),
                               ("blah_delegate_renewed_proxies", "no"),
                               ("blah_disable_limited_proxy", "yes")]:
             contents = utilities.add_or_replace_setting(contents, option, value,
                                                         quote_value=True)
         utilities.atomic_write(self.BLAH_CONFIG, contents)
Ejemplo n.º 4
0
 def write_lsf_confpath_to_blah_config(self):
     if os.path.exists(self.BLAH_CONFIG):
         contents = utilities.read_file(self.BLAH_CONFIG)
         contents = utilities.add_or_replace_setting(
             contents,
             'lsf_confpath',
             self.options['lsf_conf'].value,
             quote_value=True)
         utilities.atomic_write(self.BLAH_CONFIG, contents)
Ejemplo n.º 5
0
 def write_blah_disable_wn_proxy_renewal_to_blah_config(self):
     if os.path.exists(self.BLAH_CONFIG):
         contents = utilities.read_file(self.BLAH_CONFIG)
         contents = utilities.add_or_replace_setting(
             contents,
             "blah_disable_wn_proxy_renewal",
             "yes",
             quote_value=True)
         utilities.atomic_write(self.BLAH_CONFIG, contents)
Ejemplo n.º 6
0
 def set_pbs_pro_in_blah_config(self):
     if os.path.exists(self.BLAH_CONFIG):
         contents = utilities.read_file(self.BLAH_CONFIG)
         new_value = "yes" if self.opt_val('pbs_flavor') == "pro" else "no"
         contents = utilities.add_or_replace_setting(contents,
                                                     "pbs_pro",
                                                     new_value,
                                                     quote_value=False)
         utilities.atomic_write(self.BLAH_CONFIG, contents)
Ejemplo n.º 7
0
 def write_gridmap_to_htcondor_ce_config(self):
     contents = utilities.read_file(HTCONDOR_CE_CONFIG_FILE,
                                    default="# This file is managed by osg-configure\n")
     if self.options['authorization_method'].value == 'xacml':
         # Remove GRIDMAP setting
         contents = re.sub(r'(?m)^\s*GRIDMAP\s*=.*?$[\n]?', "", contents)
     else:
         contents = utilities.add_or_replace_setting(contents, "GRIDMAP", "/etc/grid-security/grid-mapfile",
                                                     quote_value=False)
     utilities.atomic_write(HTCONDOR_CE_CONFIG_FILE, contents)
 def write_htcondor_ce_sentinel(self):
     if self.htcondor_gateway_enabled and utilities.ce_installed():
         contents = utilities.read_file(
             self.HTCONDOR_CE_CONFIG_FILE,
             default="# This file is managed by osg-configure\n")
         contents = utilities.add_or_replace_setting(contents,
                                                     "OSG_CONFIGURED",
                                                     "true",
                                                     quote_value=False)
         utilities.atomic_write(self.HTCONDOR_CE_CONFIG_FILE, contents)
Ejemplo n.º 9
0
    def _write_route_config_vars(self):
        """
        Write condor-ce config attributes for the bosco job route. Sets values for:
        - BOSCO_RMS
        - BOSCO_ENDPOINT

        """
        contents = utilities.read_file(self.HTCONDOR_CE_CONFIG_FILE,
                                       default="# This file is managed by osg-configure\n")
        contents = utilities.add_or_replace_setting(contents, "BOSCO_RMS", self.options['batch'].value,
                                                    quote_value=False)
        contents = utilities.add_or_replace_setting(contents, "BOSCO_ENDPOINT", self.options['endpoint'].value,
                                                    quote_value=False)
        utilities.atomic_write(self.HTCONDOR_CE_CONFIG_FILE, contents)
Ejemplo n.º 10
0
    def setup_blah_config(self):
        """
        Populate blah.config with correct values

        Return True if successful, False otherwise
        """
        if os.path.exists(self.BLAH_CONFIG):
            contents = utilities.read_file(self.BLAH_CONFIG)
            contents = utilities.add_or_replace_setting(contents, "sge_rootpath", self.options['sge_root'].value,
                                                        quote_value=True)
            contents = utilities.add_or_replace_setting(contents, "sge_cellname", self.options['sge_cell'].value,
                                                        quote_value=True)
            return utilities.atomic_write(self.BLAH_CONFIG, contents)
        return False
 def write_binpaths_to_blah_config(self, jobmanager, submit_binpath):
     """
     Change the *_binpath variables in /etc/blah.config for the given
     jobmanager to point to the locations specified by the user in the
     config for that jobmanager. Does not do anything if /etc/blah.config
     is missing (e.g. if blahp is not installed).
     :param jobmanager: The name of a job manager that has a _binpath
       variable in /etc/blah.config
     :param submit_binpath: The fully-qualified path to the submit
       executables for that jobmanager
     """
     if os.path.exists(self.BLAH_CONFIG):
         contents = utilities.read_file(self.BLAH_CONFIG)
         contents = utilities.add_or_replace_setting(contents, jobmanager + "_binpath", submit_binpath,
                                                     quote_value=True)
         utilities.atomic_write(self.BLAH_CONFIG, contents)
 def write_binpaths_to_blah_config(self, jobmanager, submit_binpath):
     """
     Change the *_binpath variables in /etc/blah.config for the given
     jobmanager to point to the locations specified by the user in the
     config for that jobmanager. Does not do anything if /etc/blah.config
     is missing (e.g. if blahp is not installed).
     :param jobmanager: The name of a job manager that has a _binpath
       variable in /etc/blah.config
     :param submit_binpath: The fully-qualified path to the submit
       executables for that jobmanager
     """
     if os.path.exists(self.BLAH_CONFIG):
         contents = utilities.read_file(self.BLAH_CONFIG)
         contents = utilities.add_or_replace_setting(contents, jobmanager + "_binpath", submit_binpath,
                                                     quote_value=False)
         utilities.atomic_write(self.BLAH_CONFIG, contents)
Ejemplo n.º 13
0
    def setup_blah_config(self):
        """
        Populate blah.config with correct values

        Return True if successful, False otherwise
        """
        if os.path.exists(self.BLAH_CONFIG):
            contents = utilities.read_file(self.BLAH_CONFIG)
            contents = utilities.add_or_replace_setting(
                contents,
                "sge_rootpath",
                self.options['sge_root'].value,
                quote_value=True)
            contents = utilities.add_or_replace_setting(
                contents,
                "sge_cellname",
                self.options['sge_cell'].value,
                quote_value=True)
            return utilities.atomic_write(self.BLAH_CONFIG, contents)
        return False
Ejemplo n.º 14
0
 def write_lsf_confpath_to_blah_config(self):
     if os.path.exists(self.BLAH_CONFIG):
         contents = utilities.read_file(self.BLAH_CONFIG)
         contents = utilities.add_or_replace_setting(contents, 'lsf_confpath', self.options['lsf_conf'].value,
                                                     quote_value=True)
         utilities.atomic_write(self.BLAH_CONFIG, contents)
Ejemplo n.º 15
0
    def setup_htcondor_ce_config(self):
        """
        Populate the config file that tells htcondor-ce where the condor
        pool is and where the spool directory is.

        Returns True if successful, False otherwise
        """
        if not utilities.rpm_installed('htcondor-ce'):
            self.log(
                "Unable to configure htcondor-ce for Condor: htcondor-ce not installed",
                level=logging.ERROR)
            return False

        def get_condor_ce_config_val(variable):
            return utilities.get_condor_config_val(
                variable,
                executable='condor_ce_config_val',
                quiet_undefined=True)

        # Get values for the settings we want to update. We can get the
        # values from condor_config_val; in the case of JOB_ROUTER_SCHEDD2_NAME,
        # we have FULL_HOSTNAME as a fallback in case SCHEDD_NAME is missing.
        # We also get the current / default value from condor_ce_config_val;
        # only update the setting in case the value from
        # condor_config_val is different from the value from condor_ce_config_val.
        condor_ce_config = {}
        for condor_ce_config_key, condor_config_keys in [
            ('JOB_ROUTER_SCHEDD2_NAME', ['SCHEDD_NAME', 'FULL_HOSTNAME']),
            ('JOB_ROUTER_SCHEDD2_POOL', ['COLLECTOR_HOST']),
            ('JOB_ROUTER_SCHEDD2_SPOOL', ['SPOOL'])
        ]:

            condor_config_value = None
            for condor_config_value in (utilities.get_condor_config_val(
                    k, quiet_undefined=True) for k in condor_config_keys):
                if condor_config_value:
                    break

            condor_ce_config_value = get_condor_ce_config_val(
                condor_ce_config_key)
            if not (condor_config_value or condor_ce_config_value):
                self.log(
                    "Unable to determine value for %s from %s and default not set; check your Condor config"
                    % (condor_ce_config_key, ' or '.join(condor_config_keys)),
                    level=logging.ERROR)
                return False
            elif not condor_config_value:
                continue  # can't set anything for this

            # Special case for JOB_ROUTER_SCHEDD2_POOL: append port if necessary (SOFTWARE-1744)
            if condor_ce_config_key == 'JOB_ROUTER_SCHEDD2_POOL':
                condor_collector_port = (utilities.get_condor_config_val(
                    'COLLECTOR_PORT', quiet_undefined=True) or '9618')
                condor_config_value = self._add_port_if_necessary(
                    condor_config_value, condor_collector_port)

            if not condor_ce_config_value or condor_ce_config_value != condor_config_value:
                condor_ce_config[condor_ce_config_key] = condor_config_value

        if condor_ce_config:
            buf = utilities.read_file(
                JobManagerConfiguration.HTCONDOR_CE_CONFIG_FILE,
                default="# This file is managed by osg-configure\n")
            for key, value in condor_ce_config.items():
                buf = utilities.add_or_replace_setting(buf,
                                                       key,
                                                       value,
                                                       quote_value=False)

            if not utilities.atomic_write(
                    JobManagerConfiguration.HTCONDOR_CE_CONFIG_FILE, buf):
                return False

        return True
 def write_htcondor_ce_sentinel(self):
     if self.htcondor_gateway_enabled:
         contents = utilities.read_file(self.HTCONDOR_CE_CONFIG_FILE,
                                        default="# This file is managed by osg-configure\n")
         contents = utilities.add_or_replace_setting(contents, "OSG_CONFIGURED", "true", quote_value=False)
         utilities.atomic_write(self.HTCONDOR_CE_CONFIG_FILE, contents)
 def write_blah_disable_wn_proxy_renewal_to_blah_config(self):
     if os.path.exists(self.BLAH_CONFIG):
         contents = utilities.read_file(self.BLAH_CONFIG)
         contents = utilities.add_or_replace_setting(contents, "blah_disable_wn_proxy_renewal", "yes",
                                                     quote_value=False)
         utilities.atomic_write(self.BLAH_CONFIG, contents)