Esempio n. 1
0
def _get_src_nid(filename):
    master_node = 0
    net_info = ""

    while True:
        cmd = "sdfs.stat %s -v | grep master | awk '{print $7}'" % (filename)
        out, err = exec_shell(cmd, p=False, need_return=True)
        if len(out.split('\n')[0]) != 0:
            master_node = int(out.split('\n')[0])
            break

    dmsg("++++++++++++++filename:%s, master:%d+++++++++++++++" % (filename, master_node))
    if master_node == 0:
        cmd = "sdfs.stat %s -v | grep available | awk '{print $1,$2}' | tail -n1" % (filename)
    else:
        cmd = "sdfs.stat %s -v | grep available | awk '{print $1,$2}' | head -n1" % (filename)

    while True:
        out, err = exec_shell(cmd, p=False, need_return=True)
        if len(out.split('\n')[0]) != 0:
            net_info = out.split('\n')[0]
            break

    nid = net_info.split(" ")[1].split("(")[1].split(")")[0]

    return nid
Esempio n. 2
0
def file_set_attr(config, key, value, filename):
    cmd = "%s -s %s -V %s %s" % (config.uss_attr, key, value, filename)
    try:
        exec_shell(cmd)
        return True
    except Exp, err:
        return False
Esempio n. 3
0
def _get_dest_nid(filename):
    replica_nids = []
    cluster_nids = []
    dest_nid = ""

    cmd = "sdfs.stat %s -v | grep net |awk '{print $2}'| cut -d '(' -f2 | cut -d ')' -f 1" % (filename)
    out, err = exec_shell(cmd, p=False, need_return=True)
    replica_nids = out.split('\n')
    if replica_nids[len(replica_nids) - 1] == "":
        replica_nids.pop() #delete the last '\n'

    print "replica nid:%s" % (replica_nids)

    cmd = "sdfs.cluster list | grep cds | grep running | awk '{print $3}'"
    out, err = exec_shell(cmd, p=False, need_return=True)
    cluster_nids = out.split('\n')
    if cluster_nids[len(cluster_nids) - 1] == "":
        cluster_nids.pop() #delete the last '\n'

    print "cluster nid:%s" % (cluster_nids)
    for nid in cluster_nids:
        if nid not in replica_nids:
            dest_nid = nid
            break

    return dest_nid
Esempio n. 4
0
def _mount():
    cmd = "mount | grep /dev/drbd0|grep /var/lib/leveldb"
    try:
        exec_shell(cmd)
    except Exp, e:
        dwarn('%s' % e)
        return False
Esempio n. 5
0
def is_redis_stop():
    cmd = "ps -ef | grep redis-server | grep -v grep"
    try:
        exec_shell(cmd)  #redis exists
        return False
    except Exp, e:
        return True  #redis stopped
Esempio n. 6
0
def mounted(mount_point='/mnt/nfs'):
    _exec = 'cat /proc/mounts | grep %s' % (mount_point)
    try:
        exec_shell(_exec, need_return=True, timeout=10)
    except Exp, e:
        dwarn("%s : %s\n" % (_exec, str(e)))
        return False
Esempio n. 7
0
def vip_isexist(vip):
    cmd = "ip addr | grep '%s/' >/dev/null" % (vip)
    try:
        exec_shell(cmd, p=False)
        return True
    except Exp, e:
        return False
Esempio n. 8
0
def _vip_exist(eth, vip):
    cmd = "ip addr|grep %s|grep %s" % (vip, eth)
    try:
        exec_shell(cmd, p=True)
    except Exp, e:
        dwarn('_vip exist %s' % e)
        return False
Esempio n. 9
0
def connected_ad():
    _exec_wbinfo = "/usr/local/samba/bin/wbinfo -t"
    try:
        exec_shell(_exec_wbinfo)
        return True
    except Exp, e:
        return False
Esempio n. 10
0
def _delete_local_vip(vip, mask):
    try:
        dev = get_dev_by_addr(vip)
        cmd = "ip addr del %s/%s dev %s" % (vip, mask, dev)
        exec_shell(cmd)
    except Exp, e:
        raise Exp(e.errno, "delete vip:%s dev:%s fail, %s", vip, dev, e.err)
Esempio n. 11
0
def locks_destroy():
    cmd = "rm -rf %s" % NFS_LOCK_PATH
    try:
        exec_shell(cmd)
    except Exp, e:
        ret = e.errno
        raise Exp(ret, "%s failed. ret: %d, %s" % (cmd, ret, e))
Esempio n. 12
0
def umount_nfsv4(mount_point='/mnt/nfs'):
    _exec = 'umount -l %s' % mount_point
    try:
        exec_shell(_exec)
    except Exp, e:
        derror('umount %s failed' % (mount_point))
        sys.exit(e.errno)
Esempio n. 13
0
def _create(args):
    config = Config()
    for i in range(args.n):
        filename = "xx_%d.txt" % (i)
        abs_file = os.path.join(args.dir, filename)
        cmd = "%s %s" % (config.uss_touch, abs_file)
        exec_shell(cmd)
Esempio n. 14
0
def create_ftp_user(config, username, password):
    _exec = '%s -s -g 5000 -u 5000 -p %s %s' % \
                    (config.uss_user, password, username)
    try:
        exec_shell(_exec, timeout=10)
    except Exp, e:
        logging.error('errno:%d, error:%s' % (e.errno, str(e)))
        sys.exit(-1)
Esempio n. 15
0
def group_ls():
    try:
        cmd = "sdfs.group -l"
        exec_shell(cmd)
    except Exception as e:
        derror("%s: ret:%s, %s" % (cmd, e.errno, os.strerror(e.errno)))
        sys.exit(e.errno)
    print '\n'
Esempio n. 16
0
def register(slist, hlist):
    for ssd in slist:
        _exec_echo = "echo %s > /sys/fs/bcache/register" % ssd
        try:
            exec_shell(_exec_echo)
        except Exp, err:
            dwarn('%s register failed' % (ssd))
            return False
Esempio n. 17
0
def create_group(config, groupname):
    _exec = '%s -s -g 5000 %s' % (config.uss_group, groupname)

    try:
        exec_shell(_exec, timeout=10)
    except Exp, e:
        logging.error('errno:%d, error:%s' % (e.errno, str(e)))
        sys.exit(-1)
Esempio n. 18
0
def _minio_cmd(cmd):
    try:
        exec_shell(cmd)
        return ERROR_SUCCESS
    except Exp, e:
        minio_log = "%s failed, %s." % (cmd, os.strerror(e.errno))
        #redis_log(MINIO_LOG_ERR, MINIO_NAME, minio_log)
        return e.errno
Esempio n. 19
0
def locks_init():
    content = str(uuid.uuid1())
    cmd = "mkdir %s" % NFS_LOCK_PATH
    try:
        exec_shell(cmd)
    except Exp, e:
        ret = e.errno
        if (ret != errno.EEXIST):
            raise Exp(ret, "%s failed. ret: %d, %s" % (cmd, ret, e))
Esempio n. 20
0
def _check_localdisk():
    states = drbd_dstate()
    if states[0] in ['Failed', 'Diskless']:
        raise Exp("disk error")
        #cmd = "uss.node stop"
        #exec_shell(cmd)

    cmd = "mount|grep '/var/lib/leveldb'"
    exec_shell(cmd)
Esempio n. 21
0
def file_move(config, src_file, dst_file):
    cmd = "%s %s %s" % (config.uss_mv, src_file, dst_file)
    try:
        exec_shell(cmd)
        file_set_attr(config, "move", "true", dst_file)
        return True
    except Exp, err:
        file_set_attr(config, "move", "false", dst_file)
        return False
Esempio n. 22
0
 def tenant_del(self, name):
     fname = _get_full_name(name, is_raise=0)
     if len(fname) != 0:
         cmd = "ps -ef | grep '%s ' | grep -v 'grep' | awk '{print $2}'| xargs kill -9" % (fname)
         exec_shell(cmd)
         cmd = "rm -rf %s/%s" % (MINIO_CONF_PATH, fname)
         exec_shell(cmd)
     else:
         dwarn("name:%s not exists, please check it!" % name)
Esempio n. 23
0
def test_mkdir(config):
    try:
        _exec_mkdir = "%s /zz" % (config.uss_mkdir)
        exec_shell(_exec_mkdir)
        _exec_stat = "%s /zz" % (config.uss_stat)
        exec_shell(_exec_stat)
    except Exp, err:
        dmsg("test_mkdir or test_stat failed\n")
        sys.exit(-1)
Esempio n. 24
0
def samba_stop():
    smbd_location = "/usr/local/samba/sbin/smbd"
    nmbd_location = "/usr/local/samba/sbin/nmbd"

    if os.path.isfile(smbd_location) and os.path.isfile(nmbd_location):
        try:
            exec_shell("pkill -9 smbd")
            exec_shell("pkill -9 nmbd")
        except Exception as e:
            pass
Esempio n. 25
0
def file_link(config, target, link_name):
    cmd = "%s %s %s" % (config.uss_ln, target, link_name)
    try:
        #if linked(config, target) == "false": #link属性不存在,或者属性值为false
        exec_shell(cmd)
        file_set_attr(config, "link", "true", target)
        return True
    except Exp, err:
        file_set_attr(config, "link", "false", target)
        return False
Esempio n. 26
0
    def _ldap_enable(self, server, dn):
        cmd = "pkill -9 winbindd;pkill -9 nscd"
        cmd = cmd + ' ;authconfig --disablewinbind --disablewins --disablesssd --disablenis --enableldap --enableldapauth --ldapserver="%s" --ldapbasedn="%s" --enablemkhomedir --update' % (
            server, dn)
        cmd = cmd + " ;systemctl start nslcd"
        print cmd
        self._exec_cmd_on_cluster_nodes(cmd, is_raise=0)

        _exec_attr_set = "%s -s mode -V ldap /system" % (self.config.uss_attr)
        exec_shell(_exec_attr_set)
Esempio n. 27
0
def _remove(args):
    config = Config()
    file_list = list_dir(config, args.dir)
    for file in file_list:
        abs_file = os.path.join(args.dir, file)
        cmd = '%s %s' % (config.uss_rm, abs_file)
        try:
            exec_shell(cmd)
        except Exp, err:
            return False
Esempio n. 28
0
def confirm_redis_stop():
    while True:
        is_stop = is_redis_stop()
        if not is_stop:
            cmd = "pkill -9 redis-server"
            try:
                exec_shell(cmd)
            except Exp, e:
                pass
        else:
            break
Esempio n. 29
0
def user_test_shell(cmd, ignore_errno=0):
    try:
        exec_shell(cmd)
    except Exception as e:
        ret = e.errno
        if (ret != ignore_errno):
            derror('%s fail ret:%d, %s' % (cmd, ret, e))
        else:
            return ignore_errno

    return 0
Esempio n. 30
0
def _write(args):
    config = Config()
    abs_file_list = []
    file_list = list_dir(config, args.dir)
    for file in file_list:
        abs_file = os.path.join(args.dir, file)
        abs_file_list.append(abs_file)

    for abs_file in abs_file_list:
        cmd = "%s hello %s" % (config.uss_write, abs_file)
        exec_shell(cmd)
def load_sqlfile(filename, debug, db_params):
    additional_params = ""
    if debug:
        additional_params += "-a "

    cmd = "psql {host_user} -d {db} -f {filename} {additional_params}".format(
        host_user=_make_db_args(db_params),
        db=db_params['name'],
        filename=filename,
        additional_params=additional_params)
        
    return exec_shell(cmd)
def drop_database(params):
    cmd = "dropdb" + " " + _make_db_args_name(params)
    return exec_shell(cmd)
def check_db_existence(params):
    """Return True if database exists."""

    cmd = "psql " + _make_db_args(params) + " -lqt | cut -d \| -f 1 | grep -w {db_name}".format(db_name=params['name'])
    return exec_shell(cmd)
def create_database(params):
    cmd = "createdb" + " " + _make_db_args_name(params)
    return exec_shell(cmd)