Files
@ e970d4afbea4
Branch filter:
Location: majic-ansible-roles/roles/database/molecule/default/tests/test_default.py - annotation
e970d4afbea4
1.4 KiB
text/x-python
MAR-128: Upgraded tests for xmpp_server role:
- Switch to new Molecule configuration.
- Updated set-up playbook to use become: yes.
- Moved some preparatory steps outside of the main playbook (eases
idempotence tests).
- Updated tests to reference the yml inventory file.
- Updated tests to use new fixture (host instead of individual ones).
- Switched to extracting hostname instead of hard-coding it in a
couple of tests.
- Renamed hosts to include the Debian version.
- Updated names for some of the test data to cater to change in host
names.
- Switched to using more robust task for populating /etc/hosts.
- Switch to new Molecule configuration.
- Updated set-up playbook to use become: yes.
- Moved some preparatory steps outside of the main playbook (eases
idempotence tests).
- Updated tests to reference the yml inventory file.
- Updated tests to use new fixture (host instead of individual ones).
- Switched to extracting hostname instead of hard-coding it in a
couple of tests.
- Renamed hosts to include the Debian version.
- Updated names for some of the test data to cater to change in host
names.
- Switched to using more robust task for populating /etc/hosts.
c6e7675e63f9 c6e7675e63f9 c6e7675e63f9 8278ff584984 c6e7675e63f9 c6e7675e63f9 8278ff584984 862402d2c45b 862402d2c45b 862402d2c45b c6e7675e63f9 8278ff584984 8278ff584984 862402d2c45b 862402d2c45b 862402d2c45b 862402d2c45b 862402d2c45b 8278ff584984 862402d2c45b 862402d2c45b 862402d2c45b 862402d2c45b 8278ff584984 862402d2c45b 862402d2c45b 862402d2c45b 862402d2c45b 8278ff584984 862402d2c45b 862402d2c45b 862402d2c45b 862402d2c45b 8278ff584984 862402d2c45b 862402d2c45b 862402d2c45b 862402d2c45b 8278ff584984 8278ff584984 862402d2c45b 862402d2c45b 862402d2c45b | import testinfra.utils.ansible_runner
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
'.molecule/ansible_inventory.yml').get_hosts('all')
def test_database_created(host):
"""
Tests if database has been created.
"""
with host.sudo():
show_databases = host.run("mysql -BNe \"show databases like 'testdb'\"")
assert show_databases.rc == 0
assert show_databases.stdout == "testdb"
def test_database_user_login(host):
"""
Tests database user login.
"""
login = host.run("mysql -utestdb -ptestdbpassword -BNe 'show databases'")
assert login.rc == 0
def test_database_user_permissions(host):
"""
Tests if database user has been granted correct permissions on the database.
"""
visible_databases = host.run("mysql -utestdb -ptestdbpassword -BNe 'show databases'")
assert visible_databases.rc == 0
assert visible_databases.stdout == "information_schema\ntestdb"
with host.sudo():
permissions = host.run("mysql -BNe 'show grants for testdb@localhost'")
assert len(permissions.stdout.split("\n")) == 2
assert "GRANT USAGE ON *.* TO 'testdb'@'localhost' IDENTIFIED BY PASSWORD '*676852B7FAE972722AD20D6E74781D6B1A100544'" in permissions.stdout.split("\n")
assert "GRANT ALL PRIVILEGES ON `testdb`.* TO 'testdb'@'localhost'" in permissions.stdout.split("\n")
|