コード例 #1
0
    def check_attributes(self, attributes):
        """Check attributes currently stored and make sure that they are consistent"""
        self.log('LSFConfiguration.check_attributes started')

        attributes_ok = True

        if not self.enabled:
            self.log('LSF not enabled, returning True')
            self.log('LSFConfiguration.check_attributes completed')
            return attributes_ok

        if self.ignored:
            self.log('Ignored, returning True')
            self.log('LSFConfiguration.check_attributes completed')
            return attributes_ok

        # make sure locations exist
        if not validation.valid_location(self.options['lsf_location'].value):
            attributes_ok = False
            self.log("Non-existent location given: %s" %
                     (self.options['lsf_location'].value),
                     option='lsf_location',
                     section=self.config_section,
                     level=logging.ERROR)

        if not validation.valid_directory(self.lsf_bin_location):
            attributes_ok = False
            self.log("Given lsf_location %r has no bin/ directory" %
                     self.options['lsf_location'].value,
                     option='lsf_location',
                     section=self.config_section,
                     level=logging.ERROR)

        if self.options['lsf_conf'].value and not validation.valid_directory(
                self.options['lsf_conf'].value):
            attributes_ok = False
            self.log("Non-existent directory given: %s" %
                     (self.options['lsf_conf'].value),
                     option='lsf_conf',
                     section=self.config_section,
                     level=logging.ERROR)

        if not validation.valid_file(self.options['lsf_profile'].value):
            attributes_ok = False
            self.log("Non-existent location given: %s" %
                     (self.options['lsf_profile'].value),
                     option='lsf_profile',
                     section=self.config_section,
                     level=logging.ERROR)

        self.log('LSFConfiguration.check_attributes completed')
        return attributes_ok
コード例 #2
0
ファイル: lsf.py プロジェクト: opensciencegrid/osg-configure
    def setup_gram_config(self):
        """
        Populate the gram config file with correct values

        Returns True if successful, False otherwise
        """
        buf = open(LSFConfiguration.GRAM_CONFIG_FILE).read()
        for binfile in ['bsub', 'bqueues', 'bjobs', 'bhist', 'bacct', 'bkill']:
            bin_location = os.path.join(self.lsf_bin_location, binfile)
            if validation.valid_file(bin_location):
                buf = utilities.add_or_replace_setting(buf, binfile, 'bin_location')

        if self.options['seg_enabled'].value:
            if (self.options['log_directory'].value is None or
                    not validation.valid_directory(self.options['log_directory'].value)):
                mesg = "%s is not a valid directory location " % self.options['log_directory'].value
                mesg += "for lsf log files"
                self.log(mesg,
                         section=self.config_section,
                         option='log_directory',
                         level=logging.ERROR)
                return False

            buf = utilities.add_or_replace_setting(buf, 'log_path', self.options['log_directory'].value)

        buf = utilities.add_or_replace_setting(buf, 'lsf_profile', self.options['lsf_profile'].value)

        if not utilities.atomic_write(LSFConfiguration.GRAM_CONFIG_FILE, buf):
            return False
        return True
コード例 #3
0
ファイル: gratia.py プロジェクト: bbockelm/osg-configure
    def _configure_pbs_probe(self):
        """
        Do pbs probe specific configuration
        """
        if (self._probe_config['pbs']['accounting_log_directory'] is None or
                self._probe_config['pbs']['accounting_log_directory'] == ''):
            return True
        accounting_dir = self._probe_config['pbs']['accounting_log_directory']
        if not validation.valid_directory(accounting_dir):
            self.log(
                "PBS accounting log not present, PBS gratia probe not configured",
                level=logging.ERROR,
                option='accounting_log_directory',
                section='PBS')
            return True

        config_location = GRATIA_CONFIG_FILES['pbs']
        buf = file(config_location).read()
        buf = self.replace_setting(buf,
                                   'pbsAcctLogDir',
                                   accounting_dir,
                                   xml_file=False)
        buf = self.replace_setting(buf, 'lrmsType', 'pbs', xml_file=False)
        if not utilities.atomic_write(config_location, buf):
            return False
        return True
コード例 #4
0
ファイル: configfile.py プロジェクト: djw8605/osg-configure
def read_config_files(**kwargs):
    """
    Read config files located in /etc/osg/config.d and return a config parser
    object for it

    Keyword arguments:
    config_directory -- indicates which directory holds the config files
    case_sensitive -- indicates whether the ConfigParser should be case
      sensitive when parsing the config file, this is needed for Local Options
      section

    Raises:
    IOError -- error when parsing files
    """

    config_dir = kwargs.get('config_directory', CONFIG_DIRECTORY)
    case_sensitive = kwargs.get('case_sensitive', False)
    if not validation.valid_directory(config_dir):
        raise IOError("%s does not exist" % config_dir)
    file_list = get_file_list(config_directory=config_dir)
    for filename in file_list:
        if not validation.valid_ini_file(filename):
            sys.stderr.write("Error found in %s\n" % filename)
            sys.exit(1)
    try:
        config = ConfigParser.SafeConfigParser()
        if case_sensitive:
            config.optionxform = str
    except ConfigParser.Error, e:
        raise IOError("Can't read and parse config files:\n%s" % e)
コード例 #5
0
    def setup_gram_config(self):
        """
        Populate the gram config file with correct values

        Returns True if successful, False otherwise
        """
        contents = open(PBSConfiguration.GRAM_CONFIG_FILE).read()
        for binfile in ['qsub', 'qstat', 'qdel']:
            bin_location = os.path.join(self.pbs_bin_location, binfile)
            if validation.valid_file(bin_location):
                contents = utilities.add_or_replace_setting(contents, binfile, bin_location)

        if self.options['pbs_server'].value != '':
            contents = utilities.add_or_replace_setting(contents, 'pbs_default', self.options['pbs_server'].value)

        if self.options['seg_enabled'].value:
            if (self.options['log_directory'].value is None or
                    not validation.valid_directory(self.options['log_directory'].value)):
                mesg = "%s is not a valid directory location " % self.options['log_directory'].value
                mesg += "for pbs log files"
                self.log(mesg,
                         section=self.config_section,
                         option='log_directory',
                         level=logging.ERROR)
                return False

            contents = utilities.add_or_replace_setting(contents, 'log_path', self.options['log_directory'].value)

        if not utilities.atomic_write(PBSConfiguration.GRAM_CONFIG_FILE, contents):
            return False

        return True
コード例 #6
0
ファイル: lsf.py プロジェクト: bbockelm/osg-configure
    def setup_gram_config(self):
        """
        Populate the gram config file with correct values

        Returns True if successful, False otherwise
        """
        buf = open(LSFConfiguration.GRAM_CONFIG_FILE).read()
        for binfile in ['bsub', 'bqueues', 'bjobs', 'bhist', 'bacct', 'bkill']:
            bin_location = os.path.join(self.lsf_bin_location, binfile)
            if validation.valid_file(bin_location):
                buf = utilities.add_or_replace_setting(buf, binfile,
                                                       'bin_location')

        if self.options['seg_enabled'].value:
            if (self.options['log_directory'].value is None
                    or not validation.valid_directory(
                        self.options['log_directory'].value)):
                mesg = "%s is not a valid directory location " % self.options[
                    'log_directory'].value
                mesg += "for lsf log files"
                self.log(mesg,
                         section=self.config_section,
                         option='log_directory',
                         level=logging.ERROR)
                return False

            buf = utilities.add_or_replace_setting(
                buf, 'log_path', self.options['log_directory'].value)

        buf = utilities.add_or_replace_setting(
            buf, 'lsf_profile', self.options['lsf_profile'].value)

        if not utilities.atomic_write(LSFConfiguration.GRAM_CONFIG_FILE, buf):
            return False
        return True
コード例 #7
0
def read_config_files(**kwargs):
    """
    Read config files located in /etc/osg/config.d and return a config parser
    object for it

    Keyword arguments:
    config_directory -- indicates which directory holds the config files
    case_sensitive -- indicates whether the ConfigParser should be case
      sensitive when parsing the config file, this is needed for Local Options
      section

    Raises:
    IOError -- error when parsing files
    """

    config_dir = kwargs.get('config_directory', CONFIG_DIRECTORY)
    case_sensitive = kwargs.get('case_sensitive', False)
    if not validation.valid_directory(config_dir):
        raise IOError("%s does not exist" % config_dir)
    file_list = get_file_list(config_directory=config_dir)
    for filename in file_list:
        if not validation.valid_ini_file(filename):
            sys.stderr.write("Error found in %s\n" % filename)
            sys.exit(1)
    try:
        config = ConfigParser.SafeConfigParser()
        if case_sensitive:
            config.optionxform = str
    except ConfigParser.Error, e:
        raise IOError("Can't read and parse config files:\n%s" % e)
コード例 #8
0
    def check_attributes(self, attributes):
        """Check attributes currently stored and make sure that they are consistent"""
        self.log('SGEConfiguration.check_attributes started')
        attributes_ok = True
        if not self.enabled:
            self.log('SGE not enabled, returning True')
            self.log('SGEConfiguration.check_attributes completed')
            return attributes_ok

        if self.ignored:
            self.log('Ignored, returning True')
            self.log('SGEConfiguration.check_attributes completed')
            return attributes_ok

        # make sure locations exist
        if not validation.valid_location(self.options['sge_root'].value):
            attributes_ok = False
            self.log("Non-existent location given: %s" %
                     (self.options['sge_root'].value),
                     option='sge_root',
                     section=self.config_section,
                     level=logging.ERROR)

        settings_file = os.path.join(
            self.options['sge_root'].value,
            self.options['sge_cell'].value.lstrip("/"), 'common/settings.sh')

        if not validation.valid_file(settings_file):
            attributes_ok = False
            self.log("$SGE_ROOT/$SGE_CELL/common/settings.sh not present: %s" %
                     settings_file,
                     option='sge_cell',
                     section=self.config_section,
                     level=logging.ERROR)

        if not validation.valid_directory(
                self.options['sge_bin_location'].value):
            attributes_ok = False
            self.log("sge_bin_location not valid: %s" %
                     self.options['sge_bin_location'].value,
                     option='sge_bin_location',
                     section=self.config_section,
                     level=logging.ERROR)

        key = 'sge_config'
        if (not self.options[key].value
                or not validation.valid_file(self.options[key].value)):
            attributes_ok = False
            self.log("%s is not a valid file: %s" %
                     (key, self.options[key].value),
                     section=self.config_section,
                     option=key,
                     level=logging.ERROR)

        self.log('SGEConfiguration.check_attributes completed')
        return attributes_ok
コード例 #9
0
ファイル: slurm.py プロジェクト: bbockelm/osg-configure
    def check_attributes(self, attributes):
        """Check attributes currently stored and make sure that they are consistent"""
        self.log('SlurmConfiguration.check_attributes started')

        attributes_ok = True

        if not self.enabled:
            self.log('SLURM not enabled, returning True')
            self.log('SlurmConfiguration.check_attributes completed')
            return attributes_ok

        if self.ignored:
            self.log('Ignored, returning True')
            self.log('SlurmConfiguration.check_attributes completed')
            return attributes_ok

        # make sure locations exist
        if not validation.valid_location(self.options['slurm_location'].value):
            attributes_ok = False
            self.log("Non-existent location given: %s" %
                     (self.options['slurm_location'].value),
                     option='slurm_location',
                     section=self.config_section,
                     level=logging.ERROR)

        if not validation.valid_directory(self.slurm_bin_location):
            attributes_ok = False
            self.log("Given slurm_location %r has no bin/ directory" %
                     self.options['slurm_location'].value,
                     option='slurm_location',
                     section=self.config_section,
                     level=logging.ERROR)

        if not validation.valid_contact(self.options['job_contact'].value,
                                        'pbs'):
            attributes_ok = False
            self.log("Invalid job contact: %s" %
                     (self.options['job_contact'].value),
                     option='job_contact',
                     section=self.config_section,
                     level=logging.ERROR)

        if not validation.valid_contact(self.options['util_contact'].value,
                                        'pbs'):
            attributes_ok = False
            self.log("Invalid util contact: %s" %
                     (self.options['util_contact'].value),
                     option='util_contact',
                     section=self.config_section,
                     level=logging.ERROR)

        self.log('SlurmConfiguration.check_attributes completed')
        return attributes_ok
コード例 #10
0
ファイル: slurm.py プロジェクト: djw8605/osg-configure
    def check_attributes(self, attributes):
        """Check attributes currently stored and make sure that they are consistent"""
        self.log('SlurmConfiguration.check_attributes started')

        attributes_ok = True

        if not self.enabled:
            self.log('SLURM not enabled, returning True')
            self.log('SlurmConfiguration.check_attributes completed')
            return attributes_ok

        if self.ignored:
            self.log('Ignored, returning True')
            self.log('SlurmConfiguration.check_attributes completed')
            return attributes_ok

        # make sure locations exist
        if not validation.valid_location(self.options['slurm_location'].value):
            attributes_ok = False
            self.log("Non-existent location given: %s" %
                     (self.options['slurm_location'].value),
                     option='slurm_location',
                     section=self.config_section,
                     level=logging.ERROR)

        if not validation.valid_directory(self.slurm_bin_location):
            attributes_ok = False
            self.log("Given slurm_location %r has no bin/ directory" % self.options['slurm_location'].value,
                     option='slurm_location',
                     section=self.config_section,
                     level=logging.ERROR)

        if not validation.valid_contact(self.options['job_contact'].value,
                                        'pbs'):
            attributes_ok = False
            self.log("Invalid job contact: %s" %
                     (self.options['job_contact'].value),
                     option='job_contact',
                     section=self.config_section,
                     level=logging.ERROR)

        if not validation.valid_contact(self.options['util_contact'].value,
                                        'pbs'):
            attributes_ok = False
            self.log("Invalid util contact: %s" %
                     (self.options['util_contact'].value),
                     option='util_contact',
                     section=self.config_section,
                     level=logging.ERROR)

        self.log('SlurmConfiguration.check_attributes completed')
        return attributes_ok
コード例 #11
0
    def check_attributes(self, attributes):
        """Check attributes currently stored and make sure that they are consistent"""
        self.log('CondorConfiguration.check_attributes started')

        if not self.enabled:
            self.log(
                'CondorConfiguration.check_attributes completed returning True'
            )
            return True

        if self.ignored:
            self.log(
                'CondorConfiguration.check_attributes completed returning True'
            )
            return True

        attributes_ok = True

        # make sure locations exist
        self.log('checking condor_location')
        if not validation.valid_location(
                self.options['condor_location'].value):
            attributes_ok = False
            self.log("Non-existent location given: %s" %
                     (self.options['condor_location'].value),
                     option='condor_location',
                     section=self.config_section,
                     level=logging.ERROR)

        if not validation.valid_directory(self.condor_bin_location):
            attributes_ok = False
            self.log("Given condor_location %r has no bin/ directory" %
                     self.options['condor_location'].value,
                     option='condor_location',
                     section=self.config_section,
                     level=logging.ERROR)

        self.log('checking condor_config')
        if not validation.valid_file(self.options['condor_config'].value):
            attributes_ok = False
            self.log("Non-existent location given: %s" %
                     (self.options['condor_config'].value),
                     option='condor_config',
                     section=self.config_section,
                     level=logging.ERROR)

        self.log('CondorConfiguration.check_attributes completed returning %s' \
                 % attributes_ok)
        return attributes_ok
コード例 #12
0
class TestStorage(unittest.TestCase):
    """
    Unit test class to test StorageConfiguration class
    """

    def testParsing1(self):
        """
        Test storage parsing
        """

        # StorageConfiguration is not enabled on non-ce installs
        if not utilities.ce_installed():
            return

        config_file = get_test_config("storage/storage1.ini")
        configuration = ConfigParser.SafeConfigParser()
        configuration.read(config_file)

        settings = storage.StorageConfiguration(logger=global_logger)
        try:
            settings.parse_configuration(configuration)
        except Exception, e:
            self.fail("Received exception while parsing configuration: %s" % e)

        attributes = settings.get_attributes()
        variables = {'OSG_STORAGE_ELEMENT': 'True',
                     'OSG_DEFAULT_SE': 'test.domain.org',
                     'OSG_GRID': '/tmp',
                     'OSG_APP': '/tmp',
                     'OSG_DATA': '/var',
                     'OSG_WN_TMP': '/usr',
                     'OSG_SITE_READ': '/bin',
                     'OSG_SITE_WRITE': '/usr/bin'}
        for var in variables:
            self.assertTrue(attributes.has_key(var),
                            "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]))
        if not validation.valid_directory('/tmp/etc'):
            # handle cases where this is not run under osg test framework
            os.mkdir('/tmp/etc')
            os.chmod('/tmp/etc', 0777)
            self.assertTrue(settings.check_attributes(attributes))
            os.rmdir('/tmp/etc')
        else:
            self.assertTrue(settings.check_attributes(attributes))
コード例 #13
0
ファイル: gratia.py プロジェクト: bbockelm/osg-configure
    def _configure_lsf_probe(self):
        """
        Do lsf probe specific configuration
        """
        if (self._probe_config['lsf']['log_directory'] is None
                or self._probe_config['lsf']['log_directory'] == ''):
            self.log(
                "LSF accounting log directory not given, LSF gratia probe not configured",
                level=logging.ERROR,
                option='log_directory',
                section='LSF')
            return True
        log_directory = self._probe_config['lsf']['log_directory']
        if not validation.valid_directory(log_directory):
            self.log(
                "LSF accounting log not present, LSF gratia probe not configured",
                level=logging.ERROR,
                option='log_directory',
                section='LSF')
            return True
        config_location = GRATIA_CONFIG_FILES['lsf']
        buf = file(config_location).read()
        buf = self.replace_setting(buf,
                                   'lsfAcctLogDir',
                                   log_directory,
                                   xml_file=False)

        # setup lsfBinDir
        if (self._probe_config['lsf']['lsf_location'] is None
                or self._probe_config['lsf']['lsf_location'] == ''):
            self.log("LSF location not given, lsf gratia probe not configured",
                     level=logging.ERROR,
                     option='lsf_location',
                     section='LSF')
            return True
        lsf_bin_dir = os.path.join(self._probe_config['lsf']['lsf_location'],
                                   'bin')
        buf = self.replace_setting(buf,
                                   'lsfBinDir',
                                   lsf_bin_dir,
                                   xml_file=False)
        buf = self.replace_setting(buf, 'lrmsType', 'lsf', xml_file=False)
        if not utilities.atomic_write(config_location, buf):
            return False
        return True
コード例 #14
0
ファイル: pbs.py プロジェクト: brianhlin/osg-configure
    def check_attributes(self, attributes):
        """Check attributes currently stored and make sure that they are consistent"""
        self.log('PBSConfiguration.check_attributes started')

        attributes_ok = True

        if not self.enabled:
            self.log('PBS not enabled, returning True')
            self.log('PBSConfiguration.check_attributes completed')
            return attributes_ok

        if self.ignored:
            self.log('Ignored, returning True')
            self.log('PBSConfiguration.check_attributes completed')
            return attributes_ok

        # make sure locations exist
        if not validation.valid_location(self.options['pbs_location'].value):
            attributes_ok = False
            self.log("Non-existent location given: %s" %
                     (self.options['pbs_location'].value),
                     option='pbs_location',
                     section=self.config_section,
                     level=logging.ERROR)

        if not validation.valid_directory(self.pbs_bin_location):
            attributes_ok = False
            self.log("Given pbs_location %r has no bin/ directory" %
                     self.options['pbs_location'].value,
                     option='pbs_location',
                     section=self.config_section,
                     level=logging.ERROR)

        if self.opt_val('pbs_flavor') not in PBS_FLAVORS:
            attributes_ok = False
            self.log("Invalid pbs_flavor %s; should be one of %s" %
                     (self.opt_val('pbs_flavor'), ", ".join(PBS_FLAVORS)),
                     option='pbs_flavor',
                     section=self.config_section,
                     level=logging.ERROR)

        self.log('PBSConfiguration.check_attributes completed')
        return attributes_ok
コード例 #15
0
ファイル: gratia.py プロジェクト: djw8605/osg-configure
    def _configure_pbs_probe(self):
        """
        Do pbs probe specific configuration
        """
        if (self._probe_config['pbs']['accounting_log_directory'] is None or
                    self._probe_config['pbs']['accounting_log_directory'] == ''):
            return True
        accounting_dir = self._probe_config['pbs']['accounting_log_directory']
        if not validation.valid_directory(accounting_dir):
            self.log("PBS accounting log not present, PBS gratia probe not configured",
                     level=logging.ERROR,
                     option='accounting_log_directory',
                     section='PBS')
            return True

        config_location = GRATIA_CONFIG_FILES['pbs']
        buf = file(config_location).read()
        buf = self.replace_setting(buf, 'pbsAcctLogDir', accounting_dir, xml_file=False)
        buf = self.replace_setting(buf, 'lrmsType', 'pbs', xml_file=False)
        if not utilities.atomic_write(config_location, buf):
            return False
        return True
コード例 #16
0
ファイル: gratia.py プロジェクト: djw8605/osg-configure
    def _configure_lsf_probe(self):
        """
        Do lsf probe specific configuration
        """
        if (self._probe_config['lsf']['log_directory'] is None or
                    self._probe_config['lsf']['log_directory'] == ''):
            self.log("LSF accounting log directory not given, LSF gratia probe not configured",
                     level=logging.ERROR,
                     option='log_directory',
                     section='LSF')
            return True
        log_directory = self._probe_config['lsf']['log_directory']
        if not validation.valid_directory(log_directory):
            self.log("LSF accounting log not present, LSF gratia probe not configured",
                     level=logging.ERROR,
                     option='log_directory',
                     section='LSF')
            return True
        config_location = GRATIA_CONFIG_FILES['lsf']
        buf = file(config_location).read()
        buf = self.replace_setting(buf, 'lsfAcctLogDir', log_directory, xml_file=False)

        # setup lsfBinDir
        if (self._probe_config['lsf']['lsf_location'] is None or
                    self._probe_config['lsf']['lsf_location'] == ''):
            self.log("LSF location not given, lsf gratia probe not configured",
                     level=logging.ERROR,
                     option='lsf_location',
                     section='LSF')
            return True
        lsf_bin_dir = os.path.join(self._probe_config['lsf']['lsf_location'], 'bin')
        buf = self.replace_setting(buf, 'lsfBinDir', lsf_bin_dir, xml_file=False)
        buf = self.replace_setting(buf, 'lrmsType', 'lsf', xml_file=False)
        if not utilities.atomic_write(config_location, buf):
            return False
        return True
コード例 #17
0
ファイル: condor.py プロジェクト: djw8605/osg-configure
    def check_attributes(self, attributes):
        """Check attributes currently stored and make sure that they are consistent"""
        self.log('CondorConfiguration.check_attributes started')

        if not self.enabled:
            self.log('CondorConfiguration.check_attributes completed returning True')
            return True

        if self.ignored:
            self.log('CondorConfiguration.check_attributes completed returning True')
            return True

        attributes_ok = True

        # make sure locations exist
        self.log('checking condor_location')
        if not validation.valid_location(self.options['condor_location'].value):
            attributes_ok = False
            self.log("Non-existent location given: %s" %
                     (self.options['condor_location'].value),
                     option='condor_location',
                     section=self.config_section,
                     level=logging.ERROR)

        if not validation.valid_directory(self.condor_bin_location):
            attributes_ok = False
            self.log("Given condor_location %r has no bin/ directory" % self.options['condor_location'].value,
                     option='condor_location',
                     section=self.config_section,
                     level=logging.ERROR)

        self.log('checking condor_config')
        if not validation.valid_file(self.options['condor_config'].value):
            attributes_ok = False
            self.log("Non-existent location given: %s" %
                     (self.options['condor_config'].value),
                     option='condor_config',
                     section=self.config_section,
                     level=logging.ERROR)

        if not validation.valid_contact(self.options['job_contact'].value,
                                        'condor'):
            attributes_ok = False
            self.log("Invalid job contact: %s" %
                     (self.options['job_contact'].value),
                     option='job_contact',
                     section=self.config_section,
                     level=logging.ERROR)

        if not validation.valid_contact(self.options['util_contact'].value,
                                        'condor'):
            attributes_ok = False
            self.log("Invalid util contact: %s" %
                     (self.options['util_contact'].value),
                     option='util_contact',
                     section=self.config_section,
                     level=logging.ERROR)

        self.log('CondorConfiguration.check_attributes completed returning %s' \
                 % attributes_ok)
        return attributes_ok
コード例 #18
0
    def setupGramConfig(self):
        """
    Populate the gram config file with correct values
    
    Returns True if successful, False otherwise
    """
        buffer = open(SGEConfiguration.GRAM_CONFIG_FILE).read()
        bin_location = os.path.join(self.options['sge_root'].value, 'bin',
                                    'qsub')
        if validation.valid_file(bin_location):
            re_obj = re.compile('^qsub=.*$', re.MULTILINE)
            (buffer, count) = re_obj.subn("qsub=\"%s\"" % bin_location, buffer,
                                          1)
            if count == 0:
                buffer += "qsub=\"%s\"\n" % bin_location
        bin_location = os.path.join(self.options['sge_root'].value, 'bin',
                                    'qstat')
        if validation.valid_file(bin_location):
            re_obj = re.compile('^qstat=.*$', re.MULTILINE)
            (buffer, count) = re_obj.subn("qstat=\"%s\"" % bin_location,
                                          buffer, 1)
            if count == 0:
                buffer += "qstat=\"%s\"\n" % bin_location
        bin_location = os.path.join(self.options['sge_root'].value, 'bin',
                                    'qdel')
        if validation.valid_file(bin_location):
            re_obj = re.compile('^qdel=.*$', re.MULTILINE)
            (buffer, count) = re_obj.subn("qdel=\"%s\"" % bin_location, buffer,
                                          1)
            if count == 0:
                buffer += "qdel=\"%s\"\n" % bin_location

        new_setting = "sge_cell=\"%s\"" % self.options['sge_cell'].value
        re_obj = re.compile('^sge_cell=.*$', re.MULTILINE)
        (buffer, count) = re_obj.subn(new_setting, buffer, 1)
        if count == 0:
            buffer += new_setting + "\n"

        new_setting = "sge_root=\"%s\"" % self.options['sge_root'].value
        re_obj = re.compile('^sge_root=.*$', re.MULTILINE)
        (buffer, count) = re_obj.subn(new_setting, buffer, 1)
        if count == 0:
            buffer += new_setting + "\n"

        if self.options['seg_enabled'].value:
            if (self.options['log_directory'].value is None
                    or not validation.valid_directory(
                        self.options['log_directory'].value)):
                mesg = "%s is not a valid directory location " % self.options[
                    'log_directory'].value
                mesg += "for sge log files"
                self.log(mesg,
                         section=self.config_section,
                         option='log_directory',
                         level=logging.ERROR)
                return False

            new_setting = "log_path=\"%s\"" % self.options[
                'log_directory'].value
            re_obj = re.compile('^log_path=.*$', re.MULTILINE)
            (buffer, count) = re_obj.subn(new_setting, buffer, 1)
            if count == 0:
                buffer += new_setting + "\n"

        if self.options['default_queue'].value != '':
            re_obj = re.compile('^default_queue=.*$', re.MULTILINE)
            (buffer, count) = re_obj.subn(
                "default_queue=\"%s\"" % self.options['default_queue'].value,
                buffer, 1)
            if count == 0:
                buffer += "default_queue=\"%s\"\n" % self.options[
                    'default_queue'].value

            re_obj = re.compile('^validate_queues=.*$', re.MULTILINE)
            if self.options['validate_queues'].value:
                (buffer, count) = re_obj.subn('validate_queues=yes', buffer, 1)
                if count == 0:
                    buffer += "validate_queues=yes\n"
            else:
                (buffer, count) = re_obj.subn('validate_queues=no', buffer, 1)
                if count == 0:
                    buffer += "validate_queues=no\n"

        if self.options['available_queues'].value != '':
            re_obj = re.compile('^available_queues=.*$', re.MULTILINE)
            (buffer, count) = re_obj.subn(
                "available_queues=\"%s\"" %
                self.options['available_queues'].value, buffer, 1)
            if count == 0:
                buffer += 'available_queues="'
                buffer += self.options['available_queues'].value
                buffer += '"\n'

        if not utilities.atomic_write(SGEConfiguration.GRAM_CONFIG_FILE,
                                      buffer):
            return False
コード例 #19
0
    def checkAttributes(self, attributes):
        """Check attributes currently stored and make sure that they are consistent"""
        self.log('SGEConfiguration.checkAttributes started')
        attributes_ok = True
        if not self.enabled:
            self.log('SGE not enabled, returning True')
            self.log('SGEConfiguration.checkAttributes completed')
            return attributes_ok

        if self.ignored:
            self.log('Ignored, returning True')
            self.log('SGEConfiguration.checkAttributes completed')
            return attributes_ok

        # make sure locations exist
        if not validation.valid_location(self.options['sge_root'].value):
            attributes_ok = False
            self.log("Non-existent location given: %s" %
                     (self.options['sge_root'].value),
                     option='sge_root',
                     section=self.config_section,
                     level=logging.ERROR)

        settings_file = os.path.join(self.options['sge_root'].value,
                                     self.options['sge_cell'].value, 'common',
                                     'settings.sh')

        if not validation.valid_file(settings_file):
            attributes_ok = False
            self.log("$SGE_ROOT/$SGE_CELL/common/settings.sh not present: %s" %
                     settings_file,
                     option='sge_cell',
                     section=self.config_section,
                     level=logging.ERROR)

        if not self.validContact(self.options['job_contact'].value, 'sge'):
            attributes_ok = False
            self.log("Invalid job contact: %s" %
                     (self.options['job_contact'].value),
                     option='job_contact',
                     section=self.config_section,
                     level=logging.ERROR)

        if not self.validContact(self.options['util_contact'].value, 'sge'):
            attributes_ok = False
            self.log("Invalid util contact: %s" %
                     (self.options['util_contact'].value),
                     option='util_contact',
                     section=self.config_section,
                     level=logging.ERROR)

        if self.options['seg_enabled'].value:
            if (self.options['log_directory'].value is None
                    or not validation.valid_directory(
                        self.options['log_directory'].value)):
                mesg = "%s is not a valid directory location " % self.options[
                    'log_directory'].value
                mesg += "for sge log files"
                self.log(mesg,
                         section=self.config_section,
                         option='log_directory',
                         level=logging.ERROR)

        self.log('SGEConfiguration.checkAttributes completed')
        return attributes_ok
コード例 #20
0
ファイル: sge.py プロジェクト: djw8605/osg-configure
    def check_attributes(self, attributes):
        """Check attributes currently stored and make sure that they are consistent"""
        self.log('SGEConfiguration.check_attributes started')
        attributes_ok = True
        if not self.enabled:
            self.log('SGE not enabled, returning True')
            self.log('SGEConfiguration.check_attributes completed')
            return attributes_ok

        if self.ignored:
            self.log('Ignored, returning True')
            self.log('SGEConfiguration.check_attributes completed')
            return attributes_ok

        # make sure locations exist
        if not validation.valid_location(self.options['sge_root'].value):
            attributes_ok = False
            self.log("Non-existent location given: %s" %
                     (self.options['sge_root'].value),
                     option='sge_root',
                     section=self.config_section,
                     level=logging.ERROR)

        settings_file = os.path.join(self.options['sge_root'].value,
                                     self.options['sge_cell'].value,
                                     'common',
                                     'settings.sh')

        if not validation.valid_file(settings_file):
            attributes_ok = False
            self.log("$SGE_ROOT/$SGE_CELL/common/settings.sh not present: %s" %
                     settings_file,
                     option='sge_cell',
                     section=self.config_section,
                     level=logging.ERROR)

        if not validation.valid_directory(self.options['sge_bin_location'].value):
            attributes_ok = False
            self.log("sge_bin_location not valid: %s" % self.options['sge_bin_location'].value,
                     option='sge_bin_location',
                     section=self.config_section,
                     level=logging.ERROR)

        if not validation.valid_contact(self.options['job_contact'].value,
                                        'sge'):
            attributes_ok = False
            self.log("Invalid job contact: %s" %
                     (self.options['job_contact'].value),
                     option='job_contact',
                     section=self.config_section,
                     level=logging.ERROR)

        if not validation.valid_contact(self.options['util_contact'].value,
                                        'sge'):
            attributes_ok = False
            self.log("Invalid util contact: %s" %
                     (self.options['util_contact'].value),
                     option='util_contact',
                     section=self.config_section,
                     level=logging.ERROR)

        if self.options['seg_enabled'].value:
            if (self.options['log_file'].value is None or
                    not validation.valid_file(self.options['log_file'].value)):
                mesg = "%s is not a valid file path " % self.options['log_file'].value
                mesg += "for sge log files"
                self.log(mesg,
                         section=self.config_section,
                         option='log_file',
                         level=logging.ERROR)
                attributes_ok = False

        key = 'sge_config'
        if (not self.options[key].value or
                not validation.valid_file(self.options[key].value)):
            attributes_ok = False
            self.log("%s is not a valid file: %s" % (key, self.options[key].value),
                     section=self.config_section,
                     option=key,
                     level=logging.ERROR)

        self.log('SGEConfiguration.check_attributes completed')
        return attributes_ok
コード例 #21
0
        variables = {'OSG_STORAGE_ELEMENT': 'False',
                     'OSG_DEFAULT_SE': 'test.domain.org',
                     'OSG_GRID': '/usr',
                     'OSG_APP': '/tmp',
                     'OSG_DATA': '/usr/bin',
                     'OSG_WN_TMP': '/usr/sbin',
                     'OSG_SITE_READ': '/tmp',
                     'OSG_SITE_WRITE': '/var'}
        for var in variables:
            self.assertTrue(attributes.has_key(var),
                            "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]))
        if not validation.valid_directory('/tmp/etc'):
            # handle cases where this is not run under osg test framework
            os.mkdir('/tmp/etc')
            os.chmod('/tmp/etc', 0777)
            self.assertTrue(settings.check_attributes(attributes))
            os.rmdir('/tmp/etc')
        else:
            self.assertTrue(settings.check_attributes(attributes))

    def testParsing3(self):
        """
        Test storage parsing
        """

        # StorageConfiguration is not enabled on non-ce installs
        if not utilities.ce_installed():