##// END OF EJS Templates
hooks: allow to bind to existing hostname automatically if nothing explicitly is set.
super-admin -
r4859:169b0860 default
parent child Browse files
Show More
@@ -645,9 +645,10 b' vcs.scm_app_implementation = http'
645 ; `http` - use http-rpc backend (default)
645 ; `http` - use http-rpc backend (default)
646 vcs.hooks.protocol = http
646 vcs.hooks.protocol = http
647
647
648 ; Host on which this instance is listening for hooks. If vcsserver is in other location
648 ; Host on which this instance is listening for hooks. vcsserver will call this host to pull/push hooks so it should be
649 ; this should be adjusted.
649 ; accessible via network.
650 vcs.hooks.host = 127.0.0.1
650 ; Use vcs.hooks.host = "*" to bind to current hostname (for Docker)
651 vcs.hooks.host = *
651
652
652 ; Start VCSServer with this instance as a subprocess, useful for development
653 ; Start VCSServer with this instance as a subprocess, useful for development
653 vcs.start_server = false
654 vcs.start_server = false
@@ -596,9 +596,10 b' vcs.scm_app_implementation = http'
596 ; `http` - use http-rpc backend (default)
596 ; `http` - use http-rpc backend (default)
597 vcs.hooks.protocol = http
597 vcs.hooks.protocol = http
598
598
599 ; Host on which this instance is listening for hooks. If vcsserver is in other location
599 ; Host on which this instance is listening for hooks. vcsserver will call this host to pull/push hooks so it should be
600 ; this should be adjusted.
600 ; accessible via network.
601 vcs.hooks.host = 127.0.0.1
601 ; Use vcs.hooks.host = "*" to bind to current hostname (for Docker)
602 vcs.hooks.host = *
602
603
603 ; Start VCSServer with this instance as a subprocess, useful for development
604 ; Start VCSServer with this instance as a subprocess, useful for development
604 vcs.start_server = false
605 vcs.start_server = false
@@ -153,18 +153,23 b' class HttpHooksCallbackDaemon(ThreadedHo'
153 # request and wastes cpu at all other times.
153 # request and wastes cpu at all other times.
154 POLL_INTERVAL = 0.01
154 POLL_INTERVAL = 0.01
155
155
156 def get_hostname(self):
157 return socket.gethostname() or '127.0.0.1'
158
156 def get_available_port(self):
159 def get_available_port(self):
157 mysocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
160 mysocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
158 mysocket.bind(('127.0.0.1', 0))
161 mysocket.bind((self.get_hostname(), 0))
159 port = mysocket.getsockname()[1]
162 port = mysocket.getsockname()[1]
160 mysocket.close()
163 mysocket.close()
161 del mysocket
164 del mysocket
162 return port
165 return port
163
166
164 def _prepare(self, txn_id=None, host=None, port=None):
167 def _prepare(self, txn_id=None, host=None, port=None):
168 if not host or host == "*":
169 host = self.get_hostname()
170 if not port:
171 port = self.get_available_port()
165
172
166 host = host or '127.0.0.1'
167 port = port or self.get_available_port()
168 server_address = (host, port)
173 server_address = (host, port)
169 self.hooks_uri = '{}:{}'.format(host, port)
174 self.hooks_uri = '{}:{}'.format(host, port)
170 self.txn_id = txn_id
175 self.txn_id = txn_id
@@ -175,29 +175,39 b' class ThreadedHookCallbackDaemon(object)'
175
175
176
176
177 class TestHttpHooksCallbackDaemon(object):
177 class TestHttpHooksCallbackDaemon(object):
178 def test_hooks_callback_generates_new_port(self, caplog):
179 with caplog.at_level(logging.DEBUG):
180 daemon = hooks_daemon.HttpHooksCallbackDaemon(host='127.0.0.1', port=8881)
181 assert daemon._daemon.server_address == ('127.0.0.1', 8881)
182
183 with caplog.at_level(logging.DEBUG):
184 daemon = hooks_daemon.HttpHooksCallbackDaemon(host=None, port=None)
185 assert daemon._daemon.server_address[1] in range(0, 66000)
186 assert daemon._daemon.server_address[0] != '127.0.0.1'
187
178 def test_prepare_inits_daemon_variable(self, tcp_server, caplog):
188 def test_prepare_inits_daemon_variable(self, tcp_server, caplog):
179 with self._tcp_patcher(tcp_server), caplog.at_level(logging.DEBUG):
189 with self._tcp_patcher(tcp_server), caplog.at_level(logging.DEBUG):
180 daemon = hooks_daemon.HttpHooksCallbackDaemon()
190 daemon = hooks_daemon.HttpHooksCallbackDaemon(host='127.0.0.1', port=8881)
181 assert daemon._daemon == tcp_server
191 assert daemon._daemon == tcp_server
182
192
183 _, port = tcp_server.server_address
193 _, port = tcp_server.server_address
184 expected_uri = '{}:{}'.format('127.0.0.1', port)
194 expected_uri = '{}:{}'.format('127.0.0.1', port)
185 msg = 'Preparing HTTP callback daemon at `{}` and ' \
195 msg = 'Preparing HTTP callback daemon at `{}` and ' \
186 'registering hook object'.format(expected_uri)
196 'registering hook object: rhodecode.lib.hooks_daemon.HooksHttpHandler'.format(expected_uri)
187 assert_message_in_log(
197 assert_message_in_log(
188 caplog.records, msg, levelno=logging.DEBUG, module='hooks_daemon')
198 caplog.records, msg, levelno=logging.DEBUG, module='hooks_daemon')
189
199
190 def test_prepare_inits_hooks_uri_and_logs_it(
200 def test_prepare_inits_hooks_uri_and_logs_it(
191 self, tcp_server, caplog):
201 self, tcp_server, caplog):
192 with self._tcp_patcher(tcp_server), caplog.at_level(logging.DEBUG):
202 with self._tcp_patcher(tcp_server), caplog.at_level(logging.DEBUG):
193 daemon = hooks_daemon.HttpHooksCallbackDaemon()
203 daemon = hooks_daemon.HttpHooksCallbackDaemon(host='127.0.0.1', port=8881)
194
204
195 _, port = tcp_server.server_address
205 _, port = tcp_server.server_address
196 expected_uri = '{}:{}'.format('127.0.0.1', port)
206 expected_uri = '{}:{}'.format('127.0.0.1', port)
197 assert daemon.hooks_uri == expected_uri
207 assert daemon.hooks_uri == expected_uri
198
208
199 msg = 'Preparing HTTP callback daemon at `{}` and ' \
209 msg = 'Preparing HTTP callback daemon at `{}` and ' \
200 'registering hook object'.format(expected_uri)
210 'registering hook object: rhodecode.lib.hooks_daemon.HooksHttpHandler'.format(expected_uri)
201 assert_message_in_log(
211 assert_message_in_log(
202 caplog.records, msg,
212 caplog.records, msg,
203 levelno=logging.DEBUG, module='hooks_daemon')
213 levelno=logging.DEBUG, module='hooks_daemon')
@@ -494,7 +494,7 b' vcs.hooks.protocol = http'
494
494
495 ; Host on which this instance is listening for hooks. If vcsserver is in other location
495 ; Host on which this instance is listening for hooks. If vcsserver is in other location
496 ; this should be adjusted.
496 ; this should be adjusted.
497 vcs.hooks.host = 127.0.0.1
497 vcs.hooks.host = *
498
498
499 ; Start VCSServer with this instance as a subprocess, useful for development
499 ; Start VCSServer with this instance as a subprocess, useful for development
500 vcs.start_server = false
500 vcs.start_server = false
General Comments 0
You need to be logged in to leave comments. Login now