forked from ome/prod-playbooks
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use the test from prod-playbooks master
- Loading branch information
1 parent
dbd3ff8
commit 547d655
Showing
1 changed file
with
39 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,102 +1,63 @@ | ||
import json | ||
import os | ||
import pytest | ||
from time import sleep, time | ||
import testinfra.utils.ansible_runner | ||
|
||
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( | ||
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') | ||
|
||
|
||
OMERO = '/opt/omero/server/OMERO.server/bin/omero' | ||
ROOT_PASSWORD = 'ChangeMe' | ||
|
||
|
||
def test_db_running_and_enabled(host): | ||
if host.system_info.distribution == 'ubuntu': | ||
service = host.service('postgresql@16-main') | ||
else: | ||
service = host.service('postgresql-16') | ||
assert service.is_running | ||
assert service.is_enabled | ||
|
||
|
||
def test_srv_running_and_enabled(host): | ||
service = host.service('omero-server') | ||
OMERO_LOGIN = '-C -s localhost -u root -w omero' | ||
|
||
|
||
@pytest.mark.parametrize("name", [ | ||
'nginx', | ||
'omero-server', | ||
'omero-web', | ||
'postgresql-13', | ||
'prometheus-node-exporter', | ||
'prometheus-omero-exporter', | ||
'prometheus-postgres-exporter', | ||
]) | ||
def test_service_running_and_enabled(host, name): | ||
service = host.service(name) | ||
assert service.is_running | ||
assert service.is_enabled | ||
|
||
|
||
def test_omero_login(host): | ||
# Ubuntu sudo doesn't set HOME so it tries to write to /root | ||
env = 'OMERO_USERDIR=/tmp/omero-{}'.format(time()) | ||
with host.sudo('omero-server'): | ||
with host.sudo('importer1'): | ||
host.check_output( | ||
'%s %s login -C -s localhost -u root -w %s' % ( | ||
env, OMERO, ROOT_PASSWORD)) | ||
|
||
|
||
@pytest.mark.parametrize('name', ['omero-web', 'nginx']) | ||
def test_services_running_and_enabled(host, name): | ||
service = host.service(name) | ||
assert service.is_running | ||
assert service.is_enabled | ||
|
||
|
||
def test_omero_web_first_page(host): | ||
out1 = host.check_output('curl -fsL http://localhost') | ||
assert 'WEBCLIENT.active_group_id' in out1 | ||
out2 = host.check_output('curl -fsL http://localhost/webclient/login') | ||
assert 'omero:4064' in out2 | ||
'/opt/omero/server/OMERO.server/bin/omero ' | ||
'login -C -s localhost -u root -w omero') | ||
|
||
|
||
def get_cookie(cookietxt, name): | ||
for line in cookietxt.splitlines(): | ||
tokens = line.split() | ||
try: | ||
if tokens[5] == name: | ||
return tokens[6] | ||
except IndexError: | ||
pass | ||
@pytest.mark.parametrize("curl", [ | ||
'localhost:9449/metrics', | ||
'-u monitoring:monitoring -k https://localhost/metrics/9449', | ||
]) | ||
def test_omero_metrics(host, curl): | ||
out = host.check_output('curl -f %s' % curl) | ||
assert 'omero_sessions_active' in out | ||
|
||
|
||
# https://github.com/openmicroscopy/omero-grid-docker/blob/0.1.0/test_login.sh | ||
def test_omero_web_login(host): | ||
LOGIN_URL = 'http://localhost/webclient/login/' | ||
CURL = 'curl -f -i -k -s -c cookies.txt -b cookies.txt -e %s' % LOGIN_URL | ||
def test_omero_metrics_auth_fail(host): | ||
out = host.run( | ||
'curl -f -u monitoring:incorrect -k https://localhost/metrics/9449') | ||
assert out.rc == 22 | ||
assert '401' in out.stderr | ||
|
||
for i in range(60): | ||
sleep(2) | ||
host.check_output('%s %s' % (CURL, LOGIN_URL)) | ||
csrf = get_cookie(host.file('cookies.txt').content_string, 'csrftoken') | ||
if csrf: | ||
break | ||
assert csrf | ||
|
||
data = '&'.join([ | ||
'csrfmiddlewaretoken=%s' % csrf, | ||
'username=root', | ||
'password=%s' % ROOT_PASSWORD, | ||
'server=1', | ||
'url=%2Fwebclient%2F', | ||
]) | ||
def test_omero_nginx_ssl(host): | ||
out = host.check_output('curl -fkI https://localhost/') | ||
assert 'Location: /webclient/' in out | ||
|
||
for i in range(60): | ||
sleep(2) | ||
host.check_output('%s -d "%s" -X POST %s' % ( | ||
CURL, data, LOGIN_URL)) | ||
sessionid = get_cookie( | ||
host.file('cookies.txt').content_string, 'sessionid') | ||
if sessionid: | ||
break | ||
assert sessionid | ||
|
||
def test_local_ldap(host): | ||
initialised = host.check_output( | ||
'/home/ldap/ldapmanager get dc=openmicroscopy,dc=org') | ||
if len(initialised.strip()) == 0: | ||
host.check_output('/home/ldap/ldapmanager init') | ||
|
||
def test_omero_web_public(host): | ||
out = host.check_output( | ||
'curl -f http://localhost/webclient/api/containers/') | ||
r = json.loads(out) | ||
assert r['screens'] == [] | ||
assert r['plates'] == [] | ||
assert r['projects'] == [] | ||
assert r['datasets'] == [] | ||
'/home/ldap/ldapmanager get dc=openmicroscopy,dc=org') | ||
assert 'dn: dc=openmicroscopy,dc=org' in out |