Exemplo n.º 1
0
def add_user(vo, usercert, use_voms_admin=False):
    """Add the user identified by the given cert to the specified VO. May use voms-admin or direct MySQL statements.
    The CA cert that issued the user cert must already be in the database's 'ca' table - this happens automatically if
    the CA cert is in /etc/grid-security/certificates when the VOMS database is created.
    """
    usercert_dn, usercert_issuer = cagen.certificate_info(usercert)
    if use_voms_admin:
        hostname = socket.getfqdn()

        command = ('voms-admin', '--vo', core.config['voms.vo'], '--host',
                   hostname, '--nousercert', 'create-user', usercert_dn,
                   usercert_issuer, 'OSG Test User', 'root@localhost')
        core.check_system(command, 'Add VO user')

    else:
        dbname = 'voms_' + vo

        # Find the index in the "ca" table ("cid") for the OSG Test CA that gets created by voms_install_db.
        output, _, _, = mysql.check_execute(
            r'''SELECT cid FROM ca WHERE ca='%(usercert_issuer)s';''' %
            locals(), 'Get ID of user cert issuer from database', dbname)
        output = output.strip()
        assert output, "User cert issuer not found in database"
        ca = int(output)

        mysql.check_execute(
            r'''
            INSERT INTO `usr` VALUES (1,'%(usercert_dn)s',%(ca)d,NULL,'root@localhost',NULL);
            INSERT INTO `m` VALUES (1,1,1,NULL,NULL);''' % locals(),
            'Add VO user', dbname)
Exemplo n.º 2
0
def add_user(vo, usercert, use_voms_admin=False):
    """Add the user identified by the given cert to the specified VO. May use voms-admin or direct MySQL statements.
    The CA cert that issued the user cert must already be in the database's 'ca' table - this happens automatically if
    the CA cert is in /etc/grid-security/certificates when the VOMS database is created.
    """
    usercert_dn, usercert_issuer = cagen.certificate_info(usercert)
    if use_voms_admin:
        hostname = socket.getfqdn()

        command = ('voms-admin', '--vo', core.config['voms.vo'], '--host', hostname, '--nousercert', 'create-user',
               usercert_dn, usercert_issuer, 'OSG Test User', 'root@localhost')
        core.check_system(command, 'Add VO user')

    else:
        dbname = 'voms_' + vo

        # Find the index in the "ca" table ("cid") for the OSG Test CA that gets created by voms_install_db.
        output, _, _, = mysql.check_execute(r'''SELECT cid FROM ca WHERE ca='%(usercert_issuer)s';''' % locals(),
                                            'Get ID of user cert issuer from database', dbname)
        output = output.strip()
        assert output, "User cert issuer not found in database"
        ca = int(output)

        mysql.check_execute(r'''
            INSERT INTO `usr` VALUES (1,'%(usercert_dn)s',%(ca)d,NULL,'root@localhost',NULL);
            INSERT INTO `m` VALUES (1,1,1,NULL,NULL);''' % locals(),
            'Add VO user', dbname)
Exemplo n.º 3
0
    def test_02_start_slurmdbd(self):
        core.state['slurmdbd.started-service'] = False
        self.slurm_reqs()
        core.skip_ok_unless_installed('slurm-slurmdbd')
        self.skip_bad_unless(mysql.is_running(), 'slurmdbd requires mysql')
        core.config['slurmdbd.config'] = '/etc/slurm/slurmdbd.conf'
        core.config['slurmdbd.user'] = "******"
        core.config['slurmdbd.name'] = "osg_test_slurmdb"

        mysql.check_execute("create database %s; " % core.config['slurmdbd.name'], 'create slurmdb')
        mysql.check_execute("create user %s; " % core.config['slurmdbd.user'], 'add slurmdb user')
        mysql.check_execute("grant usage on *.* to %s; " % core.config['slurmdbd.user'], 'slurmdb user access')
        mysql.check_execute("grant all privileges on %s.* to %s identified by '%s'; " % (core.config['slurmdbd.name'],
                                                                                         core.config['slurmdbd.user'],
                                                                                         core.options.password),
                            'slurmdb user permissions')
        mysql.check_execute("flush privileges;", 'reload privileges')

        db_config_vals = {'name':core.config['slurmdbd.name'],
                          'user':core.config['slurmdbd.user'].split('\'')[1],
                          'pass':core.options.password}
        files.write(core.config['slurmdbd.config'],
                    SLURMDBD_CONFIG % db_config_vals,
                    owner='slurm',
                    chmod=0o644)
        service.check_start('slurmdbd')

        # Adding the cluster to the database
        command = ('sacctmgr', '-i', 'add', 'cluster', CLUSTER_NAME)
        core.check_system(command, 'add slurm cluster')
Exemplo n.º 4
0
 def test_02_stop_slurmdbd(self):
     self.slurm_reqs()
     core.skip_ok_unless_installed('slurm-slurmdbd')
     self.skip_ok_unless(core.state['slurmdbd.started-service'], 'did not start slurmdbd')
     # service requires config so we stop it first; use stop() since slurmdbd fails to remove pid file
     service.stop('slurmdbd')
     files.restore(core.config['slurmdbd.config'], 'slurm')
     mysql.check_execute("drop database %s; " % core.config['slurmdbd.name'] + \
                         "drop user %s;" % core.config['slurmdbd.user'],
                         'drop mysql slurmdb')
Exemplo n.º 5
0
 def test_02_stop_slurmdbd(self):
     self.slurm_reqs()
     core.skip_ok_unless_installed('slurm-slurmdbd')
     self.skip_ok_unless(core.state['slurmdbd.started-service'],
                         'did not start slurmdbd')
     # service requires config so we stop it first; use stop() since slurmdbd fails to remove pid file
     service.stop('slurmdbd')
     files.restore(core.config['slurmdbd.config'], 'slurm')
     mysql.check_execute("drop database %s; " % core.config['slurmdbd.name'] + \
                         "drop user %s;" % core.config['slurmdbd.user'],
                         'drop mysql slurmdb')
Exemplo n.º 6
0
    def test_02_start_slurmdbd(self):
        core.state['slurmdbd.started-service'] = False
        core.state['slurmdbd.ready'] = False
        self.slurm_reqs()
        self.skip_bad_unless(mysql.is_running(), 'slurmdbd requires mysql')
        core.config['slurmdbd.config'] = os.path.join(
            core.config['slurm.config-dir'], 'slurmdbd.conf')
        core.config['slurmdbd.user'] = "******"
        core.config['slurmdbd.name'] = "osg_test_slurmdb"

        mysql.check_execute(
            "create database %s; " % core.config['slurmdbd.name'],
            'create slurmdb')
        mysql.check_execute("create user %s; " % core.config['slurmdbd.user'],
                            'add slurmdb user')
        mysql.check_execute(
            "grant usage on *.* to %s; " % core.config['slurmdbd.user'],
            'slurmdb user access')
        mysql.check_execute(
            "grant all privileges on %s.* to %s identified by '%s'; " %
            (core.config['slurmdbd.name'], core.config['slurmdbd.user'],
             core.options.password), 'slurmdb user permissions')
        mysql.check_execute("flush privileges;", 'reload privileges')

        files.write(core.config['slurmdbd.config'],
                    SLURMDBD_CONFIG.format(
                        name=core.config['slurmdbd.name'],
                        user=core.config['slurmdbd.user'].split('\'')[1],
                        password=core.options.password,
                        port=mysql.PORT),
                    owner='slurm',
                    chmod=0o644)

        stat = core.get_stat(SLURMDBD_LOG)
        service.check_start('slurmdbd')
        sentinel = core.monitor_file(SLURMDBD_LOG, stat,
                                     'slurmdbd version.+started', 30.0)
        if sentinel:
            core.state['slurmdbd.ready'] = True

        # Adding the cluster to the database
        command = ('sacctmgr', '-i', 'add', 'cluster', CLUSTER_NAME)
        core.check_system(command, 'add slurm cluster')
Exemplo n.º 7
0
def add_user(vo, usercert):
    """Add the user identified by the given cert to the specified VO. Uses direct MySQL statements instead of voms-admin.
    The CA cert that issued the user cert must already be in the database's 'ca' table - this happens automatically if
    the CA cert is in /etc/grid-security/certificates when the VOMS database is created.
    """
    usercert_dn, usercert_issuer = cagen.certificate_info(usercert)
    dbname = 'voms_' + vo

    # Find the index in the "ca" table ("cid") for the OSG Test CA that gets created by voms_install_db.
    output, _, _, = mysql.check_execute(
        r'''SELECT cid FROM ca WHERE ca='%(usercert_issuer)s';''' % locals(),
        'Get ID of user cert issuer from database', dbname)
    output = output.strip()
    assert output, "User cert issuer not found in database"
    ca = int(output)

    mysql.check_execute(
        r'''
        INSERT INTO `usr` VALUES (1,'%(usercert_dn)s',%(ca)d,NULL,'root@localhost',NULL);
        INSERT INTO `m` VALUES (1,1,1,NULL,NULL);''' % locals(), 'Add VO user',
        dbname)
Exemplo n.º 8
0
    def test_02_start_slurmdbd(self):
        core.state['slurmdbd.started-service'] = False
        self.slurm_reqs()
        core.skip_ok_unless_installed('slurm-slurmdbd')
        self.skip_bad_unless(mysql.is_running(), 'slurmdbd requires mysql')
        core.config['slurmdbd.config'] = os.path.join(
            core.config['slurm.config-dir'], 'slurmdbd.conf')
        core.config['slurmdbd.user'] = "******"
        core.config['slurmdbd.name'] = "osg_test_slurmdb"

        mysql.check_execute(
            "create database %s; " % core.config['slurmdbd.name'],
            'create slurmdb')
        mysql.check_execute("create user %s; " % core.config['slurmdbd.user'],
                            'add slurmdb user')
        mysql.check_execute(
            "grant usage on *.* to %s; " % core.config['slurmdbd.user'],
            'slurmdb user access')
        mysql.check_execute(
            "grant all privileges on %s.* to %s identified by '%s'; " %
            (core.config['slurmdbd.name'], core.config['slurmdbd.user'],
             core.options.password), 'slurmdb user permissions')
        mysql.check_execute("flush privileges;", 'reload privileges')

        db_config_vals = {
            'name': core.config['slurmdbd.name'],
            'user': core.config['slurmdbd.user'].split('\'')[1],
            'pass': core.options.password
        }
        files.write(core.config['slurmdbd.config'],
                    SLURMDBD_CONFIG % db_config_vals,
                    owner='slurm',
                    chmod=0o644)
        service.check_start('slurmdbd')

        # Adding the cluster to the database
        command = ('sacctmgr', '-i', 'add', 'cluster', CLUSTER_NAME)
        core.check_system(command, 'add slurm cluster')