Exemplo n.º 1
0
def setup_vol(volname='', dist='', rep='', dispd='', red='', stripe='', \
        trans='', servers=''):
    """
        Setup a gluster volume for testing.
        It first formats the back-end bricks and then creates a
        trusted storage pool by doing peer probe. And then it creates
        a volume of specified configuration.

        When the volume is created, it sets a global flag to indicate
        that the volume is created. If another testcase calls this
        function for the second time with same volume name, the function
        checks for the flag and if found, will return True.

        Returns True on success and False for failure.
    """
    if servers == '':
        servers = tc.nodes
    volinfo = get_volume_info(server=servers[0])
    if volinfo is not None and volname in volinfo.keys():
        tc.logger.debug("volume %s already exists in %s. Returning..." \
                % (volname, servers[0]))
        return True
    ret = env_setup_servers(servers=servers)
    if not ret:
        tc.logger.error("Formatting backend bricks failed. Aborting...")
        return False
    ret = start_glusterd(servers)
    if not ret:
        tc.logger.error("glusterd did not start in at least one server")
        return False
    time.sleep(5)
    ret = peer_probe(servers[0], servers[1:])
    if not ret:
        tc.logger.error("Unable to peer probe one or more machines")
        return False
    if rep != 1 and dispd != 1:
        tc.logger.warning("Both replica count and disperse count is specified")
        tc.logger.warning("Ignoring the disperse and using the replica count")
        dispd = 1
        red = 1
    ret = create_volume(volname, dist, rep, stripe, trans, servers, \
            dispd=dispd, red=red)
    if ret[0] != 0:
        tc.logger.error("Unable to create volume %s" % volname)
        return False
    time.sleep(2)
    ret = start_volume(volname, servers[0])
    if not ret:
        tc.logger.error("volume start %s failed" % volname)
        return False
    tc.global_flag[volname] = True
    return True
Exemplo n.º 2
0
def setup_geo_rep_session(setup=""):
    """
        Does initial setup and creates a geo-rep session and updates a global
        variable upon success. Other testcases, can skip the setup part if the
        global variable is set

        If the 'setup' is not set, a geo-rep session setup between master
        cluster and slave cluster

        If the 'setup' is set to 'fanout', the session is setup between master
        cluster and slave clusters

        If the 'setup' is set to 'cascaded' then a cascaded geo-rep session
        is setup between master to intermediate master(s) to slave cluster
    """
    mastervol = tc.config_data["MASTERVOL"]
    mnode = tc.gm_nodes[0]
    dist = tc.config_data["DIST_COUNT"]
    rep = tc.config_data["REP_COUNT"]
    stripe = tc.config_data["STRIPE"]
    trans = tc.config_data["TRANS_TYPE"]
    guser = tc.config_data["GEO_USER"]
    mountbroker = ""
    rc = True
    try:
        if tc.global_flag["setup_fs_done"]:
            tc.logger.debug("bricks are already formatted. Skipping setup_fs")
    except KeyError:
        tc.logger.debug("The bricks are not formatted yet. Execute setup_fs")
        tc.global_flag["setup_fs_done"] = False
    if not tc.global_flag["setup_fs_done"]:
        ret = env_setup_servers()
        if not ret:
            tc.logger.error("env_setup_servers failed. Aborting tests...")
            return False
    ret = start_glusterd()
    if not ret:
        tc.logger.error("Unable to start glusterd. Exiting")
        return False
    ret = peer_probe(mnode, tc.gm_nodes[1:])
    if not ret:
        tc.logger.error("peer probe failed in master cluster")
        return False
    ret = create_volume(mastervol, dist, rep, stripe, trans, servers=tc.gm_nodes)
    if 0 != ret[0]:
        tc.logger.error("Unable to create geo-rep master volume. " "Please check the gluster logs")
        return False
    ret = start_volume(mastervol, mnode)
    if not ret:
        tc.logger.error("volume start master volume failed")
        return False
    if setup == "":
        slavevol = tc.config_data["SLAVEVOL"]
        snode = tc.gs_nodes[0]
        ret = peer_probe(snode, tc.gs_nodes[1:])
        if not ret:
            tc.logger.error("peer probe failed in slave cluster")
            return False
        ret = create_volume(slavevol, dist, rep, stripe, trans, servers=tc.gs_nodes)
        if ret[0] != 0:
            tc.logger.error("Unable to create the slave volume")
            return False
        ret = start_volume(slavevol, snode)
        if not ret:
            tc.logger.error("volume start failed in slave cluster")
            return False
        if tc.config_data["MOUNTBROKER"] == "True":
            mountbroker = "%s@" % guser
            ret = setup_geo_rep_mountbroker()
            if not ret:
                tc.logger.error("mountbroker setup failed. Aborting...")
                return False
        tc.run(mnode, "gluster system execute gsec_create")
        ret = create_geo_passwordless_ssh(mnode, snode, guser)
        if not ret:
            return False
        ret = tc.run(
            mnode,
            "gluster volume geo-replication %s %s%s::%s create push-pem" % (mastervol, mountbroker, snode, slavevol),
        )
        if ret[0] != 0:
            rc = False
        if tc.config_data["MOUNTBROKER"] == "True":
            ret = tc.run(
                snode, "/usr/libexec/glusterfs/set_geo_rep_pem_keys.sh %s %s %s" % (guser, mastervol, slavevol)
            )
            if ret[0] != 0:
                tc.logger.error("Couldn't set pem keys in slave")
                rc = False
        if tc.config_data["USE_META_VOL"] == "True":
            ret = geo_rep_setup_metavolume(mastervol, slavevol, snode)
            if not ret:
                tc.logger.error("Unable to setup meta-volume for geo-rep")
                rc = False
        syn_mode = tc.config_data["GEO_SYNC_MODE"]
        ret = set_sync_mode(mastervol, slavevol, syn_mode)
        if not ret:
            tc.logger.error("Unable to set the sync mode to %s" % sync_mode)
            rc = False
        ret = tc.run(
            mnode,
            "gluster volume geo-replication %s %s%s::%s \
start"
            % (mastervol, mountbroker, snode, slavevol),
        )
        if ret[0] != 0:
            rc = False
        ret = tc.run(
            mnode,
            "gluster volum geo-replication %s %s%s::%s \
status"
            % (mastervol, mountbroker, snode, slavevol),
        )
        if ret[0] != 0 or re.search(r"faulty", ret[1] + ret[2]):
            tc.logger.error("geo-rep status faulty. Please check the logs")
            rc = False
        time.sleep(60)
        ret = tc.run(
            mnode,
            "gluster volum geo-replication %s %s%s::%s \
status"
            % (mastervol, mountbroker, snode, slavevol),
        )
        if ret[0] != 0 or re.search(r"faulty", ret[1] + ret[2]):
            tc.logger.error("geo-rep session faulty after 60 seconds")
            rc = False
        tc.geo_rep_setup = True
    elif setup == "fanout":
        # The support for fan-out and cascaded will be added in future
        pass
    elif setup == "cascaded":
        # The support for fan-out and cascaded will be added future
        pass
    else:
        tc.logger.error("The setup %s is not supported" % setup)
        return False
    return rc
Exemplo n.º 3
0
def setup_vol(volname='', dist='', rep='', dispd='', red='', stripe='', \
        trans='', servers=''):
    """
        Setup a gluster volume for testing.
        It first formats the back-end bricks and then creates a
        trusted storage pool by doing peer probe. And then it creates
        a volume of specified configuration.

        When the volume is created, it sets a global flag to indicate
        that the volume is created. If another testcase calls this
        function for the second time with same volume name, the function
        checks for the flag and if found, will return True.

        Returns True on success and False for failure.
    """
    if volname == '':
        volname = tc.config_data['VOLNAME']
    if dist == '':
        dist = tc.config_data['DIST_COUNT']
    if rep == '':
        rep = tc.config_data['REP_COUNT']
    if dispd == '':
        dispd = tc.config_data['DISPERSE']
    if red == '':
        red = tc.config_data['REDUNDANCY']
    if stripe == '':
        stripe = tc.config_data['STRIPE']
    if trans == '':
        trans = tc.config_data['TRANS_TYPE']
    if servers == '':
        servers = tc.nodes
    volinfo = get_volume_info(server=servers[0])
    if volinfo is not None and volname in volinfo.keys():
        tc.logger.debug("volume %s already exists in %s. Returning..." \
                % (volname, servers[0]))
        return True
    ret = env_setup_servers(servers=servers)
    if not ret:
        tc.logger.error("Formatting backend bricks failed. Aborting...")
        return False
    ret = start_glusterd(servers)
    if not ret:
        tc.logger.error("glusterd did not start in at least one server")
        return False
    ret = peer_probe(servers[0], servers[1:])
    if not ret:
        tc.logger.error("Unable to peer probe one or more machines")
        return False
    if rep != 1 and dispd != 1:
        tc.logger.warning("Both replica count and disperse count is specified")
        tc.logger.warning("Ignoring the disperse and using the replica count")
        dispd = 1
        red = 1
    ret = create_volume(volname, dist, rep, stripe, trans, servers, \
            dispd=dispd, red=red)
    if ret[0] != 0:
        tc.logger.error("Unable to create volume %s" % volname)
        return False
    time.sleep(2)
    ret = start_volume(volname, servers[0])
    if not ret:
        tc.logger.error("volume start %s failed" % volname)
        return False
    if tc.config_data['ENABLE_QUOTA'] == 'True':
        ret0 = enable_quota(volname, servers[0])
        ret1 = set_quota_limit(volname, server=servers[0])
        if ret0[0] != 0 or ret1[0] != 0:
            tc.logger.error("Quota setup failed")
            return False
    if tc.config_data['ENABLE_USS'] == 'True':
        ret = tc.run(servers[0], "gluster volume set %s features.uss enable" \
                % volname)
        if ret[0] != 0:
            tc.logger.error("Unable to enable USS for volume %s" % volname)
            return False
    tc.global_flag[volname] = True
    return True