Applied changes to service tests
This commit is contained in:
parent
7b86859576
commit
284ec681b3
@ -1,16 +1,17 @@
|
|||||||
import os
|
import os
|
||||||
import pytest
|
import pytest
|
||||||
import testinfra.utils.ansible_runner
|
import testinfra.utils.ansible_runner
|
||||||
|
import re
|
||||||
|
|
||||||
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
|
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
|
||||||
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')
|
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')
|
||||||
|
|
||||||
def get_wazuh_version():
|
def get_wazuh_version():
|
||||||
"""This return the version of Wazuh."""
|
"""This returns the version of Wazuh."""
|
||||||
return "3.13.1"
|
return "3.13.1"
|
||||||
|
|
||||||
def test_wazuh_packages_are_installed(host):
|
def test_wazuh_packages_are_installed(host):
|
||||||
"""Test if the main packages are installed."""
|
"""Test the main packages are installed."""
|
||||||
manager = host.package("wazuh-manager")
|
manager = host.package("wazuh-manager")
|
||||||
api = host.package("wazuh-api")
|
api = host.package("wazuh-api")
|
||||||
assert manager.is_installed
|
assert manager.is_installed
|
||||||
@ -19,17 +20,27 @@ def test_wazuh_packages_are_installed(host):
|
|||||||
assert api.version.startswith(get_wazuh_version())
|
assert api.version.startswith(get_wazuh_version())
|
||||||
|
|
||||||
def test_wazuh_services_are_running(host):
|
def test_wazuh_services_are_running(host):
|
||||||
"""Test if the services are enabled and running.
|
"""Test the services are enabled and running.
|
||||||
|
|
||||||
When assert commands are commented, this means that the service command has
|
When assert commands are commented, this means that the service command has
|
||||||
a wrong exit code: https://github.com/wazuh/wazuh-ansible/issues/107
|
a wrong exit code: https://github.com/wazuh/wazuh-ansible/issues/107
|
||||||
"""
|
"""
|
||||||
manager = host.service("wazuh-manager")
|
# This currently doesn't work with out current Docker base images
|
||||||
api = host.service("wazuh-api")
|
# manager = host.service("wazuh-manager")
|
||||||
|
# api = host.service("wazuh-api")
|
||||||
# assert manager.is_running
|
# assert manager.is_running
|
||||||
assert manager.is_running
|
|
||||||
# assert api.is_running
|
# assert api.is_running
|
||||||
assert api.is_running
|
output = host.check_output('ps aux | grep ossec | tr -s " " | cut -d" " -f11')
|
||||||
|
assert 'ossec-authd' in output
|
||||||
|
assert 'wazuh-modulesd' in output
|
||||||
|
assert 'wazuh-db' in output
|
||||||
|
assert 'ossec-execd' in output
|
||||||
|
assert 'ossec-monitord' in output
|
||||||
|
assert 'ossec-remoted' in output
|
||||||
|
assert 'ossec-logcollector' in output
|
||||||
|
assert 'ossec-analysisd' in output
|
||||||
|
assert 'ossec-syscheckd' in output
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("wazuh_file, wazuh_owner, wazuh_group, wazuh_mode", [
|
@pytest.mark.parametrize("wazuh_file, wazuh_owner, wazuh_group, wazuh_mode", [
|
||||||
("/var/ossec/etc/sslmanager.cert", "root", "root", 0o640),
|
("/var/ossec/etc/sslmanager.cert", "root", "root", 0o640),
|
||||||
@ -39,14 +50,14 @@ def test_wazuh_services_are_running(host):
|
|||||||
])
|
])
|
||||||
|
|
||||||
def test_wazuh_files(host, wazuh_file, wazuh_owner, wazuh_group, wazuh_mode):
|
def test_wazuh_files(host, wazuh_file, wazuh_owner, wazuh_group, wazuh_mode):
|
||||||
"""Test if Wazuh related files exist and have proper owners and mode."""
|
"""Test Wazuh related files exist and have proper owners and mode."""
|
||||||
wazuh_file_host = host.file(wazuh_file)
|
wazuh_file_host = host.file(wazuh_file)
|
||||||
assert wazuh_file_host.user == wazuh_owner
|
assert wazuh_file_host.user == wazuh_owner
|
||||||
assert wazuh_file_host.group == wazuh_group
|
assert wazuh_file_host.group == wazuh_group
|
||||||
assert wazuh_file_host.mode == wazuh_mode
|
assert wazuh_file_host.mode == wazuh_mode
|
||||||
|
|
||||||
def test_filebeat_is_installed(host):
|
def test_filebeat_is_installed(host):
|
||||||
"""Test if the elasticsearch package is installed."""
|
"""Test the elasticsearch package is installed."""
|
||||||
filebeat = host.package("filebeat")
|
filebeat = host.package("filebeat")
|
||||||
assert filebeat.is_installed
|
assert filebeat.is_installed
|
||||||
assert filebeat.version.startswith('7.8.0')
|
assert filebeat.version.startswith('7.8.0')
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user