42 lines
1.2 KiB
Python
42 lines
1.2 KiB
Python
import testinfra.utils.ansible_runner
|
|
|
|
def test_packages(host):
|
|
for package_name in ['postgresql-13', 'python3-psycopg2']:
|
|
package = host.package(package_name)
|
|
assert package.is_installed
|
|
|
|
def test_config_file(host):
|
|
path = host.file('/etc/postgresql/13/main/postgresql.conf')
|
|
assert path.exists
|
|
assert path.is_file
|
|
assert path.user == 'root'
|
|
assert path.group == 'root'
|
|
assert path.mode == 0o644
|
|
assert path.contains("listen_addresses = '*'")
|
|
|
|
def test_hba_file(host):
|
|
path = host.file('/etc/postgresql/13/main/pg_hba.conf')
|
|
assert path.exists
|
|
assert path.is_file
|
|
assert path.user == 'root'
|
|
assert path.group == 'root'
|
|
assert path.mode == 0o644
|
|
assert path.contains('hostssl "myappli" all samenet md5')
|
|
|
|
|
|
def test_service(host):
|
|
service = host.service('postgresql@13-main')
|
|
assert service.is_running
|
|
assert service.is_enabled
|
|
|
|
def test_socket(host):
|
|
socket = host.socket('tcp://127.0.0.1:5432')
|
|
assert socket.is_listening
|
|
|
|
def test_database(host):
|
|
output = host.check_output('su - postgres -c "psql -c \'\\l\'"')
|
|
assert 'myappli' in output
|
|
|
|
def test_user(host):
|
|
output = host.check_output('su - postgres -c "psql -c \'\\du\'"')
|
|
assert 'myuser' in output
|