def test_apply_esd_fallback_persist_profile_nopersist(adapter):
        adapter = ServiceModelAdapter(mock.MagicMock())
        esd = dict(lbaas_fallback_persist="hash")

        vip = dict(profiles=[])

        adapter._apply_esd(vip, esd)

        assert "policies" not in vip
        assert "persist" not in vip
        assert "fallbackPersistence" not in vip
    def test_apply_empty_esd(adapter):
        adapter = ServiceModelAdapter(mock.MagicMock())
        esd = dict()
        vip = dict()
        adapter._apply_esd(vip, esd)

        assert "persist" not in vip
        assert "fallbackPersistence" not in vip
        assert "profiles" not in vip
        assert "rules" not in vip
        assert "policies" not in vip
    def test_apply_esd_policy(adapter):
        adapter = ServiceModelAdapter(mock.MagicMock())
        esd = dict(lbaas_policy=["demo_policy"])
        vip = dict(profiles=[])

        adapter._apply_esd(vip, esd)

        assert "persist" not in vip
        assert "fallbackPersistence" not in vip
        assert vip['rules'] == []
        assert vip['policies'] == [dict(name='demo_policy',
                                        partition="Common")]
    def test_apply_esd_irules_empty(adapter):
        adapter = ServiceModelAdapter(mock.MagicMock())
        esd = dict(lbaas_irule=[])

        vip = dict(profiles=[])

        adapter._apply_esd(vip, esd)

        assert "policies" not in vip
        assert "persist" not in vip
        assert "fallbackPersistence" not in vip
        assert not vip['rules']
    def test_apply_esd_persist_profile(adapter):
        adapter = ServiceModelAdapter(mock.MagicMock())
        esd = dict(lbaas_persist="hash")
        vip = dict(profiles=[])

        adapter._apply_esd(vip, esd)

        assert "fallbackPersistence" not in vip
        assert "policies" not in vip

        assert vip['persist'] == [dict(name="hash")]
        assert vip['profiles'] == [
            dict(name="tcp", partition="Common", context="all")]
    def test_apply_esd_fallback_persist_profile_collision(adapter):
        adapter = ServiceModelAdapter(mock.MagicMock())
        esd = dict(lbaas_fallback_persist="hash",
                   lbaas_persist="sourceip")

        vip = dict(profiles=[], fallbackPersistence='mock')

        adapter._apply_esd(vip, esd)

        assert "policies" not in vip

        assert vip['persist'] == [dict(name="sourceip")]
        assert vip['fallbackPersistence'] == 'hash'
        assert vip['profiles'] == [dict(
            name="tcp", partition="Common", context="all")]
    def test_apply_esd_irules(adapter):
        adapter = ServiceModelAdapter(mock.MagicMock())
        esd = dict(lbaas_irule=[
            "_sys_https_redirect",
            "_sys_APM_ExchangeSupport_helper"
        ])
        vip = dict(profiles=[])

        adapter._apply_esd(vip, esd)

        assert "policies" not in vip
        assert "persist" not in vip
        assert "fallbackPersistence" not in vip
        assert vip['rules'] == [
            "/Common/_sys_https_redirect",
            "/Common/_sys_APM_ExchangeSupport_helper"]
    def test_apply_esd_ctcp_profile(adapter):
        adapter = ServiceModelAdapter(mock.MagicMock())
        esd = dict(lbaas_ctcp="tcp-mobile-optimized")
        vip = dict(profiles=["/Common/http"])

        adapter._apply_esd(vip, esd)

        assert "persist" not in vip
        assert "fallbackPersistence" not in vip
        assert "policies" not in vip

        expected = dict(profiles=["/Common/http",
                                  dict(name="tcp-mobile-optimized",
                                       partition="Common",
                                       context="all")
                                  ],
                        rules=[])
        assert vip == expected
    def test_apply_esd_http_profiles(adapter):
        adapter = ServiceModelAdapter(mock.MagicMock())
        esd = dict(lbaas_http_profile="http_profile")
        vip = dict(profiles=["/Common/http"])

        adapter._apply_esd(vip, esd)

        assert "persist" not in vip
        assert "fallbackPersistence" not in vip
        assert "policies" not in vip

        expected = dict(profiles=[
            dict(name="tcp", partition="Common", context="all"),
            "/Common/http_profile"
        ],
                        rules=[])

        assert vip == expected
    def test_apply_esd_ssl_profiles(adapter):
        adapter = ServiceModelAdapter(mock.MagicMock())
        esd = dict(lbaas_cssl_profile="clientssl")
        vip = dict(profiles=["/Common/http"])

        adapter._apply_esd(vip, esd)

        assert "persist" not in vip
        assert "fallbackPersistence" not in vip
        assert "policies" not in vip

        expected = dict(profiles=["/Common/http",
                                  dict(name="tcp",
                                       partition="Common",
                                       context="all"),
                                  dict(name="clientssl",
                                       partition="Common",
                                       context="clientside")
                                  ],
                        rules=[])

        assert vip == expected

        esd = dict(lbaas_sssl_profile="serverssl")
        vip = dict(profiles=["/Common/http"])

        adapter._apply_esd(vip, esd)

        assert "persist" not in vip
        assert "fallbackPersistence" not in vip
        assert "policies" not in vip

        expected = dict(profiles=["/Common/http",
                                  dict(name="tcp",
                                       partition="Common",
                                       context="all"),
                                  dict(name="serverssl",
                                       partition="Common",
                                       context="serverside")
                                  ],
                        rules=[])

        assert vip == expected
    def test_apply_esd_stcp_profile(adapter):
        adapter = ServiceModelAdapter(mock.MagicMock())
        esd = dict(lbaas_stcp="tcp-lan-optimized")
        vip = dict(profiles=["/Common/http"])

        adapter._apply_esd(vip, esd)

        assert "persist" not in vip
        assert "fallbackPersistence" not in vip
        assert "policies" not in vip

        expected = dict(profiles=[
            "/Common/http",
            dict(name="tcp-lan-optimized",
                 partition="Common",
                 context="serverside"),
            dict(name="tcp", partition="Common", context="clientside")
        ],
                        rules=[])

        assert vip == expected