def test_vcl_update_cluster_filter_for_director(): settings.SIGNALS = 'on' cluster1 = LogicalCluster.objects.create(name="first cluster") """ Created, but not used, just to check if cluster filtering works. """ LogicalCluster.objects.create(name="second cluster") probe1 = Probe.objects.create(name='test_probe', url='/status') director1 = Director.objects.create( name='first_service', router='req.url', route_expression='/first', probe=probe1, active_active=False, mode='round-robin', remove_path=False, ) director1.cluster.add(cluster1) with patch('vaas.manager.signals.regenerate_and_reload_vcl', return_value=None) as regenerate_and_reload_vcl_mock: kwargs = {'instance': director1} vcl_update(Director, **kwargs) assert_equals([call([cluster1])], regenerate_and_reload_vcl_mock.call_args_list) settings.SIGNALS = 'off'
def test_vcl_update_if_sender_not_allowed(): settings.SIGNALS = 'on' with patch('vaas.manager.signals.regenerate_and_reload_vcl', return_value=None) as regenerate_and_reload_vcl_mock: vcl_update(None) assert_equals([], regenerate_and_reload_vcl_mock.call_args_list) settings.SIGNALS = 'off'
def test_vcl_update_cluster_filter_for_vcltemplateblock(): settings.SIGNALS = 'on' cluster1 = LogicalCluster.objects.create(name="first cluster") """ Created, but not used, just to check if cluster filtering works. """ LogicalCluster.objects.create(name="second cluster") template = VclTemplate.objects.create(name="template") template_block = VclTemplateBlock.objects.create(template=template) VarnishServer.objects.create(ip='127.0.0.2', port='6082', hostname='localhost-1', secret='secret-1', dc=Dc.objects.create(name='Tokyo', symbol='dc4'), cluster=cluster1, template=template) with patch('vaas.manager.signals.regenerate_and_reload_vcl', return_value=None) as regenerate_and_reload_vcl_mock: kwargs = {'instance': template_block} vcl_update(VclTemplateBlock, **kwargs) assert_equals([call([cluster1])], regenerate_and_reload_vcl_mock.call_args_list) settings.SIGNALS = 'off'
def test_vcl_update_cluster_filter_for_vcltemplateblock(): settings.SIGNALS = 'on' cluster1 = LogicalCluster.objects.create(name="first cluster") """ Created, but not used, just to check if cluster filtering works. """ LogicalCluster.objects.create(name="second cluster") template = VclTemplate.objects.create(name="template") template_block = VclTemplateBlock.objects.create(template=template) VarnishServer.objects.create( ip='127.0.0.2', port='6082', hostname='localhost-1', secret='secret-1', dc=Dc.objects.create(name='Tokyo', symbol='dc2'), cluster=cluster1, template=template ) with patch('vaas.manager.signals.regenerate_and_reload_vcl', return_value=None) as regenerate_and_reload_vcl_mock: kwargs = {'instance': template_block} vcl_update(VclTemplateBlock, **kwargs) assert_equals([call([cluster1])], regenerate_and_reload_vcl_mock.call_args_list) settings.SIGNALS = 'off'
def test_vcl_update_cluster_filter_for_director(): settings.SIGNALS = "on" cluster1 = LogicalCluster.objects.create(name="alpha cluster") """ Created, but not used, just to check if cluster filtering works. """ LogicalCluster.objects.create(name="beta cluster") probe1 = Probe.objects.create(name="test_alpha_probe", url="/status") director1 = Director.objects.create( name="first_alpha", router="req.url", route_expression="/first", probe=probe1, active_active=False, mode="round-robin", remove_path=False, time_profile=TimeProfile.objects.create(name="alpha"), ) director1.cluster.add(cluster1) with patch("vaas.manager.signals.regenerate_and_reload_vcl", return_value=None) as regenerate_and_reload_vcl_mock: kwargs = {"instance": director1} vcl_update(Director, **kwargs) assert_equals([call([cluster1])], regenerate_and_reload_vcl_mock.call_args_list) settings.SIGNALS = "off"
def test_vcl_update_cluster_filter_for_vcltemplateblock(): settings.SIGNALS = "on" cluster1 = LogicalCluster.objects.create(name="3 cluster") """ Created, but not used, just to check if cluster filtering works. """ LogicalCluster.objects.create(name="4 cluster") template = VclTemplate.objects.create(name="template") template_block = VclTemplateBlock.objects.create(template=template) VarnishServer.objects.create( ip="127.0.0.2", port="6082", hostname="localhost-1", secret="secret-1", dc=Dc.objects.create(name="Tokyo", symbol="dc4"), cluster=cluster1, template=template, ) with patch("vaas.manager.signals.regenerate_and_reload_vcl", return_value=None) as regenerate_and_reload_vcl_mock: kwargs = {"instance": template_block} vcl_update(VclTemplateBlock, **kwargs) assert_equals([call([cluster1])], regenerate_and_reload_vcl_mock.call_args_list) settings.SIGNALS = "off"
def test_backend_change_should_trigger_vcl_change_for_clusters_where_service_mesh_is_disabled(self): settings.SIGNALS = 'on' 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) with patch('vaas.manager.signals.regenerate_and_reload_vcl', return_value=None) as regenerate_and_reload_vcl_mock: kwargs = {'instance': backend1} vcl_update(Backend, **kwargs) assert_equals([call([cluster_without_sm])], regenerate_and_reload_vcl_mock.call_args_list) settings.SIGNALS = 'off'
def test_vcl_update_if_sender_allowed(): settings.SIGNALS = 'on' probe1 = Probe.objects.create(name='test_probe', url='/status') director1 = Director.objects.create(name='first_service', router='req.url', route_expression='/first', probe=probe1, active_active=False, mode='round-robin', remove_path=False) with patch('vaas.manager.signals.regenerate_and_reload_vcl', return_value=None) as regenerate_and_reload_vcl_mock: kwargs = {'instance': director1} vcl_update(Director, **kwargs) assert_equals([call([])], regenerate_and_reload_vcl_mock.call_args_list) settings.SIGNALS = 'off'
def test_vcl_update_if_sender_allowed(): settings.SIGNALS = 'on' probe1 = Probe.objects.create(name='test_probe', url='/status') director1 = Director.objects.create( name='first_service', router='req.url', route_expression='/first', probe=probe1, active_active=False, mode='round-robin', remove_path=False ) with patch('vaas.manager.signals.regenerate_and_reload_vcl', return_value=None) as regenerate_and_reload_vcl_mock: kwargs = {'instance': director1} vcl_update(Director, **kwargs) assert_equals([call([])], regenerate_and_reload_vcl_mock.call_args_list) settings.SIGNALS = 'off'
def test_vcl_update_if_sender_allowed(): settings.SIGNALS = "on" probe1 = Probe.objects.create(name="test_beta_probe", url="/status") director1 = Director.objects.create( name="first_beta", router="req.url", route_expression="/first", probe=probe1, active_active=False, mode="round-robin", remove_path=False, time_profile=TimeProfile.objects.create(name="gamma"), ) with patch("vaas.manager.signals.regenerate_and_reload_vcl", return_value=None) as regenerate_and_reload_vcl_mock: kwargs = {"instance": director1} vcl_update(Director, **kwargs) assert_equals([call([])], regenerate_and_reload_vcl_mock.call_args_list) settings.SIGNALS = "off"