Exemple #1
0
def set_volume_options(volume_name, hostname, options):
    """options should be of following form

    [

      {"option2": "Value2"},

      {"option3": "Value3"},

      {"option1": "Value1"},

    ]
    """
    recipe = []
    option_key_list = []
    option_value_list = []
    for option in options:
        option_key_list.append(option.keys()[0])
        option_value_list.append(option.values()[0])
    host_vol = hostname + ":" + volume_name
    recipe.append(
        gf.get_volume(
            host_vol,
            "set",
            option_keys=option_key_list,
            option_values=option_value_list
        )
    )

    config_str = cook_gdeploy_config(recipe)

    out, err, rc = invoke_gdeploy(config_str)

    return out, err, rc
Exemple #2
0
def delete_volume(volume_name, host=None, force=None):
    recipe = []
    if host:
        host_list = [host]
        recipe.append(gf.get_hosts(host_list))

    force = "yes" if force else "no"

    recipe.append(gf.get_volume(volume_name, action="delete", force=force))

    config_str = cook_gdeploy_config(recipe)

    out, err, rc = invoke_gdeploy(config_str)

    return out, err, rc
Exemple #3
0
def expand_volume(volume_name, brick_details,
                  replica_count=None, disperse_count=None,
                  force=False, increase_replica_count=False):
    """Brick details should be of following form, its a list of list

    where each sublist is a collection of bricks which forms a replica

    set(in case of replicated volume) or a subvolume(in case of a

    distributed dispersed volume)

    [

        [

         {"hostname1": "brick1"},

         {"hostname2": "brick1"},

         {"hostname3": "brick1"},

         {"hostname4": "brick1"}

        ],

        [

         {"hostname1": "brick2"},

         {"hostname2": "brick2"},

         {"hostname3": "brick2"},

         {"hostname4": "brick2"}

        ],

        [

         {"hostname1": "brick3"},

         {"hostname2": "brick3"},

         {"hostname4": "brick3"},

         {"hostname3": "brick3"}

        ],

    ]

    """

    recipe = []
    brick_list = []
    host_list = set()
    if replica_count and not increase_replica_count:
        if len(brick_details[0]) != int(replica_count):
            out = "insufficient brick sets for replica count" + \
                  ": %s. Brick set count %s" % (
                      replica_count, len(brick_details[0])
                  )
            err = out
            rc = 1
            return out, err, rc

    if disperse_count:
        if len(brick_details[0]) != (
                int(disperse_count)):
            out = "insufficient nos bricks for disperse count" + \
                  ": %s. Brick count: %s" % (
                      disperse_count,
                      len(brick_details[0])
                  )
            err = out
            rc = 1
            return out, err, rc

    set_length = len(brick_details[0])
    for replica_set in brick_details:
        if len(replica_set) != set_length:
            out = "number of bricks in different sets are not same" + \
                  "Bricks passed: %s" % (
                      str(brick_details)
                  )
            err = out
            rc = 1
            return out, err, rc

        for el in replica_set:
            host_list.add(el.keys()[0])
            brick_list.append(el.keys()[0] + ":" + el.values()[0])
    recipe.append(gf.get_hosts(list(host_list)))

    arg_dict = {}
    force = "yes" if force else "no"
    arg_dict.update({"force": force})
    if increase_replica_count:
        arg_dict.update({"replica_count": replica_count})
        arg_dict.update({"state": "force"})

    args = [volume_name, "add-brick", brick_list]

    recipe.append(
        gf.get_volume(*args, **arg_dict)
    )

    config_str = cook_gdeploy_config(recipe)

    out, err, rc = invoke_gdeploy(config_str)

    return out, err, rc
    def test_get_volume(self):
        volume_name = "vol1"
        action = "create"
        brick_dirs = [
            "/mnt/brick/b1", "/mnt/brick/b2", "/mnt/brick/b3", "/mnt/brick/b3"
        ]
        transport = "tcp"
        replica_count = 2
        disperse = "yes"
        disperse_count = 2
        redundancy_count = 2
        force = "yes"
        target_host = "12.23.34.45"
        option_keys = ["key1", "key2", "key3", "key4"]
        option_values = ["value1", "value2", "value3", "value4"]

        volume = gf.get_volume(volume_name,
                               action,
                               brick_dirs,
                               transport,
                               replica_count,
                               disperse,
                               disperse_count,
                               redundancy_count,
                               force,
                               target_host,
                               option_keys=option_keys,
                               option_values=option_values)

        expected_volume = {
            "volume:12.23.34.45": {
                "volname":
                "vol1",
                "action":
                "create",
                "brick_dirs": [
                    "/mnt/brick/b1", "/mnt/brick/b2", "/mnt/brick/b3",
                    "/mnt/brick/b3"
                ],
                "transport":
                "tcp",
                "replica_count":
                "2",
                "disperse":
                "yes",
                "disperse_count":
                "2",
                "redundancy_count":
                "2",
                "force":
                "yes",
                "ignore_volume_errors":
                "no",
                "key": ["key1", "key2", "key3", "key4"],
                "value": ["value1", "value2", "value3", "value4"]
            }
        }
        assert volume == expected_volume

        action = "unsupported_action"
        pytest.raises(gf.UnsupportedOptionError, gf.get_volume, volume_name,
                      action)

        action = "set"
        pytest.raises(gf.UnsupportedOptionError, gf.get_volume, volume_name,
                      action)

        action = "rebalance"
        pytest.raises(gf.UnsupportedOptionError, gf.get_volume, volume_name,
                      action)

        action = "add-brick"
        pytest.raises(gf.UnsupportedOptionError, gf.get_volume, volume_name,
                      action)

        action = "create"
        pytest.raises(gf.UnsupportedOptionError,
                      gf.get_volume,
                      volume_name,
                      action,
                      force="Invalid-option")