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)
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)
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)
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)
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)
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 )
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 )
def enable_backend(modeladmin, request, queryset): switch_state_and_reload(queryset, True)
def enable_varnish_servers(modeladmin, request, queryset): switch_state_and_reload(queryset, True)
def disable_varnish_servers(modeladmin, request, queryset): switch_state_and_reload(queryset, False)
def enable_director(modeladmin, request, queryset): switch_state_and_reload(queryset, True)
def disable_backend(modeladmin, request, queryset): switch_state_and_reload(queryset, False)
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)
def disable_director(modeladmin, request, queryset): switch_state_and_reload(queryset, False)