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 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)
Example #3
0
    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)
Example #4
0
    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)
Example #5
0
    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)

        self.log('PBSConfiguration.check_attributes completed')
        return attributes_ok
Example #6
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
Example #7
0
    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
Example #8
0
    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
Example #9
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
Example #10
0
    def check_attributes(self, attributes):
        """Check attributes currently stored and make sure that they are consistent"""
        self.log('NetworkConfiguration.check_attributes started')
        attributes_ok = True

        for name in ['source_state_file', 'port_state_file']:
            if utilities.blank(self.options[name].value):
                continue

            if not validation.valid_location(self.options[name].value):
                self.log("File is not present: %s" % self.options[name].value,
                         option=name,
                         section=self.config_section,
                         level=logging.WARNING)

        for name in ['source_range', 'port_range']:
            if utilities.blank(self.options[name].value):
                continue

            matches = re.match(r'(\d+),(\d+)', self.options[name].value)
            if matches is None:
                self.log("Invalid range specification, expected low_port,high_port, " +
                         "got %s" % self.options[name].value,
                         option=name,
                         section=self.config_section,
                         level=logging.ERROR)
                attributes_ok = False

        if (not utilities.blank(self.options['source_state_file'].value) and
                utilities.blank(self.options['source_range'].value)):
            self.log("If you specify a source_state_file, " +
                     "source_range must be given",
                     option='source_state_file',
                     section=self.config_section,
                     level=logging.ERROR)
            attributes_ok = False

        if (not utilities.blank(self.options['port_state_file'].value) and
                utilities.blank(self.options['port_range'].value)):
            self.log("If you specify a port_state_file, " +
                     "port_range must be given",
                     option='port_state_file',
                     section=self.config_section,
                     level=logging.ERROR)
            attributes_ok = False

        self.log('NetworkConfiguration.check_attributes completed')
        return attributes_ok
Example #11
0
    def check_attributes(self, attributes):
        """Check attributes currently stored and make sure that they are consistent"""
        self.log('InstallLocations.check_attributes started')
        attributes_ok = True

        if self._self_configured:
            return True

        # make sure locations exist
        for option in self.options.values():
            if option.name == 'user_vo_map':
                # skip the user vo map check since we'll create it later if it doesn't
                # exist
                continue
            if not validation.valid_location(option.value):
                attributes_ok = False
                self.log("Invalid location: %s" % option.value,
                         option=option.name,
                         section=self.config_section,
                         level=logging.ERROR)

        self.log('InstallLocations.check_attributes completed')
        return attributes_ok
Example #12
0
    def check_attributes(self, attributes):
        """Check attributes currently stored and make sure that they are consistent"""
        self.log('InstallLocations.check_attributes started')
        attributes_ok = True

        if self._self_configured:
            return True

        # make sure locations exist
        for option in self.options.values():
            if option.name == 'user_vo_map':
                # skip the user vo map check since we'll create it later if it doesn't
                # exist
                continue
            if not validation.valid_location(option.value):
                attributes_ok = False
                self.log("Invalid location: %s" % option.value,
                         option=option.name,
                         section=self.config_section,
                         level=logging.ERROR)

        self.log('InstallLocations.check_attributes completed')
        return attributes_ok
Example #13
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
Example #14
0
    def _check_app_dir(self, app_dir):
        """"
        Checks to make sure that the OSG_APP directory exists and the VO directories have
        the proper permissions.  Returns True if everything is okay, False otherwise.

        APP_DIR must exist and have a etc directory with 1777 permissions for success.

        If APP_DIR begins with /cvmfs/oasis.opensciencegrid.org, skip tests

        If APP_DIR is explicitly UNSET, skip tests
        """
        try:
            if self._app_dir_in_oasis(app_dir):
                self.log('OSG_APP is an OASIS repository, skipping tests',
                         level=logging.INFO)
                return True

            # Added for SOFTWARE-1567
            if app_dir == 'UNSET':
                self.log('OSG_APP is UNSET, skipping tests',
                         level=logging.INFO)
                return True

            if app_dir == 'UNAVAILABLE':
                self.log('OSG_APP ("app_dir" in the [Storage]) section is not configured.'
                         ' If it is not available, explicitly set it to UNSET.'
                         ' Otherwise, point it to the directory VO software can be obtained from.'
                         , level=logging.WARNING)
                return True

            if not validation.valid_location(app_dir) or not os.path.isdir(app_dir):
                self.log("Directory not present: %s" % app_dir,
                         section=self.config_section,
                         option='app_dir',
                         level=logging.ERROR)
                return False

            etc_dir = os.path.join(app_dir, "etc")
            if not validation.valid_location(etc_dir) or not os.path.isdir(etc_dir):
                self.log("$OSG_APP/etc directory not present: %s" % etc_dir,
                         section=self.config_section,
                         option='app_dir',
                         level=logging.ERROR)
                return False

            permissions = stat.S_IMODE(os.stat(etc_dir).st_mode)
            # check to make sure permissions are 777, 1777 2777 775 1775 2775 755 1755 2755
            all_rwx = stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO
            og_rwx = stat.S_IRWXU | stat.S_IRWXG | stat.S_IROTH | stat.S_IXOTH
            o_rwx = stat.S_IRWXU | stat.S_IRGRP | stat.S_IXGRP
            o_rwx |= stat.S_IROTH | stat.S_IXOTH
            allowed = [all_rwx | stat.S_ISVTX,  # 1777
                       all_rwx,  # 777
                       all_rwx | stat.S_ISGID,  # 2777
                       og_rwx,  # 775
                       og_rwx | stat.S_ISVTX,  # 2775
                       og_rwx | stat.S_ISGID,  # 2775
                       o_rwx,  # 755
                       o_rwx | stat.S_ISVTX,  # 1755
                       o_rwx | stat.S_ISGID]  # 2755
            if permissions not in allowed:
                self.log("Permissions on $OSG_APP/etc should be 777, 1777, " \
                         "2777, 775, 1775, 2775, 755, 1755, 2755 " \
                         "for sites: %s" % etc_dir,
                         section=self.config_section,
                         option='app_dir',
                         level=logging.WARNING)
        # pylint: disable-msg=W0703
        except Exception:
            self.log("Can't check $OSG_APP, got an exception",
                     level=logging.ERROR,
                     exception=True)
            return False

        return True
Example #15
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,
                                     '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
Example #16
0
    def _check_app_dir(self, app_dir):
        """"
        Checks to make sure that the OSG_APP directory exists and the VO directories have
        the proper permissions.  Returns True if everything is okay, False otherwise.

        APP_DIR must exist and have a etc directory with 1777 permissions for success.

        If APP_DIR begins with /cvmfs/oasis.opensciencegrid.org, skip tests

        If APP_DIR is explicitly UNSET, skip tests
        """
        try:
            if self._app_dir_in_oasis(app_dir):
                self.log("OSG_APP is an OASIS repository, skipping tests", level=logging.INFO)
                return True

            # Added for SOFTWARE-1567
            if app_dir == "UNSET":
                self.log("OSG_APP is UNSET, skipping tests", level=logging.INFO)
                return True

            if app_dir == "UNAVAILABLE":
                self.log(
                    'OSG_APP ("app_dir" in the [Storage]) section is not configured.'
                    " If it is not available, explicitly set it to UNSET."
                    " Otherwise, point it to the directory VO software can be obtained from.",
                    level=logging.WARNING,
                )
                return True

            if not validation.valid_location(app_dir) or not os.path.isdir(app_dir):
                self.log(
                    "Directory not present: %s" % app_dir,
                    section=self.config_section,
                    option="app_dir",
                    level=logging.ERROR,
                )
                return False

            etc_dir = os.path.join(app_dir, "etc")
            if not validation.valid_location(etc_dir) or not os.path.isdir(etc_dir):
                self.log(
                    "$OSG_APP/etc directory not present: %s" % etc_dir,
                    section=self.config_section,
                    option="app_dir",
                    level=logging.ERROR,
                )
                return False

            permissions = stat.S_IMODE(os.stat(etc_dir).st_mode)
            # check to make sure permissions are 777, 1777 2777 775 1775 2775 755 1755 2755
            all_rwx = stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO
            og_rwx = stat.S_IRWXU | stat.S_IRWXG | stat.S_IROTH | stat.S_IXOTH
            o_rwx = stat.S_IRWXU | stat.S_IRGRP | stat.S_IXGRP
            o_rwx |= stat.S_IROTH | stat.S_IXOTH
            allowed = [
                all_rwx | stat.S_ISVTX,  # 1777
                all_rwx,  # 777
                all_rwx | stat.S_ISGID,  # 2777
                og_rwx,  # 775
                og_rwx | stat.S_ISVTX,  # 2775
                og_rwx | stat.S_ISGID,  # 2775
                o_rwx,  # 755
                o_rwx | stat.S_ISVTX,  # 1755
                o_rwx | stat.S_ISGID,
            ]  # 2755
            if permissions not in allowed:
                self.log(
                    "Permissions on $OSG_APP/etc should be 777, 1777, "
                    "2777, 775, 1775, 2775, 755, 1755, 2755 "
                    "for sites: %s" % etc_dir,
                    section=self.config_section,
                    option="app_dir",
                    level=logging.WARNING,
                )
        # pylint: disable-msg=W0703
        except Exception:
            self.log("Can't check $OSG_APP, got an exception", level=logging.ERROR, exception=True)
            return False

        return True
Example #17
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)

        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
Example #18
0
    def _check_auth_settings(self):
        """ Check authorization/certificate settings and make sure that they are valid """

        check_value = True

        # Do not allow both the service cert settings and proxy settings
        # first create some helper variables
        blank_service_vals = (
            utilities.blank(self.options['service_cert'].value)
            and utilities.blank(self.options['service_key'].value)
            and utilities.blank(self.options['service_proxy'].value))

        default_service_vals = (self.options['service_cert'].value ==
                                self.options['service_cert'].default_value)
        default_service_vals &= (self.options['service_key'].value ==
                                 self.options['service_key'].default_value)
        default_service_vals &= (self.options['service_proxy'].value ==
                                 self.options['service_proxy'].default_value)

        blank_user_proxy = utilities.blank(self.options['user_proxy'].value)

        if (not blank_user_proxy and default_service_vals):
            self.log('User proxy specified and service_cert, service_key, ' +
                     'service_proxy at default values, assuming user_proxy ' +
                     'takes precedence in ' + self.config_section + ' section')
            self.use_service_cert = False
        elif not blank_user_proxy and not blank_service_vals:
            self.log(
                "You cannot specify user_proxy with any of (service_cert, " +
                "service_key, service_proxy).  They are mutually exclusive " +
                "options in %s section." % self.config_section,
                level=logging.ERROR)
            check_value = False

        # Make sure that either a service cert or user cert is selected
        if not ((self.options['service_cert'].value
                 and self.options['service_key'].value
                 and self.options['service_proxy'].value)
                or self.options['user_proxy'].value):
            self.log("You must specify either service_cert/service_key/" +
                     "service_proxy *or* user_proxy in order to provide " +
                     "credentials for RSV to run jobs in " +
                     " %s section" % self.config_section,
                     level=logging.ERROR)
            check_value = False

        if not blank_user_proxy:
            # if not using a service certificate, make sure that the proxy file exists
            value = self.options['user_proxy'].value
            if utilities.blank(value) or not validation.valid_file(value):
                self.log("user_proxy does not point to an existing file: %s" %
                         value,
                         section=self.config_section,
                         option='user_proxy',
                         level=logging.ERROR)
                check_value = False
        else:
            for optname in 'service_cert', 'service_key':
                value = self.options[optname].value
                if utilities.blank(value):
                    self.log("%s must have a valid location" % optname,
                             section=self.config_section,
                             option=optname,
                             level=logging.ERROR)
                    check_value = False
                elif not self.copy_host_cert_for_service_cert and not validation.valid_file(
                        value):
                    self.log("%s must point to an existing file" % optname,
                             section=self.config_section,
                             option=optname,
                             level=logging.ERROR)
                    check_value = False

            value = self.options['service_proxy'].value
            if utilities.blank(value):
                self.log("service_proxy must have a valid location: %s" %
                         value,
                         section=self.config_section,
                         option='service_proxy',
                         level=logging.ERROR)
                check_value = False

            value = os.path.dirname(self.options['service_proxy'].value)
            if not validation.valid_location(value):
                self.log("service_proxy must be located in a valid " +
                         "directory: %s" % value,
                         section=self.config_section,
                         option='service_proxy',
                         level=logging.ERROR)
                check_value = False

        return check_value