def test_inventory_lb_and_waf(model):

    # initialize the inventory
    inputs = model["init"]["inputs"]
    inputs["cmd"] = "init"
    inputs["extra_vars"]["deployment_type"] = "lb_and_waf"
    print inputs

    em = EnvironmentManagerFactory(**inputs)
    outputs = getattr(em, "init")()
    assert (len(outputs["playbook_results"].playbooks) > 0 and
            outputs["playbook_results"].statuscode == 0)

    inventory = em.inventory()
    print inventory
    verify_deployment_model(model["init"]["inputs"]["extra_vars"][
                            "deployment_model"], inventory)

    assert inventory["all"]["vars"]["deployment_type"] == "lb_and_waf"
    assert set(inventory["bigips"]["vars"]["modules"]
               ) == set(["avr", "asm", "ltm"])
    if "gtms" in inventory:
        assert set(inventory["gtms"]["vars"]["modules"]) == set(["avr", "gtm"])

    # remove the inventory
    inputs = model["remove"]["inputs"]
    inputs["cmd"] = "remove"
    em = EnvironmentManagerFactory(**inputs)
    outputs = getattr(em, "remove")()
    assert (len(outputs["playbook_results"].playbooks) > 0 and
            outputs["playbook_results"].statuscode == 0)
def test_inventory_w_analytics_and_waf(model):

    # initialize the inventory
    inputs = model["init"]["inputs"]
    inputs["cmd"] = "init"
    inputs["extra_vars"]["deploy_analytics"] = "true"
    inputs["extra_vars"]["deployment_type"] = "lb_and_waf"
    print inputs

    em = EnvironmentManagerFactory(**inputs)
    outputs = getattr(em, "init")()
    assert (len(outputs["playbook_results"].playbooks) > 0 and
            outputs["playbook_results"].statuscode == 0)

    inventory = em.inventory()
    print inventory
    verify_deployment_model(model["init"]["inputs"]["extra_vars"][
                            "deployment_model"], inventory)

    # check various things for analytics deployment
    assert inventory["all"]["vars"]["deploy_analytics"] == "true"
    assert len(inventory["analyticshosts"]["hosts"]) == 1
    host = inventory["analyticshosts"]["hosts"][0]
    assert host in inventory["all"]['hosts']

    # check various things for waf deployment
    assert inventory["all"]["vars"]["deployment_type"] == "lb_and_waf"
    assert set(inventory["bigips"]["vars"]["modules"]
               ) == set(["avr", "asm", "ltm"])
    if "gtms" in inventory:
        assert set(inventory["gtms"]["vars"]["modules"]) == set(["avr", "gtm"])

    # remove the inventory
    inputs = model["remove"]["inputs"]
    inputs["cmd"] = "remove"
    em = EnvironmentManagerFactory(**inputs)
    outputs = getattr(em, "remove")()
    assert (len(outputs["playbook_results"].playbooks) > 0 and
            outputs["playbook_results"].statuscode == 0)
def test_inventory_w_analytics(model):
    """ default deployment_model is lb_only"""

    # initialize the inventory
    inputs = model["init"]["inputs"]
    inputs["cmd"] = "init"
    inputs["extra_vars"]["deploy_analytics"] = "true"
    print inputs

    em = EnvironmentManagerFactory(**inputs)
    outputs = getattr(em, "init")()
    assert (len(outputs["playbook_results"].playbooks) > 0 and
            outputs["playbook_results"].statuscode == 0)

    inventory = em.inventory()
    print inventory
    verify_deployment_model(model["init"]["inputs"]["extra_vars"][
                            "deployment_model"], inventory)

    # check that we set the global deploy_analytics flag to true
    assert inventory["all"]["vars"]["deploy_analytics"] == "true"

    # check that *1* analytics host is being deployed
    assert len(inventory["analyticshosts"]["hosts"]) == 1

    # check that there is *1* analytics host in the all group..
    host = inventory["analyticshosts"]["hosts"][0]
    assert host in inventory["all"]['hosts']

    # remove the inventory
    inputs = model["remove"]["inputs"]
    inputs["cmd"] = "remove"
    em = EnvironmentManagerFactory(**inputs)
    outputs = getattr(em, "remove")()
    assert (len(outputs["playbook_results"].playbooks) > 0 and
            outputs["playbook_results"].statuscode == 0)