Show More
@@ -645,9 +645,10 b' vcs.scm_app_implementation = http' | |||
|
645 | 645 | ; `http` - use http-rpc backend (default) |
|
646 | 646 | vcs.hooks.protocol = http |
|
647 | 647 | |
|
648 |
; Host on which this instance is listening for hooks. |
|
|
649 | ; this should be adjusted. | |
|
650 | vcs.hooks.host = 127.0.0.1 | |
|
648 | ; Host on which this instance is listening for hooks. vcsserver will call this host to pull/push hooks so it should be | |
|
649 | ; accessible via network. | |
|
650 | ; Use vcs.hooks.host = "*" to bind to current hostname (for Docker) | |
|
651 | vcs.hooks.host = * | |
|
651 | 652 | |
|
652 | 653 | ; Start VCSServer with this instance as a subprocess, useful for development |
|
653 | 654 | vcs.start_server = false |
@@ -596,9 +596,10 b' vcs.scm_app_implementation = http' | |||
|
596 | 596 | ; `http` - use http-rpc backend (default) |
|
597 | 597 | vcs.hooks.protocol = http |
|
598 | 598 | |
|
599 |
; Host on which this instance is listening for hooks. |
|
|
600 | ; this should be adjusted. | |
|
601 | vcs.hooks.host = 127.0.0.1 | |
|
599 | ; Host on which this instance is listening for hooks. vcsserver will call this host to pull/push hooks so it should be | |
|
600 | ; accessible via network. | |
|
601 | ; Use vcs.hooks.host = "*" to bind to current hostname (for Docker) | |
|
602 | vcs.hooks.host = * | |
|
602 | 603 | |
|
603 | 604 | ; Start VCSServer with this instance as a subprocess, useful for development |
|
604 | 605 | vcs.start_server = false |
@@ -153,18 +153,23 b' class HttpHooksCallbackDaemon(ThreadedHo' | |||
|
153 | 153 | # request and wastes cpu at all other times. |
|
154 | 154 | POLL_INTERVAL = 0.01 |
|
155 | 155 | |
|
156 | def get_hostname(self): | |
|
157 | return socket.gethostname() or '127.0.0.1' | |
|
158 | ||
|
156 | 159 | def get_available_port(self): |
|
157 | 160 | mysocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
|
158 |
mysocket.bind(( |
|
|
161 | mysocket.bind((self.get_hostname(), 0)) | |
|
159 | 162 | port = mysocket.getsockname()[1] |
|
160 | 163 | mysocket.close() |
|
161 | 164 | del mysocket |
|
162 | 165 | return port |
|
163 | 166 | |
|
164 | 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 | 173 | server_address = (host, port) |
|
169 | 174 | self.hooks_uri = '{}:{}'.format(host, port) |
|
170 | 175 | self.txn_id = txn_id |
@@ -175,29 +175,39 b' class ThreadedHookCallbackDaemon(object)' | |||
|
175 | 175 | |
|
176 | 176 | |
|
177 | 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 | 188 | def test_prepare_inits_daemon_variable(self, tcp_server, caplog): |
|
179 | 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 | 191 | assert daemon._daemon == tcp_server |
|
182 | 192 | |
|
183 | 193 | _, port = tcp_server.server_address |
|
184 | 194 | expected_uri = '{}:{}'.format('127.0.0.1', port) |
|
185 | 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 | 197 | assert_message_in_log( |
|
188 | 198 | caplog.records, msg, levelno=logging.DEBUG, module='hooks_daemon') |
|
189 | 199 | |
|
190 | 200 | def test_prepare_inits_hooks_uri_and_logs_it( |
|
191 | 201 | self, tcp_server, caplog): |
|
192 | 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 | 205 | _, port = tcp_server.server_address |
|
196 | 206 | expected_uri = '{}:{}'.format('127.0.0.1', port) |
|
197 | 207 | assert daemon.hooks_uri == expected_uri |
|
198 | 208 | |
|
199 | 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 | 211 | assert_message_in_log( |
|
202 | 212 | caplog.records, msg, |
|
203 | 213 | levelno=logging.DEBUG, module='hooks_daemon') |
@@ -494,7 +494,7 b' vcs.hooks.protocol = http' | |||
|
494 | 494 | |
|
495 | 495 | ; Host on which this instance is listening for hooks. If vcsserver is in other location |
|
496 | 496 | ; this should be adjusted. |
|
497 |
vcs.hooks.host = |
|
|
497 | vcs.hooks.host = * | |
|
498 | 498 | |
|
499 | 499 | ; Start VCSServer with this instance as a subprocess, useful for development |
|
500 | 500 | vcs.start_server = false |
General Comments 0
You need to be logged in to leave comments.
Login now