def test_should_create_varnish_api_clients_for_all_servers(self): expected_construct_args = [ call(['127.0.0.1', '6082', 1.0], 'secret-1'), call(['127.0.0.2', '6083', 1.0], 'secret-2'), call(['127.0.0.3', '6084', 1.0], 'secret-3') ] sample_extractor = Mock(servers=servers) with patch('vaas.cluster.cluster.ServerExtractor', Mock(return_value=sample_extractor)): with patch.object(VarnishApi, '__init__', return_value=None) as construct_mock: varnish_cluster = VarnishApiProvider() api_objects = [] for api in varnish_cluster.get_varnish_api(): """ Workaround - we cannot mock __del__ method: https://docs.python.org/3/library/unittest.mock.html We inject sock field to eliminate warning raised by cleaning actions in __del__ method """ api.sock = None api_objects.append(api) assert_equals(3, len(api_objects)) assert_list_equal(expected_construct_args, construct_mock.call_args_list)
def test_should_throw_vcl_load_exception_on_any_error_while_connecting_to_varnish_api( self): with patch.object(VarnishApi, '__init__', side_effect=Exception): with patch.object(VarnishApi, '__del__'): varnish_cluster = VarnishApiProvider() with self.assertRaises(VclLoadException): varnish_cluster.get_api(servers[0])
def test_should_create_varnish_api_for_connected_servers(self): expected_construct_args = [ call(['127.0.0.1', '6082', 1.0], 'secret-1'), call(['127.0.0.2', '6083', 1.0], 'secret-2'), call(['127.0.0.3', '6084', 1.0], 'secret-3') ] sample_extractor = Mock(servers=servers) api_init_side_effect = { 'secret-1': Exception(), 'secret-2': None, 'secret-3': None } with patch('vaas.cluster.cluster.ServerExtractor', Mock(return_value=sample_extractor)): with patch.object(VarnishApi, '__init__', side_effect=lambda host_port_timeout, secret: api_init_side_effect[secret]) as construct_mock: with patch('telnetlib.Telnet.close', Mock()): varnish_cluster = VarnishApiProvider() api_objects = [] for api in varnish_cluster.get_connected_varnish_api(): """ Workaround - we cannot mock __del__ method: https://docs.python.org/3/library/unittest.mock.html We inject sock field to eliminate warning raised by cleaning actions in __del__ method """ api.sock = None api_objects.append(api) assert_equals(2, len(api_objects)) assert_list_equal(expected_construct_args, construct_mock.call_args_list)
def __init__(self): self.varnish_api_provider = VarnishApiProvider() self.logger = logging.getLogger('vaas') self.timestamp = datetime.datetime.utcnow().replace(tzinfo=utc)
def get_list_display(self, request): self.varnish_api_provider = VarnishApiProvider() return super(VarnishServerAdmin, self).get_list_display(request)
def __init__(self): self.varnish_api_provider = VarnishApiProvider() self.logger = logging.getLogger('vaas')
def __init__(self): self.varnish_api_provider = VarnishApiProvider()
def provide_backend_status_manager(): return BackendStatusManager(VarnishApiProvider(), ServerExtractor().servers, settings.VAAS_GATHER_STATUSES_CONNECT_TIMEOUT, settings.VAAS_GATHER_STATUSES_MAX_WORKERS)