mirror of
https://github.com/odoo/runbot.git
synced 2025-03-27 13:25:47 +07:00
[FIX] *: ngrok tunnel for 3.x
ngrok 3 scrambled some of the tunnel configuration keys. Most notably, it replaced the ill-named `bind_tls` by an explicit list of http `schemes`. Although it *removed* `bind_tls` so the fix is necessary for ngrok to work again (especially as ngrok2 is reaching EOL). While at it, improve the tunnel setup somewhat: - remove fixme which we're probably not going to fix after all - if we spawn ngrok ourselves, keep the handle around so we can - kill the process we spawned directly instead of looking it up somewhat awkwardly
This commit is contained in:
parent
cea1b62ac2
commit
7054c865d7
23
conftest.py
23
conftest.py
@ -65,7 +65,6 @@ import warnings
|
|||||||
import xmlrpc.client
|
import xmlrpc.client
|
||||||
from contextlib import closing
|
from contextlib import closing
|
||||||
|
|
||||||
import psutil
|
|
||||||
import pytest
|
import pytest
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
@ -197,6 +196,7 @@ def tunnel(pytestconfig, port):
|
|||||||
if tunnel == '':
|
if tunnel == '':
|
||||||
yield f'http://localhost:{port}'
|
yield f'http://localhost:{port}'
|
||||||
elif tunnel == 'ngrok':
|
elif tunnel == 'ngrok':
|
||||||
|
own = None
|
||||||
web_addr = 'http://localhost:4040/api'
|
web_addr = 'http://localhost:4040/api'
|
||||||
addr = 'localhost:%d' % port
|
addr = 'localhost:%d' % port
|
||||||
# try to find out if ngrok is running, and if it's not attempt
|
# try to find out if ngrok is running, and if it's not attempt
|
||||||
@ -205,13 +205,9 @@ def tunnel(pytestconfig, port):
|
|||||||
# FIXME: this is for xdist to avoid workers running ngrok at the
|
# FIXME: this is for xdist to avoid workers running ngrok at the
|
||||||
# exact same time, use lockfile instead
|
# exact same time, use lockfile instead
|
||||||
time.sleep(random.SystemRandom().randint(1, 10))
|
time.sleep(random.SystemRandom().randint(1, 10))
|
||||||
# FIXME: use config file so we can set web_addr to something else
|
|
||||||
# than localhost:4040 (otherwise we can't disambiguate
|
|
||||||
# between the ngrok we started and an ngrok started by
|
|
||||||
# some other user)
|
|
||||||
requests.get(web_addr)
|
requests.get(web_addr)
|
||||||
except requests.exceptions.ConnectionError:
|
except requests.exceptions.ConnectionError:
|
||||||
subprocess.Popen(NGROK_CLI, stdout=subprocess.DEVNULL)
|
own = subprocess.Popen(NGROK_CLI, stdout=subprocess.DEVNULL)
|
||||||
for _ in range(5):
|
for _ in range(5):
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
with contextlib.suppress(requests.exceptions.ConnectionError):
|
with contextlib.suppress(requests.exceptions.ConnectionError):
|
||||||
@ -223,8 +219,8 @@ def tunnel(pytestconfig, port):
|
|||||||
requests.post(f'{web_addr}/tunnels', json={
|
requests.post(f'{web_addr}/tunnels', json={
|
||||||
'name': str(port),
|
'name': str(port),
|
||||||
'proto': 'http',
|
'proto': 'http',
|
||||||
'bind_tls': True, # only https
|
|
||||||
'addr': addr,
|
'addr': addr,
|
||||||
|
'schemes': ['https'],
|
||||||
'inspect': True,
|
'inspect': True,
|
||||||
}).raise_for_status()
|
}).raise_for_status()
|
||||||
|
|
||||||
@ -252,17 +248,14 @@ def tunnel(pytestconfig, port):
|
|||||||
raise TimeoutError("ngrok tunnel deletion failed")
|
raise TimeoutError("ngrok tunnel deletion failed")
|
||||||
|
|
||||||
r = requests.get(f'{web_addr}/tunnels')
|
r = requests.get(f'{web_addr}/tunnels')
|
||||||
|
assert r.ok, f'{r.reason} {r.text}'
|
||||||
# there are still tunnels in the list -> bail
|
# there are still tunnels in the list -> bail
|
||||||
if r.ok and r.json()['tunnels']:
|
if not own or r.json()['tunnels']:
|
||||||
return
|
return
|
||||||
|
|
||||||
# ngrok is broken or all tunnels have been shut down -> try to
|
# no more tunnels and we started ngrok -> try to kill it
|
||||||
# find and kill it (but only if it looks a lot like we started it)
|
own.terminate()
|
||||||
for p in psutil.process_iter():
|
own.wait(30)
|
||||||
if p.name() == 'ngrok' and p.cmdline() == NGROK_CLI:
|
|
||||||
p.terminate()
|
|
||||||
break
|
|
||||||
return
|
|
||||||
else:
|
else:
|
||||||
raise TimeoutError("ngrok tunnel creation failed (?)")
|
raise TimeoutError("ngrok tunnel creation failed (?)")
|
||||||
elif tunnel == 'localtunnel':
|
elif tunnel == 'localtunnel':
|
||||||
|
Loading…
Reference in New Issue
Block a user