def test_delete_lag_with_connections_without_force_delete(
        placeboify, maybe_sleep, dependencies):
    client = placeboify.client("directconnect")
    with pytest.raises(Exception) as error_message:
        lag_module.ensure_absent(client, dependencies.lag_1.get("lag_id"),
                                 "ansible_lag_1", False, True, True, 120)
        assert "To force deletion of the LAG use delete_force: True" in error_message
def dependencies():

    # each LAG dict will contain the keys: module, connections, virtual_interfaces
    Dependencies = collections.namedtuple("Dependencies", ["lag_1", "lag_2"])
    lag_1 = dict()
    lag_2 = dict()

    vanilla_params = {
        "name": "ansible_lag_1",
        "location": "EqSe2",
        "num_connections": 1,
        "min_links": 0,
        "bandwidth": "1Gbps"
    }

    for lag in ("ansible_lag_1", "ansible_lag_2"):
        params = dict(vanilla_params)
        params["name"] = lag
        if lag == "ansible_lag_1":
            lag_1["module"] = FakeModule(**params)
        else:
            lag_2["module"] = FakeModule(**params)

    if os.getenv("PLACEBO_RECORD"):
        region, ec2_url, aws_connect_kwargs = get_aws_connection_info(
            lag_1["module"], boto3=True)
        client = boto3_conn(lag_1["module"],
                            conn_type="client",
                            resource="directconnect",
                            region=region,
                            endpoint=ec2_url,
                            **aws_connect_kwargs)
        # See if link aggregation groups exist
        for name in ("ansible_lag_1", "ansible_lag_2"):
            lag_id = lag_module.create_lag(client,
                                           num_connections=1,
                                           location="EqSe2",
                                           bandwidth="1Gbps",
                                           name=name,
                                           connection_id=None)
            if name == "ansible_lag_1":
                lag_1["lag_id"] = lag_id
                lag_1["name"] = name
            else:
                lag_2["lag_id"] = lag_id
                lag_2["name"] = name
        yield Dependencies(lag_1=lag_1, lag_2=lag_2)
    else:
        lag_1.update(lag_id="dxlag-fgkk4dja", name="ansible_lag_1")
        lag_2.update(lag_id="dxlag-fgytkicv", name="ansible_lag_2")
        yield Dependencies(lag_1=lag_1, lag_2=lag_2)

    if os.getenv("PLACEBO_RECORD"):
        # clean up
        lag_module.ensure_absent(client, lag_1["lag_id"], lag_1["name"], True,
                                 True, True, 120)
        lag_module.ensure_absent(client, lag_2["lag_id"], lag_2["name"], True,
                                 True, True, 120)
def dependencies():

    # each LAG dict will contain the keys: module, connections, virtual_interfaces
    Dependencies = collections.namedtuple("Dependencies", ["lag_1", "lag_2"])
    lag_1 = dict()
    lag_2 = dict()

    vanilla_params = {"name": "ansible_lag_1",
                      "location": "EqSe2",
                      "num_connections": 1,
                      "min_links": 0,
                      "bandwidth": "1Gbps"}

    for lag in ("ansible_lag_1", "ansible_lag_2"):
        params = dict(vanilla_params)
        params["name"] = lag
        if lag == "ansible_lag_1":
            lag_1["module"] = FakeModule(**params)
        else:
            lag_2["module"] = FakeModule(**params)

    if os.getenv("PLACEBO_RECORD"):
        region, ec2_url, aws_connect_kwargs = get_aws_connection_info(lag_1["module"], boto3=True)
        client = boto3_conn(lag_1["module"], conn_type="client", resource="directconnect", region=region, endpoint=ec2_url, **aws_connect_kwargs)
        # See if link aggregation groups exist
        for name in ("ansible_lag_1", "ansible_lag_2"):
            lag_id = lag_module.create_lag(client, num_connections=1, location="EqSe2", bandwidth="1Gbps", name=name, connection_id=None)
            if name == "ansible_lag_1":
                lag_1["lag_id"] = lag_id
                lag_1["name"] = name
            else:
                lag_2["lag_id"] = lag_id
                lag_2["name"] = name
        yield Dependencies(lag_1=lag_1, lag_2=lag_2)
    else:
        lag_1.update(lag_id="dxlag-fgkk4dja", name="ansible_lag_1")
        lag_2.update(lag_id="dxlag-fgytkicv", name="ansible_lag_2")
        yield Dependencies(lag_1=lag_1, lag_2=lag_2)

    if os.getenv("PLACEBO_RECORD"):
        # clean up
        lag_module.ensure_absent(client, lag_1["lag_id"], lag_1["name"], True, True, True, 120)
        lag_module.ensure_absent(client, lag_2["lag_id"], lag_2["name"], True, True, True, 120)
def test_delete_lag_with_connections(placeboify, maybe_sleep, dependencies):
    client = placeboify.client("directconnect")
    changed = lag_module.ensure_absent(client, dependencies.lag_1.get("lag_id"), "ansible_lag_1", True, True, True, 120)
    assert changed
def test_delete_lag_with_connections_without_force_delete(placeboify, maybe_sleep, dependencies):
    client = placeboify.client("directconnect")
    with pytest.raises(Exception) as error_message:
        lag_module.ensure_absent(client, dependencies.lag_1.get("lag_id"), "ansible_lag_1", False, True, True, 120)
        assert "To force deletion of the LAG use delete_force: True" in error_message
def test_delete_nonexistent_lag(placeboify, maybe_sleep):
    client = placeboify.client("directconnect")
    changed = lag_module.ensure_absent(client, "dxlag-XXXXXXXX", "doesntexist", True, True, True, 120)
    assert not changed