예제 #1
0
파일: test_signals.py 프로젝트: bieli/vaas
def test_switch_state_and_reload_cluster_filter_for_backend():
    cluster1 = LogicalCluster.objects.create(name="first cluster")
    # Created, but not used, just to check if cluster filtering works.
    LogicalCluster.objects.create(name="second cluster")
    dc1 = Dc.objects.create(symbol='dc1', name='First datacenter')
    probe = Probe.objects.create(name='default_probe', url='/ts.1')
    director1 = Director.objects.create(name='first_service',
                                        route_expression='/first',
                                        mode='random',
                                        probe=probe)
    backend1 = Backend.objects.create(dc=dc1,
                                      director=director1,
                                      address='192.168.200.10',
                                      port=8080,
                                      weight=1)
    director1.cluster.add(cluster1)

    queryset = Backend.objects.all().filter(id=backend1.id)
    queryset.update = Mock()

    with patch('vaas.manager.signals.regenerate_and_reload_vcl',
               return_value=None) as regenerate_and_reload_vcl_mock:

        switch_state_and_reload(queryset, True)
        assert_equals([call(enabled=True)], queryset.update.call_args_list)
        assert_equals([call([cluster1])],
                      regenerate_and_reload_vcl_mock.call_args_list)
예제 #2
0
def switch_backend_status(modeladmin, request, queryset):
    enabledSet = Backend.objects.filter(
        pk__in=map(lambda backend: backend.pk, queryset.filter(enabled=True)))
    disabledSet = Backend.objects.filter(
        pk__in=map(lambda backend: backend.pk, queryset.filter(enabled=False)))
    switch_state_and_reload(disabledSet, True)
    switch_state_and_reload(enabledSet, False)
예제 #3
0
def test_switch_state_and_reload_cluster_filter_for_backend():
    cluster1 = LogicalCluster.objects.create(name="first cluster")
    """
    Created, but not used, just to check if cluster filtering works.
    """
    LogicalCluster.objects.create(name="second cluster")
    dc1 = Dc.objects.create(symbol="dc3", name="First datacenter")
    probe = Probe.objects.create(name="default_probe", url="/ts.1")
    director1 = Director.objects.create(
        name="first_gamma",
        route_expression="/first",
        mode="random",
        probe=probe,
        time_profile=TimeProfile.objects.create(name="beta"),
    )
    backend1 = Backend.objects.create(dc=dc1, director=director1, address="192.168.200.10", port=8080, weight=1)
    director1.cluster.add(cluster1)

    queryset = Backend.objects.all().filter(id=backend1.id)
    queryset.update = Mock()

    with patch("vaas.manager.signals.regenerate_and_reload_vcl", return_value=None) as regenerate_and_reload_vcl_mock:

        switch_state_and_reload(queryset, True)
        assert_equals([call(enabled=True)], queryset.update.call_args_list)
        assert_equals([call([cluster1])], regenerate_and_reload_vcl_mock.call_args_list)
예제 #4
0
def test_switch_state_and_reload_with_empty_list():
    queryset = MagicMock()
    queryset.update = Mock()
    with patch("vaas.manager.signals.regenerate_and_reload_vcl", return_value=None) as regenerate_and_reload_vcl_mock:

        switch_state_and_reload(queryset, True)
        assert_equals([call(enabled=True)], queryset.update.call_args_list)
        """
        shouldn't refresh any cluster, because of empty list
        """
        assert_equals([call([])], regenerate_and_reload_vcl_mock.call_args_list)
예제 #5
0
파일: test_signals.py 프로젝트: bieli/vaas
def test_switch_state_and_reload_with_empty_list():
    queryset = MagicMock()
    queryset.update = Mock()
    with patch('vaas.manager.signals.regenerate_and_reload_vcl',
               return_value=None) as regenerate_and_reload_vcl_mock:

        switch_state_and_reload(queryset, True)
        assert_equals([call(enabled=True)], queryset.update.call_args_list)
        """
        shouldn't refresh any cluster, because of empty list
        """
        assert_equals([call([])],
                      regenerate_and_reload_vcl_mock.call_args_list)
예제 #6
0
def test_switch_state_and_reload_cluster_filter_for_backend():
    cluster1 = LogicalCluster.objects.create(name="first cluster")
    """
    Created, but not used, just to check if cluster filtering works.
    """
    LogicalCluster.objects.create(name="second cluster")
    dc1 = Dc.objects.create(symbol='dc1', name='First datacenter')
    probe = Probe.objects.create(name='default_probe', url='/ts.1')
    director1 = Director.objects.create(
        name='first_service',
        route_expression='/first',
        mode='random',
        probe=probe
    )
    backend1 = Backend.objects.create(
        dc=dc1,
        director=director1,
        address='192.168.200.10',
        port=8080,
        weight=1
    )
    director1.cluster.add(cluster1)

    queryset = Backend.objects.all().filter(id=backend1.id)
    queryset.update = Mock()

    with patch(
        'vaas.manager.signals.regenerate_and_reload_vcl',
        return_value=None
    ) as regenerate_and_reload_vcl_mock:

        switch_state_and_reload(queryset, True)
        assert_equals(
            [call(enabled=True)],
            queryset.update.call_args_list
        )
        assert_equals(
            [call([cluster1])],
            regenerate_and_reload_vcl_mock.call_args_list
        )
예제 #7
0
    def test_should_not_reload_clusters_if_service_mesh_is_enabled_and_director_is_reachable_via_sm(self):
        cluster_with_sm = LogicalCluster.objects.create(name="cluster_with_sm", service_mesh_routing=True)
        cluster_without_sm = LogicalCluster.objects.create(name="cluster_without_sm", service_mesh_routing=False)
        dc1 = Dc.objects.create(symbol='dc3', name='First datacenter')
        probe = Probe.objects.create(name='default_probe', url='/ts.1')
        director_reachable_via_sm = Director.objects.create(
            name='first_gamma',
            route_expression='/first',
            mode='random',
            probe=probe,
            time_profile=TimeProfile.objects.create(name='beta'),
            reachable_via_service_mesh=True

        )
        backend1 = Backend.objects.create(
            dc=dc1,
            director=director_reachable_via_sm,
            address='192.168.200.10',
            port=8080,
            weight=1
        )
        director_reachable_via_sm.cluster.add(cluster_with_sm)
        director_reachable_via_sm.cluster.add(cluster_without_sm)

        queryset = Backend.objects.all().filter(id=backend1.id)
        queryset.update = Mock()

        with patch(
                'vaas.manager.signals.regenerate_and_reload_vcl',
                return_value=None
        ) as regenerate_and_reload_vcl_mock:
            switch_state_and_reload(queryset, True)
            assert_equals(
                [call(enabled=True)],
                queryset.update.call_args_list
            )
            assert_equals(
                [call([cluster_without_sm])],
                regenerate_and_reload_vcl_mock.call_args_list
            )
예제 #8
0
def enable_backend(modeladmin, request, queryset):
    switch_state_and_reload(queryset, True)
예제 #9
0
def enable_varnish_servers(modeladmin, request, queryset):
    switch_state_and_reload(queryset, True)
예제 #10
0
def disable_varnish_servers(modeladmin, request, queryset):
    switch_state_and_reload(queryset, False)
예제 #11
0
def enable_director(modeladmin, request, queryset):
    switch_state_and_reload(queryset, True)
예제 #12
0
def disable_backend(modeladmin, request, queryset):
    switch_state_and_reload(queryset, False)
예제 #13
0
def enable_backend(modeladmin, request, queryset):
    switch_state_and_reload(queryset, True)
예제 #14
0
def enable_varnish_servers(modeladmin, request, queryset):
    switch_state_and_reload(queryset, True)
예제 #15
0
def disable_varnish_servers(modeladmin, request, queryset):
    switch_state_and_reload(queryset, False)
예제 #16
0
def disable_backend(modeladmin, request, queryset):
    switch_state_and_reload(queryset, False)
예제 #17
0
def switch_backend_status(modeladmin, request, queryset):
    enabledSet = Backend.objects.filter(pk__in=map(lambda backend: backend.pk, queryset.filter(enabled=True)))
    disabledSet = Backend.objects.filter(pk__in=map(lambda backend: backend.pk, queryset.filter(enabled=False)))
    switch_state_and_reload(disabledSet, True)
    switch_state_and_reload(enabledSet, False)
예제 #18
0
def enable_director(modeladmin, request, queryset):
    switch_state_and_reload(queryset, True)
예제 #19
0
def disable_director(modeladmin, request, queryset):
    switch_state_and_reload(queryset, False)
예제 #20
0
def disable_director(modeladmin, request, queryset):
    switch_state_and_reload(queryset, False)