Browse Source

tests: fix 'certs' directory for libvirt

keep-around/5aacff7c9cd58cb3cde90e9196e88a617e8bcb6f
Loïc Dachary 7 months ago
committed by some
parent
commit
5aacff7c9c
Signed by: dachary GPG Key ID: 992D23B392F9E4F2
  1. 42
      playbooks/api/tests/test_api.py
  2. 5
      playbooks/openedx/tests/test_openedx.py
  3. 5
      playbooks/psono/tests/test_psono.py
  4. 5
      playbooks/weblate/tests/test_weblate.py
  5. 5
      playbooks/wordpress/tests/test_wordpress.py

42
playbooks/api/tests/test_api.py

@ -20,7 +20,8 @@ def get_domain(inventory):
return yaml.safe_load(open(vars_dir + '/domain.yml'))['domain']
def api_sign_in(pytestconfig, host):
def api_sign_in(request, pytestconfig, host):
certs = request.session.infrastructure.certs()
domain = get_domain(pytestconfig.getoption("--ansible-inventory"))
#
@ -28,7 +29,7 @@ def api_sign_in(pytestconfig, host):
#
lab = requests.Session()
lab_url = f'https://lab.{domain}'
r = lab.get(lab_url + '/users/sign_in', verify='certs')
r = lab.get(lab_url + '/users/sign_in', verify=certs)
r.raise_for_status()
soup = BeautifulSoup(r.text, 'html.parser')
authenticity_token = soup.select(
@ -42,13 +43,13 @@ def api_sign_in(pytestconfig, host):
'user[login]': 'root',
'user[password]': gitlab_utils.get_password(),
'user[remember_me]': 0,
}, verify='certs')
}, verify=certs)
r.raise_for_status()
#
# Revoke all tokens (in case test is run multiple times)
#
r = lab.get(lab_url + '/profile/applications', verify='certs')
r = lab.get(lab_url + '/profile/applications', verify=certs)
r.raise_for_status()
soup = BeautifulSoup(r.text, 'html.parser')
for f in soup.select('.oauth-authorized-applications form'):
@ -58,7 +59,7 @@ def api_sign_in(pytestconfig, host):
continue
data[input['name']] = input['value']
url = urlparse(f['action'])
r = lab.post(lab_url + url.path, params=url.query, data=data, verify='certs')
r = lab.post(lab_url + url.path, params=url.query, data=data, verify=certs)
r.raise_for_status()
#
@ -68,7 +69,7 @@ def api_sign_in(pytestconfig, host):
api.url = f'https://api.{domain}'
r = api.get(api.url + '/accounts/gitlab/login/?process=login',
allow_redirects=False,
verify='certs')
verify=certs)
# print(r.headers['Location'])
assert 'oauth/authorize' in r.headers['Location']
r.raise_for_status()
@ -76,7 +77,7 @@ def api_sign_in(pytestconfig, host):
#
# GitLab OAuth confirmation page
#
r = lab.get(r.headers['Location'], verify='certs')
r = lab.get(r.headers['Location'], verify=certs)
r.raise_for_status()
assert 'An error' not in r.text
soup = BeautifulSoup(r.text, 'html.parser')
@ -91,19 +92,19 @@ def api_sign_in(pytestconfig, host):
# print(soup.prettify())
r = lab.post(lab_url + '/oauth/authorize', data=data,
allow_redirects=False,
verify='certs')
verify=certs)
r.raise_for_status()
assert 'accounts/gitlab/login/callback' in r.headers['Location']
# print(r.headers['Location'])
r = api.get(r.headers['Location'], allow_redirects=False, verify='certs')
r = api.get(r.headers['Location'], allow_redirects=False, verify=certs)
# print(r.headers['Location'])
r.raise_for_status()
if '/accounts/social/signup/' == r.headers['Location']:
#
# API confirm email
#
r = api.get(f"{api.url}{r.headers['Location']}", verify='certs')
r = api.get(f"{api.url}{r.headers['Location']}", verify=certs)
r.raise_for_status()
soup = BeautifulSoup(r.text, 'html.parser')
data = {}
@ -114,7 +115,7 @@ def api_sign_in(pytestconfig, host):
# print(str(data))
# print(soup.prettify())
r = api.post(f'{api.url}/accounts/social/signup/', data=data,
allow_redirects=False, verify='certs')
allow_redirects=False, verify=certs)
r.raise_for_status()
assert r.headers['Location'] == '/member/'
@ -122,7 +123,7 @@ def api_sign_in(pytestconfig, host):
#
# API member page
#
r = api.get(f"{api.url}{r.headers['Location']}", verify='certs')
r = api.get(f"{api.url}{r.headers['Location']}", verify=certs)
r.raise_for_status()
#
# Get rest-framework token
@ -142,8 +143,9 @@ def api_sign_in(pytestconfig, host):
# enough ssh api-host
# docker exec -ti enough_enough-enough_1 journalctl -n 200 -f --unit enough
#
def test_delegate_test_dns(pytestconfig, host):
token = api_sign_in(pytestconfig, host)
def test_delegate_test_dns(request, pytestconfig, host):
certs = request.session.infrastructure.certs()
token = api_sign_in(request, pytestconfig, host)
domain = get_domain(pytestconfig.getoption("--ansible-inventory"))
url = f"https://api.{domain}"
s = requests.Session()
@ -152,7 +154,7 @@ def test_delegate_test_dns(pytestconfig, host):
"name": "foo",
"ip": "1.2.3.4",
}
r = s.post(f'{url}/delegate-test-dns/', json=data, timeout=60, verify='certs')
r = s.post(f'{url}/delegate-test-dns/', json=data, timeout=60, verify=certs)
# print(r.text)
r.raise_for_status()
resolver = dns.resolver.Resolver()
@ -161,7 +163,8 @@ def test_delegate_test_dns(pytestconfig, host):
assert '1.2.3.4' == str(resolver.query(f'ns-foo.test.{domain}.', 'a')[0])
def test_delegate_dns(pytestconfig, host):
def test_delegate_dns(request, pytestconfig, host):
certs = request.session.infrastructure.certs()
domain = get_domain(pytestconfig.getoption("--ansible-inventory"))
url = f"https://api.{domain}"
s = requests.Session()
@ -169,7 +172,7 @@ def test_delegate_dns(pytestconfig, host):
"name": f"bar",
"ip": "5.6.7.8",
}
r = s.post(f'{url}/delegate-dns/', json=data, timeout=60, verify='certs')
r = s.post(f'{url}/delegate-dns/', json=data, timeout=60, verify=certs)
# print(r.text)
r.raise_for_status()
resolver = dns.resolver.Resolver()
@ -178,10 +181,11 @@ def test_delegate_dns(pytestconfig, host):
assert '5.6.7.8' == str(resolver.query(f'ns-bar.d.{domain}.', 'a')[0])
def test_ping(pytestconfig, host):
def test_ping(request, pytestconfig, host):
certs = request.session.infrastructure.certs()
domain = get_domain(pytestconfig.getoption("--ansible-inventory"))
url = f"https://api.{domain}"
s = requests.Session()
r = s.get(f'{url}/ping/', timeout=60, verify='certs')
r = s.get(f'{url}/ping/', timeout=60, verify=certs)
r.raise_for_status()
assert 'pong' == r.text

5
playbooks/openedx/tests/test_openedx.py

@ -9,11 +9,12 @@ def get_address(inventory):
open(vars_dir + '/domain.yml'))['domain']
def test_openedx(pytestconfig):
def test_openedx(request, pytestconfig):
certs = request.session.infrastructure.certs()
# openedx freshly recreated may take few mins to be operationnal
url = get_address(pytestconfig.getoption("--ansible-inventory"))
for i in range(60, 0, -1):
r = requests.get(url, timeout=5, verify='certs')
r = requests.get(url, timeout=5, verify=certs)
if r.status_code == requests.codes.ok:
break
time.sleep(5)

5
playbooks/psono/tests/test_psono.py

@ -9,11 +9,12 @@ def get_address(inventory):
open(vars_dir + '/domain.yml'))['domain']
def test_psono(pytestconfig):
def test_psono(request, pytestconfig):
certs = request.session.infrastructure.certs()
# psono freshly recreated may take few mins to be operationnal
url = get_address(pytestconfig.getoption("--ansible-inventory"))
for i in range(60, 0, -1):
r = requests.get(url, timeout=5, verify='certs')
r = requests.get(url, timeout=5, verify=certs)
if r.status_code == requests.codes.ok:
break
time.sleep(5)

5
playbooks/weblate/tests/test_weblate.py

@ -9,11 +9,12 @@ def get_address(inventory):
open(vars_dir + '/domain.yml'))['domain']
def test_weblate(pytestconfig):
def test_weblate(request, pytestconfig):
certs = request.session.infrastructure.certs()
# weblate freshly recreated may take few mins to be operationnal
url = get_address(pytestconfig.getoption("--ansible-inventory"))
for i in range(60, 0, -1):
r = requests.get(url, timeout=5, verify='certs')
r = requests.get(url, timeout=5, verify=certs)
if r.status_code == requests.codes.ok:
break
time.sleep(5)

5
playbooks/wordpress/tests/test_wordpress.py

@ -9,11 +9,12 @@ def get_address(inventory):
open(vars_dir + '/domain.yml'))['domain']
def test_wordpress(pytestconfig):
def test_wordpress(request, pytestconfig):
certs = request.session.infrastructure.certs()
# wordpress freshly recreated may take few mins to be operationnal
url = get_address(pytestconfig.getoption("--ansible-inventory"))
for i in range(60, 0, -1):
r = requests.get(url, timeout=5, verify='certs')
r = requests.get(url, timeout=5, verify=certs)
if r.status_code == requests.codes.ok:
break
time.sleep(5)

Loading…
Cancel
Save