|
| 1 | +import os |
| 2 | +import pytest |
| 3 | +import testinfra.utils.ansible_runner |
| 4 | + |
| 5 | +testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( |
| 6 | + os.environ['MOLECULE_INVENTORY_FILE'] |
| 7 | +).get_hosts('all') |
| 8 | + |
| 9 | +debian_pkg = [] |
| 10 | +debian_pkg.append('python-psycopg2') |
| 11 | +debian_pkg.append('libpq-dev') |
| 12 | +debian_pkg.append('pgadmin4') |
| 13 | +debian_pkg.append('postgresql-client-9.5') |
| 14 | +debian_pkg.append('postgresql-9.5') |
| 15 | +debian_pkg.append('postgresql-contrib-9.5') |
| 16 | +debian_pkg.append('postgresql-server-dev-9.5') |
| 17 | + |
| 18 | + |
| 19 | +def test_debian_pkg(host): |
| 20 | + os = host.system_info.distribution |
| 21 | + |
| 22 | + if os == 'debian': |
| 23 | + debian_package = host.package(debian_pkg) |
| 24 | + |
| 25 | + assert debian_package.is_installed |
| 26 | + |
| 27 | + |
| 28 | +redhat_pkg = [] |
| 29 | +redhat_pkg.append('postgresql-contrib') |
| 30 | +redhat_pkg.append('postgresql-devel') |
| 31 | +redhat_pkg.append('python-psycopg2') |
| 32 | +redhat_pkg.append('postgresql95') |
| 33 | +redhat_pkg.append('postgresql95-server') |
| 34 | + |
| 35 | + |
| 36 | +def test_redhat_pkg(host): |
| 37 | + os = host.system_info.distribution |
| 38 | + |
| 39 | + if os == 'redhat': |
| 40 | + redhat_package = host.package(redhat_pkg) |
| 41 | + |
| 42 | + assert redhat_package.is_installed |
| 43 | + |
| 44 | + |
| 45 | +def test_postgresql_service(host): |
| 46 | + os = host.system_info.distribution |
| 47 | + |
| 48 | + if os == 'debian': |
| 49 | + debian_service = host.service('postgresql') |
| 50 | + |
| 51 | + assert debian_service.is_running |
| 52 | + |
| 53 | + elif os == 'redhat': |
| 54 | + redhat_service = host.service('postgresql9.5') |
| 55 | + |
| 56 | + assert redhat_service.is_running |
| 57 | + |
| 58 | + |
| 59 | +@pytest.mark.parametrize('user', ['demo1', 'demo2']) |
| 60 | +def test_user(host, user): |
| 61 | + c1 = "sudo -u postgres psql -t -c" |
| 62 | + user_status = host.run(c1+"'\\du' | cut -d \\| -f 1 | grep -w "+user) |
| 63 | + |
| 64 | + assert user_status.succeeded |
| 65 | + |
| 66 | + |
| 67 | +@pytest.mark.parametrize('db', ['test1', 'test2']) |
| 68 | +def test_database(host, db): |
| 69 | + c1 = "sudo -u postgres psql -t -c" |
| 70 | + db_status = host.run(c1+"'\\l' | cut -d \\| -f 1 | grep -w "+db) |
| 71 | + |
| 72 | + assert db_status.succeeded |
0 commit comments