def test_valid_user(self):
        """
        Check the valid_user functionality
        """

        self.assertTrue(validation.valid_user("root"), "root not marked as a valid user")

        self.assertFalse(validation.valid_user("hacked"), "'hacked' is considered a valid user")
Exemple #2
0
    def test_valid_user(self):
        """
        Check the valid_user functionality
        """

        self.assertTrue(validation.valid_user('root'),
                        "root not marked as a valid user")

        self.assertFalse(validation.valid_user('hacked'),
                         "'hacked' is considered a valid user")
Exemple #3
0
    def _parse_configuration(self, configuration):
        """
        The meat of parse_configuration, runs after we've checked that GIP is
        enabled and we have the right RPMs installed.
        """
        # The following is to set the user that gip files need to belong to
        # This can be overridden by setting the 'user' option in the [GIP] section
        self.gip_user = '******'
        if configuration.has_option(self.config_section, 'batch'):
            batch_opt = configuration.get(self.config_section, 'batch').lower()
            if (not utilities.blank(batch_opt)
                    and batch_opt not in self._valid_batch_opt):
                msg = "The batch setting in %s must be a valid option " \
                      "(e.g. %s), %s was given" % (self.config_section,
                                                   ",".join(self._valid_batch_opt),
                                                   batch_opt)
                self.log(msg, level=logging.ERROR)
                raise exceptions.SettingError(msg)

        if utilities.ce_installed():
            self._parse_configuration_ce(configuration)

        # Check for the presence of the classic SE
        has_classic_se = True
        try:
            has_classic_se = configuration.getboolean("GIP",
                                                      "advertise_gsiftp")
        # pylint: disable-msg=W0702
        # pylint: disable-msg=W0703
        # pylint: disable-msg=W0704
        except Exception:
            pass

        has_se = False
        for section in configuration.sections():
            if not section.lower().startswith('se'):
                continue
            has_se = True
            self.check_se(configuration, section)
        if not has_se and not has_classic_se:
            try:
                self._check_entry(configuration, "GIP", "se_name", REQUIRED,
                                  STRING)
            except:
                msg = "There is no `SE` section, the old-style SE" + \
                      "setup in GIP is not configured, and there is no classic SE. " + \
                      " At least one must be configured.  Please see the configuration" \
                      " documentation."
                raise exceptions.SettingError(msg)
        if configuration.has_option(self.config_section, 'user'):
            username = configuration.get(self.config_section, 'user')
            if not validation.valid_user(username):
                err_msg = "%s is not a valid account on this system" % username
                self.log(err_msg,
                         section=self.config_section,
                         option='user',
                         level=logging.ERROR)
                raise exceptions.SettingError(err_msg)
            self.gip_user = username
Exemple #4
0
    def _parse_configuration(self, configuration):
        """
        The meat of parse_configuration, runs after we've checked that GIP is
        enabled and we have the right RPMs installed.
        """
        # The following is to set the user that gip files need to belong to
        # This can be overridden by setting the 'user' option in the [GIP] section
        self.gip_user = '******'
        if configuration.has_option(self.config_section, 'batch'):
            batch_opt = configuration.get(self.config_section, 'batch').lower()
            if (not utilities.blank(batch_opt) and
                        batch_opt not in self._valid_batch_opt):
                msg = "The batch setting in %s must be a valid option " \
                      "(e.g. %s), %s was given" % (self.config_section,
                                                   ",".join(self._valid_batch_opt),
                                                   batch_opt)
                self.log(msg, level=logging.ERROR)
                raise exceptions.SettingError(msg)

        if utilities.ce_installed():
            self._parse_configuration_ce(configuration)

        # Check for the presence of the classic SE
        has_classic_se = True
        try:
            has_classic_se = configuration.getboolean("GIP", "advertise_gsiftp")
        # pylint: disable-msg=W0702
        # pylint: disable-msg=W0703
        # pylint: disable-msg=W0704
        except Exception:
            pass

        has_se = False
        for section in configuration.sections():
            if not section.lower().startswith('se'):
                continue
            has_se = True
            self.check_se(configuration, section)
        if not has_se and not has_classic_se:
            try:
                self._check_entry(configuration, "GIP", "se_name", REQUIRED, STRING)
            except:
                msg = "There is no `SE` section, the old-style SE" + \
                      "setup in GIP is not configured, and there is no classic SE. " + \
                      " At least one must be configured.  Please see the configuration" \
                      " documentation."
                raise exceptions.SettingError(msg)
        if configuration.has_option(self.config_section, 'user'):
            username = configuration.get(self.config_section, 'user')
            if not validation.valid_user(username):
                err_msg = "%s is not a valid account on this system" % username
                self.log(err_msg,
                         section=self.config_section,
                         option='user',
                         level=logging.ERROR)
                raise exceptions.SettingError(err_msg)
            self.gip_user = username
Exemple #5
0
    def check_attributes(self, attributes):
        """Check attributes currently stored and make sure that they are consistent"""
        self.log('BoscoConfiguration.check_attributes started')
        
        attributes_ok = True
        
        if not self.enabled:
            self.log('Bosco not enabled, returning True')
            self.log('BoscoConfiguration.check_attributes completed')
            return attributes_ok

        if self.ignored:
            self.log('Ignored, returning True')
            self.log('BoscoConfiguration.check_attributes completed')
            return attributes_ok
            
        #if not validation.valid_domain(self.options['endpoint'].value):
        #    attributes_ok = False
        #    self.log("Endpoint is not a valid hostname: %s" % 
        #             (self.options['endpoint'].value),
        #             option='endpoint',
        #             section=self.config_section,
        #             level=logging.ERROR)
        
        if self.options['batch'].value not in ['pbs', 'lsf', 'sge', 'condor', 'slurm']:
            attributes_ok = False
            self.log("Batch attribute is not valid: %s" % 
                     (self.options['batch'].value),
                     option='batch',
                     section=self.config_section,
                     level=logging.ERROR)
        
        # Change the  batch value to pbs if it slurm, for now
        if self.options['batch'].value is 'slurm':
            self.options['batch'].value = 'pbs'
        
        # TODO: check if the ssh_key has the correct permissions!
        if not validation.valid_file(self.options['ssh_key'].value):
            attributes_ok = False
            self.log("ssh_key given is not a file: %s" %
                     (self.options['ssh_key'].value),
                     option='ssh_key',
                     section=self.config_section,
                     level=logging.ERROR)
        
        
        if not validation.valid_integer(self.options['max_jobs'].value):
            attributes_ok = False
            self.log("max_jobs is not an integer: %s" %
                     (self.options['max_jobs'].value),
                     option='max_jobs',
                     section=self.config_section,
                     level=logging.ERROR)
        
        # Split the users, comma seperated
        split_users = self.options['users'].value.split(',')
        for user in split_users:
            if not validation.valid_user(user.strip()):
                attributes_ok = False
                self.log("%s is not a valid user" %
                         (user.strip()),
                         option='users',
                         section=self.config_section,
                         level=logging.ERROR)

        # TODO: validate list of usernames

        endpoint = self.options['endpoint'].value
        if len(endpoint.split('@')) != 2:
            attributes_ok = False
            self.log("endpoint not in user@host format: %s" %
                     endpoint,
                     option='endpoint',
                     section=self.config_section,
                     level=logging.ERROR)
        
        self.log('BoscoConfiguration.check_attributes completed')
        return attributes_ok