def test_use_new_vcl(self, varnish_api_mock): varnish_api_mock.vcl_content_active.return_value = 'vcl old content' varnish_api_mock.vcl_use.return_value = [[200]] loader = VclLoader(varnish_api_mock) assert_true(VclStatus.OK, loader.use_vcl(Vcl('vcl content')))
def test_do_not_load_new_vcl_if_it_can_not_be_compiled(self, varnish_api_mock): varnish_api_mock.vcl_content_active.return_value = 'vcl old content' varnish_api_mock.vcl_inline.return_value = [[400]] loader = VclLoader(varnish_api_mock) assert_equals(VclStatus.ERROR, loader.load_new_vcl(Vcl('vcl content')))
def test_load_new_vcl(self, varnish_api_mock): varnish_api_mock.vcl_content_active.return_value = 'vcl old content' varnish_api_mock.vcl_inline.return_value = [[200]] loader = VclLoader(varnish_api_mock) assert_equals(VclStatus.OK, loader.load_new_vcl(Vcl('vcl content')))
def test_return_error_if_cannot_discard_unused_vcl(self, varnish_api_mock): varnish_api_mock.vcls.return_value = {'available': ['unused-1', 'usused-2']} varnish_api_mock.vcl_discard.return_value = [[400]] loader = VclLoader(varnish_api_mock) assert_equals(VclStatus.ERROR, loader.discard_unused_vcls()) assert_equals([call('unused-1'), call('usused-2')], varnish_api_mock.vcl_discard.call_args_list)
def test_do_not_load_new_vcl_if_no_changes(self, varnish_api_mock): varnish_api_mock.vcl_active_name.return_value = 'vcl-current-vol_cfff4' vcl = Mock() vcl.name = 'vcl-new-vol_cfff4' loader = VclLoader(varnish_api_mock) assert_equals(VclStatus.NO_CHANGES, loader.load_new_vcl(vcl))
def test_do_not_load_new_vcl_if_no_changes(self, varnish_api_mock): varnish_api_mock.vcl_active_name.return_value = 'vcl-current-vol.cfff4' vcl = Mock() vcl.name = 'vcl-new-vol.cfff4' loader = VclLoader(varnish_api_mock) assert_equals(VclStatus.NO_CHANGES, loader.load_new_vcl(vcl))
def test_should_suppress_varnish_command_execution_exception_if_proper_parameter_is_passed( self, varnish_api_mock): varnish_api_mock.vcl_content_active.return_value = 'vcl old content' varnish_api_mock.vcl_inline.side_effect = AssertionError() loader = VclLoader(varnish_api_mock, True) assert_equals(VclStatus.NO_CHANGES, loader.load_new_vcl(Vcl('vcl content')))
def test_vcl_is_not_changed(self, varnish_api_mock): varnish_api_mock.vcl_active_name.return_value = 'vcl-current-vol_cfff2' vcl = Vcl('vcl content') vcl.name = 'vcl-new-vol.cfff2' loader = VclLoader(varnish_api_mock) assert_false(loader.vcl_has_changed(vcl))
def test_vcl_is_not_changed(self, varnish_api_mock): varnish_api_mock.vcl_active_name.return_value = 'vcl-current-vol.cfff2' vcl = Vcl('vcl content') vcl.name = 'vcl-new-vol.cfff2' loader = VclLoader(varnish_api_mock) assert_false(loader.vcl_has_changed(vcl))
def load_vcl_list(self, vcl_list): to_use = [] start = time.time() aggregated_result = True with ThreadPoolExecutor(max_workers=self.max_workers) as executor: future_results = [] for server, vcl in vcl_list: loader = VclLoader(self.api_provider.get_api(server)) future_results.append( tuple([ vcl, loader, server, executor.submit(loader.load_new_vcl, vcl) ])) for vcl, loader, server, future_result in future_results: result = future_result.result() if result == VclStatus.ERROR: aggregated_result = False if result == VclStatus.OK: to_use.append(tuple([vcl, loader, server])) if aggregated_result is False: raise VclLoadException self.logger.debug("vcl's loaded: %f" % (time.time() - start)) return to_use
def _append_vcl(self, vcl, server, future_results, executor): loader = VclLoader(self.api_provider.get_api(server)) future_results.append( tuple([ vcl, loader, server, executor.submit(loader.load_new_vcl, vcl) ]))
def _append_vcl(self, vcl, server, future_results, executor): """Suppress exceptions if cannot load vcl for server in maintenance state""" loader = VclLoader(self.api_provider.get_api(server), server.status == 'maintenance') future_results.append( tuple([ vcl, loader, server, executor.submit(loader.load_new_vcl, vcl) ]))
def _append_vcl(self, vcl, server, future_results, executor): """Suppress exceptions if cannot load vcl for server in maintenance state""" try: loader = VclLoader(self.api_provider.get_api(server), server.status == 'maintenance') future_results.append( tuple([ vcl, loader, server, executor.submit(loader.load_new_vcl, vcl) ])) except VclLoadException as e: if server.cluster.partial_reload: return raise e
def test_do_not_discard_unused_vcl_if_not_exists(self, varnish_api_mock): varnish_api_mock.vcls.return_value = {'available': []} loader = VclLoader(varnish_api_mock) assert_equals(VclStatus.NO_CHANGES, loader.discard_unused_vcls())
def test_vcl_is_changed(self, varnish_api_mock): varnish_api_mock.vcl_content_active.return_value = 'vcl old content' loader = VclLoader(varnish_api_mock) assert_true(loader.vcl_has_changed(Vcl('vcl content')))
def test_should_suppress_varnish_command_execution_exception_if_proper_parameter_is_passed(self, varnish_api_mock): varnish_api_mock.vcl_content_active.return_value = 'vcl old content' varnish_api_mock.vcl_inline.side_effect = AssertionError() loader = VclLoader(varnish_api_mock, True) assert_equals(VclStatus.NO_CHANGES, loader.load_new_vcl(Vcl('vcl content')))